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.
|
|
"use strict"; const common_vendor = require("../common/vendor.js"); const config_site_config = require("./site.config.js"); const config_api = require("./api.js"); let { H5_API, WX_API, httpPrefix } = config_site_config.obj; let num = 0; 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 || {}; let loginInfo = common_vendor.index.getStorageSync("loginInfo") || {}; let token = loginInfo.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; } return config; }, (config) => { return Promise.reject(config); }); common_vendor.index.$u.http.interceptors.response.use(async (response) => { var _a; const data = response.data; data.code = data.errorcode; if (data.code == 401) { console.log("报401的接口"); console.log(response.config.url); common_vendor.index.$u.toast("登录异常,请稍后"); if (num) return; num++; let loginInfo = common_vendor.index.getStorageSync("loginInfo"); const res = await config_api.loginApi({ "type": loginInfo.type, "username": loginInfo.phone }); res.data.phone = loginInfo.phone; res.data.type = loginInfo.type; common_vendor.index.setStorageSync("loginInfo", res.data); num = 0; 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); } } const custom = (_a = response.config) == null ? void 0 : _a.custom; if (data.code !== 0) { console.log("不正常的code"); console.log(data); if (custom.toast !== false) { common_vendor.index.$u.toast(data.message); } 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;
|