zhangqiOMG 2 years ago
parent
commit
baf7247390

+ 21 - 12
src/App.vue

@@ -10,15 +10,27 @@
     },
     methods:{},
     watch: {
-      $route(to,from) {
-        console.log(to,from)
-        let at_modules = JSON.parse(sessionStorage.getItem('active_modules'))
-        to.meta.modules = at_modules
-        let app = to.meta.modules.apps.filter(e=>{
-          if (e.name === to.name) return e
-        })
-        console.log(app)
-        // this.$store.dispatch('setActiveApp',{app:app[0],val:''})
+      $route(val) {
+        if (!val.meta.modules) {
+          let at_modules = JSON.parse(sessionStorage.getItem('active_modules'))
+          val.meta.modules?'':val.meta.modules = at_modules
+        } else {
+          
+          let app = val.meta.modules.apps.filter(e=>{
+            if (e.name === val.name) return e
+          })
+          sessionStorage.setItem('active_modules',JSON.stringify(val.meta.modules))
+          
+          this.$store.dispatch('setActiveApp',{app:app[0],val:''})
+
+          let system = JSON.parse(sessionStorage.getItem('module_info'))
+          
+          let at_system = system.filter(e=>{
+            if (e.systemid === val.meta.modules.systemid)
+            return e
+          })
+          this.$store.dispatch('getModules',{mod:at_system[0].modules})
+        }
       }
     }
   }
@@ -31,9 +43,6 @@ body{
 .rightBar{
   width:60px;
   height:100vh;
-  /* background:#afc7fb; */
-  /* opacity: .9; */
-  /* border-left:1px solid #f1f2f3; */
   background: rgba(255,255,255,.5);
   box-shadow: 0 2px 5px rgb(0 0 0 / 10%);
 }

+ 1 - 1
src/components/newLayout/index.vue

@@ -36,7 +36,7 @@ export default {
   },
   methods:{
     getModules (mod,type) {
-      this.$refs['menu'].setModules(mod,type)
+      // this.$refs['menu'].setModules(mod,type)
     },
      // 查询应用授权
     async query_userauth () {

+ 4 - 3
src/components/newLayout/modules/aside.vue

@@ -85,7 +85,8 @@ export default {
   methods:{
     handelMenuClick (item,type) {
       this.active = String(item.systemid)
-      this.$emit('getModules',item.modules,type)
+      // this.$emit('getModules',item.modules,type)
+      this.$store.dispatch('getModules',{mod:item.modules,type:type})
     },
     handelMenuAppClick (app,type) {
       let system = JSON.parse(sessionStorage.getItem('module_info'))
@@ -105,8 +106,8 @@ export default {
       })[0]
 
       sessionStorage.setItem('active_modules',JSON.stringify(at_modules))
-
-      this.$emit('getModules',at_sys_modules,type)
+      
+      this.$store.dispatch('getModules',{mod:at_sys_modules,type:type})
 
       this.$store.dispatch('setActiveApp',{name:app.systemappname,app:at_app,val:''})
 

+ 13 - 11
src/components/newLayout/modules/menu.vue

@@ -2,7 +2,7 @@
   <div class="menu_panel">
     <div  v-if="show">
       <el-menu router v-if="show"  :default-active="activeIndex" active-text-color="#3874f6" text-color="#333" class="el-menu-demo shadow" mode="horizontal" @select="handleSelect">
-        <el-submenu v-show="hasMoreApp(mod)" v-for="(mod,index) in modules" :key="index" :index="String(index)">
+        <el-submenu v-show="hasMoreApp(mod)" v-for="(mod,index) in sys_modules" :key="index" :index="String(index)">
           <template slot="title"><b>{{mod.systemmodulename}}</b></template>
           <el-menu-item :index="app.path" v-for="(app) in mod.apps" :key="app.index" @click="setActiveModules(mod,app)">{{app.meta.title}}</el-menu-item>
         </el-submenu>
@@ -24,19 +24,20 @@ export default {
   },
   computed:{
     ...mapGetters({
-      acitveApp:'acitveApp'
+      acitveApp:'acitveApp',
+      sys_modules:'sys_modules'
     })
   },
   methods:{
-    setModules (mod,type) {
-      this.modules = mod
-      if (type === 'system') {
-        this.setActiveModules(mod[0],mod[0].apps[0])
-        let inactivePath = mod[0].apps[0].path
-        this.$router.push({path:inactivePath})
-      }
+    // setModules (mod,type) {
+    //   this.modules = mod
+    //   if (type === 'system') {
+    //     this.setActiveModules(mod[0],mod[0].apps[0])
+    //     let inactivePath = mod[0].apps[0].path
+    //     this.$router.push({path:inactivePath})
+    //   }
       
-    },
+    // },
     hasMoreApp (mod) {
       if (mod.apps.length > 1) {
         return true
@@ -51,7 +52,8 @@ export default {
     },
     setDefaultData (mod) {
       let system = JSON.parse(sessionStorage.getItem('module_info'))
-      this.setModules(system[0].modules)
+      // this.setModules(system[0].modules)
+      this.$store.dispatch('getModules',{mod:system[0].modules})
     },
     handleSelect(key, keyPath) {
       this.activeIndex = key

+ 20 - 0
src/store/index.js

@@ -1,6 +1,7 @@
 import Vue from 'vue';
 import Vuex from 'vuex';
 import axios from 'axios'
+import router from '../router';
 import api from '../api/api'
 import tool from '../utils/tool'
 Vue.use(Vuex);
@@ -21,6 +22,7 @@ export default new Vuex.Store({
     acitveApp:null,
     appname:'',
     menuApp:[],
+    sys_modules:[],
     searchValue:'',
     closeDrawerTemp:false,
     DrawerShow:false
@@ -41,6 +43,7 @@ export default new Vuex.Store({
     searchValue:state => state.searchValue,
     closeDrawerTemp:state => state.closeDrawerTemp,
     DrawerShow:state => state.DrawerShow,
+    sys_modules:state => state.sys_modules
     
   },
   mutations: {
@@ -71,12 +74,17 @@ export default new Vuex.Store({
     sendDataToForm (state,data) {
       state.dataToForm = data
     },
+    
     setActiveApp (state,data) {
       state.appname = data.name
       state.acitveApp = data.app
         //头部区域搜索所传入的数值
       state.searchValue = data.val
     },
+    systemModules (state,data) {
+      state.sys_modules = data
+      console.log(state.sys_modules,'mod')
+    },
     setAppMenu (state,data) {
       state.menuApp = data
     },
@@ -200,6 +208,18 @@ export default new Vuex.Store({
     sendDataToForm ({commit}, data) {
       commit('sendDataToForm',data)
     },
+    getModules ({commit}, data) {
+      if (data.type === 'system') {
+        commit('setActiveApp',{name:data.mod[0].apps[0].systemappname,app:data.mod[0].apps[0],val:''})
+        sessionStorage.setItem('active_modules',JSON.stringify(data.mod[0]))
+
+        let inactivePath = data.mod[0].apps[0].path
+
+        router.push({path:inactivePath})
+
+      }
+      commit('systemModules',data.mod)
+    },
     // 设置活动中的应用
     setActiveApp ({commit}, data) {
       commit('setActiveApp',data)