Commit dba305be5c5823b77002d5e078685f36b1f3cfed

Authored by fengtao
1 parent 76387b66

fix:修改系统管理角色分配和租户管理角色管理菜单分配让所有一级自动展开

... ... @@ -13,7 +13,7 @@
13 13 v-if="treeData.length"
14 14 checkable
15 15 toolbar
16   - autoExpandParent
  16 + :expandedKeys="treeExpandData"
17 17 ref="treeRef"
18 18 :treeData="treeData"
19 19 :replaceFields="{ title: 'menuName' }"
... ... @@ -43,6 +43,7 @@
43 43 components: { BasicDrawer, BasicForm, BasicTree },
44 44 emits: ['success', 'register'],
45 45 setup(_, { emit }) {
  46 + const treeExpandData = ref([]);
46 47 const isUpdate = ref<boolean>(true);
47 48 const treeData = ref<TreeItem[]>([]);
48 49 const roleMenus = ref<string[]>([]);
... ... @@ -69,13 +70,12 @@
69 70 }
70 71 });
71 72 }
72   - // function lookForAllId(data = [], arr = []) {
73   - // for (const item of data) {
74   - // arr.push(item.parentId);
75   - // if (item.children && item.children.length > 0) lookForAllId(item.children, arr);
76   - // }
77   - // return arr;
78   - // }
  73 + function lookForAllId(data = [], arr = []) {
  74 + for (const item of data) {
  75 + arr.push(item.id);
  76 + }
  77 + return arr;
  78 + }
79 79 const originMenus = ref();
80 80 const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
81 81 allCheckedKeys.value = [];
... ... @@ -98,6 +98,9 @@
98 98 //通过角色id去获取角色对应的菜单的ids
99 99 roleMenus.value = await getMenusIdsByRoleId(data.record.id);
100 100 originMenus.value = [...roleMenus.value];
  101 +
  102 + const getAllIds = lookForAllId(treeData.value, []);
  103 + treeExpandData.value = getAllIds;
101 104 for (let item of treeData.value) {
102 105 if (item?.children != 0) {
103 106 pidArr.value.push(item.key);
... ... @@ -138,7 +141,6 @@
138 141 status: values.status,
139 142 menu: allCheckedKeys.value.length ? allCheckedKeys.value : originMenus.value,
140 143 };
141   - console.log(allCheckedKeys.value);
142 144 if (allCheckedKeys.value.length == 0) return createMessage.error('请勾选权限菜单');
143 145 if (req.menu == undefined) return createMessage.error('请勾选权限菜单');
144 146 saveOrUpdateRoleInfoWithMenu(req).then(() => {
... ... @@ -165,6 +167,7 @@
165 167 treeRef,
166 168 handleCheckClick,
167 169 allCheckedKeys,
  170 + treeExpandData,
168 171 };
169 172 },
170 173 });
... ...
... ... @@ -12,6 +12,7 @@
12 12 <BasicTree
13 13 v-if="treeData.length > 0"
14 14 :treeData="treeData"
  15 + :expandedKeys="treeExpandData"
15 16 autoExpandParent
16 17 :replaceFields="{ title: 'menuName' }"
17 18 :checkedKeys="roleMenus"
... ... @@ -46,6 +47,8 @@
46 47 components: { BasicDrawer, BasicForm, BasicTree },
47 48 emits: ['success', 'register'],
48 49 setup(_, { emit }) {
  50 + const treeExpandData = ref([]);
  51 +
49 52 const isUpdate = ref(true);
50 53 const treeData = ref<TreeItem[]>([]);
51 54 const roleMenus = ref<string[]>([]);
... ... @@ -71,6 +74,12 @@
71 74 }
72 75 });
73 76 }
  77 + function lookForAllId(data = [], arr = []) {
  78 + for (const item of data) {
  79 + arr.push(item.id);
  80 + }
  81 + return arr;
  82 + }
74 83
75 84 const originMenus = ref();
76 85 const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
... ... @@ -95,6 +104,8 @@
95 104 //通过角色id去获取角色对应的菜单的ids
96 105 roleMenus.value = await getMenusIdsByRoleId(data.record.id);
97 106 originMenus.value = [...roleMenus.value];
  107 + const getAllIds = lookForAllId(treeData.value, []);
  108 + treeExpandData.value = getAllIds;
98 109 for (let item of treeData.value) {
99 110 if (item?.children != 0) {
100 111 pidArr.value.push(item.key);
... ... @@ -160,6 +171,7 @@
160 171 roleMenus,
161 172 treeRef,
162 173 handleCheckClick,
  174 + treeExpandData,
163 175 };
164 176 },
165 177 });
... ...