黄伟杰 5 days ago
commit 4623e356fe

@ -1,6 +1,5 @@
import { useCache, CACHE_KEY } from '@/hooks/web/useCache'
import { TokenType } from '@/api/login/types'
import { decrypt, encrypt } from '@/utils/jsencrypt'
const { wsCache } = useCache()
@ -47,14 +46,19 @@ export type LoginFormType = {
export const getLoginForm = () => {
const loginForm: LoginFormType = wsCache.get(CACHE_KEY.LoginForm)
if (loginForm) {
loginForm.password = decrypt(loginForm.password) as string
// Never restore a password from browser storage. Also sanitize legacy cache entries.
loginForm.password = ''
wsCache.set(CACHE_KEY.LoginForm, loginForm, { exp: 30 * 24 * 60 * 60 })
}
return loginForm
}
export const setLoginForm = (loginForm: LoginFormType) => {
loginForm.password = encrypt(loginForm.password) as string
wsCache.set(CACHE_KEY.LoginForm, loginForm, { exp: 30 * 24 * 60 * 60 })
wsCache.set(
CACHE_KEY.LoginForm,
{ ...loginForm, password: '' },
{ exp: 30 * 24 * 60 * 60 }
)
}
export const removeLoginForm = () => {

@ -58,6 +58,7 @@
label-position="top"
label-width="120px"
size="large"
autocomplete="off"
>
<el-row style="margin-right: -10px; margin-left: -10px">
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
@ -80,6 +81,7 @@
<el-form-item prop="username">
<el-input
v-model="loginData.loginForm.username"
autocomplete="off"
:placeholder="t('login.usernamePlaceholder')"
:prefix-icon="iconAvatar"
/>
@ -89,6 +91,7 @@
<el-form-item prop="password">
<el-input
v-model="loginData.loginForm.password"
autocomplete="new-password"
:placeholder="t('login.passwordPlaceholder')"
:prefix-icon="iconLock"
show-password
@ -199,8 +202,8 @@ const loginData = reactive({
tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE !== 'false',
loginForm: {
tenantName: '内蒙必硕',
username: 'admin',
password: 'admin123',
username: '',
password: '',
captchaVerification: '',
rememberMe: false
}

@ -8,6 +8,7 @@
label-position="top"
label-width="120px"
size="large"
autocomplete="off"
>
<el-row style="margin-right: -10px; margin-left: -10px">
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
@ -31,6 +32,7 @@
<el-form-item prop="username">
<el-input
v-model="loginData.loginForm.username"
autocomplete="off"
:placeholder="t('login.usernamePlaceholder')"
:prefix-icon="iconAvatar"
/>
@ -40,6 +42,7 @@
<el-form-item prop="password">
<el-input
v-model="loginData.loginForm.password"
autocomplete="new-password"
:placeholder="t('login.passwordPlaceholder')"
:prefix-icon="iconLock"
show-password
@ -160,6 +163,7 @@ const verify = ref()
const captchaType = ref('blockPuzzle') // blockPuzzle clickWord
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
const defaultTenantName = import.meta.env.VITE_APP_DEFAULT_LOGIN_TENANT || ''
const LoginRules = {
tenantName: [required],
@ -171,11 +175,11 @@ const loginData = reactive({
captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE,
tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE,
loginForm: {
tenantName: import.meta.env.VITE_APP_DEFAULT_LOGIN_TENANT || '',
username: import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME || '',
password: import.meta.env.VITE_APP_DEFAULT_LOGIN_PASSWORD || '',
tenantName: defaultTenantName,
username: '',
password: '',
captchaVerification: '',
rememberMe: true //
rememberMe: false
}
})
@ -213,7 +217,7 @@ const getLoginFormCache = () => {
username: loginForm.username ? loginForm.username : loginData.loginForm.username,
password: loginForm.password ? loginForm.password : loginData.loginForm.password,
rememberMe: loginForm.rememberMe,
tenantName: loginForm.tenantName ? loginForm.tenantName : loginData.loginForm.tenantName
tenantName: defaultTenantName || loginForm.tenantName || loginData.loginForm.tenantName
}
}
}
@ -315,7 +319,9 @@ watch(
)
onMounted(() => {
getLoginFormCache()
getTenantByWebsite()
if (!defaultTenantName) {
getTenantByWebsite()
}
})
</script>

Loading…
Cancel
Save