app.js 4.7 KB
/*
 * @Author: yangming yangming@didihu.com.cn
 * @Date: 2023-01-03 14:25:43
 * @LastEditors: yangming yangming@didihu.com.cn
 * @LastEditTime: 2023-01-04 17:57:08
 * @FilePath: \miniprogram\app.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// app.js
// 初始化sentry
// import sentryInit from "~/utils/sentryConfig/sentryInit";
// sentryInit();
import router from "./router/index.js";
import util from "./utils/util.js";
import eventbus from "./utils/evenbus";
// import USER from '~/api/usersApi/index'
import TRACK from "./utils/Track";
import Tracking from '~/utils/tracking'
const $Tracking = new Tracking()
import {
  busassistantApi
} from './api/api'

// 判断小程序是否需要更新
import getUpdateManager from "./utils/lib/wxUpdateManager";
import {
  setPageParams,
  login
} from "~/utils/appFn/index";

import {
  setSystem_info
} from "~/utils/cache/storageApi";

// 微信小程序异步使用 使用方法wx.pro+对应api即可 promisify 这个是配置单独某个api
// import { promisifyAll } from './utils/lib/wx-promise-pro'
// promisifyAll()

// 实例化对象存储
import {
  Storage
} from "./utils/cache/storage";
const $Storage = new Storage();
import wxApi from "./utils/utils_wx";
const { createVersionConfig } = require('./utils/versionConfig.js')
import {
  reportClick,
  reportStop,
  reportHide
} from './api/sopApi'
App({
  onLaunch(options) {
    /**挂载到wx对象 */
    wx.$authStatus = false;
    wx.$util = util;
    wx.$router = router;
    wx.$eventbus = eventbus;
    wx.$storage = $Storage; /** 挂载全局缓存方法 */
    wx.$api = wxApi;
    wx.$imgUrl =
      "https://img02.glsx.com.cn/weapp/resource/miniprogram-test/glsx/";
    // wx.$imgUrl = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/'
    wx.$Track = new TRACK(options, {
      onLoadFun: [
        reportClick
      ],
      onHideFun:[
        reportHide
      ]
    });
    wx.$tracking = $Tracking
    // wx.$imgUrl = 'https://img01.glsx.com.cn/weapp/resource/dj-shopmall/'
    // 存储设备信息
    wx.$versionConfig = createVersionConfig({
      request: {
        baseUrl: 'https://config-center-backend.glsx.com.cn/glsxAdmin/config'
      }
    })
    setSystem_info();
    const {
      scene,
      query: {
        pageType
      }
    } = wx.getEnterOptionsSync(),
      userInfo = $Storage.get("userInfo");
    if (userInfo && userInfo.userType && ![1011, 1012, 1013].includes(scene)) {
      if (
        (options.path.includes("shopMall") ||
          options.path.includes("packageShopmall")) &&
        !options.path.includes("packageExpandedGold") &&
        !pageType && !options.path.includes("GHUserLogin") && !options.path.includes("ghEquity") && options.path != "packageShopmall/packageMine/pages/integral/index/index"
      ) {
        setTimeout(() => {
          wx.reLaunch({
            url: "/packageStoreAssistant/packageAuth/pages/authentication/loading/loading",
          });
        }, 100);
      }

    }
  },
  onShow(options) {
    console.log(options)
    const {
      path
    } = options;
    getUpdateManager();
    setPageParams(options);
    const noPath = ["pages/tab", "pages/crowdfunding", "packageStoreAssistant", "pages/blank/blank", "packageShopmall/packageRescue/pages/accident/index/index", 'packageShopmall/packageExpandedGold/pages/activity/index/index', 'packageShopmall/packageMine/pages/integral/index/index']
    try {
      noPath.map(e => {
        if (path.startsWith(e)) throw true
      })
    } catch (error) {
      return
    }
    login()
  },
  // 获取公共数据
  getBaseData() {
    console.log("method")
    return new Promise((resolve, reject) => {
      busassistantApi.getDiscoverList().then(res => {
        console.log(res, '555');
        resolve(res.data)
      })
    })
  },
  /**兼容旧链接 */
  onPageNotFound(res) {
    console.log(res, "不存在的页面");
    wx.reLaunch({
      url: `/pages/pageNotFound/pageNotFound?res=${encodeURIComponent(
        JSON.stringify(res)
      )}`,
    });
  },
  async getVersionInfo(request) {
    if (request) this.globalData.versionData = null
    const {
      versionData
    } = this.globalData
    if (versionData) return versionData
    else {
      const res = await wx.$versionConfig.get({
        moduleUrl: 'mini-merchant',
        env: 'update'
      })
      this.globalData.versionData = res
      return res
    }
  },
  globalData: {
    merchantId: "101430",
    cheapGoodsList: [],
    isLoadingOver: false,
    pageParam: {
      appearance: 1,
      pageSize: 0,
      pageCount: 3
    },
    versionData: null,
    ROUTE_QUERY: {},
  },
  onHide() {
    util.customerbehavior(2)
  }
})