mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
update: mobile 服务端接口地址提示语优化
This commit is contained in:
@@ -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}`
|
||||
}
|
||||
|
||||
// 处理动态域名
|
||||
|
||||
Reference in New Issue
Block a user