From 62d62ede02d2cf40ef11b4613b6324754d7957e2 Mon Sep 17 00:00:00 2001 From: h_mo <596417202@qq.com> Date: Mon, 8 May 2023 21:17:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20tabBar=E9=A1=B5=E9=9D=A2=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages.json | 10 ++++++++-- src/pages/login/index.vue | 13 +++++++++---- src/router/guard.ts | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pages.json b/src/pages.json index 0f7ead6..917f867 100644 --- a/src/pages.json +++ b/src/pages.json @@ -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 } }, { diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 8a07611..48b1a3b 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -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); }); diff --git a/src/router/guard.ts b/src/router/guard.ts index e97a8eb..85335fb 100644 --- a/src/router/guard.ts +++ b/src/router/guard.ts @@ -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' });