浏览代码

fix: 修复tabbar异常

Tim_Walker 1 年之前
父节点
当前提交
b22aff6ebd
共有 3 个文件被更改,包括 17 次插入23 次删除
  1. 11 22
      src/components/tabbar/index.vue
  2. 1 0
      src/store/getters.js
  3. 5 1
      src/store/modules/app.js

+ 11 - 22
src/components/tabbar/index.vue

@@ -38,15 +38,8 @@
 import { mapGetters } from 'vuex';
 export default {
   name: 'TabBar',
-  // props: {
-  //   : {
-  //     type: String,
-  //     default: 'clientHome',
-  //   },
-  // },
   data() {
     return {
-      currentTab:'clientHome',
       clientList: [
         {
           text: '首页',
@@ -125,12 +118,10 @@ export default {
     };
   },
   computed:{
-    ...mapGetters(['scope'])
+    ...mapGetters(['scope','currentTab'])
   },
   methods: {
     handTab(row) {
-      console.log(row);
-      this.currentTab = row.name
       if(this.scope === 'CUSTOMER'){
         uni.switchTab({
           url:row.pagePath
@@ -140,20 +131,18 @@ export default {
           url:row.pagePath
         })
       }
-      // uni.navigateTo({
-      //     url:row.pagePath
-      //   })
-      // if (this.isShow) {
-      //   uni.switchTab({
-      //     url: row.pagePath,
-      //   });
-      // } else {
-      //   uni.redirectTo({
-      //     url: row.pagePath,
-      //   });
-      // }
+      this.$store.commit('SET_CURRENT_TAB',row.name)
     },
   },
+  watch:{
+    scope(newV,oldV){
+      if(newV=== 'MERCHANT'){
+        this.$store.commit("SET_CURRENT_TAB",this.merchantList[0].name)
+      }else{
+        this.$store.commit("SET_CURRENT_TAB",this.clientList[0].name)
+      }
+    }
+  }
 };
 </script>
 

+ 1 - 0
src/store/getters.js

@@ -1,6 +1,7 @@
 const getters = {
   // app 系统信息
   app: state => state.app,
+  currentTab: state =>state.app.currentTab,
   // auth 信息
   id: state => state.auth.id,
   accessToken: state => state.auth.accessToken,

+ 5 - 1
src/store/modules/app.js

@@ -1,10 +1,14 @@
 export default {
   state: () => ({
-    system: {}
+    system: {},
+    currentTab:'clientHome'
   }),
   mutations: {
     SET_APP_SYSTEM(state, info) {
       state.system = info
+    },
+    SET_CURRENT_TAB(state, currentTab) {
+      state.currentTab = currentTab
     }
   },
   actions: {