update: mobile 服务端接口地址提示语优化

This commit is contained in:
zhuoqinglian
2026-03-10 16:14:04 +08:00
parent ed41de7b8e
commit ff1076deac
3 changed files with 23 additions and 5 deletions
+11 -3
View File
@@ -42,6 +42,14 @@ const alovaInstance = createAlova({
statesHook: VueHook,
beforeRequest: onAuthRequired((method) => {
// 检查混合内容错误(HTTPS页面请求HTTP接口)
const currentProtocol = typeof window !== 'undefined' && window.location.protocol
const requestProtocol = method.baseURL?.split(':')[0]
if (currentProtocol === 'https:' && requestProtocol === 'http') {
const errorMessage = '无法配置http协议地址,请检查接口地址'
throw new Error(errorMessage)
}
// 设置默认 Content-Type
method.config.headers = {
'Content-Type': ContentTypeEnum.JSON,
@@ -55,14 +63,14 @@ const alovaInstance = createAlova({
// 处理认证信息
if (!ignoreAuth) {
const token = uni.getStorageSync('token')
if (!token) {
const authInfo = JSON.parse(uni.getStorageSync('token') || '{}')
if (!authInfo.token) {
// 跳转到登录页
uni.reLaunch({ url: '/pages/login/index' })
throw new Error('[请求错误]:未登录')
}
// 添加 Authorization 头
method.config.headers.Authorization = `Bearer ${token}`
method.config.headers.Authorization = `Bearer ${authInfo.token}`
}
// 处理动态域名