App.vue 9.85 KB
Newer Older
程默 committed
1
<script>
程默 committed
2
import shop from "@/api/shop";
3
import spokesman from "@/api/spokesman";
程默 committed
4

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

程默 committed
8
export default {
9 10 11
  created() {
    // NODE_ENV
    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
程默 committed
12
    console.log(extConfig, "-----------extConfig");
程默 committed
13
    if (JSON.stringify(extConfig) == "{}") {
柳士祥 committed
14
      extConfig = process.env.NODE_ENV == "development" ? { mixid: "antgood", shopid: 67}:{ "mixid":"CL", "shopid":1166 };
程默 committed
15
    }
程默 committed
16 17


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

30 31 32 33
    let logs;
    if (mpvuePlatform === "my") {
      logs = mpvue.getStorageSync({ key: "logs" }).data || [];
      logs.unshift(Date.now());
程默 committed
34
      mpvue.setStorageSync({
35
        key: "logs",
程默 committed
36
        data: logs,
37
      });
程默 committed
38
    } else {
39 40 41
      logs = mpvue.getStorageSync("logs") || [];
      logs.unshift(Date.now());
      mpvue.setStorageSync("logs", logs);
程默 committed
42
    }
程默 committed
43 44
    // 初始
    this.getShopInfo(extConfig);
程智春 committed
45

1  
程智春 committed
46 47


程默 committed
48
    // 页面配置信息
程默 committed
49
    this.getThemePage(extConfig);
1  
程智春 committed
50

51 52 53
    // 商城配置
    this.shopConfiguration()

1  
程智春 committed
54 55 56 57 58 59 60 61 62 63
    setTimeout(() => {
      let mpApp = getApp();

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


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

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

      return JSON.stringify(pageData);
程默 committed
170
    },
程默 committed
171
    //商城配置
程默 committed
172
    getShopInfo({ mixid }) {
程默 committed
173
      shop.getShopInfo({ shopMixId: mixid }).then((res) => {
程默 committed
174
        if (res.data.code == 200) {
程默 committed
175 176 177
          // 收集用户数据
          this.$mpBehavior.init("mayi-moblie-shop-mp", res.data.data.id, {
            mode: process.env.NODE_ENV,
侯体倬 committed
178 179
            gid: res.data.data.groupId,
            mixid: mixid
程默 committed
180 181
          })

程默 committed
182 183 184 185 186 187
          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
188
          this.mpApp.globalData.shopInfo = res.data.data;
程默 committed
189

程默 committed
190 191 192 193 194 195 196 197
          // 获取底部栏数据
          let val = JSON.parse(defaultComponentModel);
          if (val && val.defaultComponentModel) {
            // 底部导航数据赋值
            let footerVal = val.defaultComponentModel.filter((item, index) => {
              return item.componentName == "底部导航";
            })[0];

程默 committed
198 199
            // 显示条件(未处理)
            footerVal.componentData.list=footerVal.componentData.list.filter(item=>item.visible==undefined || item.visible==1) || [];
200 201 202 203 204
            footerVal.componentData.list.forEach(ele=>{
              if(ele.link.name=="分销员中心" || ele.link.name=="分销商中心") {
                ele.show = false;
              }
            })
程默 committed
205 206 207 208 209 210
            this.mpApp.globalData.footerVal = footerVal;
            // app中异步数据回调 底部栏数据
            if (mpApp.footerCallBack) {
              mpApp.footerCallBack(footerVal);
            }
          }
程默 committed
211 212

          // 设置主题色
程默 committed
213 214
          themeColor["--main-color"] = val.themeColor.mainColor;
          themeColor["--minor-color"] = val.themeColor.minorColor;
李嘉林 committed
215
          mpApp.themeColorCallBack(themeColor);
程智春 committed
216
          mpApp.themeColor = themeColor
李嘉林 committed
217 218 219 220 221 222 223 224 225

          wx.setStorage({
            key: "shopName",
            data: res.data.data.shopName
          });
          wx.setStorage({
            key: "logoUrl",
            data: process.env.IMG_DOMAIN + res.data.data.logoUrl
          });
程默 committed
226 227
          //
          console.log(this.mpApp, "mmmmm74", themeColor);
程默 committed
228 229 230
        }
      });
    },
231 232 233 234 235 236 237 238 239 240
    //商城配置
    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
241 242
    async getThemePage({ mixid, shopid }) {
      await shop
程默 committed
243
        .themePagesInfo({
程默 committed
244 245
          shopid,
          shopMixId: mixid,
李嘉林 committed
246
          homePageFlag: true
程默 committed
247 248 249 250 251 252
        })
        .then((response) => {
          if (response.data.code == 200) {
            let data = response.data.data;
            if (Array.isArray(data) && data.length > 0) {
              console.log("90", data);
程默 committed
253 254 255 256 257 258 259 260
              // 设置显示条件
              this.setVisible(data,()=>{
                console.log(1711111111);
                this.mpApp.globalData.pageList = data;
                // app中异步数据回调 底部栏数据
                if (this.mpApp.pageCallBack) {
                  this.mpApp.pageCallBack(data);
                }
程智春 committed
261 262 263 264

                if(this.mpApp.indexBgCallBack){
                  this.mpApp.indexBgCallBack(data)
                }
程默 committed
265
              });
程默 committed
266 267 268 269 270 271

            }
          }
        })
        .catch((err) => {});
    },
程默 committed
272
    // ---
程默 committed
273
  },
程默 committed
274 275
  onError(data) {
    console.log(data, "js异常捕获");
程默 committed
276
    this.$mpAnalytics.recordError({
程默 committed
277
      data,
程默 committed
278
      keyword: data,
程默 committed
279
      extendsInfo: {
程默 committed
280 281
        mixid: this.$store.state.mixid || null,
      },
282
    });
程默 committed
283
  },
284
};
程默 committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
</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
304
/* @import url("../static/nicon/iconfont.css"); */
程智春 committed
305
@import url("../static/font/iconfont.css");
306
@import url("../static/css/common.scss");
程默 committed
307
</style>