Commit 87aeeacf34f06497edeab5795e6e3acaea7bf2fd
Merge branch 'dev-ft' into 'main'
fix:修复菜单管理下的角色管理,修复逐户下面的角色管理,按钮级别回显问题 See merge request huang/yun-teng-iot-front!209
Showing
2 changed files
with
33 additions
and
46 deletions
| ... | ... | @@ -26,7 +26,7 @@ |
| 26 | 26 | </BasicDrawer> |
| 27 | 27 | </template> |
| 28 | 28 | <script lang="ts"> |
| 29 | - import { defineComponent, ref, computed, unref } from 'vue'; | |
| 29 | + import { defineComponent, ref, computed, unref, nextTick } from 'vue'; | |
| 30 | 30 | import { BasicForm, useForm } from '/@/components/Form/index'; |
| 31 | 31 | import { formSchema } from './role.data'; |
| 32 | 32 | import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; |
| ... | ... | @@ -49,6 +49,9 @@ |
| 49 | 49 | const allCheckedKeys = ref<string[]>([]); |
| 50 | 50 | const roleId = ref<string>(''); |
| 51 | 51 | const treeRef = ref(); |
| 52 | + const checked: any = ref([]); //需要选中的节点 | |
| 53 | + const pidArr: any = ref([]); //获取父节点 | |
| 54 | + | |
| 52 | 55 | const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({ |
| 53 | 56 | labelWidth: 100, |
| 54 | 57 | schemas: formSchema, |
| ... | ... | @@ -66,16 +69,6 @@ |
| 66 | 69 | } |
| 67 | 70 | }); |
| 68 | 71 | } |
| 69 | - | |
| 70 | - /** | |
| 71 | - * 根据角色id获取所有的菜单ids----里面包含父级id---会造成回显数据时 | |
| 72 | - * 存在父级id则默认勾选所有子级id | |
| 73 | - */ | |
| 74 | - function useChildrenIdsRemoveParentId(str, arr) { | |
| 75 | - let index = arr.indexOf(str); | |
| 76 | - arr.splice(index, 1); | |
| 77 | - return arr; | |
| 78 | - } | |
| 79 | 72 | const originMenus = ref(); |
| 80 | 73 | const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { |
| 81 | 74 | resetFields(); |
| ... | ... | @@ -92,19 +85,25 @@ |
| 92 | 85 | } |
| 93 | 86 | // 更新 |
| 94 | 87 | if (unref(isUpdate)) { |
| 88 | + checked.value = []; | |
| 95 | 89 | //通过角色id去获取角色对应的菜单的ids |
| 96 | 90 | roleMenus.value = await getMenusIdsByRoleId(data.record.id); |
| 97 | 91 | originMenus.value = [...roleMenus.value]; |
| 98 | - | |
| 99 | - for (let m of treeData.value) { | |
| 100 | - console.log(m); | |
| 101 | - for (let m1 of roleMenus.value) { | |
| 102 | - // 利用continue特性优化一下性能 | |
| 103 | - if (!(m.key === m1 && m.children.length)) continue; | |
| 104 | - useChildrenIdsRemoveParentId(m1, roleMenus.value); | |
| 92 | + for (let item of treeData.value) { | |
| 93 | + pidArr.value.push(item.key); | |
| 94 | + for (let item1 of item?.children) { | |
| 95 | + pidArr.value.push(item1.key); | |
| 105 | 96 | } |
| 106 | 97 | } |
| 107 | - treeRef.value.setCheckedKeys(roleMenus.value); | |
| 98 | + for (let item of roleMenus.value) { | |
| 99 | + let isP = pidArr.value.includes(item); | |
| 100 | + if (!isP) { | |
| 101 | + checked.value.push(item); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + nextTick(() => { | |
| 105 | + treeRef.value.setCheckedKeys(checked.value); | |
| 106 | + }); | |
| 108 | 107 | roleId.value = data.record.id; |
| 109 | 108 | setFieldsValue(data.record); |
| 110 | 109 | } | ... | ... |
| ... | ... | @@ -51,6 +51,9 @@ |
| 51 | 51 | const allCheckedKeys = ref<string[]>([]); |
| 52 | 52 | const roleId = ref(''); |
| 53 | 53 | const treeRef = ref(); |
| 54 | + const checked: any = ref([]); //需要选中的节点 | |
| 55 | + const pidArr: any = ref([]); //获取父节点 | |
| 56 | + | |
| 54 | 57 | const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({ |
| 55 | 58 | labelWidth: 90, |
| 56 | 59 | schemas: formSchema, |
| ... | ... | @@ -68,15 +71,6 @@ |
| 68 | 71 | }); |
| 69 | 72 | } |
| 70 | 73 | |
| 71 | - /** | |
| 72 | - * 根据角色id获取所有的菜单ids----里面包含父级id---会造成回显数据时 | |
| 73 | - * 存在父级id则默认勾选所有子级id | |
| 74 | - */ | |
| 75 | - function useChildrenIdsRemoveParentId(str, arr) { | |
| 76 | - let index = arr.indexOf(str); | |
| 77 | - arr.splice(index, 1); | |
| 78 | - return arr; | |
| 79 | - } | |
| 80 | 74 | const originMenus = ref(); |
| 81 | 75 | const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { |
| 82 | 76 | setDrawerProps({ confirmLoading: false }); |
| ... | ... | @@ -94,29 +88,24 @@ |
| 94 | 88 | } |
| 95 | 89 | // 更新 |
| 96 | 90 | if (unref(isUpdate)) { |
| 91 | + checked.value = []; | |
| 97 | 92 | //通过角色id去获取角色对应的菜单的ids |
| 98 | 93 | roleMenus.value = await getMenusIdsByRoleId(data.record.id); |
| 99 | 94 | originMenus.value = [...roleMenus.value]; |
| 100 | - console.log('Query role ids', roleMenus.value); | |
| 101 | - console.log('TreeData ids', treeData.value); | |
| 102 | - for (let m of treeData.value) { | |
| 103 | - console.log('m', m); | |
| 104 | - for (let m1 of roleMenus.value) { | |
| 105 | - if (m?.key != m1 && m?.children.length == 0) { | |
| 106 | - useChildrenIdsRemoveParentId(m1, roleMenus.value); | |
| 107 | - } | |
| 95 | + for (let item of treeData.value) { | |
| 96 | + pidArr.value.push(item.key); | |
| 97 | + for (let item1 of item?.children) { | |
| 98 | + pidArr.value.push(item1.key); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + for (let item of roleMenus.value) { | |
| 102 | + let isP = pidArr.value.includes(item); | |
| 103 | + if (!isP) { | |
| 104 | + checked.value.push(item); | |
| 108 | 105 | } |
| 109 | 106 | } |
| 110 | - // for (let m of treeData.value) { | |
| 111 | - // for (let m1 of roleMenus.value) { | |
| 112 | - // if (m.key != m1 && m?.children.length == 0) { | |
| 113 | - // useChildrenIdsRemoveParentId(m1, roleMenus.value); | |
| 114 | - // } | |
| 115 | - // } | |
| 116 | - // } | |
| 117 | 107 | nextTick(() => { |
| 118 | - console.log('Finally data', roleMenus.value); | |
| 119 | - treeRef.value.setCheckedKeys(roleMenus.value); | |
| 108 | + treeRef.value.setCheckedKeys(checked.value); | |
| 120 | 109 | }); |
| 121 | 110 | roleId.value = data.record.id; |
| 122 | 111 | setFieldsValue(data.record); |
| ... | ... | @@ -154,7 +143,6 @@ |
| 154 | 143 | }; |
| 155 | 144 | |
| 156 | 145 | return { |
| 157 | - useChildrenIdsRemoveParentId, | |
| 158 | 146 | registerDrawer, |
| 159 | 147 | registerForm, |
| 160 | 148 | getTitle, | ... | ... |