mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 17:49:19 +08:00
最近一丢丢
This commit is contained in:
@@ -62,15 +62,19 @@ const REMEMBER_ME_KEY = `REMEMBER_ME_USERNAME_${location.hostname}`;
|
||||
|
||||
const localUsername = localStorage.getItem(REMEMBER_ME_KEY) || '';
|
||||
|
||||
const rememberMe = ref(!!localUsername);
|
||||
// 清理可能存在的 undefined 值
|
||||
const cleanLocalUsername = localUsername === 'undefined' ? '' : localUsername;
|
||||
|
||||
const rememberMe = ref(!!cleanLocalUsername);
|
||||
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formApi.validate();
|
||||
const values = await formApi.getValues();
|
||||
if (valid) {
|
||||
const username = values?.account || values?.username;
|
||||
localStorage.setItem(
|
||||
REMEMBER_ME_KEY,
|
||||
rememberMe.value ? values?.username : '',
|
||||
rememberMe.value && username && username !== 'undefined' ? username : '',
|
||||
);
|
||||
emit('submit', values);
|
||||
}
|
||||
@@ -81,8 +85,13 @@ function handleGo(path: string) {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (localUsername) {
|
||||
formApi.setFieldValue('username', localUsername);
|
||||
// 清理 localStorage 中可能存在的 undefined 值
|
||||
if (localUsername === 'undefined') {
|
||||
localStorage.removeItem(REMEMBER_ME_KEY);
|
||||
}
|
||||
|
||||
if (cleanLocalUsername) {
|
||||
formApi.setFieldValue('account', cleanLocalUsername);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user