From bee039b624a1338b2db6c1db8e3ae7627c50a69c Mon Sep 17 00:00:00 2001 From: xuqingkai Date: Mon, 8 May 2023 15:59:49 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20uni-mini-router?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E5=89=8D=E7=BD=AE=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E5=AE=88=E5=8D=AB=E6=97=A0=E6=B3=95=E6=8C=87=E5=90=91=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E7=B1=BB=E5=9E=8B=E4=B8=8D=E5=90=8C=E7=9A=84=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/pages/login/index.vue | 10 +++++++++- src/router/guard.ts | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9f1b671..6906ca9 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "prettier": "^2.8.8", "sass": "^1.62.1", "typescript": "^5.0.4", - "uni-mini-router": "^0.0.9", + "uni-mini-router": "^0.0.11", "uni-read-pages-vite": "^0.0.6", "unocss": "^0.51.12", "unocss-preset-weapp": "^0.6.1", diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 213609a..8a07611 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -28,7 +28,8 @@ const submit = (e: any) => { setTimeout(() => { if (unref(pageQuery)?.redirect) { // 如果有存在redirect(重定向)参数,登录成功后直接跳转 - router.replace({ name: unref(pageQuery).redirect, params: omit(unref(pageQuery), ['redirect']) }); + // 这里replace方法无法跳转tabbar页面故改为replaceAll + router.replaceAll({ name: unref(pageQuery).redirect, params: omit(unref(pageQuery), ['redirect']) }); } else { // 不存在则回到首页 router.replaceAll({ name: 'Home' }); @@ -61,26 +62,32 @@ const submit = (e: any) => { .container { margin: 0 auto; width: 80%; + .title { padding: 320rpx 0 32rpx 0; text-align: center; } + .form-wrap { padding: 20rpx 24rpx; box-shadow: 16rpx 16rpx 30rpx #e5e7eb; + .form { .form-item { display: flex; height: 88rpx; border-bottom: 2rpx solid #dbeafe; align-items: center; + .form-label { min-width: 96rpx; } + .form-element { flex-grow: 1; } } + .submit-btn { margin-top: 44rpx; border: 4rpx solid #bfdbfe; @@ -88,6 +95,7 @@ const submit = (e: any) => { border-radius: 8rpx; font-size: 28rpx; color: #ffffff; + :hover { background-color: #3b82f6; } diff --git a/src/router/guard.ts b/src/router/guard.ts index 30d5e39..e97a8eb 100644 --- a/src/router/guard.ts +++ b/src/router/guard.ts @@ -16,10 +16,10 @@ function createBeforeEachGuard(router: Router) { } else if (!authStore.isLogin && to && to.name !== 'Login') { // 如果没有登录且目标路由不是登录页面则跳转到登录页面 // 将目标路由和参数传入登录页面,登录成功后直接跳转到目标路由,优化体验 - next({ name: 'Login',params:{redirect: to.name, ...to.query} }); + next({ name: 'Login', params: { redirect: to.name, ...to.query }, navType: 'replaceAll' }); } else if (authStore.isLogin && to && to.name === 'Login') { // 如果已经登录且目标页面是登录页面则跳转至首页 - next({ name: 'Home' }); + next({ name: 'Home', navType: 'replaceAll' }); } else { next(); }