fix(login): 记住我同时记住密码并回填

This commit is contained in:
Zhou Weidong authored and trae-solo-agent committed 2026-10-29 09:58:57 +08:00
1 parent e2618735ba
commit 9a58b98f12
3 files changed
+7 -14

No files matched your search

+1
View File
@@ -2,6 +2,7 @@
export type UserLoginType = {
username: string
password?: string
}
export type UserType = {
+1 -11
View File
@@ -104,17 +104,7 @@ export const useUserStore = defineStore('user', {
this.loginInfo = loginInfo
}
},
persist: {
afterRestore: (context) => {
const loginInfo = context.store.loginInfo as
(UserLoginType & { password?: string }) | undefined
if (loginInfo?.password !== undefined) {
context.store.setLoginInfo(
loginInfo.username ? { username: loginInfo.username } : undefined
)
}
}
}
persist: true
})
export const useUserStoreWithOut = () => {
+5 -3
View File
@@ -132,7 +132,7 @@ const remember = ref(userStore.getRememberMe)
const initLoginInfo = () => {
const loginInfo = userStore.getLoginInfo
if (loginInfo) {
setValues({ username: loginInfo.username })
setValues({ username: loginInfo.username, password: loginInfo.password })
}
}
onMounted(() => {
@@ -169,10 +169,12 @@ const signIn = async () => {
const res = await loginApi(formData)
if (res) {
// 是否记住我
// 是否记住我:勾选时把账号密码一起持久化到 localStorage,
// 下次打开登录页自动回填,免重复输入。
if (unref(remember)) {
userStore.setLoginInfo({
username: formData.username
username: formData.username,
password: formData.password
})
} else {
userStore.setLoginInfo(undefined)