main.js 7.45 KB
Newer Older
程默 committed
1 2
import Vue from 'vue'
import App from './App'
程默 committed
3
import Store from './store/index'
程默 committed
4
import "../static/nicon/iconfont.css"
李嘉林 committed
5
import goodsApi from "./api/goods"
程智春 committed
6
import orderApi from "./api/order"
李嘉林 committed
7
import promoteApi from "./api/promote";
程智春 committed
8
import indexApi from './api/index'
李嘉林 committed
9
import { createdUserJWTApi, getBcakUrlApi } from "./api/daoke";
10
import cartApi from './api/cart'
李嘉林 committed
11
import classificationApi from "./api/classification";
12
import spokesmanApi from './api/spokesman'
李嘉林 committed
13
import { DFSImg, concatUrl, serialize } from "@/utils/index";
14 15
//一些js工具类
import tool from "@/utils/tool";
柳士祥 committed
16
var log = require('./utils/log')
张卓 committed
17
import fenxiaoModel from "@/utils/fenxiaoModel";
李嘉林 committed
18 19 20 21 22 23 24
import {
  $themeAddToCard,
  $themeArticleLike,
  getCoupon,
  themeMemberCardClick
} from "@/utils/mayi";
// import { $themeToLink, $themeAddToCard, $themeArticleLike } from "@/utils/mayi";
李嘉林 committed
25
import "@/utils/themeModule";
程默 committed
26
// import { themeToLinkInit } from "@/utils/themeModule";
程智春 committed
27
import shop from "./api/shop";
张卓 committed
28
import spokesman from "@/api/spokesman";
侯体倬 committed
29
import live from "@/api/live"
程默 committed
30 31 32

Vue.config.productionTip = false
App.mpType = 'app'
程默 committed
33 34
Vue.prototype.$store = Store

程默 committed
35 36
// 用户行为收集
console.log(Store.state,'---35')
程默 committed
37
let mpBehavior = require("../node_modules/mayi-analytics/dist/mayi.mpBehavior")
程默 committed
38 39
Vue.prototype.$mpBehavior = mpBehavior;

程默 committed
40
// 异常监控(行为收集)
程默 committed
41 42 43
let mpAnalytics = require("../node_modules/mayi-analytics/dist/mayi.mpAnalytics.js")
    .default;
mpAnalytics.init({
程默 committed
44
    url: process.env.NODE_ENV == 'production' ? "https://analytics.mayi888.com/ma.gif" : "https://analytics.mayi888.cn/ma.gif", //错误上报地址
程默 committed
45 46 47 48
    app: "mayi-mp-shop",//项目名称
    wx
});
Vue.prototype.$mpAnalytics = mpAnalytics;
程默 committed
49 50 51

const app = new Vue(App)
app.$mount()
程默 committed
52 53

// glob挂载到
程默 committed
54
let mpApp = getApp();
程默 committed
55
Vue.prototype.mpApp = mpApp
李嘉林 committed
56
// 初始化
张卓 committed
57 58 59 60 61 62 63 64 65 66 67 68
mpApp.fenxiaoModel = new fenxiaoModel({
  query_login_spoken:spokesman.query_login_spoken,
  becomepokesmanCustomer:spokesman.becomepokesmanCustomer,
  saveCustomerInviterInviteeRel:spokesman.saveCustomerInviterInviteeRel,
  getHomePageQuickAccess:spokesman.getHomePageQuickAccess,
  query_isEntry:spokesman.query_isEntry,
  getDistributorHomepage:spokesman.getDistributorHomepage,
  getDistributorHomepageGoodsList: spokesman.getDistributorHomepageGoodsList,
  getSpokesmanidByShare: spokesman.getSpokesmanidByShare,
  oneClickShopQuickCopy: spokesman.oneClickShopQuickCopy,
  apply_for_withdraw: spokesman.apply_for_withdraw
});
李嘉林 committed
69 70 71 72 73 74 75 76 77
// 多主题方法初始化
global.themeToLinkInit({
  homeNative: 2,
  wx,
  getCoupon,
  themeMemberCardClick,
  requireFun: {
    createdUserJWT: createdUserJWTApi,
    getBcakUrl: getBcakUrlApi
chengzhichun committed
78 79
  },
  extend:Store.state.extConfig
李嘉林 committed
80
});
程默 committed
81
// 数据异步回调函数
程默 committed
82
// 商城
程默 committed
83
mpApp.shopCallBack = function () { }
程默 committed
84
// 多主题页面
程默 committed
85
mpApp.pageCallBack = function () { }
程默 committed
86
// 底部栏
程默 committed
87 88 89
mpApp.footerCallBack = function () { }
// webview变化
mpApp.webviewCallBack = function () { }
李嘉林 committed
90
mpApp.shareInit = function () {};
李嘉林 committed
91
mpApp.themeColorCallBack = function () {};
程默 committed
92

