Răsfoiți Sursa

动态tabbar修改

jwyu 3 ani în urmă
părinte
comite
14da7736a3
3 a modificat fișierele cu 22 adăugiri și 19 ștergeri
  1. 17 15
      mixin/index.js
  2. 2 4
      pages/activity/activity.vue
  3. 3 0
      store/modules/user.js

+ 17 - 15
mixin/index.js

@@ -10,20 +10,12 @@ const tabbarPathList=['pages/activity/activity','pages/buy/buy','pages/chart/cha
 
 module.exports = {
   watch: {
-    tabbar(){
-      const page = this.$mp&&this.$mp.page;
-      if(page&&tabbarPathList.includes(page.route)){
-        if (page&&typeof page.getTabBar === "function" && page.getTabBar()){;
-          page.getTabBar().setData({
-            list: this.tabbar,
-            selected:this.tabbar[0].pagePath
-          });
-        }
-      }
+    tabbarList(){
+      this.handleSetTabBarItem()
     }
   },
   computed: {
-    tabbar(){
+    tabbarList(){
       return store.state.user.tabbarList
     }
   },
@@ -49,22 +41,32 @@ module.exports = {
       globalBgMusic:uni.getBackgroundAudioManager()
     };
   },
-  onLoad() {
-    this.handleSetTabBarItem()
-  },
+  onLoad() {},
   onShow(){
     this.userInfo=this.$store.state.user.userInfo
     this.handleActivityListPageRefresh()
+    this.$store.dispatch('getTabBar')
+    this.handleSetTabBarItem()
   },
   methods: {
     // 设置tabbar的选中态
     handleSetTabBarItem(){
       const page = this.$mp&&this.$mp.page;
       const tabbarList=this.$store.state.user.tabbarList
+      if(!page||tabbarList.length==0) return
+      
+      let selected=page.route
+      // 如果用户的tabbar 改变了 并且他点击的tabbar选项正好不存在了 则重定向到第一个tabbar
+      let temarr=tabbarList.map(item=>item.pagePath)
+      if(tabbarPathList.includes(selected)&&!temarr.includes(selected)){
+        selected=tabbarList[0].pagePath
+        uni.switchTab({ url: `/${selected}` })
+      }
+
       if(tabbarPathList.includes(page.route)){
         if (page&&typeof page.getTabBar === "function" && page.getTabBar()) {
           page.getTabBar().setData({
-            selected: page.route,
+            selected: selected,
             list:tabbarList
           });
         }

+ 2 - 4
pages/activity/activity.vue

@@ -321,8 +321,7 @@ export default {
                 this.pupData.show=true
             }else if(res.code===403){
                 if(res.data.type=='contact'){
-                    this.pupData.content=`<p>您暂无权限参加此会议,若想参加请联系对口销售--${res.data.name}:</p>
-                                          <p>${res.data.mobile}</p>`
+                    this.pupData.content=`<p>您暂无权限参加此会议,若想参加请联系对口销售--${res.data.name}:${res.data.mobile}</p>`
                     this.pupData.mobile=res.data.mobile
                 }else if(res.data.type=='apply'){
                     this.pupData.content=`<p style="margin-top:20px">您暂无权限参加此会议,若想参加可以申请开通哦</p>`
@@ -385,8 +384,7 @@ export default {
                 this.pupData.show=true
             }else if(res.code===403){
                 if(res.data.type=='contact'){
-                    this.pupData.content=`<p>您暂无权限参加此活动,若想参加请联系对口销售--${res.data.name}:</p>
-                                          <p>${res.data.mobile}</p>`
+                    this.pupData.content=`<p>您暂无权限参加此活动,若想参加请联系对口销售--${res.data.name}:${res.data.mobile}</p>`
                     this.pupData.mobile=res.data.mobile
                 }else if(res.data.type=='apply'){
                     this.pupData.content=`<p style="margin-top:20px">您暂无权限参加此活动,若想参加可以申请开通哦</p>`

+ 3 - 0
store/modules/user.js

@@ -1,6 +1,7 @@
 import { apiUserInfo, apiUserTabBar } from "@/api/user";
 
 const token = uni.getStorageSync("token") || "";
+let lastTabbarList=[]//上次请求的tabbar数据
 const userModules = {
 	state: {
 		token: token,
@@ -22,6 +23,8 @@ const userModules = {
 
 		// 设置tabbar权限
 		setTabBar(state, data) {
+			if(lastTabbarList.toString()===data.toString()) return
+			lastTabbarList=data
 			// 默认的tabbar数据
 			let defaultTabBarList = [
 				{