From ff1076deac7e7c1a393dd9be0da3ac6e38ffe3c4 Mon Sep 17 00:00:00 2001 From: zhuoqinglian <1035449612@qq.com> Date: Tue, 10 Mar 2026 16:14:04 +0800 Subject: [PATCH] =?UTF-8?q?update:=20mobile=20=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=9C=B0=E5=9D=80=E6=8F=90=E7=A4=BA=E8=AF=AD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-mobile/src/http/request/alova.ts | 14 +++++++++++--- main/manager-mobile/src/http/request/enum.ts | 4 ++++ main/manager-mobile/src/pages/settings/index.vue | 10 ++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/main/manager-mobile/src/http/request/alova.ts b/main/manager-mobile/src/http/request/alova.ts index 752987b4..3120cfed 100644 --- a/main/manager-mobile/src/http/request/alova.ts +++ b/main/manager-mobile/src/http/request/alova.ts @@ -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}` } // 处理动态域名 diff --git a/main/manager-mobile/src/http/request/enum.ts b/main/manager-mobile/src/http/request/enum.ts index 1868fe08..048b5617 100644 --- a/main/manager-mobile/src/http/request/enum.ts +++ b/main/manager-mobile/src/http/request/enum.ts @@ -12,6 +12,7 @@ export enum ResultEnum { ServiceUnavailable = 503, // 服务不可用(原为serviceUnavailable) GatewayTimeout = 504, // 网关超时(原为gatewayTimeout) HttpVersionNotSupported = 505, // HTTP版本不支持(原为httpVersionNotSupported) + MixedContent = 600, // 混合内容错误(HTTPS页面请求HTTP接口) } export enum ContentTypeEnum { JSON = 'application/json;charset=UTF-8', @@ -59,6 +60,9 @@ export function ShowMessage(status: number | string): string { case 505: message = 'HTTP版本不受支持(505)' break + case 600: + message = '混合内容错误(600)' + break default: message = `连接出错(${status})!` } diff --git a/main/manager-mobile/src/pages/settings/index.vue b/main/manager-mobile/src/pages/settings/index.vue index 02436948..34871eca 100644 --- a/main/manager-mobile/src/pages/settings/index.vue +++ b/main/manager-mobile/src/pages/settings/index.vue @@ -87,12 +87,18 @@ async function testServerBaseUrl() { if (response.statusCode === 200) { return true } else { - toast.error(t('message.invalidAddress')) + toast.error({ + msg: t('message.invalidAddress'), + duration: 3000, + }) return false } } catch (error) { console.error('测试服务端地址失败:', error) - toast.error(t('message.invalidAddress')) + toast.error({ + msg: t('message.invalidAddress'), + duration: 3000, + }) return false } }