feat: weapi支持checkToken

This commit is contained in:
MoeFurina
2026-07-22 19:40:12 +08:00
parent 7822ab08d3
commit 4826c65042
2 changed files with 23 additions and 1 deletions
+20 -1
View File
@@ -34,5 +34,24 @@ module.exports = async (query) => {
}
}
// 模块加载时自动获取一次 Token,确保 request.js 使用时不为空
fetch()
.then((token) => {
_token = token
})
.catch(() => {
// 静默失败,后续请求时会重试
})
// 给 request.js 读取用
module.exports.getToken = () => _token
module.exports.getToken = () => {
if (!_token) {
// 如果 Token 为空,异步触发获取
fetch()
.then((token) => {
_token = token
})
.catch(() => {})
}
return _token
}