You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.8 KiB
75 lines
2.8 KiB
2 years ago
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
var config_1 = require("./config");
|
||
|
var words_1 = require("./words");
|
||
|
function request(_a) {
|
||
|
var method = _a.method, url = _a.url, _b = _a.options, options = _b === void 0 ? {} : _b, _c = _a.ifToken, ifToken = _c === void 0 ? true : _c;
|
||
|
return new Promise(function (resolve, reject) {
|
||
|
var header = {};
|
||
|
if (ifToken) {
|
||
|
header = {
|
||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||
|
'Authorization': wx.getStorageSync('token')
|
||
|
};
|
||
|
}
|
||
|
else {
|
||
|
header = {
|
||
|
'Content-Type': 'application/json; charset=UTF-8'
|
||
|
};
|
||
|
}
|
||
|
wx.request({
|
||
|
url: "" + config_1.config.apiUrl + url,
|
||
|
method: method,
|
||
|
data: method === 'GET' ? options : JSON.stringify(options),
|
||
|
header: header,
|
||
|
success: function (response) {
|
||
|
if (response.statusCode === 200) {
|
||
|
if (response.data.code === 0) {
|
||
|
resolve(response.data);
|
||
|
}
|
||
|
else {
|
||
|
var _a = response.data, code = _a.code, msg = _a.msg;
|
||
|
if (code == 10005 || code == 10006 || code == 10007) {
|
||
|
console.log("登录失效");
|
||
|
getApp().toGuidePageAfterHint();
|
||
|
}
|
||
|
else if (code < 10000 && code >= 8000) {
|
||
|
wx.showToast({
|
||
|
title: msg,
|
||
|
icon: "none",
|
||
|
duration: 3000,
|
||
|
});
|
||
|
}
|
||
|
else if (code != 0) {
|
||
|
wx.showToast({
|
||
|
title: words_1.default.common.requestFail,
|
||
|
icon: "none",
|
||
|
duration: 1500,
|
||
|
});
|
||
|
}
|
||
|
console.log('response.data', response.data);
|
||
|
reject(response.data);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
wx.showToast({
|
||
|
title: '无法完成请求,请重新尝试。',
|
||
|
icon: 'none',
|
||
|
duration: 3000
|
||
|
});
|
||
|
reject(false);
|
||
|
}
|
||
|
},
|
||
|
fail: function (err) {
|
||
|
wx.showToast({
|
||
|
title: '网络不给力,请稍后重试',
|
||
|
icon: 'none',
|
||
|
duration: 3000
|
||
|
});
|
||
|
reject(err);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
exports.default = request;
|