CzRger 1 kuukausi sitten
vanhempi
commit
fe327d84f8
3 muutettua tiedostoa jossa 48 lisäystä ja 17 poistoa
  1. 5 0
      src/api/modules/manage/role.ts
  2. 8 3
      src/stores/web.ts
  3. 35 14
      src/views/manage/system/role/auth.vue

+ 5 - 0
src/api/modules/manage/role.ts

@@ -35,4 +35,9 @@ export const rolesDoAuthorization = (params: any) => handle({
   url: `/${suffix}/roles/doAuthorization`,
   method: 'post',
   params
+})
+// 授权查看
+export const rolesFindAllByRoleId = (id: any) => handle({
+  url: `/${suffix}/roles/findAllByRoleId/${id}`,
+  method: 'get',
 })

+ 8 - 3
src/stores/web.ts

@@ -4,7 +4,8 @@ import {frontGetAllSysLabelsForQd} from "@/api/modules/web/list";
 
 export const useWebStore = defineStore('web', {
   state: () => ({
-    searchAreaTree: []
+    searchAreaTree: [],
+    treeLevelSplit: '???'
   }),
   getters: {
     searchAreaIndexTotal() {
@@ -33,6 +34,10 @@ export const useWebStore = defineStore('web', {
             deep(v.children)
           } else {
             map.set(v.treeId, v)
+            // 索引额外添加键id
+            if (v.indexTableName) {
+              map.set(v.id, v)
+            }
           }
         })
       }
@@ -53,10 +58,10 @@ export const useWebStore = defineStore('web', {
               type.children = type.sysIndexList?.map(index => {
                 index.treeId = index.indexTableName
                 index.treeName = index.indexName
-                index.__id = tag.treeId + '_' + type.treeId + '_' + index.treeId
+                index.__id = tag.treeId + this.treeLevelSplit + type.treeId + this.treeLevelSplit + index.treeId
                 return index
               })
-              type.__id = tag.treeId + '_' + type.treeId
+              type.__id = tag.treeId + this.treeLevelSplit + type.treeId
               return type
             })
             tag.__id = tag.treeId

+ 35 - 14
src/views/manage/system/role/auth.vue

@@ -32,8 +32,7 @@
 import {computed, getCurrentInstance, nextTick, reactive, ref, watch} from "vue";
 import {useDictionaryStore, useWebStore} from "@/stores";
 import {ElMessage, ElMessageBox} from "element-plus";
-import {rolesDoAuthorization} from "@/api/modules/manage/role";
-import {frontGetAllSysLabelsForQd} from "@/api/modules/web/list";
+import {rolesDoAuthorization, rolesFindAllByRoleId} from "@/api/modules/manage/role";
 
 const emit = defineEmits(['update:show', 'refresh'])
 const {proxy} = getCurrentInstance()
@@ -44,7 +43,6 @@ const props = defineProps({
   transfer: {}
  })
 const state: any = reactive({
-  form: {},
   loading: false,
   tree: {
     filter: '',
@@ -64,22 +62,45 @@ watch(() => state.tree.filter, (n) => {
   ref_tree.value?.filter(n)
 })
 const onSubmit = () => {
-  console.log(ref_tree.value.getCheckedKeys(false))
-  console.log(ref_tree.value.getCheckedKeys(true))
-  console.log(ref_tree.value.getCheckedNodes(false, false))
-  console.log(ref_tree.value.getCheckedNodes(false, true))
-  console.log(ref_tree.value.getCheckedNodes(true, true))
-  console.log(ref_tree.value.getCheckedNodes(true, false))
-  // rolesDoAuthorization({
-  //   "roleId": props.transfer.id,
-  //   "indexIds": []
-  // })
+  ElMessageBox.confirm("是否提交?", "提示", {
+    confirmButtonText: "确定",
+    cancelButtonText: "取消",
+    type: "warning",
+  } as any).then(() => {
+    state.loading = true
+    rolesDoAuthorization({
+      roleId: props.transfer.id,
+      sysRoleIndexs: ref_tree.value.getCheckedKeys(true).map(v => {
+        const ids = v.split(WebStore.treeLevelSplit)
+        return {
+          roleId: props.transfer.id,
+          labelId: ids[0],
+          typeId: ids[1],
+          indexId: WebStore.searchAreaIndexMap.get(ids[2]).id,
+        }
+      })
+    }).then(rse => {
+      ElMessage.success('授权成功!')
+      emit('update:show', false)
+      emit('refresh')
+      state.loading = false
+    }).catch(() => {
+      state.loading = false
+    })
+  }).catch(() => {})
 }
 const initTree = () => {
   state.loading = true
   WebStore.getSearchAreaTree().then(res => {
     state.tree.options = JSON.parse(JSON.stringify(res))
-    console.log(state.tree.options)
+    initDetail()
+  })
+}
+const initDetail = () => {
+  rolesFindAllByRoleId(props.transfer.id).then(res => {
+    ref_tree.value.setCheckedKeys(res.data.map(v => {
+      return v.labelId + WebStore.treeLevelSplit + v.typeId + WebStore.treeLevelSplit + WebStore.searchAreaIndexMap.get(v.indexId)?.treeId
+    }))
     state.loading = false
   })
 }