Bladeren bron

修改系统的菜单权限问题(super_admin 可查看系统管理和基础数据)

baiyanting 1 jaar geleden
bovenliggende
commit
024e9752dc
4 gewijzigde bestanden met toevoegingen van 383 en 371 verwijderingen
  1. 7 2
      src/components/Sidebar.vue
  2. 1 2
      src/pages/Login.vue
  3. 1 1
      src/permission.js
  4. 374 366
      src/router/index.js

+ 7 - 2
src/components/Sidebar.vue

@@ -23,7 +23,10 @@
             </template>
 
             <template v-for="subItem in item.children" :key="subItem.name">
-              <el-menu-item :index="replaceRoute(subItem.path)">
+              <el-menu-item
+                v-if="subItem.isshow?.includes(identity) || !subItem.isshow"
+                :index="replaceRoute(subItem.path)"
+              >
                 {{ subItem.meta.title }}
               </el-menu-item>
             </template>
@@ -52,13 +55,15 @@
 import { computed } from "vue";
 import { useRoute, useRouter } from "vue-router";
 import { useStore } from "vuex";
-const identity = sessionStorage.getItem("identity");
+// const identity = sessionStorage.getItem("identity");
 
 const route = useRoute();
 const store = useStore();
 const router = useRouter();
 let onRoutes = computed(() => route.path.replace("/", ""));
 let collapse = computed(() => store.state.collapse);
+const identity = computed(() => store.getters.roles);
+// console.log(identity);
 
 const replaceRoute = (route) => {
   const regex = /\/:[^?]+?\?/g;

+ 1 - 2
src/pages/Login.vue

@@ -142,7 +142,6 @@ const loginFun = async () => {
         ElMessage.success("登录成功");
       }
     });
-    sessionStorage.setItem("identity", res.identity || "admin");
   } else {
     ElMessage.error(msg);
   }
@@ -201,4 +200,4 @@ const loginFun = async () => {
     }
   }
 }
-</style>
+</style>

+ 1 - 1
src/permission.js

