first commit
This commit is contained in:
74
unpackage/dist/dev/mp-alipay/request/index.js
vendored
Normal file
74
unpackage/dist/dev/mp-alipay/request/index.js
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../common/vendor.js");
|
||||
const store_index = require("../store/index.js");
|
||||
const config = require("../config.js");
|
||||
require("../uni_modules/uview-plus/index.js");
|
||||
const uni_modules_uviewPlus_libs_function_index = require("../uni_modules/uview-plus/libs/function/index.js");
|
||||
const http = (url, params, method, Headers) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let Authorization = store_index.store.state.token || "";
|
||||
let header = {
|
||||
Authorization,
|
||||
...Headers
|
||||
};
|
||||
common_vendor.index.request({
|
||||
url: config.API_URL + url,
|
||||
data: params || {},
|
||||
method: method || "POST",
|
||||
header,
|
||||
success: (res) => {
|
||||
const data = res.data;
|
||||
if (data.code == 401 || res.statusCode == 401) {
|
||||
common_vendor.index.clearStorageSync();
|
||||
store_index.store.commit("setToken", "");
|
||||
common_vendor.index.showModal({
|
||||
title: "提示",
|
||||
content: `${Authorization ? "登录失效" : "你还未登录"},是否前往登录?`,
|
||||
success: function(res2) {
|
||||
if (res2.confirm) {
|
||||
common_vendor.index.navigateTo({
|
||||
url: "/pages/login/login"
|
||||
});
|
||||
} else if (res2.cancel) {
|
||||
console.log("用户点击取消");
|
||||
}
|
||||
}
|
||||
});
|
||||
reject(data);
|
||||
return;
|
||||
}
|
||||
if (data.code == 10 && !data.success) {
|
||||
reject(data);
|
||||
return;
|
||||
}
|
||||
if (data.code !== 1 && !data.success) {
|
||||
uni_modules_uviewPlus_libs_function_index.toast(data.msg);
|
||||
reject(data);
|
||||
return;
|
||||
}
|
||||
resolve(data.data || null);
|
||||
},
|
||||
fail: (err) => {
|
||||
if (err.code == 401 || err.statusCode == 401) {
|
||||
common_vendor.index.clearStorageSync();
|
||||
store_index.store.commit("setToken", "");
|
||||
common_vendor.index.showModal({
|
||||
title: "提示",
|
||||
content: `${Authorization ? "登录失效" : "你还未登录"},是否前往登录?`,
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
common_vendor.index.navigateTo({
|
||||
url: "/pages/login/login"
|
||||
});
|
||||
} else if (res.cancel) {
|
||||
console.log("用户点击取消");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
exports.http = http;
|
||||
Reference in New Issue
Block a user