Browse Source

修改bug

asd123a20 2 years ago
parent
commit
6da263ec80
4 changed files with 22 additions and 9 deletions
  1. 4 2
      lib/last.js
  2. 5 5
      src/components/heads/nav/index.vue
  3. 10 1
      src/store/index.js
  4. 3 1
      src/views/Home.vue

+ 4 - 2
lib/last.js

@@ -4,8 +4,10 @@ const last = {
     Vue.prototype.$last = function(options) {
       const last = item => {
         const isCode = options.menus.filter(j => j.code == item);
-        const children = this.menusall.filter(k => k.parentCode == isCode[0]?.code);
-        if (children.length > 0) return last(children[0]?.code);
+        if (isCode.length > 0) {
+          const children = options.menus.filter(k => k.parentCode == isCode[0]?.code);
+          if (children.length > 0) return last(children[0]?.code);
+        }
         return isCode[0];
       };
       const item = last(options.code);

+ 5 - 5
src/components/heads/nav/index.vue

@@ -16,9 +16,9 @@ export default {
     navItem
   },
   computed: {
-    ...mapState(['menusall']),
+    ...mapState(['menusalls']),
     menus() {
-      const menus = this.$tree(this.menusall) ?? [];
+      const menus = this.$tree(this.menusalls) ?? [];
       return menus;
     }
   },
@@ -28,17 +28,17 @@ export default {
     };
   },
   async mounted() {
-    await this.menusQueryAll();
+    await this.menusQueryAlls();
   },
   methods: {
-    ...mapActions(['menusQueryAll']),
+    ...mapActions(['menusQueryAlls']),
     async handleSelect(env) {
       // 获取最后一级菜单
       const last = await this.setactiveIndex(env);
       // 赋值当前选选个
       this.activeIndex = last?.code;
       // 缓存写入当前一例菜单
-      this.$setParentsetSession({ menus: this.menusall, iscode: last });
+      this.$setParentsetSession({ menus: this.menusalls, iscode: last });
       // 写入当前菜单编码
       sessionStorage.setItem('code', this.activeIndex);
       // 获取当前一例的顶级菜单编码

+ 10 - 1
src/store/index.js

@@ -15,6 +15,7 @@ const api = {
 
 const state = () => ({
   menusall: [],
+  menusalls: [],
   websiteInfo: [],
   imgNewsList: [],
   linkTypeList: [],
@@ -32,10 +33,15 @@ const actions = {
     return res.data;
   },
   async menusQueryAll ({ commit }) {
-    const res = await $axios.get(api.menusQuery, { isshow: true });
+    const res = await $axios.get(api.menusQuery);
     commit('menusQueryAll', res);
     return res;
   },
+  async menusQueryAlls ({ commit }) {
+    const res = await $axios.get(api.menusQuery, { isshow: true });
+    commit('menusQueryAlls', res);
+    return res;
+  },
   async websiteQuery ({ commit }) {
     const res = await $axios.get(api.websiteQuery);
     commit('websiteQuery', res);
@@ -95,6 +101,9 @@ const mutations = {
   menusQueryAll(state, payload) {
     state.menusall = payload.data;
   },
+  menusQueryAlls(state, payload) {
+    state.menusalls = payload.data;
+  },
   websiteQuery(state, payload) {
     state.websiteInfo = payload.data;
   },

+ 3 - 1
src/views/Home.vue

@@ -111,9 +111,11 @@ export default {
     await this.btnClick({ name: '09', type: 'threeDatazc', limit: 3, parentCode: true });
     // 通知公告
     await this.btnClick({ name: '10', type: 'threeDatagg', limit: 4, parentCode: true });
+    // 所有菜单
+    await this.menusQueryAll();
   },
   methods: {
-    ...mapActions(['contentsQuery']),
+    ...mapActions(['contentsQuery', 'menusQueryAll']),
     async btnClick(e) {
       const filter = { bind: e?.name };
       if (e?.parentCode) filter.parentCode = e?.name;