This commit is contained in:
lik
2026-09-03 11:35:21 +08:00
parent f8f7afceb8
commit b4c8bf0add
45 changed files with 2989 additions and 426 deletions
+19 -5
View File
@@ -1,17 +1,31 @@
class Request {
constructor(baseURL = 'https://api.huashengtec.com') {
//constructor(baseURL = 'http://127.0.0.1:9010') {
//constructor(baseURL = 'http://127.0.0.1:9004') {
this.baseURL = baseURL
}
request(options) {
return new Promise((resolve, reject) => {
const { url, method = 'GET', data = {}, header = {}, ...rest } = options
async request(options) {
const { url, method = 'GET', data = {}, header = {}, skipAuthWait = false, ...rest } = options
// 等待登录完成后再携带 token,避免页面请求早于 app.js 登录的竞态
// skipAuthWait: 登录请求自身使用,否则会等待自己导致死锁
let token = ''
try {
const app = getApp()
const token = app?.globalData?.user?.security?.token || ''
if (skipAuthWait) {
token = app?.globalData?.user?.security?.token || ''
} else if (app && app.ensureLogin) {
const user = await app.ensureLogin()
token = user?.security?.token || ''
} else {
token = app?.globalData?.user?.security?.token || ''
}
} catch (e) {
// 登录失败仍继续请求,由服务端返回未授权错误
}
return new Promise((resolve, reject) => {
data.appId = 'wxapp-escort-admin'
wx.request({