Przeglądaj źródła

feat(layout): 根据船务公司动态显示菜单项

- 在 Aside.vue 中使用 ref 创建 menu 数组,以便响应式更新
- 根据 store 中的 shippingCompany 状态添加或隐藏菜单项
- 在 main.js 中从本地存储获取 shippingCompany 并更新到 store
- 在 store/index.js 中添加 changeShippingCompany mutation 以保存船务公司信息
wzg 10 miesięcy temu
rodzic
commit
ccf7993eb7
3 zmienionych plików z 16 dodań i 10 usunięć
  1. 12 10
      src/layout/Aside.vue
  2. 1 0
      src/main.js
  3. 3 0
      src/store/index.js

+ 12 - 10
src/layout/Aside.vue

@@ -35,7 +35,7 @@ function changeIndex(path) {
   store.commit("clearAlive");
   defaultActive.value = path;
 }
-let menu = [
+let menu = ref([
   {
     icon: "Fold",
     title: "海事总台",
@@ -128,17 +128,19 @@ let menu = [
         path: "/workStation/insuranceManage",
         name: "保险管理",
       },
-      {
-        path: "/workStation/oilPriceManage",
-        name: "油价管理",
-      },
-      {
-        path: "/workStation/legalAidManage",
-        name: "法律援助管理",
-      },
     ],
   },
-];
+]);
+if (store.state.shippingCompany === "汇很多船务公司") {
+  menu.value.at(-1).items.push({
+    path: "/workStation/oilPriceManage",
+    name: "油价管理",
+  });
+  menu.value.at(-1).items.push({
+    path: "/workStation/legalAidManage",
+    name: "法律援助管理",
+  });
+}
 </script>
 <style scoped>
 .el-sub-menu__title i {

+ 1 - 0
src/main.js

@@ -36,6 +36,7 @@ router.beforeEach(async (to, from, next) => {
   let id = localStorage.loginAccountId;
   if (id) {
     store.commit("changeLogin", true);
+    store.commit("changeShippingCompany", localStorage.shippingCompany);
     if (0 === to.matched.length) {
       next("/index");
     } else if (to.path == "/login" || to.path == "/") {

+ 3 - 0
src/store/index.js

@@ -23,6 +23,9 @@ const store = createStore({
     changefirstTitle(state, text) {
       state.firstTitle = text;
     },
+    changeShippingCompany(state, text) {
+      state.shippingCompany = text;
+    },
     changeTitleSecond(state, text) {
       state.secondTitle = text;
     },