app.js 1.79 KB
//app.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({
  get: fetchApi.fetch,
  post: (params) => {
    params.method = 'post';
    return fetchApi.fetch(params);
  },
  api: api,
  config: config,
  router: router,
  store: store,
  onLaunch(options) {
    console.log("options:", options);
    this.share()
  },
  globalData: {
    indexInfo: null,
    userInfo: null,
    wxcode: store.getItem("wxcode"),
    tlMemberCode: "",
    giftInfo: null, // 来自 gift-shop
    addressEditInfo: null, // 编辑时的临时对象
    // postMessageData: null,
  },
  //重写分享方法
  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'
            };
          };
        }
      }
    })
  },
  // 获取用户基本信息
  queryIndex(query = {
    auth: true
  }) {
    return new Promise((resolve, reject) => {
      this.post({
        url: this.api.member,
        data: {},
        loading: true,
      }).then((result) => {
        this.globalData.indexInfo = result;
        // this.globalData.userInfo = result.userInfo;
        resolve(result)
      }).catch((err) => {
        reject();
      });
    });
  }
})