/*
* 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
}
}
})
网友评论