Преглед изворни кода

更新 登录无权限提示;实时更新当前角色权限及菜单;登录跳转页面为权限内页面

wzh пре 3 година
родитељ
комит
8d4ada8ef8

+ 11 - 6
src/main.js

@@ -23,12 +23,17 @@ router.beforeEach(async (to, from, next) => {
   if (localStorage.userId) {
     store.commit("changeLogin", true);
     let rolePermission = localStorage.rolePermission?.split(",") || [];
-    if (0 === to.matched.length) {
-      next("/voyage/voyageList");
-    } else if (to.path == "/login" || to.path == "/") {
-      next("/voyage/voyageList");
-    } else if (rolePermission?.indexOf(to.meta.code) == -1) {
-      next("/voyage/voyageList");
+    if (store.state.menuData.length) {
+      let path = store.state?.menuData[0]?.items[0].path;
+      if (0 === to.matched.length) {
+        next(path);
+      } else if (to.path == "/login" || to.path == "/") {
+        next(path);
+      } else if (rolePermission?.indexOf(to.meta.code) == -1) {
+        next(path);
+      } else {
+        next();
+      }
     } else {
       next();
     }

+ 15 - 11
src/store/index.js

@@ -69,27 +69,31 @@ const store = createStore({
       return new Promise((resolve, reject) => {
         api.getPermissionByUserId({ loginAccountId }).then((e) => {
           let res = e.data.result || [];
-          let arr = [...new Set([...res, "VOYAGELIST"])];
+          let arr = [...new Set([...res])];
           commit("setUserPermissionData", arr);
           localStorage.setItem("rolePermission", arr);
           let data = [];
           for (let i in menuData) {
-            if (menuData[i].title == "航次管理") {
+            // if (menuData[i].title == "航次管理") {
+            //   data[i] = menuData[i];
+            // } else {
+            if (arr.indexOf(menuData[i].code) != -1) {
               data[i] = menuData[i];
-            } else {
-              if (arr.indexOf(menuData[i].code) != -1) {
-                data[i] = menuData[i];
-                let arr0 = [];
-                for (let j in data[i].items) {
-                  if (arr.indexOf(data[i].items[j].code) != -1) {
-                    arr0.push(data[i].items[j]);
-                  }
+              let arr0 = [];
+              for (let j in data[i].items) {
+                if (arr.indexOf(data[i].items[j].code) != -1) {
+                  arr0.push(data[i].items[j]);
                 }
-                data[i].items = arr0;
               }
+              data[i].items = arr0;
             }
+            // }
           }
+          data = data.filter((item) => {
+            return item;
+          });
           commit("setMenuData", data);
+          resolve(1);
         });
       });
     },

+ 3 - 0
src/views/accountManage/subAccountList.vue

@@ -175,6 +175,7 @@
 import api from "../../apis/fetch";
 import { ref, onMounted, reactive } from "vue";
 import { ElNotification, ElMessageBox } from "element-plus";
+import store from "../../store/index";
 
 let tableData = ref([]);
 let currentPage = ref(1);
@@ -274,6 +275,8 @@ async function addSubAccount() {
     message: res.data.msg,
     type: status ? "success" : "error",
   });
+  store.dispatch("GetBasePermissionData", localStorage.loginAccountId);
+  store.dispatch("GetUserPermission", localStorage.loginAccountId);
   resetForm();
   getSubAccountList();
 }

+ 2 - 0
src/views/authManage/addRole.vue

@@ -153,6 +153,8 @@ async function addRole() {
       message: res.data.msg,
       type: "success",
     });
+    store.dispatch("GetBasePermissionData", localStorage.loginAccountId);
+    store.dispatch("GetUserPermission", localStorage.loginAccountId);
     router.replace("/authManage/roleList");
   } else {
     console.log(res);

+ 24 - 11
src/views/index/Login.vue

@@ -55,7 +55,7 @@
   </div>
 </template>
 <script>
-import { ref, reactive, toRefs } from "vue";
+import { ref, reactive, toRefs, computed } from "vue";
 import { ElNotification } from "element-plus";
 import store from "../../store";
 import router from "../../router";
@@ -98,12 +98,6 @@ export default {
             password,
           });
           if (res.data.status == 0) {
-            ElNotification.success({
-              title: "成功",
-              duration: 2000,
-              message: res.data.msg,
-              type: "success",
-            });
             let {
               userId,
               userName,
@@ -112,6 +106,21 @@ export default {
               loginAccountId,
               rolePermission,
             } = res.data.result;
+            if (!rolePermission.length) {
+              ElNotification.error({
+                title: "失败",
+                duration: 2000,
+                message: "暂无权限,请联系管理员",
+                type: "error",
+              });
+              return;
+            }
+            ElNotification.success({
+              title: "成功",
+              duration: 2000,
+              message: res.data.msg,
+              type: "success",
+            });
             localStorage.setItem("userId", userId);
             localStorage.setItem("userName", userName);
             localStorage.setItem("phone", phone);
@@ -119,15 +128,19 @@ export default {
             localStorage.setItem("userType", 1);
             localStorage.setItem("loginAccountId", loginAccountId);
             rolePermission = rolePermission || [];
-            let arr = [...new Set([...rolePermission, "VOYAGELIST"])];
+            let arr = [...new Set([...rolePermission])];
             localStorage.setItem("rolePermission", arr);
-            store.commit("changeLogin", true);
             store.dispatch(
               "GetBasePermissionData",
               localStorage.loginAccountId
             );
-            store.dispatch("GetUserPermission", localStorage.loginAccountId);
-            router.replace({ path: "/voyage/voyageList" });
+            let res1 = await store.dispatch(
+              "GetUserPermission",
+              localStorage.loginAccountId
+            );
+
+            router.replace({ path: store.state.menuData[0]?.items[0].path });
+            store.commit("changeLogin", true);
           } else {
             ElNotification.error({
               title: "错误",