tabbarPage.vue 4.6 KB
Newer Older
程默 committed
1 2 3 4
<!--
 tabbar
-->
<template>
李嘉林 committed
5 6
  <div>
    <web-view :src="pageUrl1" @error="handleError" @message="getMessage"></web-view>
程默 committed
7 8
    <div style="width: 100%;height: 90vh;display: flex;justify-content: center;align-items: center;"
    >
程默 committed
9 10 11 12 13 14
      <van-loading size="40px" type="spinner"></van-loading>
    </div>
  </div>
</template>

<script>
李嘉林 committed
15
let forUrlAddKey = require("mayi-front-tools/forUrlAddKey").default;
程默 committed
16 17 18
import {
  getUrlofLink,
  checkTabbarPage,
chengzhichun committed
19
  getUrlofQuery
程默 committed
20
} from "../utils/mayi.js";
李嘉林 committed
21
import { serialize, DFSImg} from "@/utils/index";
李嘉林 committed
22
import { getStoreInfo } from "@/utils/mayi.js";
李嘉林 committed
23 24
const app = getApp();
const { log } = app;
程默 committed
25

程默 committed
26 27 28 29 30 31 32 33 34 35 36
export default {
  props: {
    index: {
      type: Number,
      default: 1,
    },
  },
  data() {
    return {
      link: process.env.BASE_URL,
      page: "/",
李嘉林 committed
37
      params: "?mixid=" + this.$store.state.mixid,
程默 committed
38
      ss: "",
chengzhichun committed
39
      timestamp:"",
李嘉林 committed
40 41
      isMiniPage : false,
      showPage : true,
李嘉林 committed
42
      pageUrl1: "",
程默 committed
43 44 45 46
    };
  },
  computed: {
    pageUrl() {
李嘉林 committed
47 48
      console.log(this.link, '******', this.page, '-------', this.params, '++++++++')
      this.params +=
程默 committed
49
        `&native_test=1&tabbar=${this.index}&location_obj=${wx.getStorageSync(
程默 committed
50
          "location"
李嘉林 committed
51 52 53 54 55 56
        )}`
      // url添加门店信息参数
      let { offlineShopCode, offlineShopName } = getStoreInfo();
      if (offlineShopCode) {
        this.params+=`&offlineShopCode=${offlineShopCode}&offlineShopName=${offlineShopName}`
      }
李嘉林 committed
57 58 59 60
      let pageUrl1 = (this.page.startsWith('http://') || this.page.startsWith('https://'))? (this.page + this.params) : this.link+this.page+this.params
      let pageUrl = forUrlAddKey(decodeURIComponent(pageUrl1));
      console.log(pageUrl,'--pageUrl')
      return pageUrl + this.ss + this.timestamp;
李嘉林 committed
61
    }
程默 committed
62 63
  },
  onLoad(options) {
李嘉林 committed
64
    console.log('--onLoad')
李嘉林 committed
65
    let tabIndex = this.index>=this.mpApp.globalData.footerVal.componentData.list.length?this.mpApp.globalData.footerVal.componentData.list.length-1:this.index;
66
    this.params = this.$options.data.call(this).params
程默 committed
67 68
    let ss = wx.getStorageSync("sessionid");
    this.ss = ss ? `&sessionid=${ss}` : "";
李嘉林 committed
69 70 71 72
    let enterpriseAccount = wx.getStorageSync("enterpriseAccount");
    if(enterpriseAccount) {
      this.ss += enterpriseAccount ? `&enterpriseAccount=${enterpriseAccount}` : "";
    }
程智春 committed
73
    
程默 committed
74 75 76
    if (!ss) {
      this.params += this.params.includes("logOut") ? "" : "&logOut=true";
    }
程智春 committed
77 78 79 80

    if(wx.getStorageSync("workBox")){
      this.params += `&workBox=${wx.getStorageSync("workBox")}`
    }
程默 committed
81 82
    // tabbar 跳转
    let homeIndex = checkTabbarPage("/");
李嘉林 committed
83
    console.log(homeIndex,tabIndex,'--tabIndex')
李嘉林 committed
84 85
    homeIndex != 0 && homeIndex == tabIndex && (tabIndex = 0);
    console.log(this.mpApp.globalData.footerVal,tabIndex,this.mpApp.globalData.footerVal.componentData.list.length,'--this.mpApp.globalData.footerVal')
86 87 88
    let urlLink = this.mpApp.globalData.footerVal.componentData.list[tabIndex].link;
    console.log(urlLink,'---urlLink')
    if (urlLink) {
程默 committed
89
      this.page = getUrlofLink(
90
        urlLink
程默 committed
91
      );
程默 committed
92
      let query=serialize(options)
李嘉林 committed
93 94 95 96
      let urlPrams = urlLink.link.split('?')[1]?urlLink.link.split('?')[1]:"";
      console.log(query,'==================', this.params,'-----------------',urlPrams)
      // // 只兼容底部导航进入活动页面添加参数,跳转完成删除
      if(query){
李嘉林 committed
97
        this.params+='&'+query
李嘉林 committed
98 99 100
      } else {
        this.params+=urlPrams?'&'+urlPrams:''
      }
程默 committed
101
    }
chengzhichun committed
102
     let  reg = /^\/pages\//;
103 104 105
    console.log(this.pageUrl,'pageUrl======================',urlLink)
    if (urlLink) {
      if(reg.test(urlLink.link)){
chengzhichun committed
106
        wx.reLaunch({
107
          url: urlLink.link,
chengzhichun committed
108 109 110
        });
      }
    }
李嘉林 committed
111
    this.pageUrl1 = this.pageUrl;
程默 committed
112
  },
李嘉林 committed
113 114
  onShow(){
    console.log('--onShow--')
李嘉林 committed
115
    this.loadPage();
李嘉林 committed
116
  },
程默 committed
117
  methods: {
李嘉林 committed
118 119 120 121 122 123 124 125 126 127 128 129
    loadPage() {
      // 需要重新加载页面
      let pageList = ['/shopCart/shoppingCart'];
      let includesPage = pageList.filter(item => this.pageUrl.indexOf(item) > -1);
      console.log(includesPage,'-----includesPage')
      // 重载页面
      let reloadTabbarPage = wx.getStorageSync("reloadTabbarPage") || 0;
      if(reloadTabbarPage == 1 || includesPage.length>0){
        this.showPage = false;
        setTimeout(() => {
          this.showPage = true;
        }, 0);
李嘉林 committed
130
        this.pageUrl1 = this.pageUrl + `&tim=${new Date().getTime()}`
李嘉林 committed
131
        wx.removeStorageSync("reloadTabbarPage");
李嘉林 committed
132
        console.log(this.pageUrl1,'--this.pageUrl1')
李嘉林 committed
133 134
      }
    },
程默 committed
135 136 137 138 139
    handleError(data) {
      wx.showLoading({
        title: "网页加载失败 请右上角刷新",
      });
    },
李嘉林 committed
140 141 142 143
    //右上角分享时触发
    getMessage(res) {
      this.$emit("getMessage",res);
    },
程默 committed
144 145 146
  },
};
</script>