1 Star 0 Fork 397

mjy191/CRMEB_WechatApplet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
request.js 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
等风来,随风去 提交于 2020-07-04 18:42 . 更新3.2版本
import util from './util.js';
import authLogin from './autuLogin.js';
import { HEADER , TOKENNAME} from './../config.js';
/**
* 发送请求
*/
export default function request(api, method, data, {noAuth = false, noVerify = false})
{
let Url = getApp().globalData.url, header = HEADER;
if (!noAuth) {
//登录过期自动登录
if (!util.checkLogin()) return authLogin().then(res => { return request(api, method, data, { noAuth, noVerify}); });
}
if (getApp().globalData.token) header[TOKENNAME] = 'Bearer ' + getApp().globalData.token;
return new Promise((reslove, reject) => {
wx.request({
url: Url + '/api/' + api,
method: method || 'GET',
header: header,
data: data || {},
success: (res) => {
if (noVerify)
reslove(res.data, res);
else if (res.data.status == 200)
reslove(res.data, res);
else if (res.data.status == 402)
reslove(res.data, res);
else if ([410000, 410001, 410002].indexOf(res.data.status) !== -1) {
util.logout()
return authLogin().then(res => { return request(api, method, data, { noAuth, noVerify }); });
} else
reject(res.data.msg || '系统错误');
},
fail: (msg) => {
reject('请求失败');
}
})
});
}
['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
request[method] = (api, data, opt) => request(api, method, data, opt || {})
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
微信
1
https://gitee.com/mjy191/CRMEB_WechatApplet.git
git@gitee.com:mjy191/CRMEB_WechatApplet.git
mjy191
CRMEB_WechatApplet
CRMEB_WechatApplet
master

搜索帮助