Commit dba305be5c5823b77002d5e078685f36b1f3cfed

Authored by fengtao
1 parent 76387b66

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

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