feat: tabBar页面登录优化

This commit is contained in:
h_mo 2023-05-08 21:17:04 +08:00
parent 4e68c4f5f3
commit 62d62ede02
3 changed files with 18 additions and 7 deletions

View File

@ -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
}
},
{

View File

@ -28,11 +28,16 @@ const submit = (e: any) => {
setTimeout(() => {
if (unref(pageQuery)?.redirect) {
// redirect()
// replacetabbarreplaceAll
router.replaceAll({ name: unref(pageQuery).redirect, params: omit(unref(pageQuery), ['redirect']) });
const params = omit(unref(pageQuery), ['redirect', 'tabBar']);
if (unref(pageQuery)?.tabBar) {
// replacetabbarreplaceAll
router.replaceAll({ name: unref(pageQuery).redirect, params });
} else {
router.replace({ name: unref(pageQuery).redirect, params });
}
} else {
//
router.replaceAll({ name: 'Home' });
//
router.back();
}
}, 1500);
});

View File

@ -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' });