角色编辑全选

This commit is contained in:
Mrtangl 2022-04-19 18:26:55 +08:00
parent 5e609f41af
commit 87210c2001
1 changed files with 19 additions and 14 deletions

View File

@ -43,7 +43,7 @@
<el-tree
ref="treeRef"
:data="menu.permissionsTree"
node-key="auth_key"
node-key="id"
default-expand-all
icon="ArrowRight"
:props="{
@ -93,14 +93,15 @@ export default defineComponent({
formData: {
name: '', //
remark: '', //
auth_keys: [], //
menus: [], // id
isDisable: 0,
sort: ''
sort: '',
menuIds: '', // ID,
},
menu: {
permissionsTree: [], //
allAuthKeys: [] // auth_keys
allAuthKeys: [] // id
}
})
)
@ -132,13 +133,13 @@ export default defineComponent({
.then((res: any) => {
//
menu.value.permissionsTree = res
// console.log('res', res)
console.log('res', res)
//
const menuFlatten = flatten(res, [], 'sons')
const menuFlatten = flatten(res, [], 'children')
// console.log(menuFlatten)
// auth_key
menu.value.allAuthKeys = menuFlatten.map((item: any) => item.auth_key) as never
// id
menu.value.allAuthKeys = menuFlatten.map((item: any) => item.id) as never
})
.catch((err: any) => {
console.log('err', err)
@ -160,6 +161,11 @@ export default defineComponent({
}
//
const roleEdit = () => {
// id
formData.value.menus.length == 0
? formData.value.menuIds = ''
: formData.value.menuIds = formData.value.menus.join(',')
apiRoleEdit({
...formData.value,
id: id.value
@ -184,9 +190,8 @@ export default defineComponent({
console.log('res', res)
formData.value = res
// formData.value.auth_keys = []
treeRef.value?.setCheckedKeys(res.auth_keys)
treeRef.value?.setCheckedKeys(res.menus)
})
.catch((err: any) => {
console.log('err', err)
@ -196,17 +201,17 @@ export default defineComponent({
//
const handlePermissionsCheckChange = (data: any, checked: boolean) => {
console.log(data)
if (!data.auth_key) {
if (!data.id) {
return
}
const index = formData.value.auth_keys.findIndex(item => item == data.auth_key)
const index = formData.value.menus.findIndex(item => item == data.id)
if (checked) {
index == -1 && (formData.value.auth_keys as any).push(data.auth_key)
index == -1 && (formData.value.menus as any).push(data.id)
return
}
if (index != -1) {
formData.value.auth_keys.splice(index, 1)
formData.value.menus.splice(index, 1)
}
}