@@ -44,7 +44,7 @@ router.beforeEach((to, from, next) => {
             next("/");
         } else {
             if (store.getters.roles.length == 0) {
-                store.dispatch("user/GetInfo").then(async() => {
+                store.dispatch("user/GetInfo").then(async () => {
                     next();
                 });
             } else {

+ 374 - 366
src/router/index.js

@@ -1,396 +1,404 @@
 import {
-    createRouter,
-    createWebHistory,
-    createWebHashHistory,
+  createRouter,
+  createWebHistory,
+  createWebHashHistory,
 } from "vue-router";
 import Home from "../pages/Home.vue";
 import store from "@/store";
 import { getCookie } from "@/utils/auth"; // getToken from cookie
 const routes = [
-    { path: "/", redirect: "/safe/realwaring" },
-    {
-        path: "/",
-        name: "Home",
-        redirect: "/safe/realwaring",
-        // redirect: '/firstPage',
-        component: Home,
-        children: [
-            //   {
-            //     icon: "el-icon-s-home",
-            //     path: "/firstPage",
-            //     name: "shouye",
-            //     meta: {
-            //       title: "系统首页",
-            //     },
-            //     component: () => import("../pages/firstPage.vue"),
-            //   },
+  { path: "/", redirect: "/safe/realwaring" },
+  {
+    path: "/",
+    name: "Home",
+    redirect: "/safe/realwaring",
+    // redirect: '/firstPage',
+    component: Home,
+    children: [
+      //   {
+      //     icon: "el-icon-s-home",
+      //     path: "/firstPage",
+      //     name: "shouye",
+      //     meta: {
+      //       title: "系统首页",
+      //     },
+      //     component: () => import("../pages/firstPage.vue"),
+      //   },
 
-            //   {
-            //     icon: "el-icon-s-home",
-            //     path: "/dashboard",
-            //     name: "dashboard",
-            //     meta: {
-            //       title: "系统首页",
-            //     },
-            //     component: () =>
-            //       import(
-            //         /* webpackChunkName: "dashboard" */
-            //         "../pages/Dashboard.vue"
-            //       ),
-            //   },
+      //   {
+      //     icon: "el-icon-s-home",
+      //     path: "/dashboard",
+      //     name: "dashboard",
+      //     meta: {
+      //       title: "系统首页",
+      //     },
+      //     component: () =>
+      //       import(
+      //         /* webpackChunkName: "dashboard" */
+      //         "../pages/Dashboard.vue"
+      //       ),
+      //   },
 
-            {
-                icon: "iconfont iconfengji",
-                path: "/safe",
-                name: "safe",
-                redirect: "/safe/realwaring",
-                meta: {
-                    title: "安全运行",
-                },
-                component: () =>
-                    import ("../pages/routerView.vue"),
-                children: [{
-                        path: "/safe/realwaring",
-                        name: "saferealwaring",
-                        meta: {
-                            title: "实时报警",
-                            keepAlive: true, //需要被缓存的组件
-                        },
-                        component: () =>
-                            import (
-                                /* webpackChunkName: "form" */
-                                "../pages/safe/realwaring.vue"
-                            ),
-                    },
-                    {
-                        path: "/safe/historywaring/:deviceId?/:alarmId?",
-                        name: "safehistorywaring",
-                        meta: {
-                            title: "报警记录",
-                        },
-                        component: () =>
-                            import (
-                                /* webpackChunkName: "form" */
-                                "../pages/safe/historywaring.vue"
-                            ),
-                    },
-                    {
-                        path: "/safe/dataSearch",
-                        name: "safedataSearch",
-                        meta: {
-                            title: "数据查询",
-                        },
-                        component: () =>
-                            import (
-                                /* webpackChunkName: "form" */
-                                "../pages/safe/datasearch.vue"
-                            ),
-                    },
-                ],
+      {
+        icon: "iconfont iconfengji",
+        path: "/safe",
+        name: "safe",
+        redirect: "/safe/realwaring",
+        meta: {
+          title: "安全运行",
+        },
+        component: () => import("../pages/routerView.vue"),
+        children: [
+          {
+            path: "/safe/realwaring",
+            name: "saferealwaring",
+            isshow: "super_admin,common",
+            meta: {
+              title: "实时报警",
+              keepAlive: true, //需要被缓存的组件
+            },
+            component: () =>
+              import(
+                /* webpackChunkName: "form" */
+                "../pages/safe/realwaring.vue"
+              ),
+          },
+          {
+            path: "/safe/historywaring/:deviceId?/:alarmId?",
+            name: "safehistorywaring",
+            isshow: "super_admin,common",
+            meta: {
+              title: "报警记录",
+            },
+            component: () =>
+              import(
+                /* webpackChunkName: "form" */
+                "../pages/safe/historywaring.vue"
+              ),
+          },
+          {
+            path: "/safe/dataSearch",
+            name: "safedataSearch",
+            isshow: "super_admin,common",
+            meta: {
+              title: "数据查询",
             },
+            component: () =>
+              import(
+                /* webpackChunkName: "form" */
+                "../pages/safe/datasearch.vue"
+              ),
+          },
+        ],
+      },
 
-            {
-                icon: "iconfont iconguzhangzhenduan",
-                path: "/faultDiagnosis",
-                name: "faultDiagnosis",
-                redirect: "/faultDiagnosis/warning",
-                meta: {
-                    title: "状态检修",
-                    permission: true,
-                },
-                component: () =>
-                    import (
-                        /* webpackChunkName: "permission" */
-                        "../pages/routerView.vue"
-                    ),
-                children: [
-                    // {
-                    //     icon: 'el-icon-s-home',
-                    //     path: '/faultDiagnosis/record',
-                    //     name: 'faultDiagnosissrecord',
-                    //     meta: {
-                    //         title: '预警记录',
-                    //     },
-                    //     component: () =>
-                    //         import (
-                    //             /* webpackChunkName: "form" */
-                    //             '../pages/faultDiagnosis/record.vue'
-                    //         ),
-                    // },
-                    //   {
-                    //     icon: "el-icon-s-home",
-                    //     path: "/faultDiagnosis/warning",
-                    //     name: "faultDiagnosiswarning",
-                    //     meta: {
-                    //       title: "预警分析",
-                    //     },
-                    //     component: () =>
-                    //       import(
-                    //         /* webpackChunkName: "form" */
-                    //         "../pages/faultDiagnosis/warning.vue"
-                    //       ),
-                    //   },
-                    //   {
-                    //     icon: "el-icon-s-home",
-                    //     path: "/faultDiagnosis/statistics",
-                    //     name: "faultDiagnosisstatistics",
-                    //     meta: {
-                    //       title: "预警统计",
-                    //     },
-                    //     component: () =>
-                    //       import(
-                    //         /* webpackChunkName: "form" */
-                    //         "../pages/faultDiagnosis/statistics.vue"
-                    //       ),
-                    //   },
-                    {
-                        icon: "el-icon-s-home",
-                        path: "/basedata/FanDataStatisticTable",
-                        name: "FanDataStatisticTable",
-                        meta: {
-                            title: "原始报警分析",
-                            keepAlive: true,
-                        },
-                        component: () =>
-                            import ("../pages/baseData/FanDataStatisticTable.vue"),
-                    },
-                    //   {
-                    //     icon: "el-icon-s-home",
-                    //     path: "/basedata/FanDataStatisticTable",
-                    //     name: "FanDataStatisticTable",
-                    //     meta: {
-                    //       title: "原始报警统计",
-                    //       keepAlive: true,
-                    //     },
-                    //     component: () =>
-                    //       import("../pages/baseData/FanDataStatisticTable.vue"),
-                    //   },
-                    //   {
-                    //     icon: "el-icon-s-home",
-                    //     path: "/faultDiagnosis/report",
-                    //     name: "faultDiagnosisreport",
-                    //     meta: {
-                    //       title: "隐患报告",
-                    //     },
-                    //     component: () => import("../pages/faultDiagnosis/report.vue"),
-                    //   },
-                    //   {
-                    //     icon: "el-icon-s-home",
-                    //     path: "/faultDiagnosis/dangerReportReview",
-                    //     name: "dangerReportReview",
-                    //     meta: {
-                    //       title: "报告评审",
-                    //     },
-                    //     component: () =>
-                    //       import("../pages/faultDiagnosis/dangerReportReview.vue"),
-                    //   },
-                    //   {
-                    //     icon: "el-icon-s-home",
-                    //     path: "/faultDiagnosis/patrolInspectionPlan",
-                    //     name: "patrolInspectionPlan",
-                    //     meta: {
-                    //       title: "巡检计划",
-                    //     },
-                    //     component: () =>
-                    //       import("../pages/faultDiagnosis/patrolInspectionPlan.vue"),
-                    //   },
+      {
+        icon: "iconfont iconguzhangzhenduan",
+        path: "/faultDiagnosis",
+        name: "faultDiagnosis",
+        isshow: "super_admin,common",
+        redirect: "/faultDiagnosis/warning",
+        meta: {
+          title: "状态检修",
+          permission: true,
+        },
+        component: () =>
+          import(
+            /* webpackChunkName: "permission" */
+            "../pages/routerView.vue"
+          ),
+        children: [
+          // {
+          //     icon: 'el-icon-s-home',
+          //     path: '/faultDiagnosis/record',
+          //     name: 'faultDiagnosissrecord',
+          //     meta: {
+          //         title: '预警记录',
+          //     },
+          //     component: () =>
+          //         import (
+          //             /* webpackChunkName: "form" */
+          //             '../pages/faultDiagnosis/record.vue'
+          //         ),
+          // },
+          //   {
+          //     icon: "el-icon-s-home",
+          //     path: "/faultDiagnosis/warning",
+          //     name: "faultDiagnosiswarning",
+          //     meta: {
+          //       title: "预警分析",
+          //     },
+          //     component: () =>
+          //       import(
+          //         /* webpackChunkName: "form" */
+          //         "../pages/faultDiagnosis/warning.vue"
+          //       ),
+          //   },
+          //   {
+          //     icon: "el-icon-s-home",
+          //     path: "/faultDiagnosis/statistics",
+          //     name: "faultDiagnosisstatistics",
+          //     meta: {
+          //       title: "预警统计",
+          //     },
+          //     component: () =>
+          //       import(
+          //         /* webpackChunkName: "form" */
+          //         "../pages/faultDiagnosis/statistics.vue"
+          //       ),
+          //   },
+          {
+            icon: "el-icon-s-home",
+            path: "/basedata/FanDataStatisticTable",
+            name: "FanDataStatisticTable",
+            isshow: "super_admin,common",
+            meta: {
+              title: "原始报警分析",
+              keepAlive: true,
+            },
+            component: () =>
+              import("../pages/baseData/FanDataStatisticTable.vue"),
+          },
+          //   {
+          //     icon: "el-icon-s-home",
+          //     path: "/basedata/FanDataStatisticTable",
+          //     name: "FanDataStatisticTable",
+          //     meta: {
+          //       title: "原始报警统计",
+          //       keepAlive: true,
+          //     },
+          //     component: () =>
+          //       import("../pages/baseData/FanDataStatisticTable.vue"),
+          //   },
+          //   {
+          //     icon: "el-icon-s-home",
+          //     path: "/faultDiagnosis/report",
+          //     name: "faultDiagnosisreport",
+          //     meta: {
+          //       title: "隐患报告",
+          //     },
+          //     component: () => import("../pages/faultDiagnosis/report.vue"),
+          //   },
+          //   {
+          //     icon: "el-icon-s-home",
+          //     path: "/faultDiagnosis/dangerReportReview",
+          //     name: "dangerReportReview",
+          //     meta: {
+          //       title: "报告评审",
+          //     },
+          //     component: () =>
+          //       import("../pages/faultDiagnosis/dangerReportReview.vue"),
+          //   },
+          //   {
+          //     icon: "el-icon-s-home",
+          //     path: "/faultDiagnosis/patrolInspectionPlan",
+          //     name: "patrolInspectionPlan",
+          //     meta: {
+          //       title: "巡检计划",
+          //     },
+          //     component: () =>
+          //       import("../pages/faultDiagnosis/patrolInspectionPlan.vue"),
+          //   },
 
-                    //   {
-                    //     icon: "el-icon-s-home",
-                    //     path: "/faultDiagnosis/Recommend",
-                    //     name: "faultDiagnosisRecommend",
-                    //     meta: {
-                    //       title: "诊断报告",
-                    //     },
-                    //     component: () =>
-                    //       import(
-                    //         /* webpackChunkName: "form" */
-                    //         "../pages/faultDiagnosis/Recommend.vue"
-                    //       ),
-                    //   },
+          //   {
+          //     icon: "el-icon-s-home",
+          //     path: "/faultDiagnosis/Recommend",
+          //     name: "faultDiagnosisRecommend",
+          //     meta: {
+          //       title: "诊断报告",
+          //     },
+          //     component: () =>
+          //       import(
+          //         /* webpackChunkName: "form" */
+          //         "../pages/faultDiagnosis/Recommend.vue"
+          //       ),
+          //   },
 
-                    // {
-                    //     icon: 'el-icon-s-home',
-                    //     path: '/faultDiagnosis/fault',
-                    //     name: 'faultDiagnosisfault',
-                    //     meta: {
-                    //         title: '故障诊断',
-                    //     },
-                    //     component: () =>
-                    //         import (
-                    //             /* webpackChunkName: "form" */
-                    //             '../pages/faultDiagnosis/fault.vue'
-                    //         ),
-                    // },
+          // {
+          //     icon: 'el-icon-s-home',
+          //     path: '/faultDiagnosis/fault',
+          //     name: 'faultDiagnosisfault',
+          //     meta: {
+          //         title: '故障诊断',
+          //     },
+          //     component: () =>
+          //         import (
+          //             /* webpackChunkName: "form" */
+          //             '../pages/faultDiagnosis/fault.vue'
+          //         ),
+          // },
 
-                    // {
-                    //     icon: 'el-icon-s-home',
-                    //     path: '/faultDiagnosis/cluster',
-                    //     name: 'faultDiagnosiscluster',
-                    //     meta: {
-                    //         title: '聚类分析',
-                    //     },
-                    //     component: () =>
-                    //         import (
-                    //             /* webpackChunkName: "form" */
-                    //             '../pages/faultDiagnosis/cluster.vue'
-                    //         ),
-                    // },
-                ],
+          // {
+          //     icon: 'el-icon-s-home',
+          //     path: '/faultDiagnosis/cluster',
+          //     name: 'faultDiagnosiscluster',
+          //     meta: {
+          //         title: '聚类分析',
+          //     },
+          //     component: () =>
+          //         import (
+          //             /* webpackChunkName: "form" */
+          //             '../pages/faultDiagnosis/cluster.vue'
+          //         ),
+          // },
+        ],
+      },
+      {
+        icon: "iconfont iconbaojingpeizhi",
+        path: "/alarmconfig",
+        name: "alarmconfig",
+        isshow: "super_admin,common",
+        redirect: "/alarmconfig/station",
+        meta: {
+          title: "预警配置",
+        },
+        component: () =>
+          import(
+            /* webpackChunkName: "tabs" */
+            "../pages/routerView.vue"
+          ),
+        children: [
+          {
+            icon: "el-icon-s-home",
+            path: "/alarmConfig/custom",
+            isshow: "super_admin,common",
+            name: "alarmConfigcustom",
+            meta: {
+              title: "自定义预警",
             },
-            {
-                icon: "iconfont iconbaojingpeizhi",
-                path: "/alarmconfig",
-                name: "alarmconfig",
-                // isshow: ["admin", "superuser"],
-                redirect: "/alarmconfig/station",
-                meta: {
-                    title: "预警配置",
-                },
-                component: () =>
-                    import (
-                        /* webpackChunkName: "tabs" */
-                        "../pages/routerView.vue"
-                    ),
-                children: [{
-                        icon: "el-icon-s-home",
-                        path: "/alarmConfig/custom",
-                        name: "alarmConfigcustom",
-                        meta: {
-                            title: "自定义预警",
-                        },
-                        component: () =>
-                            import (
-                                /* webpackChunkName: "form" */
-                                "../pages/alarmConfig/bj_custom/custom.vue"
-                            ),
-                    },
-                    {
-                        icon: "el-icon-s-home",
-                        path: "/alarmConfig/fan",
-                        name: "alarmConfigfan",
-                        meta: {
-                            title: "风机报警",
-                        },
-                        component: () =>
-                            import (
-                                /* webpackChunkName: "form" */
-                                "../pages/alarmConfig/bj_windturbine/windturbine.vue"
-                            ),
-                    },
-
-                    {
-                        icon: "el-icon-s-home",
-                        path: "/alarmConfig/Logs",
-                        name: "alarmConfigLogs",
-                        meta: {
-                            title: "规则修改日志",
-                        },
-                        component: () =>
-                            import (
-                                /* webpackChunkName: "form" */
-                                "../pages/alarmConfig/Logs.vue"
-                            ),
-                    },
-                ],
+            component: () =>
+              import(
+                /* webpackChunkName: "form" */
+                "../pages/alarmConfig/bj_custom/custom.vue"
+              ),
+          },
+          {
+            icon: "el-icon-s-home",
+            path: "/alarmConfig/fan",
+            isshow: "super_admin,common",
+            name: "alarmConfigfan",
+            meta: {
+              title: "风机报警",
             },
+            component: () =>
+              import(
+                /* webpackChunkName: "form" */
+                "../pages/alarmConfig/bj_windturbine/windturbine.vue"
+              ),
+          },
 
-            {
-                icon: "iconfont iconjichushuju",
-                path: "/basedata",
-                name: "basedata",
-                // isshow: "admin",
-                redirect: "/basedata/station",
-                meta: {
-                    title: "基础数据",
-                },
-                component: () =>
-                    import (
-                        /* webpackChunkName: "home" */
-                        "../pages/routerView.vue"
-                    ),
-                children: [
-                    //   {
-                    //     icon: "el-icon-s-home",
-                    //     path: "/basedata/device",
-                    //     name: "basedatadevice",
-                    //     meta: {
-                    //       title: "设备模型",
-                    //       keepAlive: true,
-                    //     },
-                    //     component: () =>
-                    //       import(
-                    //         /* webpackChunkName: "form" */
-                    //         "../pages/baseData/device.vue"
-                    //       ),
-                    //   },
-                    {
-                        icon: "el-icon-s-home",
-                        path: "/basedata/dictionary",
-                        name: "basedatadictionary",
-                        meta: {
-                            title: "字典维护",
-                            keepAlive: true,
-                        },
-                        component: () =>
-                            import (
-                                /* webpackChunkName: "form" */
-                                "../pages/baseData/dictionary.vue"
-                            ),
-                    },
-                ],
-            },
-            //   {
-            //     icon: "el-icon-user-solid",
-            //     path: "/userManage",
-            //     name: "userManage",
-            //     isshow: "admin",
-            //     meta: {
-            //       title: "用户管理",
-            //     },
-            //     component: () => import("../pages/userManage/userManage.vue"),
-            //   },
-            {
-                icon: "iconfont iconxitongcaidan",
-                path: "/systemManage",
-                isshow: "admin",
-                name: "systemManage",
-                meta: {
-                    title: "系统管理",
-                },
-                component: () =>
-                    import ("../pages/systemManage/systemManage.vue"),
+          {
+            icon: "el-icon-s-home",
+            path: "/alarmConfig/Logs",
+            isshow: "super_admin,common",
+            name: "alarmConfigLogs",
+            meta: {
+              title: "规则修改日志",
             },
+            component: () =>
+              import(
+                /* webpackChunkName: "form" */
+                "../pages/alarmConfig/Logs.vue"
+              ),
+          },
         ],
-    },
-    {
-        path: "/login",
-        name: "Login",
+      },
+
+      {
+        icon: "iconfont iconjichushuju",
+        path: "/basedata",
+        name: "basedata",
+        isshow: "super_admin",
+        redirect: "/basedata/station",
         meta: {
-            title: "登录",
+          title: "基础数据",
         },
         component: () =>
-            import (
-                /* webpackChunkName: "login" */
-                "../pages/Login.vue"
-            ),
-    },
-    {
+          import(
+            /* webpackChunkName: "home" */
+            "../pages/routerView.vue"
+          ),
+        children: [
+          //   {
+          //     icon: "el-icon-s-home",
+          //     path: "/basedata/device",
+          //     name: "basedatadevice",
+          //     meta: {
+          //       title: "设备模型",
+          //       keepAlive: true,
+          //     },
+          //     component: () =>
+          //       import(
+          //         /* webpackChunkName: "form" */
+          //         "../pages/baseData/device.vue"
+          //       ),
+          //   },
+          {
+            icon: "el-icon-s-home",
+            path: "/basedata/dictionary",
+            isshow: "super_admin",
+            name: "basedatadictionary",
+            meta: {
+              title: "字典维护",
+              keepAlive: true,
+            },
+            component: () =>
+              import(
+                /* webpackChunkName: "form" */
+                "../pages/baseData/dictionary.vue"
+              ),
+          },
+        ],
+      },
+      //   {
+      //     icon: "el-icon-user-solid",
+      //     path: "/userManage",
+      //     name: "userManage",
+      //     isshow: "admin",
+      //     meta: {
+      //       title: "用户管理",
+      //     },
+      //     component: () => import("../pages/userManage/userManage.vue"),
+      //   },
+      {
         icon: "iconfont iconxitongcaidan",
-        path: "/check",
-        // isshow: "admin",
-        name: "check",
+        path: "/systemManage",
+        isshow: "super_admin",
+        name: "systemManage",
         meta: {
-            title: "单点登录",
+          title: "系统管理",
         },
-        component: () =>
-            import ("@/pages/check/check.vue"),
+        component: () => import("../pages/systemManage/systemManage.vue"),
+      },
+    ],
+  },
+  {
+    path: "/login",
+    name: "Login",
+    meta: {
+      title: "登录",
+    },
+    component: () =>
+      import(
+        /* webpackChunkName: "login" */
+        "../pages/Login.vue"
+      ),
+  },
+  {
+    icon: "iconfont iconxitongcaidan",
+    path: "/check",
+    // isshow: "admin",
+    name: "check",
+    meta: {
+      title: "单点登录",
     },
+    component: () => import("@/pages/check/check.vue"),
+  },
 ];
 const constantRoutes = [];
 const router = createRouter({
-    history: createWebHashHistory(""),
-    routes,
+  history: createWebHashHistory(""),
+  routes,
 });
 
-export default router;
+export default router;