|
|
@ -21,31 +21,32 @@ import { useI18n } from 'vue-i18n' |
|
|
|
import { NInput, NButton, NSwitch, NForm, NFormItem, FormRules } from 'naive-ui' |
|
|
|
import { NInput, NButton, NSwitch, NForm, NFormItem, FormRules } from 'naive-ui' |
|
|
|
import { useRouter } from 'vue-router' |
|
|
|
import { useRouter } from 'vue-router' |
|
|
|
import type { Router } from 'vue-router' |
|
|
|
import type { Router } from 'vue-router' |
|
|
|
|
|
|
|
import { queryLog } from '@/service/modules/login' |
|
|
|
|
|
|
|
|
|
|
|
const Login = defineComponent({ |
|
|
|
const login = defineComponent({ |
|
|
|
name: 'login', |
|
|
|
name: 'login', |
|
|
|
setup() { |
|
|
|
setup() { |
|
|
|
const { t, locale } = useI18n() |
|
|
|
const { t, locale } = useI18n() |
|
|
|
const state = reactive({ |
|
|
|
const state = reactive({ |
|
|
|
loginFormRef: ref(), |
|
|
|
loginFormRef: ref(), |
|
|
|
loginForm: { |
|
|
|
loginForm: { |
|
|
|
username: '', |
|
|
|
userName: '', |
|
|
|
password: '', |
|
|
|
userPassword: '', |
|
|
|
}, |
|
|
|
}, |
|
|
|
rules: { |
|
|
|
rules: { |
|
|
|
username: { |
|
|
|
userName: { |
|
|
|
trigger: ['input', 'blur'], |
|
|
|
trigger: ['input', 'blur'], |
|
|
|
validator() { |
|
|
|
validator() { |
|
|
|
if (state.loginForm.username === '') { |
|
|
|
if (state.loginForm.userName === '') { |
|
|
|
return new Error(`${t('login.username_tips')}`) |
|
|
|
return new Error(`${t('login.userName_tips')}`) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
password: { |
|
|
|
userPassword: { |
|
|
|
trigger: ['input', 'blur'], |
|
|
|
trigger: ['input', 'blur'], |
|
|
|
validator() { |
|
|
|
validator() { |
|
|
|
if (state.loginForm.password === '') { |
|
|
|
if (state.loginForm.userPassword === '') { |
|
|
|
return new Error(`${t('login.password_tips')}`) |
|
|
|
return new Error(`${t('login.userPassword_tips')}`) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
@ -60,7 +61,10 @@ const Login = defineComponent({ |
|
|
|
const handleLogin = () => { |
|
|
|
const handleLogin = () => { |
|
|
|
state.loginFormRef.validate((valid: any) => { |
|
|
|
state.loginFormRef.validate((valid: any) => { |
|
|
|
if (!valid) { |
|
|
|
if (!valid) { |
|
|
|
router.push({ path: 'home' }) |
|
|
|
queryLog({...state.loginForm}).then((res: Response) => { |
|
|
|
|
|
|
|
console.log('res', res) |
|
|
|
|
|
|
|
router.push({ path: 'home' }) |
|
|
|
|
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log('Invalid') |
|
|
|
console.log('Invalid') |
|
|
|
} |
|
|
|
} |
|
|
@ -91,29 +95,29 @@ const Login = defineComponent({ |
|
|
|
<div class={styles['form-model']}> |
|
|
|
<div class={styles['form-model']}> |
|
|
|
<NForm rules={this.rules} ref='loginFormRef'> |
|
|
|
<NForm rules={this.rules} ref='loginFormRef'> |
|
|
|
<NFormItem |
|
|
|
<NFormItem |
|
|
|
label={this.t('login.username')} |
|
|
|
label={this.t('login.userName')} |
|
|
|
label-style={{ color: 'black' }} |
|
|
|
label-style={{ color: 'black' }} |
|
|
|
path='username' |
|
|
|
path='userName' |
|
|
|
> |
|
|
|
> |
|
|
|
<NInput |
|
|
|
<NInput |
|
|
|
type='text' |
|
|
|
type='text' |
|
|
|
size='large' |
|
|
|
size='large' |
|
|
|
v-model={[this.loginForm.username, 'value']} |
|
|
|
v-model={[this.loginForm.userName, 'value']} |
|
|
|
placeholder={this.t('login.username_tips')} |
|
|
|
placeholder={this.t('login.userName_tips')} |
|
|
|
autofocus |
|
|
|
autofocus |
|
|
|
onKeydown={withKeys(this.handleLogin, ['enter'])} |
|
|
|
onKeydown={withKeys(this.handleLogin, ['enter'])} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</NFormItem> |
|
|
|
</NFormItem> |
|
|
|
<NFormItem |
|
|
|
<NFormItem |
|
|
|
label={this.t('login.password')} |
|
|
|
label={this.t('login.userPassword')} |
|
|
|
label-style={{ color: 'black' }} |
|
|
|
label-style={{ color: 'black' }} |
|
|
|
path='password' |
|
|
|
path='userPassword' |
|
|
|
> |
|
|
|
> |
|
|
|
<NInput |
|
|
|
<NInput |
|
|
|
type='password' |
|
|
|
type='password' |
|
|
|
size='large' |
|
|
|
size='large' |
|
|
|
v-model={[this.loginForm.password, 'value']} |
|
|
|
v-model={[this.loginForm.userPassword, 'value']} |
|
|
|
placeholder={this.t('login.password_tips')} |
|
|
|
placeholder={this.t('login.userPassword_tips')} |
|
|
|
onKeydown={withKeys(this.handleLogin, ['enter'])} |
|
|
|
onKeydown={withKeys(this.handleLogin, ['enter'])} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</NFormItem> |
|
|
|
</NFormItem> |
|
|
@ -128,4 +132,4 @@ const Login = defineComponent({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
export default Login |
|
|
|
export default login |
|
|
|