fix(认证): 修复首次登录改密跳转
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
import { useLoginStore } from '@/stores/login'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const loginStore = useLoginStore()
|
||||
|
||||
@@ -13,6 +14,19 @@ const confirmPassword = ref('')
|
||||
const errorMessage = ref('')
|
||||
const isSubmitting = ref(false)
|
||||
|
||||
function getAfterChangeRedirect() {
|
||||
const redirect = route.query.redirect
|
||||
if (
|
||||
typeof redirect === 'string' &&
|
||||
redirect.startsWith('/') &&
|
||||
!redirect.startsWith('//') &&
|
||||
redirect !== '/change-password'
|
||||
) {
|
||||
return redirect
|
||||
}
|
||||
return '/workbench/home'
|
||||
}
|
||||
|
||||
function validatePassword() {
|
||||
if (!currentPassword.value || !newPassword.value || !confirmPassword.value) {
|
||||
return '请完整填写当前密码、新密码和确认密码'
|
||||
@@ -51,7 +65,10 @@ async function handleSubmit() {
|
||||
currentPassword: currentPassword.value,
|
||||
newPassword: newPassword.value,
|
||||
})
|
||||
await router.replace({ name: 'login', query: { passwordChanged: '1' } })
|
||||
await router.replace({
|
||||
name: 'login',
|
||||
query: { passwordChanged: '1', redirect: getAfterChangeRedirect() },
|
||||
})
|
||||
} catch (error: unknown) {
|
||||
errorMessage.value =
|
||||
error instanceof Error && error.message ? error.message : '密码修改失败,请稍后重试'
|
||||
@@ -74,8 +91,14 @@ async function handleLogout() {
|
||||
<main class="password-page">
|
||||
<form class="password-card" novalidate @submit.prevent="handleSubmit">
|
||||
<div class="password-brand">医签通</div>
|
||||
<h1>首次登录,请修改密码</h1>
|
||||
<p class="password-description">为保护患者信息,设置新密码后需要重新登录。</p>
|
||||
<h1>{{ loginStore.user?.passwordChangeRequired ? '首次登录,请修改密码' : '修改密码' }}</h1>
|
||||
<p class="password-description">
|
||||
{{
|
||||
loginStore.user?.passwordChangeRequired
|
||||
? '为保护患者信息,设置新密码后需要重新登录。'
|
||||
: '修改密码后需要重新登录。'
|
||||
}}
|
||||
</p>
|
||||
|
||||
<label>
|
||||
<span>当前密码</span>
|
||||
|
||||
Reference in New Issue
Block a user