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.
78 lines
2.8 KiB
78 lines
2.8 KiB
"use strict";
|
|
const common_vendor = require("../common/vendor.js");
|
|
const config_site_config = require("./site.config.js");
|
|
const store_index = require("../store/index.js");
|
|
let { H5_API, WX_API, httpPrefix } = config_site_config.obj;
|
|
const counterStore = store_index.useUserStoreHook();
|
|
let secretKey = "22d90e09d1374f0f9e4accd07d333e55";
|
|
const request = (vm) => {
|
|
common_vendor.index.$u.http.setConfig((config) => {
|
|
let prefix = config.prefix ? config.prefix : httpPrefix;
|
|
config.baseURL = H5_API + WX_API + prefix;
|
|
return config;
|
|
});
|
|
common_vendor.index.$u.http.interceptors.request.use((config) => {
|
|
var _a;
|
|
config.data = config.data || {};
|
|
config.data["timestamp"] = Date.now();
|
|
let jsonString = JSON.stringify(config.data);
|
|
let strSecretKey = jsonString + secretKey;
|
|
let hash = common_vendor.md5(strSecretKey);
|
|
config.header["Signature"] = hash;
|
|
config.data = jsonString;
|
|
let token = common_vendor.index.getStorageSync("token");
|
|
if (token) {
|
|
config.header.Authorization = "Bearer " + token;
|
|
}
|
|
let noToken = (_a = config.custom) == null ? void 0 : _a.noToken;
|
|
if (noToken && config.header.Authorization) {
|
|
delete config.header.Authorization;
|
|
}
|
|
console.log("config");
|
|
console.log(config);
|
|
return config;
|
|
}, (config) => {
|
|
return Promise.reject(config);
|
|
});
|
|
common_vendor.index.$u.http.interceptors.response.use(async (response) => {
|
|
var _a;
|
|
const data = response.data;
|
|
if (data.code == 406 && response.config.url != "member/auth/refresh-token" && response.config.url !== "member/auth/logout") {
|
|
let obj = response.config;
|
|
let method = obj.method.toLowerCase();
|
|
if (method == "get") {
|
|
return common_vendor.index.$u.http[method](obj.url, { params: obj.params });
|
|
} else {
|
|
return common_vendor.index.$u.http[method](obj.url, obj.data);
|
|
}
|
|
}
|
|
if (data.code == 401) {
|
|
console.log("报401的接口");
|
|
let url = response.config.url;
|
|
console.log(url);
|
|
if (url == "mime/houses" || url == "face/user_info") {
|
|
console.log("还是到这里面来了?");
|
|
return Promise.reject(data);
|
|
}
|
|
return counterStore.goLogin();
|
|
}
|
|
const custom = (_a = response.config) == null ? void 0 : _a.custom;
|
|
if (data.code !== 0 && data.code != 406 && data.code != "200240213") {
|
|
console.log("不正常的code");
|
|
console.log(data);
|
|
if (custom.toast !== false) {
|
|
common_vendor.index.$u.toast(data.msg);
|
|
}
|
|
if (custom == null ? void 0 : custom.catch) {
|
|
return Promise.reject(data);
|
|
} else {
|
|
return new Promise(() => {
|
|
});
|
|
}
|
|
}
|
|
return data === void 0 ? {} : data;
|
|
}, (response) => {
|
|
return Promise.reject(response);
|
|
});
|
|
};
|
|
exports.request = request;
|