Explorar o código

feat: 权限及菜单更新

From-wh %!s(int64=2) %!d(string=hai) anos
pai
achega
753fbe3b21

+ 11 - 0
template/admin/src/api/systemMenus.js

@@ -21,6 +21,17 @@ export function getTable(data) {
     params: data,
   });
 }
+/**
+ * @description 权限--刷新菜单及权限
+ * @param {Object} param data {Object} 传值参数
+ */
+export function getMenusUnique(data) {
+  return request({
+    url: '/setting/menus/unique',
+    method: 'get',
+    params: data,
+  });
+}
 
 /**
  * 权限 -- 添加

+ 32 - 0
template/admin/src/libs/system/index.js

@@ -203,6 +203,38 @@ function flattenSiderMenu(menuList, newList) {
 
 export { flattenSiderMenu };
 
+export const findFirstNonNullChildren = (arr) => {
+  // 如果数组为空,返回null
+  if (!arr || arr.length === 0) {
+    return null;
+  }
+  // 找到第一个对象
+  const firstObj = arr[0];
+  // 如果第一个对象没有children属性,返回该对象
+  if (!firstObj.children) {
+    return firstObj;
+  }
+
+  // 如果第一个对象的children属性是数组,
+  // 递归查找children属性中的第一个非null children属性
+  if (Array.isArray(firstObj.children)) {
+    return findFirstNonNullChildren(firstObj.children);
+  }
+  // 如果数组中没有非null children属性,返回null
+  return null;
+};
+
+// 多级嵌套数组处理成一维数组
+export const formatFlatteningRoutes = (arr) => {
+  if (arr.length <= 0) return false;
+  for (let i = 0; i < arr.length; i++) {
+    if (arr[i].children) {
+      arr = arr.slice(0, i + 1).concat(arr[i].children, arr.slice(i + 1));
+    }
+  }
+  return arr;
+};
+
 /**
  * @description 判断列表1中是否包含了列表2中的某一项
  * 因为用户权限 access 为数组,includes 方法无法直接得出结论

+ 3 - 33
template/admin/src/pages/account/login/index.vue

@@ -74,7 +74,7 @@ import { setCookies } from '@/libs/util';
 import '@/assets/js/canvas-nest.min';
 import Verify from '@/components/verifition/Verify';
 import { PrevLoading } from '@/utils/loading.js';
-
+import { formatFlatteningRoutes, findFirstNonNullChildren } from '@/libs/system';
 export default {
   components: {
     Verify,
@@ -211,7 +211,7 @@ export default {
           this.$store.commit('menus/setopenMenus', []);
           this.$store.commit('menus/getmenusNav', data.menus);
           this.$store.dispatch('routesList/setRoutesList', data.menus);
-          let arr = this.formatFlatteningRoutes(this.$router.options.routes);
+          let arr = formatFlatteningRoutes(this.$router.options.routes);
           this.formatTwoStageRoutes(arr);
           // 记录用户信息
           this.$store.commit('userInfo/name', data.user_info.account);
@@ -243,7 +243,7 @@ export default {
           PrevLoading.start();
 
           return this.$router.replace({
-            path: this.findFirstNonNullChildren(res.data.menus).path || this.$routeProStr + '/',
+            path: findFirstNonNullChildren(res.data.menus).path || this.$routeProStr + '/',
           });
         })
         .catch((res) => {
@@ -269,36 +269,6 @@ export default {
       });
       return newArr;
     },
-    // 多级嵌套数组处理成一维数组
-    formatFlatteningRoutes(arr) {
-      if (arr.length <= 0) return false;
-      for (let i = 0; i < arr.length; i++) {
-        if (arr[i].children) {
-          arr = arr.slice(0, i + 1).concat(arr[i].children, arr.slice(i + 1));
-        }
-      }
-      return arr;
-    },
-    findFirstNonNullChildren(arr) {
-      // 如果数组为空,返回null
-      if (!arr || arr.length === 0) {
-        return null;
-      }
-      // 找到第一个对象
-      const firstObj = arr[0];
-      // 如果第一个对象没有children属性,返回该对象
-      if (!firstObj.children) {
-        return firstObj;
-      }
-
-      // 如果第一个对象的children属性是数组,
-      // 递归查找children属性中的第一个非null children属性
-      if (Array.isArray(firstObj.children)) {
-        return this.findFirstNonNullChildren(firstObj.children);
-      }
-      // 如果数组中没有非null children属性,返回null
-      return null;
-    },
     checkSocket() {
       getWorkermanUrl().then((res) => {
         let url = res.data.admin;

+ 1 - 1
template/admin/src/pages/setting/systemMenus/components/menusFrom.vue

@@ -405,7 +405,7 @@ export default {
         .then(async (res) => {
           this.$Message.success(res.msg);
           this.modals = false;
-          // this.$emit('getList');
+          this.$emit('changeMenu');
           this.getAddFrom();
           this.$store.dispatch('admin/menus/getMenusNavList');
         })

+ 35 - 1
template/admin/src/pages/setting/systemMenus/index.vue

@@ -87,6 +87,7 @@
       :formValidate="formValidate"
       :titleFrom="titleFrom"
       @getList="getList"
+      @changeMenu="getMenusUnique"
       ref="menusFrom"
       @clearFrom="clearFrom"
     ></menus-from>
@@ -137,9 +138,19 @@
 
 <script>
 import { mapState } from 'vuex';
-import { getTable, menusDetailsApi, isShowApi, editMenus, getRuleList, menusBatch } from '@/api/systemMenus';
+import {
+  getTable,
+  menusDetailsApi,
+  isShowApi,
+  editMenus,
+  getRuleList,
+  menusBatch,
+  getMenusUnique,
+} from '@/api/systemMenus';
 import formCreate from '@form-create/iview';
 import menusFrom from './components/menusFrom';
+import { formatFlatteningRoutes } from '@/libs/system';
+
 export default {
   name: 'systemMenus',
   data() {
@@ -400,6 +411,29 @@ export default {
           this.$Message.error(res.msg);
         });
     },
+    getMenusUnique() {
+      getMenusUnique().then((res) => {
+        let data = res.data;
+        this.$store.commit('userInfo/uniqueAuth', data.uniqueAuth);
+        this.$store.commit('menus/getmenusNav', data.menus);
+        this.$store.dispatch('routesList/setRoutesList', data.menus);
+        let arr = formatFlatteningRoutes(this.$router.options.routes);
+        this.formatTwoStageRoutes(arr);
+      });
+    },
+    formatTwoStageRoutes(arr) {
+      if (arr.length <= 0) return false;
+      const newArr = [];
+      const cacheList = [];
+      arr.forEach((v) => {
+        if (v && v.meta && v.meta.keepAlive) {
+          newArr.push({ ...v });
+          cacheList.push(v.name);
+          this.$store.dispatch('keepAliveNames/setCacheKeepAlive', cacheList);
+        }
+      });
+      return newArr;
+    },
     // 关闭按钮
     cancel() {
       this.$emit('onCancel');