fix: 严格按后端account字段修复记住账号

This commit is contained in:
2026-02-06 15:53:35 +08:00
parent c8b63cf0f5
commit a5080912b5
2 changed files with 9 additions and 11 deletions

View File

@@ -14,9 +14,8 @@ export namespace AuthApi {
/** 登录接口参数 */ /** 登录接口参数 */
export interface LoginParams { export interface LoginParams {
account?: string; account: string;
password?: string; password: string;
username?: string;
} }
/** 登录接口返回值 */ /** 登录接口返回值 */
@@ -45,9 +44,8 @@ export namespace AuthApi {
* 登录 * 登录
*/ */
export async function loginApi(data: AuthApi.LoginParams) { export async function loginApi(data: AuthApi.LoginParams) {
const account = data.account ?? data.username;
return requestClient.post<AuthApi.LoginResult>('/auth/login', { return requestClient.post<AuthApi.LoginResult>('/auth/login', {
account, account: data.account,
password: data.password, password: data.password,
}); });
} }

View File

@@ -58,11 +58,11 @@ const [Form, formApi] = useVbenForm(
); );
const router = useRouter(); const router = useRouter();
const REMEMBER_ME_KEY = `REMEMBER_ME_USERNAME_${location.hostname}`; const REMEMBER_ME_KEY = `REMEMBER_ME_ACCOUNT_${location.hostname}`;
const localUsername = localStorage.getItem(REMEMBER_ME_KEY) || ''; const localAccount = localStorage.getItem(REMEMBER_ME_KEY) || '';
const rememberMe = ref(!!localUsername); const rememberMe = ref(!!localAccount);
async function handleSubmit() { async function handleSubmit() {
const { valid } = await formApi.validate(); const { valid } = await formApi.validate();
@@ -70,7 +70,7 @@ async function handleSubmit() {
if (valid) { if (valid) {
localStorage.setItem( localStorage.setItem(
REMEMBER_ME_KEY, REMEMBER_ME_KEY,
rememberMe.value ? values?.username : '', rememberMe.value ? values?.account : '',
); );
emit('submit', values); emit('submit', values);
} }
@@ -81,8 +81,8 @@ function handleGo(path: string) {
} }
onMounted(() => { onMounted(() => {
if (localUsername) { if (localAccount) {
formApi.setFieldValue('username', localUsername); formApi.setFieldValue('account', localAccount);
} }
}); });