<link rel="icon" type="image/svg+xml" href="/logo_1.jpg" /> | <link rel="icon" type="image/svg+xml" href="/logo_1.jpg" /> | ||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||||
<title>后台管理系统</title> | <title>后台管理系统</title> | ||||
<script type="module" crossorigin src="/assets/index-uU_dXTTD.js"></script> | |||||
<script type="module" crossorigin src="/assets/index-w08MfQVW.js"></script> | |||||
<link rel="stylesheet" crossorigin href="/assets/index-ioYE9aJh.css"> | <link rel="stylesheet" crossorigin href="/assets/index-ioYE9aJh.css"> | ||||
</head> | </head> | ||||
<body> | <body> |
commit | commit | ||||
}) { | }) { | ||||
try { | try { | ||||
// state.arrresult = []; | |||||
// let res = await GetUserMenulist(); | |||||
// res.data.menulist.map(item => { | |||||
// pushItem(item) | |||||
// }) | |||||
// let arr = state.arrresult; | |||||
// let arr = getArr | |||||
let arr = ['permission', 'role', 'account', 'company', 'vip', 'member', 'homemake', 'homemakeType', 'homemakePosition', 'homemakeDemand', 'homemakeAppointment', 'job', 'department', 'jobSeeker', 'jobResume', 'jobFair', 'jobFairList', 'jobFairCompany', 'information', 'section', 'article', 'list', 'putIn', 'advertisementList', 'advertisement', 'activity', 'activityList', 'activityAddress', 'statistics', 'statisticsResume', 'statisticsResumeMajor']; | |||||
state.arrresult = []; | |||||
let res = await GetUserMenulist(); | |||||
res.data.menulist.map(item => { | |||||
pushItem(item) | |||||
}) | |||||
let arr = state.arrresult; | |||||
// let arr = ['permission', 'role', 'account', 'company', 'vip', 'member', 'homemake', 'homemakeType', 'homemakePosition', 'homemakeDemand', 'homemakeAppointment', 'job', 'department', 'jobSeeker', 'jobResume', 'jobFair', 'jobFairList', 'jobFairCompany', 'information', 'section', 'article', 'list', 'putIn', 'advertisementList', 'advertisement', 'activity', 'activityList', 'activityAddress', 'statistics', 'statisticsResume', 'statisticsResumeMajor']; | |||||
let routes = routerDynamic(arr, routesModuleList); | let routes = routerDynamic(arr, routesModuleList); | ||||
LayoutRoute.children.push(...routes); | LayoutRoute.children.push(...routes); | ||||
commit('SET_MENU', LayoutRoute.children); | commit('SET_MENU', LayoutRoute.children); |
export const findidx : Function = (arr: any, val: any) => { | |||||
export const filterChildPermissionsByType : Function = (permissions : Object[]) => { | |||||
return permissions.map(parent => ({ | |||||
...parent, | |||||
childs: parent.childs ? filterOutPermissionsOfCertainType(parent.childs, 1) : undefined, | |||||
})); | |||||
} | |||||
export const filterOutPermissionsOfCertainType : Function = (permissions : Object[], excludeType : number) => { | |||||
return permissions.filter(permission => permission.p_type !== excludeType) | |||||
.map(child => ({ | |||||
...child, | |||||
childs: child.childs ? filterOutPermissionsOfCertainType(child.childs, excludeType) : undefined, | |||||
})); | |||||
} | |||||
export const findidx : Function = (arr : any, val : any) => { | |||||
return arr.findIndex(item => { | return arr.findIndex(item => { | ||||
return item.id === val | |||||
return item.id === val | |||||
}) | }) | ||||
} | } | ||||
export const intersectionAlike : Function = (objA: any, objB: any) => { | |||||
export const intersectionAlike : Function = (objA : any, objB : any) => { | |||||
const result = {}; | const result = {}; | ||||
for (const keyA in objA) { | for (const keyA in objA) { | ||||
if (objB.hasOwnProperty(keyA)) { | |||||
result[keyA] = objB[keyA]; | |||||
} | |||||
if (objB.hasOwnProperty(keyA)) { | |||||
result[keyA] = objB[keyA]; | |||||
} | |||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
export const hasValue : Function = (obj: any) => { | |||||
export const hasValue : Function = (obj : any) => { | |||||
let result = ''; | let result = ''; | ||||
result = Object.keys(obj).filter(key => obj[key] !== 0).map(key => `${obj[key]}`).join('') | result = Object.keys(obj).filter(key => obj[key] !== 0).map(key => `${obj[key]}`).join('') | ||||
return result; | return result; | ||||
} | } | ||||
export const divObj : Function = (obj: any) => { | |||||
export const divObj : Function = (obj : any) => { | |||||
const result = [] | const result = [] | ||||
obj.reduce((acc, curr, index) => { | obj.reduce((acc, curr, index) => { | ||||
curr.idx = index; | |||||
result.push(curr) | |||||
// const key = `node${index}Info`; | |||||
// acc[key] = curr; | |||||
// return acc; | |||||
curr.idx = index; | |||||
result.push(curr) | |||||
// const key = `node${index}Info`; | |||||
// acc[key] = curr; | |||||
// return acc; | |||||
}, {}); | }, {}); | ||||
return result; | return result; | ||||
} | } | ||||
export const alreadyValue: Function = (obj: any) => { | |||||
const result = [] | |||||
obj.reduce((acc, curr, index) => { | |||||
curr.idx = index; | |||||
result.push(curr) | |||||
// const key = `node${index}Info`; | |||||
// acc[key] = curr; | |||||
// return acc; | |||||
}, {}); | |||||
export const alreadyValue : Function = (obj : any) => { | |||||
const result = [] | |||||
obj.reduce((acc, curr, index) => { | |||||
curr.idx = index; | |||||
result.push(curr) | |||||
// const key = `node${index}Info`; | |||||
// acc[key] = curr; | |||||
// return acc; | |||||
}, {}); | |||||
return result; | |||||
return result; | |||||
} | } |
import { addPermission, updatePermission, getPermissionListWithchilds } from '@/apis/models'; | import { addPermission, updatePermission, getPermissionListWithchilds } from '@/apis/models'; | ||||
import { dataForm, otherDataForm, reset } from '@/views/permission/list/add/data.ts'; | import { dataForm, otherDataForm, reset } from '@/views/permission/list/add/data.ts'; | ||||
import { useCommon } from '@/hooks/useCommon'; | import { useCommon } from '@/hooks/useCommon'; | ||||
import { filterChildPermissionsByType } from '@/utils/dataHelper.ts'; | |||||
let { store, openAddModel, hideModal, message, } = useCommon(); | let { store, openAddModel, hideModal, message, } = useCommon(); | ||||
const emit = defineEmits(); | const emit = defineEmits(); | ||||
let props = defineProps(['edit_record']); | |||||
let props = defineProps(['edit_record','level_record']); | |||||
let title = ref<String>('新增权限/菜单'); | let title = ref<String>('新增权限/菜单'); | ||||
let listOptions = ref([]); | let listOptions = ref([]); | ||||
let cascaderParentId = ref([]); | let cascaderParentId = ref([]); | ||||
onMounted(() => { | onMounted(() => { | ||||
getPermissionListWithchilds({page:1, pagesize: 999}).then(res => { | getPermissionListWithchilds({page:1, pagesize: 999}).then(res => { | ||||
listOptions.value = res.data.permissions; | |||||
listOptions.value = filterChildPermissionsByType(res.data.permissions) | |||||
}) | }) | ||||
}) | }) | ||||
const pTypeChange = (val) => { | const pTypeChange = (val) => { | ||||
addOtherForm.value.isAddLevel = true; | |||||
addOtherForm.value.isTopLevel = true; | |||||
addOtherForm.value.parent_id = 0; | |||||
createForm.value.parent_id = 0; | |||||
if(val.target.value == 1) { | |||||
addOtherForm.value.isAddLevel = false; | |||||
} else { | |||||
addOtherForm.value.isAddLevel = true; | |||||
} | |||||
addOtherForm.value.isAddLevel == false | |||||
addOtherForm.value.parent_id = addOtherForm.value.parent_id != 0 ? addOtherForm.value.parent_id : 0; | |||||
createForm.value.parent_id = createForm.value.parent_id != 0 ? createForm.value.parent_id : 0; | |||||
cascaderParentId.value = [] | cascaderParentId.value = [] | ||||
} | } | ||||
if (createForm.value.name && createForm.value.p_type) { | if (createForm.value.name && createForm.value.p_type) { | ||||
if (!createForm.value.id) { | if (!createForm.value.id) { | ||||
addPermission(createForm.value).then(res => { | addPermission(createForm.value).then(res => { | ||||
getPermissionListWithchilds({page:1, pagesize: 999}).then(res => { | |||||
listOptions.value = filterChildPermissionsByType(res.data.permissions) | |||||
}) | |||||
message.success('新增菜单/权限成功'); | message.success('新增菜单/权限成功'); | ||||
hideModal(); | hideModal(); | ||||
resetForm(); | resetForm(); | ||||
emit('successAdd'); | emit('successAdd'); | ||||
}).catch(err => { | }).catch(err => { | ||||
}) | }) | ||||
} else { | } else { | ||||
updatePermission(createForm.value).then(res => { | updatePermission(createForm.value).then(res => { | ||||
getPermissionListWithchilds({page:1, pagesize: 999}).then(res => { | |||||
listOptions.value = filterChildPermissionsByType(res.data.permissions) | |||||
}) | |||||
message.success('修改菜单/权限成功'); | message.success('修改菜单/权限成功'); | ||||
hideModal(); | hideModal(); | ||||
resetForm(); | resetForm(); | ||||
emit('successAdd'); | emit('successAdd'); | ||||
}).catch(err => { | }).catch(err => { | ||||
}) | }) | ||||
} | } | ||||
return store.state.openAddModel; | return store.state.openAddModel; | ||||
}) | }) | ||||
watch(() => props.edit_record, (newVal) => { | |||||
if (newVal) { | |||||
watch(() => [props.edit_record, props.level_record], (newVal) => { | |||||
console.log(newVal) | |||||
if (newVal[0]) { | |||||
title.value = "编辑权限/菜单"; | title.value = "编辑权限/菜单"; | ||||
console.log(newVal) | |||||
createForm.value = { | createForm.value = { | ||||
id: newVal.id, | |||||
name: newVal.name, | |||||
path: newVal.path, | |||||
action: newVal.action, | |||||
module: newVal.module, | |||||
p_type: newVal.p_type, | |||||
parent_id: newVal.parent_id, | |||||
description: newVal.description, | |||||
id: newVal[0].id, | |||||
name: newVal[0].name, | |||||
path: newVal[0].path, | |||||
action: newVal[0].action, | |||||
module: newVal[0].module, | |||||
p_type: newVal[0].p_type, | |||||
parent_id: newVal[0].parent_id, | |||||
description: newVal[0].description, | |||||
} | } | ||||
if(newVal.parent_id == -1) { | |||||
if(newVal[0].parent_id == -1) { | |||||
addOtherForm.value.isAddLevel = true; | addOtherForm.value.isAddLevel = true; | ||||
addOtherForm.value.isTopLevel = true; | addOtherForm.value.isTopLevel = true; | ||||
addOtherForm.value.parent_id = -1; | addOtherForm.value.parent_id = -1; | ||||
addOtherForm.value.isTopLevel = false | addOtherForm.value.isTopLevel = false | ||||
addOtherForm.value.parent_id = 0; | addOtherForm.value.parent_id = 0; | ||||
} | } | ||||
} else if(newVal[1]){ | |||||
title.value = "添加下级权限/菜单"; | |||||
console.log(newVal[1]) | |||||
cascaderParentId.value = []; | |||||
if(newVal[1].parent_id == -1) { | |||||
cascaderParentId.value.push(newVal[1].id); | |||||
} else { | |||||
cascaderParentId.value.push(newVal[1].parent_id); | |||||
cascaderParentId.value.push(newVal[1].id); | |||||
} | |||||
createForm.value.parent_id = newVal[1].id | |||||
} else { | } else { | ||||
title.value = "新增权限/菜单" | |||||
title.value = "编辑权限/菜单"; | |||||
} | } | ||||
}) | }) | ||||
</script> | </script> |