增加新功能
This commit is contained in:
+61
-10
@@ -1,21 +1,23 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../common/vendor.js");
|
||||
const utils_auth = require("./auth.js");
|
||||
const baseUrl = "http://192.168.0.108:8087";
|
||||
const utils_config = require("./config.js");
|
||||
function request(options) {
|
||||
const { url, method = "GET", data = {}, headers = {} } = options;
|
||||
const token = utils_auth.getStorageFun(utils_auth.TOKEN_NAME);
|
||||
const defaultHeaders = {
|
||||
"HSM-AUTH": token ? token : "",
|
||||
// 如果存在token, 则添加到请求头中
|
||||
// 'HSM-AUTH': token ? token : '', // 如果存在token, 则添加到请求头中
|
||||
"content-type": ["post", "POST"].includes(method) ? "application/x-www-form-urlencoded" : "application/json"
|
||||
};
|
||||
if (token) {
|
||||
defaultHeaders["HSM-AUTH"] = token;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.showLoading({
|
||||
title: "加载中..."
|
||||
});
|
||||
common_vendor.index.request({
|
||||
url: baseUrl + url,
|
||||
url: utils_config.BASE_URL + url,
|
||||
method,
|
||||
data,
|
||||
header: {
|
||||
@@ -25,17 +27,66 @@ function request(options) {
|
||||
},
|
||||
success: (res) => {
|
||||
common_vendor.index.hideLoading();
|
||||
if (res.statusCode === 200) {
|
||||
resolve(res.data);
|
||||
} else if (res.statusCode === 201) {
|
||||
reject(new Error("Unauthorized"));
|
||||
const data2 = res.data;
|
||||
if (data2.bizcode === 100) {
|
||||
resolve(data2);
|
||||
} else if (data2.bizcode === 201) {
|
||||
if ([201, 200].includes(data2.errcode)) {
|
||||
common_vendor.index.showToast({
|
||||
title: "登录失效,请从新登录",
|
||||
icon: "none",
|
||||
// 可选 success/loading/none
|
||||
duration: 2e3,
|
||||
// 持续时长,单位ms
|
||||
mask: false,
|
||||
// 是否显示透明蒙层,防止触摸穿透
|
||||
position: "middle"
|
||||
// 位置,可选 top/middle/bottom
|
||||
});
|
||||
} else {
|
||||
common_vendor.index.showToast({
|
||||
title: data2.msg,
|
||||
icon: "none",
|
||||
// 可选 success/loading/none
|
||||
duration: 2e3,
|
||||
// 持续时长,单位ms
|
||||
mask: false,
|
||||
// 是否显示透明蒙层,防止触摸穿透
|
||||
position: "middle"
|
||||
// 位置,可选 top/middle/bottom
|
||||
});
|
||||
}
|
||||
if ([201, 200, 205].includes(data2.errcode)) {
|
||||
setTimeout(() => {
|
||||
common_vendor.index.navigateTo({
|
||||
url: "/pages/login/login"
|
||||
});
|
||||
}, 2e3);
|
||||
}
|
||||
} else {
|
||||
reject(res);
|
||||
common_vendor.index.showToast({
|
||||
title: data2.msg,
|
||||
icon: "error",
|
||||
// 可选 success/loading/none
|
||||
duration: 2e3,
|
||||
// 持续时长,单位ms
|
||||
mask: false
|
||||
// 是否显示透明蒙层,防止触摸穿透
|
||||
});
|
||||
reject(data2);
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
common_vendor.index.hideLoading();
|
||||
reject(error);
|
||||
common_vendor.index.showToast({
|
||||
title: "服务器异常,稍后再试",
|
||||
icon: "error",
|
||||
// 可选 success/loading/none
|
||||
duration: 2e3,
|
||||
// 持续时长,单位ms
|
||||
mask: false
|
||||
// 是否显示透明蒙层,防止触摸穿透
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user