From 302858f921bed077ab54dd31102f086bfe1add3c Mon Sep 17 00:00:00 2001
From: haoxuan <haoxuan>
Date: 星期三, 07 二月 2024 11:59:47 +0800
Subject: [PATCH] srm项目 系统参数设置的前端页面开发+增加相关路由+公共列表组件增加是否可以配置表头的逻辑

---
 src/router/index.js |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/src/router/index.js b/src/router/index.js
index c98cba4..f04e988 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -5,6 +5,8 @@
 import supplierRouter from "./supplier/index.js"
 import purchaseRouter from "./purchase/index.js"
 import productRouter from "./product/index.js"
+import {getMenuTreeByRole} from "@/api/menus/index"
+import store from '@/store/index.js'; 
 
 Vue.use(Router)
 const login = (resolve) => require(["@/views/other/login/index"], resolve)
@@ -13,13 +15,13 @@
 const productManage = (resolve) => require(["@/views/productManage/index"], resolve)
 const PreviewFile = (resolve) => require(["@/views/supplierManage/supplier/PreviewFile"], resolve)
 const noData = (resolve) => require(["@/views/NoData/index"], resolve)
-
+const commonSet = (resolve) => require(["@/views/systemSet/commonSet/index"], resolve) //绯荤当瑷疆
 
 export const routes = [
   // 鏃犳暟鎹〉闈�
   {
-    path: "/",
-    name: "NoData",
+    path: "noData",
+    name: "noData",
     meta: {
       title: "",
       auth: true,
@@ -54,6 +56,14 @@
     meta: {
       title: "浜у搧绠$悊",
       isAllways: true
+    }
+  },
+  {
+    path: "/systemSet/commonSet",
+    name: "commonSet",
+    component: commonSet,
+    meta: {
+      title: "閫氱敤璁剧疆"
     }
   }
 ]
@@ -107,6 +117,48 @@
 
 const router = createRouter()
 
+let isSkip = false;
+async function hasPermission(routePath) {
+  isSkip = false;
+  try {
+    const res = await getMenuTreeByRole();
+    const newPath = {
+      path: "/noData"
+    };
+    const foundObject = res.data.list.find(obj => obj.systemType === 4);
+    if (foundObject) {
+      // 瀛樺偍杩泇uex
+      store.commit('setMenus', foundObject); 
+      foundObject.menus.forEach(item => {
+        const nextPath = item.children.find(obj => obj.path === routePath);
+        if (nextPath) {
+          newPath.path = nextPath.path;
+          isSkip = true;
+        }
+      });
+    } else {
+      newPath.path = '/noData';
+    }
+    return newPath; 
+  } catch (error) {
+    return { path: "/noData" }; 
+  }
+}
+router.beforeEach(async (to, from, next) => {
+  console.log(to,from,"鐪嬬湅")
+  try {
+    const result = await hasPermission(to.path);
+    console.log(result,"result")
+    next();
+    if (!isSkip) {
+      next('/noData')
+    }
+  } catch (error) {
+    console.error('Error in navigation guard:', error);
+    next(); 
+  }
+});
+
 // router.beforeEach((to, from, next) => {
 // must call `next`
 // console.log(to, from)

--
Gitblit v1.8.0