From 5bb31516a063873aa01342bd5d6e19e30e49d3ab Mon Sep 17 00:00:00 2001 From: kk <875203880@qq.com> Date: Thu, 2 Jul 2026 19:32:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E7=95=99code=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 9 +++++---- src/pages/auth/loading.vue | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/App.vue b/src/App.vue index af3ba29..51f953d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -25,10 +25,11 @@ const code = urlParams.get('code'); if (code) { - // 有 code → 进入授权 Loading 页处理 - const loadingUrl = deviceId - ? `/pages/auth/loading?device_id=${deviceId}` - : '/pages/auth/loading'; + // 有 code → 进入授权 Loading 页处理,保留 code 参数 + let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code); + if (deviceId) { + loadingUrl += '&device_id=' + deviceId; + } uni.redirectTo({ url: loadingUrl }); return; } diff --git a/src/pages/auth/loading.vue b/src/pages/auth/loading.vue index 57b00c5..1a5ca48 100644 --- a/src/pages/auth/loading.vue +++ b/src/pages/auth/loading.vue @@ -21,9 +21,13 @@ export default { this.deviceId = options.device_id || ''; // #ifdef H5 - // 检查 URL 中是否有授权回调的 code - const urlParams = new URLSearchParams(window.location.search); - const code = urlParams.get('code'); + // 优先从页面参数获取 code(App.vue 跳转时带过来) + // 兜底从 URL search 参数获取(微信直接回调时) + let code = options.code || ''; + if (!code) { + const urlParams = new URLSearchParams(window.location.search); + code = urlParams.get('code') || ''; + } if (code) { // 有 code → 调用后端登录