黄伟杰 5 days ago
commit 4623e356fe

@ -1,6 +1,5 @@
import { useCache, CACHE_KEY } from '@/hooks/web/useCache' import { useCache, CACHE_KEY } from '@/hooks/web/useCache'
import { TokenType } from '@/api/login/types' import { TokenType } from '@/api/login/types'
import { decrypt, encrypt } from '@/utils/jsencrypt'
const { wsCache } = useCache() const { wsCache } = useCache()
@ -47,14 +46,19 @@ export type LoginFormType = {
export const getLoginForm = () => { export const getLoginForm = () => {
const loginForm: LoginFormType = wsCache.get(CACHE_KEY.LoginForm) const loginForm: LoginFormType = wsCache.get(CACHE_KEY.LoginForm)
if (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 return loginForm
} }
export const setLoginForm = (loginForm: LoginFormType) => { export const setLoginForm = (loginForm: LoginFormType) => {
loginForm.password = encrypt(loginForm.password) as string wsCache.set(
wsCache.set(CACHE_KEY.LoginForm, loginForm, { exp: 30 * 24 * 60 * 60 }) CACHE_KEY.LoginForm,
{ ...loginForm, password: '' },
{ exp: 30 * 24 * 60 * 60 }
)
} }
export const removeLoginForm = () => { export const removeLoginForm = () => {

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

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

Loading…
Cancel
Save