Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
lls_program
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-09-26 10:41:27 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3187eaa87a49e3e23d5b90340ca94bd92ea6f2a0
3187eaa8
1 parent
c93465b8
fix(路由跳转): 防止重复跳转到欢迎页和仪表盘页
添加路由跳转防抖逻辑,避免在相同页面间重复跳转 在Dashboard页面添加跳转状态标志,优化家庭状态检查逻辑
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
src/pages/Dashboard/index.vue
src/utils/authRedirect.js
src/pages/Dashboard/index.vue
View file @
3187eaa
...
...
@@ -377,6 +377,9 @@ const handleAdClick = (targetPage) => {
const family_id = ref('');
const totalFamilySteps = ref(0);
// 防抖标志,防止重复跳转
let isRedirecting = false;
/**
* 刷新Dashboard页面数据
*/
...
...
@@ -406,9 +409,10 @@ const refreshDashboardData = async () => {
totalPoints: finalTotalPoints.value
});
//
判断用户是否记录家庭, family_id为空, 跳转到Welcome页面
if (!family_id.value) {
//
更严格的家庭状态检查:只有在明确没有家庭数据且不在跳转过程中时才跳转
if (!family_id.value
&& !isRedirecting && (!data.family || !data.family.name)
) {
console.warn('用户未加入家庭,跳转到欢迎页面');
isRedirecting = true;
await Taro.redirectTo({
url: '/pages/Welcome/index'
})
...
...
@@ -416,20 +420,26 @@ const refreshDashboardData = async () => {
}
} else {
console.error('获取Dashboard数据失败:', data);
// 只有在明确的错误情况下才进行家庭状态检查
if (!isRedirecting && (data?.msg?.includes('家庭') || data?.code === 404)) {
// 检查用户是否已加入家庭
const hasFamily = await checkUserHasFamily()
// 如果用户没有加入家庭,跳转到欢迎页面
if (!hasFamily) {
console.warn('用户未加入家庭,跳转到欢迎页面');
isRedirecting = true;
await Taro.redirectTo({
url: '/pages/Welcome/index'
})
return
}
}
}
} catch (error) {
console.error('刷新Dashboard数据异常:', error);
// 网络错误等异常情况不应该触发页面跳转
}
};
...
...
@@ -458,6 +468,9 @@ useLoad(async () => {
});
useDidShow(async () => {
// 重置跳转标志
isRedirecting = false;
// 获取系统信息
getSystemInfo();
...
...
src/utils/authRedirect.js
View file @
3187eaa
...
...
@@ -107,9 +107,12 @@ export const returnToOriginalPage = async (defaultPath = '/pages/Dashboard/index
// 如果用户没有加入家庭,跳转到欢迎页面
if
(
!
hasFamily
)
{
// 避免重复跳转到Welcome页面
if
(
currentRoute
!==
'pages/Welcome/index'
)
{
await
Taro
.
redirectTo
({
url
:
'/pages/Welcome/index'
})
}
return
}
...
...
@@ -137,15 +140,25 @@ export const returnToOriginalPage = async (defaultPath = '/pages/Dashboard/index
// 错误处理:检查是否有家庭,决定跳转到哪里
try
{
const
hasFamily
=
await
checkUserHasFamily
()
const
pages
=
Taro
.
getCurrentPages
()
const
currentPage
=
pages
[
pages
.
length
-
1
]
const
currentRoute
=
currentPage
?.
route
if
(
hasFamily
)
{
// 避免重复跳转到Dashboard页面
if
(
currentRoute
!==
'pages/Dashboard/index'
)
{
await
Taro
.
redirectTo
({
url
:
'/pages/Dashboard/index'
})
}
}
else
{
// 避免重复跳转到Welcome页面
if
(
currentRoute
!==
'pages/Welcome/index'
)
{
await
Taro
.
redirectTo
({
url
:
'/pages/Welcome/index'
})
}
}
}
catch
(
finalError
)
{
console
.
error
(
'最终降级方案也失败了:'
,
finalError
)
}
...
...
Please
register
or
login
to post a comment