fix(认证): 修复首次登录改密跳转

This commit is contained in:
xy
2026-09-24 17:34:26 +08:00
parent 53c6f05969
commit f99bee4286
3 changed files with 111 additions and 16 deletions
+40 -2
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getAuthErrorMessage, getCaptcha } from '@/api/auth'
@@ -18,6 +18,7 @@ const captchaLoading = ref(false)
const errorMessage = ref('')
const isSubmitting = ref(false)
const passwordChanged = route.query.passwordChanged === '1'
const passwordChangeRequested = computed(() => route.query.redirect === '/change-password')
async function loadCaptcha() {
captchaLoading.value = true
@@ -41,6 +42,13 @@ function getRedirectPath() {
: '/workbench/home'
}
function requestPasswordChange() {
void router.replace({
name: 'login',
query: { ...route.query, redirect: '/change-password' },
})
}
async function handleLogin() {
const normalizedUsername = username.value.trim()
@@ -70,9 +78,12 @@ async function handleLogin() {
}
const session = await loginStore.login(payload)
const redirect = getRedirectPath()
await router.replace(
session.user.passwordChangeRequired ? { name: 'change-password' } : getRedirectPath(),
session.user.passwordChangeRequired
? { name: 'change-password', query: { redirect } }
: redirect,
)
} catch (error: unknown) {
errorMessage.value = getAuthErrorMessage(error)
@@ -175,6 +186,12 @@ onMounted(() => {
{{ isSubmitting ? '登录中…' : '登 录' }}
</button>
<p class="login-tip">请使用医院分配的账号登录</p>
<p v-if="passwordChangeRequested" class="login-change-hint" role="status">
登录后将进入修改密码页面
</p>
<button class="login-change-link" type="button" @click="requestPasswordChange">
修改密码
</button>
</form>
<p class="login-footer">© 2026 医签通 MEDISIGN · 患者电子签署系统 V1.1 原型</p>
@@ -348,6 +365,27 @@ onMounted(() => {
border-radius: 8px;
}
.login-change-hint {
margin: 8px 0 0;
color: var(--brand);
font-size: 12px;
text-align: center;
}
.login-change-link {
display: block;
padding: 7px 12px;
margin: 5px auto 0;
color: var(--brand);
font-size: 12px;
background: transparent;
border: 0;
}
.login-change-link:hover {
text-decoration: underline;
}
.login-footer {
position: absolute;
bottom: 18px;