Browse Source

optimize tabbar change

Zhengxiaowei 5 năm trước cách đây
mục cha
commit
8ccf6a7698

+ 1 - 1
src/api/utils.js

@@ -87,7 +87,7 @@ const refreshToken = () => {
 
 // 检查token的有效期
 const checkToken = t => {
-  return new Date() < t.time;
+  return new Date().valueOf() < t.time;
 };
 
 // 设置token

+ 11 - 3
src/views/Category/index.ux

@@ -68,7 +68,12 @@ import { pageLoad } from "../../helper";
 import storage from '@system.storage';
 
 export default {
-  props: {},
+  props: {
+    tabindex: {
+      type: Number,
+      default: 0
+    }
+  },
   data() {
     return {
       channel: [],
@@ -159,9 +164,12 @@ export default {
       console.log("e", e);
     })
   },
-  onInit() {
-    this.getCategory();
+  watchPropsChange(v) {
+    if (v === 1) this.getCategory();
   },
+  onInit() {
+    this.$watch('tabindex', 'watchPropsChange');
+  }
 }
 </script>
 

+ 8 - 3
src/views/Home/index.ux

@@ -71,7 +71,12 @@ import { getHomeList } from "../../api";
 import storage from '@system.storage';
 
 export default {
-  props: {},
+  props: {
+    tabindex: {
+      type: Number,
+      default: 0
+    }
+  },
   data() {
     return {
       typeList: [
@@ -89,8 +94,8 @@ export default {
       current: 0
     }
   },
-  onInit() {
-    this.getCityListByTabChange();
+  async onInit() {
+    await this.getCityListByTabChange();
     this.$watch('current', 'getCityListByTabChange')
   },
   typeChange(index) {

+ 3 - 3
src/views/Index/index.ux

@@ -9,10 +9,10 @@
     <div class="index-wrap">
       <tabs class="tab-content" onchange="tabbarChange" index="{{current}}">
         <tab-content>
-          <home-page @change="pageSwitch"></home-page>
-          <category-page></category-page>
+          <home-page @change="pageSwitch" tabindex="{{current}}"></home-page>
+          <category-page tabindex="{{current}}"></category-page>
           <shelf-page @change="pageSwitch" tabindex='{{current}}'></shelf-page>
-          <my-page @customer="openCustomer"></my-page>
+          <my-page @customer="openCustomer" tabindex="{{current}}"></my-page>
         </tab-content>
       </tabs>
       <div class="fixed-tabbar">

+ 10 - 2
src/views/My/index.ux

@@ -68,19 +68,27 @@
 import router from "@system.router";
 import { getUserInfo } from "../../api/index";
 export default {
-  props: {},
+  props: {
+    tabindex: {
+      type: Number,
+      default: 0
+    }
+  },
   data() {
     return {
       user: {}
     }
   },
   onInit() {
-    this.getUser();
+    this.$watch('tabindex', 'watchPropsChange');
   },
   async getUser() {
     let user = await getUserInfo();
     this.user = user;
   },
+  watchPropsChange(v) {
+    if (v === 3) this.getUser();
+  },
   showCustomerQrcode() {
     this.$emit('customer');
   },

+ 2 - 1
src/views/Shelf/index.ux

@@ -87,7 +87,8 @@ export default {
     }
   },
   onInit() {
-    this.getUserShelfBooks()
+    console.log("tabindex:", this.tabindex);
+    // this.getUserShelfBooks()
     this.$watch('isDelMode', 'listenMode')
     this.$watch('tabindex', 'watchPropsChange')
   },