From a7efc92f2a77736270cb99fd719514e05e44bc31 Mon Sep 17 00:00:00 2001 From: H1d3rOne Date: Mon, 9 Mar 2026 16:51:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A6=96=E6=AC=A1=E6=89=93?= =?UTF-8?q?=E5=BC=80=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=9C=AA=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E6=8E=88=E6=9D=83=E9=A1=B5=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题原因: 1. 授权页面pages/auth/auth未在pages.json中注册 2. uni.redirectTo无法跳转到未注册的页面 3. 缺少详细的日志输出 解决方案: 1. 在pages.json中添加授权页面配置 - 路径:pages/auth/auth - 导航栏标题:授权登录 - 导航栏背景色:#10B981(绿色) - 导航栏文字颜色:white 2. 优化App.vue跳转逻辑 - 使用uni.navigateTo替代uni.redirectTo - 添加navigateTo失败后的redirectTo备用方案 - 添加详细的console.log日志输出 - 在跳转前设置hasShownAuth标记 3. 增强调试信息 - 输出用户授权状态检查结果 - 输出hasUserInfo和hasShownAuth的值 - 输出跳转成功/失败的详细信息 测试要点: - 首次打开小程序自动跳转到授权页面 - 授权页面正常显示 - 授权成功后跳转到首页 --- xuan-deduct-uniapp/src/App.vue | 16 +++++++++++++++- xuan-deduct-uniapp/src/pages.json | 8 ++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/xuan-deduct-uniapp/src/App.vue b/xuan-deduct-uniapp/src/App.vue index cebac7b..44ecb1f 100644 --- a/xuan-deduct-uniapp/src/App.vue +++ b/xuan-deduct-uniapp/src/App.vue @@ -15,17 +15,31 @@ export default { const userInfo = uni.getStorageSync('userInfo') const hasShownAuth = uni.getStorageSync('hasShownAuth') + console.log('检查用户授权状态:', { + hasUserInfo: !!userInfo, + hasShownAuth: hasShownAuth + }) + if (!userInfo && !hasShownAuth) { console.log('首次使用,跳转到授权页面') uni.setStorageSync('hasShownAuth', true) setTimeout(() => { - uni.redirectTo({ + uni.navigateTo({ url: '/pages/auth/auth', success: () => { console.log('跳转授权页面成功') }, fail: (err) => { console.error('跳转授权页面失败:', err) + uni.redirectTo({ + url: '/pages/auth/auth', + success: () => { + console.log('redirectTo跳转授权页面成功') + }, + fail: (err2) => { + console.error('redirectTo跳转授权页面也失败:', err2) + } + }) } }) }, 500) diff --git a/xuan-deduct-uniapp/src/pages.json b/xuan-deduct-uniapp/src/pages.json index f5e2a8a..4e49eab 100644 --- a/xuan-deduct-uniapp/src/pages.json +++ b/xuan-deduct-uniapp/src/pages.json @@ -1,5 +1,13 @@ { "pages": [ + { + "path": "pages/auth/auth", + "style": { + "navigationBarTitleText": "授权登录", + "navigationBarBackgroundColor": "#10B981", + "navigationBarTextStyle": "white" + } + }, { "path": "pages/index/index", "style": {