perf: 优化首页登录
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-form size="large" class="login-content-form">
|
<el-form ref="formRef" size="large" class="login-content-form" :model="state.ruleForm" :rules="rules">
|
||||||
<el-form-item class="login-animation1">
|
<el-form-item class="login-animation1" prop="username">
|
||||||
<el-input type="text" :placeholder="$t('message.account.accountPlaceholder1')" v-model="ruleForm.username"
|
<el-input type="text" :placeholder="$t('message.account.accountPlaceholder1')" v-model="ruleForm.username"
|
||||||
clearable autocomplete="off">
|
clearable autocomplete="off">
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item class="login-animation2">
|
<el-form-item class="login-animation2" prop="password">
|
||||||
<el-input :type="isShowPassword ? 'text' : 'password'" :placeholder="$t('message.account.accountPlaceholder2')"
|
<el-input :type="isShowPassword ? 'text' : 'password'" :placeholder="$t('message.account.accountPlaceholder2')"
|
||||||
v-model="ruleForm.password">
|
v-model="ruleForm.password">
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item class="login-animation3" v-if="isShowCaptcha">
|
<el-form-item class="login-animation3" v-if="isShowCaptcha" prop="captcha">
|
||||||
<el-col :span="15">
|
<el-col :span="15">
|
||||||
<el-input type="text" maxlength="4" :placeholder="$t('message.account.accountPlaceholder3')"
|
<el-input type="text" maxlength="4" :placeholder="$t('message.account.accountPlaceholder3')"
|
||||||
v-model="ruleForm.captcha" clearable autocomplete="off">
|
v-model="ruleForm.captcha" clearable autocomplete="off">
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item class="login-animation4">
|
<el-form-item class="login-animation4">
|
||||||
<el-button type="primary" class="login-content-submit" round @click.enter="loginClick"
|
<el-button type="primary" class="login-content-submit" round @keyup.enter="loginClick" @click="loginClick"
|
||||||
:loading="loading.signIn">
|
:loading="loading.signIn">
|
||||||
<span>{{ $t('message.account.accountBtnText') }}</span>
|
<span>{{ $t('message.account.accountBtnText') }}</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
@@ -48,9 +48,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { toRefs, reactive, defineComponent, computed, onMounted, onUnmounted } from 'vue';
|
import { toRefs, reactive, defineComponent, computed, onMounted, onUnmounted, ref } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage, FormInstance, FormRules } from 'element-plus';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
@@ -66,6 +66,7 @@ import { DictionaryStore } from '/@/stores/dictionary';
|
|||||||
import { SystemConfigStore } from '/@/stores/systemConfig';
|
import { SystemConfigStore } from '/@/stores/systemConfig';
|
||||||
import { BtnPermissionStore } from '/@/plugin/permission/store.permission';
|
import { BtnPermissionStore } from '/@/plugin/permission/store.permission';
|
||||||
import { Md5 } from 'ts-md5';
|
import { Md5 } from 'ts-md5';
|
||||||
|
import { errorMessage } from '/@/utils/message';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'loginAccount',
|
name: 'loginAccount',
|
||||||
@@ -89,6 +90,26 @@ export default defineComponent({
|
|||||||
signIn: false,
|
signIn: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
username: [
|
||||||
|
{ required: true, message: '请填写账号', trigger: 'blur' },
|
||||||
|
],
|
||||||
|
password: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请填写密码',
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
captcha: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请填写验证码',
|
||||||
|
trigger: 'blur',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
const formRef = ref();
|
||||||
// 时间获取
|
// 时间获取
|
||||||
const currentTime = computed(() => {
|
const currentTime = computed(() => {
|
||||||
return formatAxis(new Date());
|
return formatAxis(new Date());
|
||||||
@@ -111,6 +132,9 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const loginClick = async () => {
|
const loginClick = async () => {
|
||||||
|
if (!formRef.value) return
|
||||||
|
await formRef.value.validate((valid: any) => {
|
||||||
|
if (valid) {
|
||||||
loginApi.login({ ...state.ruleForm, password: Md5.hashStr(state.ruleForm.password) }).then((res: any) => {
|
loginApi.login({ ...state.ruleForm, password: Md5.hashStr(state.ruleForm.password) }).then((res: any) => {
|
||||||
if (res.code === 2000) {
|
if (res.code === 2000) {
|
||||||
Session.set('token', res.data.access);
|
Session.set('token', res.data.access);
|
||||||
@@ -131,16 +155,17 @@ export default defineComponent({
|
|||||||
refreshCaptcha();
|
refreshCaptcha();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
errorMessage("请填写登录信息")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
};
|
};
|
||||||
const getUserInfo = () => {
|
const getUserInfo = () => {
|
||||||
useUserInfo().setUserInfos();
|
useUserInfo().setUserInfos();
|
||||||
};
|
};
|
||||||
|
|
||||||
const enterClickLogin = (e: any) => {
|
|
||||||
if (e.keyCode == 13 || e.keyCode == 100) {
|
|
||||||
loginClick();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// 登录成功后的跳转
|
// 登录成功后的跳转
|
||||||
const loginSuccess = () => {
|
const loginSuccess = () => {
|
||||||
//登录成功获取用户信息,获取系统字典数据
|
//登录成功获取用户信息,获取系统字典数据
|
||||||
@@ -172,17 +197,17 @@ export default defineComponent({
|
|||||||
getCaptcha();
|
getCaptcha();
|
||||||
//获取系统配置
|
//获取系统配置
|
||||||
SystemConfigStore().getSystemConfigs();
|
SystemConfigStore().getSystemConfigs();
|
||||||
// window.addEventListener('keyup', enterClickLogin, false);
|
|
||||||
});
|
|
||||||
onUnmounted(() => {
|
|
||||||
// window.removeEventListener('keyup', enterClickLogin, false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
refreshCaptcha,
|
refreshCaptcha,
|
||||||
loginClick,
|
loginClick,
|
||||||
loginSuccess,
|
loginSuccess,
|
||||||
isShowCaptcha,
|
isShowCaptcha,
|
||||||
|
state,
|
||||||
|
formRef,
|
||||||
|
rules,
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user