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 → 调用后端登录