CzRger 2 weken geleden
bovenliggende
commit
ceffad0e56
3 gewijzigde bestanden met toevoegingen van 44 en 46 verwijderingen
  1. 5 5
      src/api/modules/center/role.ts
  2. 9 34
      src/stores/modules/app.ts
  3. 30 7
      src/views/manage/center/role/auth.vue

+ 5 - 5
src/api/modules/center/role.ts

@@ -18,8 +18,8 @@ export const rolesUsersAdd = (id, params) =>
 // 角色管理-角色移除用户
 export const rolesDeleteUsers = (id, params) =>
   post(`/roles/delete/${id}/users`, params, {})
-// 角色管理-查询角色授权的菜单
-export const rolesMenus = (id) => get(`/roles/${id}/menus`, {}, {})
-// 角色管理-角色绑定授权菜单
-export const rolesMenusAdd = (id, params) =>
-  post(`/roles/${id}/menus`, params, {})
+// 角色管理-查询角色授权
+export const rolesAuths = (id) => get(`/roles/${id}/auths`, {}, {})
+// 角色管理-角色绑定授权
+export const rolesAuthsAdd = (id, params) =>
+  post(`/roles/${id}/auths`, params, {})

+ 9 - 34
src/stores/modules/app.ts

@@ -47,39 +47,14 @@ export const useAppStore = defineStore('app', {
     initAuth() {
       const aMap = new Map()
       const mMap = new Map()
-      const a = [
-        '4806d051-e037-4d9d-99a0-78aa2f2f362b',
-        'd8b2a8e5-d087-4722-b833-7b7e10df0ec0',
-        '083e7fdd-d7e6-4712-84fa-865e12458de2',
-        '43a2845a-c322-4c49-86c5-867c1e466b7f',
-        '86e9f5e8-285d-4038-abc2-a39b2ad7fcd1',
-        'd91af45a-7258-4b1e-8e0b-178e8b66d847',
-        'd446bfb3-4605-477f-a0f4-b7a0a1aa78fe',
-        'a36ccd46-f399-4bf6-8db9-157ca8d3e8c8',
-        'e16b6e20-4ea1-4160-9624-e775949b0c32',
-        '37d34d52-78c7-4272-8715-fdc88f599c4f',
-        '4342bfff-1ea8-4f4c-b562-3cdc1fde116f',
-        '78430247-a531-4c8f-8a08-c88e93a836e2',
-        '18e6009c-a72c-4359-864b-e7725fccca69',
-        '3b046708-5a14-450f-9dcd-9d869e336ed7',
-        '7b05e9a1-37cc-4701-b10c-ad1e31121ab5',
-        'ef9f545d-803e-4fbe-97cf-c89e27bd02ce',
-        'd791e13b-9e49-4697-aef1-0bcb3d05aa0c',
-        '013a2005-0977-4164-a360-7033ab28417f',
-        'c3c3bee8-70ed-43b5-beb4-d0d7541a1e5e',
-        '9da8b83f-d7f9-4081-b3f3-0d637382349f',
-        'e995a6b2-d230-4b36-a714-d4d01f92ad36',
-        '7b05e9a1-37cc-4701-b10c-ad1e31121ab5___add',
-        '7b05e9a1-37cc-4701-b10c-ad1e31121ab5___edit',
-        'ef9f545d-803e-4fbe-97cf-c89e27bd02ce___auth',
-        'ef9f545d-803e-4fbe-97cf-c89e27bd02ce___relation',
-      ]
-      a.forEach((v) => {
-        if (v.includes(this.permission.splitAuth)) {
-          aMap.set(v, v)
-        } else {
-          mMap.set(v, v)
-        }
+      this.userInfo?.roleEntities?.forEach((r) => {
+        r.roleAuthEntities?.forEach((a) => {
+          if (a.auth.includes(this.permission.splitAuth)) {
+            aMap.set(a.auth, a.auth)
+          } else {
+            mMap.set(a.auth, a.auth)
+          }
+        })
       })
       this.permission.menusMap = mMap
       this.permission.authsMap = aMap
@@ -117,7 +92,7 @@ export const useAppStore = defineStore('app', {
       })
       const Root = router.getRoutes().filter((v) => v.name === 'root')[0]
       Root.children = authMenus
-      Root.redirect = authMenus[0].redirect
+      Root.redirect = authMenus[0].redirect || authMenus[0].path
     },
     hasPermission(name, key) {
       if (key) {

+ 30 - 7
src/views/manage/center/role/auth.vue

@@ -68,6 +68,14 @@
             <div class="font-bold">{{ state.currentMenu.title }}</div>
             <div class="flex flex-1 flex-col gap-2 overflow-auto">
               <template v-if="state.currentMenu.auths?.length > 0">
+                <el-button-group size="small">
+                  <el-button type="primary" @click="onCheckAll(true)"
+                    >全选</el-button
+                  >
+                  <el-button type="info" @click="onCheckAll(false)"
+                    >取消全选</el-button
+                  >
+                </el-button-group>
                 <el-checkbox-group v-model="state.activeAuths">
                   <template v-for="item in state.currentMenu.auths">
                     <el-checkbox :value="item.value">
@@ -99,7 +107,7 @@ import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
 import { useRouter } from 'vue-router'
 import { Search } from '@element-plus/icons-vue'
 import CzrDialog from '@/components/czr-ui/CzrDialog.vue'
-import { rolesMenus, rolesMenusAdd } from '@/api/modules/center/role'
+import { rolesAuths, rolesAuthsAdd } from '@/api/modules/center/role'
 import bigModelRouter from '@/router/modules/big-model'
 
 const DialogStore = useDialogStore()
@@ -140,15 +148,15 @@ const initData = () => {
   state.loading = true
   state.activeAuths = []
   ref_tree.value?.setCheckedKeys([], false)
-  rolesMenus(props.transfer.roleId)
+  rolesAuths(props.transfer.roleId)
     .then(({ data }: any) => {
       const authArr: any = []
       const menuArr: any = []
       data.forEach((v) => {
-        if (v.includes(AppStore.permission.splitAuth)) {
-          authArr.push(v)
+        if (v.auth.includes(AppStore.permission.splitAuth)) {
+          authArr.push(v.auth)
         } else {
-          menuArr.push(v)
+          menuArr.push(v.auth)
         }
       })
       state.activeAuths = authArr
@@ -224,11 +232,26 @@ const onNodeClick = (data, node) => {
   state.currentMenu.title = getTitle(node)
   state.currentMenu.auths = data.auths
 }
+const onCheckAll = (flag) => {
+  if (flag) {
+    state.currentMenu.auths.forEach((v) => {
+      if (!state.activeAuths.includes(v.value)) {
+        state.activeAuths.push(v.value)
+      }
+    })
+  } else {
+    state.activeAuths = state.activeAuths.filter(
+      (v) => !state.currentMenu.auths.some((a) => a.value === v),
+    )
+  }
+}
 const onSubmit = () => {
   const arr = [...ref_tree.value.getCheckedKeys(), ...state.activeAuths]
   state.loading = true
-  rolesMenusAdd(props.transfer.roleId, arr)
-    .then(({ data }: any) => {})
+  rolesAuthsAdd(props.transfer.roleId, arr)
+    .then(({ data }: any) => {
+      ElMessage.success('授权成功!')
+    })
     .finally(() => {
       state.loading = false
       initData()