mirror of
https://gitee.com/h_mo/uniapp-vue3-vite-ts-template
synced 2025-04-05 19:41:44 +08:00
feat: tabBar页面登录优化
This commit is contained in:
parent
4e68c4f5f3
commit
62d62ede02
@ -6,13 +6,18 @@
|
||||
"style": {
|
||||
"navigationBarTitleText": "Home"
|
||||
},
|
||||
"meta": {}
|
||||
"meta": {
|
||||
"tabBar": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Demo",
|
||||
"path": "pages/demo/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "Demo"
|
||||
},
|
||||
"meta": {
|
||||
"tabBar": true
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -22,7 +27,8 @@
|
||||
"navigationBarTitleText": "关于"
|
||||
},
|
||||
"meta": {
|
||||
"ignoreAuth": true
|
||||
"ignoreAuth": true,
|
||||
"tabBar": true
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -28,11 +28,16 @@ const submit = (e: any) => {
|
||||
setTimeout(() => {
|
||||
if (unref(pageQuery)?.redirect) {
|
||||
// 如果有存在redirect(重定向)参数,登录成功后直接跳转
|
||||
// 这里replace方法无法跳转tabbar页面故改为replaceAll
|
||||
router.replaceAll({ name: unref(pageQuery).redirect, params: omit(unref(pageQuery), ['redirect']) });
|
||||
const params = omit(unref(pageQuery), ['redirect', 'tabBar']);
|
||||
if (unref(pageQuery)?.tabBar) {
|
||||
// 这里replace方法无法跳转tabbar页面故改为replaceAll
|
||||
router.replaceAll({ name: unref(pageQuery).redirect, params });
|
||||
} else {
|
||||
router.replace({ name: unref(pageQuery).redirect, params });
|
||||
}
|
||||
} else {
|
||||
// 不存在则回到首页
|
||||
router.replaceAll({ name: 'Home' });
|
||||
// 不存在则返回上一页
|
||||
router.back();
|
||||
}
|
||||
}, 1500);
|
||||
});
|
||||
|
@ -16,7 +16,7 @@ function createBeforeEachGuard(router: Router) {
|
||||
} else if (!authStore.isLogin && to && to.name !== 'Login') {
|
||||
// 如果没有登录且目标路由不是登录页面则跳转到登录页面
|
||||
// 将目标路由和参数传入登录页面,登录成功后直接跳转到目标路由,优化体验
|
||||
next({ name: 'Login', params: { redirect: to.name, ...to.query }, navType: 'replaceAll' });
|
||||
next({ name: 'Login', params: { redirect: to.name!, tabBar: to?.meta?.tabBar, ...to.query }, navType: 'push' });
|
||||
} else if (authStore.isLogin && to && to.name === 'Login') {
|
||||
// 如果已经登录且目标页面是登录页面则跳转至首页
|
||||
next({ name: 'Home', navType: 'replaceAll' });
|
||||
|
Loading…
x
Reference in New Issue
Block a user