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