美文网首页
App.js 配置参数

App.js 配置参数

作者: 小米和豆豆 | 来源:发表于2021-06-18 15:57 被阅读0次
    /*
    * http引用 api定义
    */
    let Api = require('./http/api.js');
    let request = require('./http/request.js');
    let router = require('./utils/router.js');
    let store = require("./utils/store.js");
    /**
     * config 环境配置
     */
    let config = require("./env/index.js");
    let env = "Qa"; //  Qa  Prod
    App.config = config[env];
    /**
     * //版本号
     */
    App.version = '1.0.0';
    App({
      Api,
      router,
      get: request.fetch,
      post: (url, data, option = {}, needToken = true) => {
        option.method = 'post';
        return request.fetch(url, data, option, needToken)
      },
      put: (url, data, option = {}, needToken = true) => {
        option.method = 'PUT';
        return request.fetch(url, data, option, needToken)
      },
      delete: (url, data, option = {}, needToken = true) => {
        option.method = 'DELETE';
        return request.fetch(url, data, option, needToken)
      },
      onLaunch: function () {
       this.goLoginTips(this.setAuth)
      },
      globalData: {
        userInfo: null,
        _isAuth: false,
        _isLogin: false,
      },
      setAuth(isAuth,isLogin=null) {
        this.globalData._isAuth = isAuth;
        this.globalData._isLogin = isLogin;
      },
      //判断有没有授权
      goLoginTips(fn) {
        // 获取授权信息//判断登录
        wx.getSetting({
          success: res => {
            if (res.authSetting['scope.userInfo']) {
              fn(true);
            } else {
              fn(false);
            }
          }
        })  
      },
      //判断有没有登录;
      isLogin(){
        const token=store.getItem('token');
        const userInfo=store.getItem('userInfo');
        if(!!token&&!!userInfo['id']){
          return true
        }else{
          return false
        }
      }
    })
    

    相关文章

      网友评论

          本文标题:App.js 配置参数

          本文链接:https://www.haomeiwen.com/subject/qamqkltx.html