李嘉林 committed
93 94 95 96 97
mpApp.indexBgCallBack = function () { }
// 打开筛选商品开关
mpApp.openFilterGoods = function () { }
// 筛选弹窗点击确认
mpApp.getFilterGoodsData = function () { }
程智春 committed
98

侯体倬 committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
/**
 * 组件点击行为收集
 * @param {event} event 原生事件
 * @param {*} componentInfo 完整信息
 * @param {*} itemInfo 具体信息
 */
mpApp.trackCpn = (event, componentInfo, itemInfo) => {
  console.log('tzBehavior测试-----', event);
  let x = 0, y = 0;
  if (event) {
    if (event.x || event.detail.x) { x = event.x || event.detail.x }
    if (event.y || event.detail.y) { y = event.y || event.detail.y }
  }
  mpBehavior.trackEvent('cpn_click', {
    xAxis: x.toFixed(2) || 0, // x轴
    yAxis: y.toFixed(2) || 0, // y轴
    cpnInfo: JSON.stringify(componentInfo), // 完整信息
    itemInfo: JSON.stringify(itemInfo) || '' // 具体信息
  })
}

李嘉林 committed
120 121
// 全局数据
mpApp.processEnv = process.env;
程默 committed
122
// 全局跳转 data为link对象
李嘉林 committed
123
// mpApp.$themeToLink = $themeToLink
程默 committed
124
console.log('3555555', wx)
李嘉林 committed
125 126
// 全局加入购物车
mpApp.$themeAddToCard = $themeAddToCard
李嘉林 committed
127 128
// 文章点赞
mpApp.$themeArticleLike = $themeArticleLike
程默 committed
129
// api
李嘉林 committed
130
mpApp.goodsApi = goodsApi;
程智春 committed
131
mpApp.orderApi = orderApi;
李嘉林 committed
132
mpApp.promoteApi = promoteApi;
程智春 committed
133
mpApp.indexApi = indexApi;
134
mpApp.cartApi = cartApi;
李嘉林 committed
135
mpApp.classificationApi = classificationApi;
李嘉林 committed
136
mpApp.DFSImg = DFSImg;
张卓 committed
137
mpApp.concatUrl = concatUrl;
138
mpApp.spokesmanApi = spokesmanApi
程智春 committed
139

程智春 committed
140 141
mpApp.getThemePage = getThemePage

程智春 committed
142
mpApp.themeColor = {}
柳士祥 committed
143
mpApp.log = log
144
mpApp.tool = tool
程智春 committed
145 146 147 148 149 150

function getThemePage({mixid,shopid}) {
  shop
    .themePagesInfo({
      shopid,
      shopMixId: mixid,
李嘉林 committed
151
      homePageFlag: true
程智春 committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    })
    .then((response) => {
      if (response.data.code == 200) {
        let data = response.data.data;
        if (Array.isArray(data) && data.length > 0) {
          console.log("90", data);

          mpApp.globalData.pageList = data;
          // app中异步数据回调 底部栏数据
          if (mpApp.pageCallBack) {
            mpApp.pageCallBack(data);
          }
        }
      }
    })
    .catch((err) => {});
}

