app.js 2.23 KB
//app.js
const ald = require('./utils/ald-stat.js')
let fetchApi = require('./http/fetch-api.js');
let api = require('./http/api');
let config = require('./config');
let router = require('./router/index');
let store = require('./utils/stroage');

require('./http/mock-data');

App({
  api: api,
  get: fetchApi.fetch,
  post: (params) => {
    params.method = 'post';
    return fetchApi.fetch(params);
  },
  stat: (data) => {
    let params = {}
    params.mode = 'log';
    params.mode = 'log';
    params.sid = false;
    params.url = api.stat;
    params.data = data;
    params.method = "POST";
    return fetchApi.fetch(params);
  },
  config: config,
  router: router,
  store: store,
  onLaunch(options) {
    let scene = options.scene;
    // 根据场景值判断分享入口
    // https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
    // 小程序由分享进入
    // if (scene == 1007 || scene == 1008 || scene == 1011 || scene == 1012 || scene == 1013) {
    //   this.globalData.share = true
    // } else {
    //   this.globalData.share = false
    // };
    const MenuRect = wx.getMenuButtonBoundingClientRect();
    const statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
    const height = (MenuRect.top - statusBarHeight) * 2 + MenuRect.height + MenuRect.top;
    this.globalData.statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
    this.globalData.barHeight = height;
    this.share();
  },
  globalData: {
    share: false,
    indexInfo: null,
    userInfo: null,
    wxcode: store.getItem("wxcode"),
    tlMemberCode: "",
  },
  //重写分享方法
  share: function () {
    //监听路由切换
    //间接实现全局设置分享内容
    wx.onAppRoute(function (res) {
      //获取加载的页面
      let pages = getCurrentPages();
      //获取当前页面的对象
      let view = pages[pages.length - 1];
      let data;
      if (view) {
        data = view.data;
        if (!data.isOverShare) {
          data.isOverShare = true;
          view.onShareAppMessage = function (res) {
            //分享配置
            return {
              title: '模板标题',
              path: 'pages/index/index',
              // imageUrl: ''
            };
          };
        }
      }
    })
  },
})