refactor: 登录页面优化
Former-commit-id: f26577eff9ac0021bb5fd28d5ba243242a33cb67
This commit is contained in:
@@ -4,55 +4,50 @@
|
|||||||
ref="loginFormRef"
|
ref="loginFormRef"
|
||||||
:model="loginData"
|
:model="loginData"
|
||||||
:rules="loginRules"
|
:rules="loginRules"
|
||||||
class="login-form"
|
class="w-[520px] mx-auto mt-[150px]"
|
||||||
auto-complete="on"
|
|
||||||
label-position="left"
|
|
||||||
>
|
>
|
||||||
<div class="title-container">
|
<div class="flex text-white items-center py-4">
|
||||||
<h3 class="title">{{ $t('login.title') }}</h3>
|
<span class="text-2xl flex-1 text-center">{{ $t('login.title') }}</span>
|
||||||
<lang-select class="set-language" />
|
<lang-select style="color: #fff" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-form-item prop="username">
|
<el-form-item prop="username" class="flex">
|
||||||
<span class="svg-container">
|
<span class="p-2 text-white">
|
||||||
<svg-icon icon-class="user" />
|
<svg-icon icon-class="user" />
|
||||||
</span>
|
</span>
|
||||||
<el-input
|
<el-input
|
||||||
|
class="flex-1"
|
||||||
ref="username"
|
ref="username"
|
||||||
|
size="large"
|
||||||
v-model="loginData.username"
|
v-model="loginData.username"
|
||||||
:placeholder="$t('login.username')"
|
:placeholder="$t('login.username')"
|
||||||
name="username"
|
name="username"
|
||||||
type="text"
|
|
||||||
tabindex="1"
|
|
||||||
auto-complete="on"
|
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-tooltip
|
<el-tooltip
|
||||||
:disabled="capslockTooltipDisabled"
|
:disabled="isCapslock === false"
|
||||||
content="Caps lock is On"
|
content="Caps lock is On"
|
||||||
placement="right"
|
placement="right"
|
||||||
>
|
>
|
||||||
<el-form-item prop="password">
|
<el-form-item class="flex" prop="password">
|
||||||
<span class="svg-container">
|
<span class="p-2 text-white">
|
||||||
<svg-icon icon-class="password" />
|
<svg-icon icon-class="password" />
|
||||||
</span>
|
</span>
|
||||||
<el-input
|
<el-input
|
||||||
ref="passwordRef"
|
class="flex-1"
|
||||||
:key="passwordType"
|
|
||||||
v-model="loginData.password"
|
v-model="loginData.password"
|
||||||
:type="passwordType"
|
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
|
:type="passwordVisible === false ? 'password' : 'input'"
|
||||||
|
size="large"
|
||||||
name="password"
|
name="password"
|
||||||
tabindex="2"
|
|
||||||
auto-complete="on"
|
|
||||||
@keyup="checkCapslock"
|
@keyup="checkCapslock"
|
||||||
@blur="capslockTooltipDisabled = true"
|
|
||||||
@keyup.enter="handleLogin"
|
@keyup.enter="handleLogin"
|
||||||
/>
|
/>
|
||||||
<span class="show-pwd" @click="showPwd">
|
<span class="mr-2" @click="passwordVisible = !passwordVisible">
|
||||||
<svg-icon
|
<svg-icon
|
||||||
:icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
|
:icon-class="passwordVisible === false ? 'eye' : 'eye-open'"
|
||||||
|
class="text-white cursor-pointer"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -62,32 +57,21 @@
|
|||||||
size="default"
|
size="default"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
type="primary"
|
type="primary"
|
||||||
style="width: 100%; margin-bottom: 30px"
|
class="w-full"
|
||||||
@click.prevent="handleLogin"
|
@click.prevent="handleLogin"
|
||||||
>{{ $t('login.login') }}
|
>{{ $t('login.login') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
|
||||||
<!-- 账号密码提示 -->
|
<!-- 账号密码提示 -->
|
||||||
<div class="tips">
|
<div class="mt-4 text-white text-sm">
|
||||||
<div style="position: relative">
|
<span>{{ $t('login.username') }}: admin</span>
|
||||||
<span style="margin-right: 20px"
|
<span class="ml-4"> {{ $t('login.password') }}: 123456</span>
|
||||||
>{{ $t('login.username') }}: admin</span
|
|
||||||
>
|
|
||||||
<span> {{ $t('login.password') }}: 123456</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<div v-if="showCopyright == true" class="copyright">
|
|
||||||
<p>{{ $t('login.copyright') }}</p>
|
|
||||||
<p>{{ $t('login.icp') }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, reactive, ref, toRefs, watch, nextTick } from 'vue';
|
|
||||||
|
|
||||||
// 组件依赖
|
// 组件依赖
|
||||||
import { ElForm, ElInput } from 'element-plus';
|
import { ElForm, ElInput } from 'element-plus';
|
||||||
import router from '@/router';
|
import router from '@/router';
|
||||||
@@ -98,34 +82,27 @@ import SvgIcon from '@/components/SvgIcon/index.vue';
|
|||||||
import { useUserStore } from '@/store/modules/user';
|
import { useUserStore } from '@/store/modules/user';
|
||||||
|
|
||||||
// API依赖
|
// API依赖
|
||||||
import { useRoute } from 'vue-router';
|
import { LocationQuery, LocationQueryValue, useRoute } from 'vue-router';
|
||||||
import { LoginData } from '@/api/auth/types';
|
import { LoginType } from '@/api/auth/types';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const loginFormRef = ref(ElForm);
|
const loginFormRef = ref(ElForm);
|
||||||
const passwordRef = ref(ElInput);
|
|
||||||
|
|
||||||
const state = reactive({
|
const loginData = ref<LoginType>({
|
||||||
redirect: '',
|
|
||||||
loginData: {
|
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: '123456'
|
password: '123456'
|
||||||
} as LoginData,
|
});
|
||||||
loginRules: {
|
|
||||||
|
const loginRules = {
|
||||||
username: [{ required: true, trigger: 'blur' }],
|
username: [{ required: true, trigger: 'blur' }],
|
||||||
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
|
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
|
||||||
},
|
};
|
||||||
loading: false,
|
|
||||||
passwordType: 'password',
|
const passwordVisible = ref(false);
|
||||||
// 大写提示禁用
|
|
||||||
capslockTooltipDisabled: true,
|
const loading = ref(false);
|
||||||
otherQuery: {},
|
|
||||||
clientHeight: document.documentElement.clientHeight,
|
|
||||||
showCopyright: true,
|
|
||||||
showDialog: false
|
|
||||||
});
|
|
||||||
|
|
||||||
function validatePassword(rule: any, value: any, callback: any) {
|
function validatePassword(rule: any, value: any, callback: any) {
|
||||||
if (value.length < 6) {
|
if (value.length < 6) {
|
||||||
@@ -135,30 +112,12 @@ function validatePassword(rule: any, value: any, callback: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
// 是否大写锁定
|
||||||
loginData,
|
const isCapslock = ref(false);
|
||||||
loginRules,
|
|
||||||
loading,
|
|
||||||
passwordType,
|
|
||||||
capslockTooltipDisabled,
|
|
||||||
showCopyright
|
|
||||||
} = toRefs(state);
|
|
||||||
|
|
||||||
function checkCapslock(e: any) {
|
function checkCapslock(e: any) {
|
||||||
const { key } = e;
|
const { key } = e;
|
||||||
state.capslockTooltipDisabled =
|
isCapslock.value = key && key.length === 1 && key >= 'A' && key <= 'Z';
|
||||||
key && key.length === 1 && key >= 'A' && key <= 'Z';
|
|
||||||
}
|
|
||||||
|
|
||||||
function showPwd() {
|
|
||||||
if (passwordType.value === 'password') {
|
|
||||||
passwordType.value = '';
|
|
||||||
} else {
|
|
||||||
passwordType.value = 'password';
|
|
||||||
}
|
|
||||||
nextTick(() => {
|
|
||||||
passwordRef.value.focus();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,220 +126,59 @@ function showPwd() {
|
|||||||
function handleLogin() {
|
function handleLogin() {
|
||||||
loginFormRef.value.validate((valid: boolean) => {
|
loginFormRef.value.validate((valid: boolean) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
state.loading = true;
|
loading.value = true;
|
||||||
userStore
|
userStore
|
||||||
.login(state.loginData)
|
.login(loginData.value)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
router.push({ path: state.redirect || '/', query: state.otherQuery });
|
const query: LocationQuery = route.query;
|
||||||
state.loading = false;
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
state.loading = false;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
const redirect = (query.redirect as LocationQueryValue) ?? '/';
|
||||||
route,
|
|
||||||
() => {
|
|
||||||
const query = route.query;
|
|
||||||
if (query) {
|
|
||||||
state.redirect = query.redirect as string;
|
|
||||||
state.otherQuery = getOtherQuery(query);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
immediate: true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
function getOtherQuery(query: any) {
|
const otherQueryParams = Object.keys(query).reduce(
|
||||||
return Object.keys(query).reduce((acc: any, cur: any) => {
|
(acc: any, cur: string) => {
|
||||||
if (cur !== 'redirect') {
|
if (cur !== 'redirect') {
|
||||||
acc[cur] = query[cur];
|
acc[cur] = query[cur];
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
},
|
||||||
}
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
router.push({ path: redirect, query: otherQueryParams });
|
||||||
window.onresize = () => {
|
})
|
||||||
if (state.clientHeight > document.documentElement.clientHeight) {
|
.finally(() => {
|
||||||
state.showCopyright = false;
|
loading.value = false;
|
||||||
} else {
|
|
||||||
state.showCopyright = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss" scoped>
|
||||||
$bg: #283443;
|
|
||||||
$light_gray: #fff;
|
|
||||||
$cursor: #fff;
|
|
||||||
|
|
||||||
/* reset element-ui css */
|
|
||||||
.login-container {
|
.login-container {
|
||||||
.title-container {
|
min-height: 100%;
|
||||||
position: relative;
|
width: 100%;
|
||||||
|
background-color: #2d3a4b;
|
||||||
.title {
|
overflow: hidden;
|
||||||
font-size: 26px;
|
|
||||||
color: $light_gray;
|
|
||||||
margin: 0px auto 40px auto;
|
|
||||||
text-align: center;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.set-language {
|
|
||||||
color: #fff;
|
|
||||||
position: absolute;
|
|
||||||
top: 3px;
|
|
||||||
font-size: 18px;
|
|
||||||
right: 0px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
.el-form-item {
|
||||||
|
border: 1px solid #ffffff1a;
|
||||||
|
background: rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.el-input {
|
.el-input {
|
||||||
display: inline-block;
|
background: transparent;
|
||||||
height: 36px;
|
// 子组件 scoped 无效使用 :deep
|
||||||
width: 85%;
|
:deep .el-input__wrapper {
|
||||||
.el-input__wrapper {
|
|
||||||
padding: 0;
|
padding: 0;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
.el-input__inner {
|
.el-input__inner {
|
||||||
background: transparent;
|
|
||||||
border: 0px;
|
|
||||||
-webkit-appearance: none;
|
|
||||||
border-radius: 0px;
|
|
||||||
color: $light_gray;
|
|
||||||
height: 36px;
|
|
||||||
caret-color: $cursor;
|
|
||||||
|
|
||||||
&:-webkit-autofill {
|
|
||||||
box-shadow: 0 0 0px 1000px $bg inset !important;
|
|
||||||
-webkit-text-fill-color: $cursor !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.el-input__inner {
|
|
||||||
&:hover {
|
|
||||||
border-color: var(--el-input-hover-border, var(--el-border-color-hover));
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.el-form-item {
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
||||||
background: rgba(0, 0, 0, 0.1);
|
|
||||||
border-radius: 5px;
|
|
||||||
color: #454545;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copyright {
|
|
||||||
width: 100%;
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
font-size: 12px;
|
|
||||||
text-align: center;
|
|
||||||
color: #cccccc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
$bg: #2d3a4b;
|
|
||||||
$dark_gray: #889aa4;
|
|
||||||
$light_gray: #eee;
|
|
||||||
|
|
||||||
.login-container {
|
|
||||||
min-height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
background-color: $bg;
|
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
.login-form {
|
|
||||||
position: relative;
|
|
||||||
width: 520px;
|
|
||||||
max-width: 100%;
|
|
||||||
padding: 160px 35px 0;
|
|
||||||
margin: 0 auto;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tips {
|
|
||||||
font-size: 14px;
|
|
||||||
color: #fff;
|
color: #fff;
|
||||||
margin-bottom: 10px;
|
background: transparent;
|
||||||
|
caret-color: #fff;
|
||||||
span {
|
|
||||||
&:first-of-type {
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.svg-container {
|
|
||||||
padding: 5px 10px;
|
|
||||||
color: $dark_gray;
|
|
||||||
vertical-align: middle;
|
|
||||||
width: 30px;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title-container {
|
|
||||||
position: relative;
|
|
||||||
|
|
||||||
.title {
|
|
||||||
font-size: 26px;
|
|
||||||
color: $light_gray;
|
|
||||||
margin: 0px auto 40px auto;
|
|
||||||
text-align: center;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.show-pwd {
|
|
||||||
position: absolute;
|
|
||||||
right: 10px;
|
|
||||||
top: 7px;
|
|
||||||
font-size: 16px;
|
|
||||||
color: $dark_gray;
|
|
||||||
cursor: pointer;
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.captcha {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
|
|
||||||
img {
|
|
||||||
height: 42px;
|
|
||||||
cursor: pointer;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.thirdparty-button {
|
|
||||||
position: absolute;
|
|
||||||
right: 40px;
|
|
||||||
bottom: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (max-width: 470px) {
|
|
||||||
.thirdparty-button {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user