Handy_Cao преди 7 месеца
родител
ревизия
9763cf2b67
променени са 2 файла, в които са добавени 33 реда и са изтрити 15 реда
  1. 32 14
      src/packages/pc/components/modules/roles/index.vue
  2. 1 1
      src/packages/pc/views/member/institution/self/components/edit/index.vue

+ 32 - 14
src/packages/pc/components/modules/roles/index.vue

@@ -6,7 +6,9 @@
             </template>
             <template #menuids>
                 <el-scrollbar max-height="300px" style="width: 100%; border: 1px solid #f2f2f2;">
-                    <el-tree :data="filteredRoutes" :props="{ label: (data: Model.MenusRsp)=> t('routes.'+data.resourceCode) }" node-key="resourceCode" />
+                    <el-tree :data="filteredRoutes"
+                        :props="{ label: (data: Model.MenusRsp) => t('routes.' + data.resourceCode) }"
+                        node-key="resourceCode" />
                 </el-scrollbar>
             </template>
         </app-table-details>
@@ -29,7 +31,7 @@ import AppTableDetails from '@pc/components/base/table-details/index.vue'
 
 const props = defineProps({
     record: {
-        type: Object as PropType<Member.OrganRoleRsp>,
+        type: Object as PropType<Model.RoleRsp>,
         required: true
     }
 })
@@ -57,16 +59,32 @@ const { data, loading } = useRequest(queryDetail, {
     },
     onSuccess: (res) => {
         const codeSet = new Set(res.data.menuids)
+
+        function filterMenu(data: Model.MenusRsp[]) {
+            return data.reduce<Model.MenusRsp[]>((result, item) => {
+                const { resourceCode, children } = item
+                if (codeSet.has(resourceCode)) {
+                    // 当前菜单项符合条件
+                    result.push({
+                        ...item,
+                        children: children ? filterMenu(children) : [],
+                    })
+                } else if (children?.length) {
+                    // 当前菜单项不符合条件,但有子菜单,递归过滤子菜单
+                    const filteredChildren = filterMenu(children)
+                    if (filteredChildren.length) {
+                        result.push({
+                            ...item,
+                            children: filteredChildren,
+                        })
+                    }
+                }
+                return result
+            }, [])
+        }
+
         // 递归过滤菜单
-        filteredRoutes.value = routerStore.userRoutes.filter(menu => {
-            if (codeSet.has(menu.resourceCode)) {
-                return true
-            }
-            if (menu.children && menu.children.length) {
-                return menu.children.some(child => codeSet.has(child.resourceCode))
-            }
-            return false
-        })
+        filteredRoutes.value = filterMenu(routerStore.userRoutes)
     },
     onError: (err) => {
         ElMessage.error(err)
@@ -74,9 +92,9 @@ const { data, loading } = useRequest(queryDetail, {
 })
 
 const detailProps: CellProp[] = [
-    { prop: 'rolename', label: t('admin.role.edit.rolename') },
-    { prop: 'sensitivefields', label: t('admin.role.edit.sensitivefields') },
-    { prop: 'menuids', label: t('admin.role.edit.menuids') },
+    { prop: 'rolename', label: 'admin.role.edit.rolename' },
+    { prop: 'sensitivefields', label: 'admin.role.edit.sensitivefields' },
+    { prop: 'menuids', label: 'admin.role.edit.menuids' },
 ]
 
 const onCancel = () => {

+ 1 - 1
src/packages/pc/views/member/institution/self/components/edit/index.vue

@@ -16,7 +16,7 @@
                 <el-form-item label="会员市场:" prop="marketid" >
                     <el-checkbox-group v-model="formData.marketids">
                         <el-checkbox v-for="item in data?.markets" v-bind:key="item.marketid" 
-                            :label="item.marketname" :value="item.marketid"/>
+                            :label="item.marketname" :value="item.marketid" />
                     </el-checkbox-group>
                 </el-form-item>
             </fieldset>