App.vue 10.7 KB
Newer Older
程默 committed
1
<script>
李嘉林 committed
2
// import "@/utils/posthog"
程默 committed
3
import shop from "@/api/shop";
4
import spokesman from "@/api/spokesman";
程默 committed
5

程默 committed
6
import { themeColor, checkShowConditionIds } from "@/utils/mayi";
7
import { query_isEntry } from "@/utils/mayi_fenxiao";
张卓 committed
8

程默 committed
9
export default {
10 11 12
  created() {
    // NODE_ENV
    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
程默 committed
13
    console.log(extConfig, "-----------extConfig");
程默 committed
14
    if (JSON.stringify(extConfig) == "{}") {
李嘉林 committed
15 16 17 18 19 20 21
      let shopItem = {
        development: { mixid: "antgood", "shopid": 67},
        production: { "mixid":"qiyeCT", "shopid": 1045 },
        xhyx_uat: { "mixid":"xhyxshop", "shopid": 1 },
        xhyx_prod: { "mixid":"antgood", "shopid": 67 },
      }
      extConfig = shopItem[process.env.NODE_ENV];
程默 committed
22
    }
程默 committed
23 24


程默 committed
25
    console.log("1444444444", extConfig);
程智春 committed
26
    this.$store.commit("setExtConfig", extConfig.mixid);
程智春 committed
27
    this.$store.commit('setExtConfigInfo',extConfig)
程默 committed
28 29 30 31 32 33 34 35 36
    // 调用API从本地缓存中获取数据
    /*
     * 平台 api 差异的处理方式:  api 方法统一挂载到 mpvue 名称空间, 平台判断通过 mpvuePlatform 特征字符串
     * 微信:mpvue === wx, mpvuePlatform === 'wx'
     * 头条:mpvue === tt, mpvuePlatform === 'tt'
     * 百度:mpvue === swan, mpvuePlatform === 'swan'
     * 支付宝(蚂蚁):mpvue === my, mpvuePlatform === 'my'
     */

37 38 39 40
    let logs;
    if (mpvuePlatform === "my") {
      logs = mpvue.getStorageSync({ key: "logs" }).data || [];
      logs.unshift(Date.now());
程默 committed
41
      mpvue.setStorageSync({
42
        key: "logs",
程默 committed
43
        data: logs,
44
      });
程默 committed
45
    } else {
46 47 48
      logs = mpvue.getStorageSync("logs") || [];
      logs.unshift(Date.now());
      mpvue.setStorageSync("logs", logs);
程默 committed
49
    }
程默 committed
50 51
    // 初始
    this.getShopInfo(extConfig);
程智春 committed
52

1  
程智春 committed
53 54


程默 committed
55
    // 页面配置信息
程默 committed
56
    this.getThemePage(extConfig);
1  
程智春 committed
57

58 59 60
    // 商城配置
    this.shopConfiguration()

1  
程智春 committed
61 62 63 64 65 66 67 68 69 70
    setTimeout(() => {
      let mpApp = getApp();

      console.log(mpApp, "this.mpApp");


      mpApp.getShopInfo = this.getShopInfo
      mpApp.getThemePage = this.getThemePage
    },300)

程默 committed
71 72
  },
  methods: {
程默 committed
73
    async setVisible(pageList, cb) {
程默 committed
74
      // 首页显示条件
程默 committed
75 76 77 78 79
      let pageInfo = pageList.filter((item) => item.pageCode == 1)[0];
      let pageData = JSON.parse(pageInfo.pageData);
      // 查询显示条件id
      let showConditionIds = checkShowConditionIds(pageData);
      // 查询可显示的条件
程默 committed
80 81
      let { data: ids ,isAreaNavigation} = await this.checkCondition(showConditionIds);
      // 没有定位组件
李嘉林 committed
82 83 84 85
      // if (!isAreaNavigation) {
      //   cb()
      //   return
      // }
程默 committed
86 87 88 89
      // 设置visible
      pageInfo.pageData = this.updateCondition(pageData, ids);
      console.log(showConditionIds, "--------------5454", ids, pageInfo);
      cb()
程默 committed
90
    },
程默 committed
91 92
    checkCondition({ allCondition }) {
      return new Promise((resolve, reject) => {
程默 committed
93
        // 获取
程默 committed
94 95 96 97 98 99 100
        let params = { showConditionIds:allCondition, region: "" };
        shop
          .checkShowCondition(params)
          .then((res) => {
            console.log(params, "check显示条件", res.data);
            if (res.data.code == 200) {
              resolve(res.data);
程默 committed
101
            }
程默 committed
102 103 104 105 106 107 108 109 110 111 112 113
          })
          .catch((err) => {
            console.log("check显示条件失败", err);
          });
      });
    },
    updateCondition(pageData, ids) {
      pageData.forEach((item) => {
        pollCondition(item);
      });
      function pollCondition(data) {
        if (Object.prototype.toString.call(data) === "[object Object]") {
李嘉林 committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
          if (data.visible && data.visible > 1 && data.visibleCopy == undefined) {
              data.visibleCopy = data.visible;
              console.log(data.visibleCopy,'--data.visibleCopy')
          }
          if ((data.visibleCopy == 2 && wx.getStorageSync('sessionid')) ||
              (data.visibleCopy == 3 && !wx.getStorageSync('sessionid'))
          ) {
              data.visible = 1;
          } else if ((data.visibleCopy == 2 && !wx.getStorageSync('sessionid')) || 
              (data.visibleCopy == 3 && wx.getStorageSync('sessionid'))
          ) {
              data.visible = 0;
          } else {
            if (data.condition != "" && data.condition != undefined) {
              data.visible = ids.some((item) => {
                return item == data.condition;
              })
                ? 1
                : 0;
            }
程默 committed
134 135 136 137 138 139 140
          }
          for (const key in data) {
            if (data.hasOwnProperty(key)) {
              const element = data[key];
              if (
                Object.prototype.toString.call(element) === "[object Object]"
              ) {
李嘉林 committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
                if (element.visible && element.visible > 1 && element.visibleCopy == undefined) {
                  element.visibleCopy = element.visible;
                }
                if ((element.visibleCopy == 2 && wx.getStorageSync('sessionid')) ||
                    (element.visibleCopy == 3 && !wx.getStorageSync('sessionid'))
                ) {
                    element.visible = 1;
                } else if ((element.visibleCopy == 2 && !wx.getStorageSync('sessionid')) || 
                    (element.visibleCopy == 3 && wx.getStorageSync('sessionid'))
                ) {
                    element.visible = 0;
                } else {
                  if (element.condition != "" && element.condition != undefined) {
                    console.log("979797", element.condition);
                    element.visible = ids.some((item) => {
                      return item == element.condition;
                    })
                      ? 1
                      : 0;
                  }
程默 committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
                }
                pollCondition(element);
              } else if (
                Object.prototype.toString.call(element) === "[object Array]" &&
                element.length > 0
              ) {
                element.forEach((item) => {
                  pollCondition(item);
                });
              }
            }
          }
        }
      }

      return JSON.stringify(pageData);
程默 committed
177
    },
程默 committed
178
    //商城配置
程默 committed
179
    getShopInfo({ mixid }) {
程默 committed
180
      shop.getShopInfo({ shopMixId: mixid }).then((res) => {
李嘉林 committed
181
        console.log("--app---getShopInfo")
程默 committed
182
        if (res.data.code == 200) {
程默 committed
183 184 185
          // 收集用户数据
          this.$mpBehavior.init("mayi-moblie-shop-mp", res.data.data.id, {
            mode: process.env.NODE_ENV,
侯体倬 committed
186 187
            gid: res.data.data.groupId,
            mixid: mixid
程默 committed
188 189
          })

程默 committed
190 191 192 193 194 195
          let mpApp = getApp();
          // 商城基本数据
          mpApp.shopCallBack && mpApp.shopCallBack(res.data.data);

          let defaultComponentModel = res.data.data.shopThemeData;
          this.mpApp.globalData.shopThemeData = res.data.data.shopThemeData;
程默 committed
196
          this.mpApp.globalData.shopInfo = res.data.data;
李嘉林 committed
197 198 199 200 201
          if(this.mpApp.globalData.shopInfo.whetherOpenEnterprisesWantGoods - 0 == 0) {
            wx.removeStorage({
              key: "enterpriseAccount"
            });
          }
程默 committed
202

程默 committed
203 204 205 206 207 208 209 210
          // 获取底部栏数据
          let val = JSON.parse(defaultComponentModel);
          if (val && val.defaultComponentModel) {
            // 底部导航数据赋值
            let footerVal = val.defaultComponentModel.filter((item, index) => {
              return item.componentName == "底部导航";
            })[0];

程默 committed
211 212
            // 显示条件(未处理)
            footerVal.componentData.list=footerVal.componentData.list.filter(item=>item.visible==undefined || item.visible==1) || [];
213 214 215 216 217
            footerVal.componentData.list.forEach(ele=>{
              if(ele.link.name=="分销员中心" || ele.link.name=="分销商中心") {
                ele.show = false;
              }
            })
程默 committed
218 219 220 221 222 223
            this.mpApp.globalData.footerVal = footerVal;
            // app中异步数据回调 底部栏数据
            if (mpApp.footerCallBack) {
              mpApp.footerCallBack(footerVal);
            }
          }
程默 committed
224 225

          // 设置主题色
程默 committed
226 227
          themeColor["--main-color"] = val.themeColor.mainColor;
          themeColor["--minor-color"] = val.themeColor.minorColor;
李嘉林 committed
228
          mpApp.themeColorCallBack(themeColor);
程智春 committed
229
          mpApp.themeColor = themeColor
李嘉林 committed
230 231 232 233 234 235 236 237 238

          wx.setStorage({
            key: "shopName",
            data: res.data.data.shopName
          });
          wx.setStorage({
            key: "logoUrl",
            data: process.env.IMG_DOMAIN + res.data.data.logoUrl
          });
程默 committed
239 240
          //
          console.log(this.mpApp, "mmmmm74", themeColor);
李嘉林 committed
241 242 243 244 245 246 247 248 249 250
          // 强制登录
          if(res.data.data.whetherToForceLogin == 1 && !wx.getStorageSync('sessionid')) {
            let backUrl = `/pages/home/main`;
            const url = `/pages/login/main?back=${encodeURIComponent(
              backUrl
            )}&hideBack=1`;
            wx.navigateTo({
              url: url
            });
          }
程默 committed
251 252 253
        }
      });
    },
254 255 256 257 258 259 260 261 262 263
    //商城配置
    shopConfiguration(){
      shop.get_shop_configuration().then(res=>{
        if (res.data.code == 200) {
          let mpApp = getApp();
          mpApp.shop_configuration = res.data.data
          console.log(mpApp.shop_configuration,'mpApp.shop_configuration');
        }
      })
    },
程默 committed
264 265
    async getThemePage({ mixid, shopid }) {
      await shop
程默 committed
266
        .themePagesInfo({
程默 committed
267 268
          shopid,
          shopMixId: mixid,
李嘉林 committed
269
          homePageFlag: false
程默 committed
270 271 272 273 274 275
        })
        .then((response) => {
          if (response.data.code == 200) {
            let data = response.data.data;
            if (Array.isArray(data) && data.length > 0) {
              console.log("90", data);
程默 committed
276
              // 设置显示条件
李嘉林 committed
277
              // 首页
程默 committed
278 279 280 281 282 283 284
              this.setVisible(data,()=>{
                console.log(1711111111);
                this.mpApp.globalData.pageList = data;
                // app中异步数据回调 底部栏数据
                if (this.mpApp.pageCallBack) {
                  this.mpApp.pageCallBack(data);
                }
程智春 committed
285 286 287 288

                if(this.mpApp.indexBgCallBack){
                  this.mpApp.indexBgCallBack(data)
                }
程默 committed
289
              });
程默 committed
290 291 292 293 294 295

            }
          }
        })
        .catch((err) => {});
    },
程默 committed
296
    // ---
程默 committed
297
  },
程默 committed
298 299
  onError(data) {
    console.log(data, "js异常捕获");
程默 committed
300
    this.$mpAnalytics.recordError({
程默 committed
301
      data,
程默 committed
302
      keyword: data,
程默 committed
303
      extendsInfo: {
程默 committed
304 305
        mixid: this.$store.state.mixid || null,
      },
306
    });
程默 committed
307
  },
308
};
程默 committed
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
</script>

<style>
.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 200rpx 0;
  box-sizing: border-box;
}
/* this rule will be remove */
* {
  transition: width 2s;
  -moz-transition: width 2s;
  -webkit-transition: width 2s;
  -o-transition: width 2s;
}
程默 committed
328
/* @import url("../static/nicon/iconfont.css"); */
程智春 committed
329
@import url("../static/font/iconfont.css");
330
@import url("../static/css/common.scss");
程默 committed
331
</style>