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.
107 lines
4.3 KiB
107 lines
4.3 KiB
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var global = require("../config/config.js");
|
|
var words_1 = require("../config/words");
|
|
var request = function (url, options) {
|
|
var token = wx.getStorageSync("token");
|
|
if (token == undefined || token == null) {
|
|
token = "";
|
|
}
|
|
return new Promise(function (resolve, reject) {
|
|
wx.request({
|
|
url: "" + global.config.apiUrl + url,
|
|
method: options.method,
|
|
data: options.method === "GET"
|
|
? options.data
|
|
: JSON.stringify(options.data),
|
|
header: {
|
|
"Content-Type": "application/json; charset=UTF-8",
|
|
Authorization: wx.getStorageSync("token"),
|
|
},
|
|
success: function (response) {
|
|
if (response.statusCode === 200) {
|
|
if (response.data.code === 0) {
|
|
if (response.data.data) {
|
|
var str = JSON.stringify(response.data.data);
|
|
response.data.data = JSON.parse(str.replaceAll("http://172.20.46.177/oss/", "https://www.yantai1s.com/oss/"));
|
|
}
|
|
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 == 10086) {
|
|
wx.showModal({
|
|
title: "提示",
|
|
content: msg,
|
|
success: function (res) {
|
|
if (res.confirm) {
|
|
wx.reLaunch({
|
|
url: "/pages/main/index",
|
|
});
|
|
}
|
|
else if (res.cancel) {
|
|
console.log("用户点击取消");
|
|
}
|
|
},
|
|
});
|
|
}
|
|
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: 2000,
|
|
});
|
|
reject(false);
|
|
}
|
|
},
|
|
fail: function (error) {
|
|
wx.showToast({
|
|
title: "网络问题,请稍后再试~",
|
|
icon: "none",
|
|
duration: 2000,
|
|
});
|
|
console.log("error", error);
|
|
reject(error.data);
|
|
},
|
|
});
|
|
});
|
|
};
|
|
function get(url, options) {
|
|
if (options === void 0) { options = {}; }
|
|
return request(url, { method: "GET", data: options });
|
|
}
|
|
function post(url, options) {
|
|
if (options === void 0) { options = {}; }
|
|
return request(url, { method: "POST", data: options });
|
|
}
|
|
function put(url, options) {
|
|
if (options === void 0) { options = {}; }
|
|
return request(url, { method: "PUT", data: options });
|
|
}
|
|
module.exports = {
|
|
get: get,
|
|
post: post,
|
|
put: put,
|
|
};
|
|
|