程智春 committed
170

侯体倬 committed
171 172 173 174 175 176 177 178 179 180
// 当前用户 id
let userId
// 分销员 id
let spokesmanId
/**
 * 全局页面切换监听
 */
wx.onAppRoute(res => {
  // 获取当前页面信息
  let currentPage = getCurrentPages()
李嘉林 committed
181 182
  console.log(currentPage,'--currentPage')
  console.log(res,'--res')
侯体倬 committed
183
  // let fromPath = currentPage[currentPage.length - 1].__displayReporter.showReferpagepath
李嘉林 committed
184 185 186 187 188 189 190 191 192 193 194 195
  let whetherToForceLogin = mpApp.globalData.shopInfo && mpApp.globalData.shopInfo.whetherToForceLogin || 0
  log.info("wx.onAppRoute", res, mpApp.globalData.shopInfo, whetherToForceLogin, wx.getStorageSync('sessionid'), res.path != "pages/login/main");
  console.log(res,mpApp.globalData.shopInfo,whetherToForceLogin,wx.getStorageSync('sessionid'),res.path !="pages/login/main",'---------wx.onAppRoute')
  if (whetherToForceLogin == 1 && !wx.getStorageSync('sessionid') && res.path !="pages/login/main") {
    let backUrl = `/pages/home/main`;
    const url = `/pages/login/main?back=${encodeURIComponent(
      backUrl
    )}&hideBack=1`;
    wx.navigateTo({
      url: url
    });
  }
侯体倬 committed
196
  new Promise((resolve) => {
李嘉林 committed
197
    if (!spokesmanId) {
侯体倬 committed
198 199
      // 获取当前分销员 id
      spokesman.getSpokesmanidByShare().then(res => {
李嘉林 committed
200 201 202 203
        Store.commit("setSpokesmanInfo",res.data.data);
        if (res.data.data.spokesmanId) {
          spokesmanId = res.data.data.spokesmanId
        }
侯体倬 committed
204 205 206 207
      })
    }
    if (!userId) { // 防止多次调用
      // 获取当前用户 id
李嘉林 committed
208 209
      live.getUserInfo().then(res => {
        if (res.data.code == 200) {
210
          Store.commit("setShopUserInfo", res.data.data);
李嘉林 committed
211 212 213 214 215
          wx.setStorageSync('loginUserInfo',res.data.data ? res.data.data : {})
          userId = res.data.data ? res.data.data.userId : ''
        }

      })
侯体倬 committed
216
    }
李嘉林 committed
217
    resolve();
侯体倬 committed
218
  }).then(() => {
李嘉林 committed
219
    let trackPageViewQuery = {
侯体倬 committed
220 221 222
      title: '',
      location: res.path,
      // path: fromPath.substring(0, fromPath.length - 5),
李嘉林 committed
223 224 225 226 227 228 229
      path: `${res.path}${serialize(res.query)?('?'+serialize(res.query)):''}`,
      sales: spokesmanId || "",
      userId: userId || ""
    }
    log.info("mpBehavior.trackPageView",trackPageViewQuery)
    console.log("mpBehavior.trackPageView",trackPageViewQuery)
    mpBehavior.trackPageView(trackPageViewQuery);
侯体倬 committed
230 231
  })
})
程智春 committed
232 233


234
// if (!mpApp.globalData.setPopupStorage){
程智春 committed
235

236 237 238 239 240 241 242 243 244
//   let popUpList = wx.getStorageSync('popUpList') || []
//   let arr = []
//   popUpList.forEach(item=> {
//     arr.push(item)
//     wx.removeStorageSync(item)
//   })
//   arr.forEach(item => {
//     popUpList.splice(popUpList.indexOf(item),1)
//   })
程智春 committed
245

246
//   wx.setStorageSync('popUpList', popUpList)
程智春 committed
247

侯体倬 committed
248
// }