app.js 1.14 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: function () {},
  globalData: {
    indexInfo: null,
    userInfo: null,
    wxcode: store.getItem("wxcode"),
    tlMemberCode: ""
  },
  // 获取用户基本信息
  queryIndex() {
    return new Promise((resolve, reject) => {
      this.post({
        url: this.api.index,
        data: {},
        loading: true,
      }).then((result) => {
        this.globalData.indexInfo = result;
        this.globalData.userInfo = result.userInfo;
        if (result.isNeedAuth == 1) {
          //需要授权
          this.router.push({
            path: "authorize"
          })
          reject();
          // resolve();
        } else {
          resolve(result)
        }
      }).catch((err) => {
        reject();
      });
    });
  }
})