Ver código fonte

权限索引树

CzRger 1 mês atrás
pai
commit
acda44de7d

+ 16 - 5
src/stores/web.ts

@@ -1,10 +1,12 @@
 import {defineStore} from "pinia";
 import {readonly} from "vue";
 import {frontGetAllSysLabelsForQd} from "@/api/modules/web/list";
+import {useAppStore} from "@/stores/app";
 
 export const useWebStore = defineStore('web', {
   state: () => ({
-    searchAreaTree: [],
+    searchAreaTree: <any>[],
+    searchAreaTreeRoleAuth: <any>[],
     treeLevelSplit: '???'
   }),
   getters: {
@@ -36,7 +38,7 @@ export const useWebStore = defineStore('web', {
             map.set(v.treeId, v)
             // 索引额外添加键id
             if (v.indexTableName) {
-              map.set(v.id, v)
+              map.set(v.indexId, v)
             }
           }
         })
@@ -49,7 +51,7 @@ export const useWebStore = defineStore('web', {
     getSearchAreaTree() {
       return new Promise(resolve => {
         frontGetAllSysLabelsForQd().then(res => {
-          this.searchAreaTree = readonly(res.data.filter(tag => tag.sysLabels?.length > 0).map(tag => {
+          const getTree = (arr) => JSON.parse(JSON.stringify(arr)).filter(tag => tag.sysLabels?.length > 0).map(tag => {
             tag.treeId = tag.id
             tag.treeName = tag.labelName
             tag.children = tag.sysLabels?.filter(type => type.sysIndexList?.length > 0).map(type => {
@@ -66,8 +68,17 @@ export const useWebStore = defineStore('web', {
             })
             tag.__id = tag.treeId
             return tag
-          }).filter(tag => tag.children?.length > 0))
-          resolve(this.searchAreaTree)
+          }).filter(tag => tag.children?.length > 0)
+          this.searchAreaTree = readonly(getTree(res.data))
+          const AppStore = useAppStore()
+          this.searchAreaTreeRoleAuth = readonly(getTree(res.data.map(tag => {
+            tag.sysLabels.map(type => {
+              type.sysIndexList = type.sysIndexList?.filter(index => AppStore.userInfo.sysRoles.some(r => r.sysRoleIndices.some(a => a.labelId == tag.id && a.typeId == type.id && a.indexId == index.indexId)))
+              return type
+            })
+            return tag
+          })))
+          resolve({allTree: this.searchAreaTree, roleTree: this.searchAreaTreeRoleAuth})
         })
       })
     }

+ 2 - 2
src/views/manage/system/role/auth.vue

@@ -91,8 +91,8 @@ const onSubmit = () => {
 }
 const initTree = () => {
   state.loading = true
-  WebStore.getSearchAreaTree().then(res => {
-    state.tree.options = JSON.parse(JSON.stringify(res))
+  WebStore.getSearchAreaTree().then(({allTree}: any) => {
+    state.tree.options = JSON.parse(JSON.stringify(allTree))
     initDetail()
   })
 }

+ 2 - 2
src/views/web/home/index.vue

@@ -129,8 +129,8 @@ const initHistory = () => {
   })
 }
 const initArea = () => {
-  WebStore.getSearchAreaTree().then(res => {
-    state.areaList = JSON.parse(JSON.stringify(res))
+  WebStore.getSearchAreaTree().then(({roleTree}: any) => {
+    state.areaList = JSON.parse(JSON.stringify(roleTree))
     state.areaTab = state.areaList[0]?.treeId
   })
 }

+ 2 - 2
src/views/web/list/index.vue

@@ -340,9 +340,9 @@ const tableConfigCpt = computed(() => {
 })
 
 const initArea = () => {
-  WebStore.getSearchAreaTree().then(res => {
+  WebStore.getSearchAreaTree().then(({roleTree}: any) => {
     const arr = []
-    JSON.parse(JSON.stringify(res)).forEach(v => {
+    JSON.parse(JSON.stringify(roleTree)).forEach(v => {
       v.children.forEach(c => {
         c.__children = JSON.parse(JSON.stringify(c.children))
         c.children = []