角色编辑全选

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