<template>
|
<div class="login-container">
|
<div class="site-title">
|
<div class="logo"><img :src="logUrl" alt=""></div>{{ platformName }}
|
</div>
|
<div class="img-hm"></div>
|
<div class="login-wrap">
|
<el-form
|
ref="loginFormRef"
|
:model="loginForm"
|
:rules="loginRules"
|
class="login-form"
|
autocomplete="on"
|
label-position="left"
|
>
|
<div class="title-container">
|
<h3 class="title">用户登录</h3>
|
</div>
|
<el-form-item class="input-item" prop="username">
|
<span class="svg-container">
|
<svg-icon icon-class="user" />
|
</span>
|
<el-input
|
ref="username"
|
v-model="loginForm.username"
|
placeholder="Username"
|
name="username"
|
type="text"
|
tabindex="1"
|
autocomplete="on"
|
/>
|
</el-form-item>
|
<el-tooltip
|
v-model="capsTooltip"
|
:content="passwordType === 'password' ?'显示密码':'隐藏密码'"
|
placement="right"
|
manual
|
>
|
<el-form-item class="input-item" prop="password">
|
<span class="svg-container">
|
<svg-icon icon-class="password" />
|
</span>
|
<el-input
|
:key="passwordType"
|
ref="password"
|
v-model="loginForm.password"
|
:type="passwordType"
|
placeholder="Password"
|
name="password"
|
tabindex="2"
|
autocomplete="on"
|
@keyup="checkCapslock"
|
@blur="capsTooltip = false"
|
@keyup.enter="handleLogin"
|
/>
|
<span class="show-pwd" @click="showPwd">
|
<svg-icon
|
:icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
|
/>
|
</span>
|
</el-form-item>
|
</el-tooltip>
|
<el-form-item>
|
<el-row class="el_row" :gutter="0">
|
<span class="svg-container pos">
|
<svg-icon icon-class="dun" />
|
</span>
|
<el-col :span="16">
|
<el-input
|
class="input"
|
placeholder="验证码"
|
v-model="loginForm.verify"
|
@keyup.enter="handleLogin"
|
></el-input>
|
</el-col>
|
<el-col :span="8">
|
<v-sidentify
|
:identifyCode="verifyCode"
|
@click="changeVerifyCode"
|
></v-sidentify>
|
</el-col>
|
</el-row>
|
</el-form-item>
|
<el-button
|
:loading="loading"
|
type="primary"
|
style="width:100%; height:50px; background: #40CFF7; color: #070E28; font-size:20px; margin-bottom:40px;"
|
@click.prevent="handleLogin"
|
>登录</el-button
|
>
|
</el-form>
|
</div>
|
</div>
|
</template>
|
|
<script setup name="Login">
|
import { ref, computed, reactive, watch, onMounted, nextTick } from 'vue';
|
import { ElMessage } from 'element-plus';
|
|
import { mapState } from 'pinia';
|
import config from '@/utils/config.js';
|
import useElement from '@/hooks/useElement.js';
|
import { getValidCode } from '@/api/user';
|
import { getToken, removeToken, setToken, getUname, setUname, removeUname, getUrole, setUrole, removeUrole } from '@/utils/auth';
|
import { useUserStore } from '@/store/user';
|
import { useSettingsStore } from '@/store/settings';
|
import { storeToRefs } from 'pinia';
|
import { useRoute, useRouter } from 'vue-router';
|
import defaultSettings from '@/settings';
|
import VSidentify from './components/verifyComponent.vue';
|
|
import gjdw from '@/assets/images/gjdw-log.png';
|
|
const platformName = defaultSettings.title;
|
|
const route = useRoute();
|
const router = useRouter();
|
|
const userStore = useUserStore();
|
const settingsStore = useSettingsStore();
|
const { login } = userStore;
|
const { changeSetting } = settingsStore;
|
|
const { $loading, $confirm, $message } = useElement();
|
|
const verifyCode = ref('');
|
const verify = ref('');
|
|
const logUrl = ref(gjdw);
|
|
|
const validateUsername = (_rule, value, callback) => {
|
if (!value.trim()) {
|
callback(new Error('请输入用户名'));
|
} else {
|
callback();
|
}
|
};
|
const validatePassword = (_rule, value, callback) => {
|
if (value.length < 1) {
|
callback(new Error('请输入密码,至少1位'));
|
} else {
|
callback();
|
}
|
};
|
|
const loginFormRef = ref();
|
const username = ref();
|
const password = ref();
|
const loginForm = reactive({
|
username: '',
|
password: '',
|
verify: ''
|
});
|
|
// TODO
|
loginForm.username = 'hw';
|
loginForm.password = '123456';
|
|
const loginRules = reactive({
|
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
|
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
|
});
|
|
const passwordType = ref('password');
|
const capsTooltip = ref(false);
|
const loading = ref(false);
|
const showDialog = ref(false);
|
const redirect = ref(undefined);
|
const otherQuery = ref({});
|
|
watch(
|
() => route.path,
|
() => {
|
let query = route.query;
|
if (query) {
|
redirect.value = query.redirect;
|
otherQuery.value = getOtherQuery(query);
|
}
|
},
|
{
|
immediate: true
|
}
|
);
|
|
onMounted(() => {
|
if (loginForm.username === '') {
|
username.value.focus();
|
} else if (loginForm.password === '') {
|
password.value.focus();
|
}
|
// themeChange('blue-theme');
|
changeVerifyCode();
|
});
|
|
// function themeChange(val) {
|
// changeSetting({
|
// key: 'theme',
|
// value: val
|
// });
|
// }
|
|
function changeVerifyCode(isLogin) {
|
let loading = $loading();
|
getValidCode()
|
.then((res) => {
|
loading.close();
|
res = res;
|
if (res.code) {
|
verifyCode.value = res.data + "";
|
} else {
|
verifyCode.value = "";
|
}
|
loginForm.verify = "";
|
})
|
.catch((error) => {
|
loading.close();
|
verifyCode.value = "";
|
loginForm.verify = "";
|
});
|
}
|
|
function checkCapslock(e) {
|
const { key } = e;
|
capsTooltip.value = key && key.length === 1 && (key >= 'A' && key <= 'Z');
|
}
|
|
function showPwd() {
|
if (passwordType.value === 'password') {
|
passwordType.value = '';
|
} else {
|
passwordType.value = 'password';
|
}
|
nextTick(() => {
|
password.value.focus();
|
})
|
}
|
|
function handleLogin() {
|
normalLogin();
|
}
|
|
|
function normalLogin() {
|
loginFormRef.value.validate(valid => {
|
return new Promise((resolve, reject) => {
|
if (valid) {
|
loading.value = true;
|
login({username:loginForm.username, password: loginForm.password, code: loginForm.verify})
|
.then((res) => {
|
loading.value = false;
|
let { code, data, msg } = res;
|
if (code && data) {
|
ElMessage({
|
message: msg,
|
type: 'success'
|
});
|
router.push({ path: redirect.value || '/', query: otherQuery.value });
|
} else {
|
ElMessage({
|
message: msg,
|
type: 'error'
|
});
|
}
|
}).catch((error) => {
|
loading.value = false;
|
console.log('error', error, '=============');
|
|
if (error?.message === 'Network Error') {
|
// 如果是网络错误,显示中文消息
|
ElMessage({
|
message: '网络错误,请检查您的网络连接或服务器状态。',
|
type: 'error'
|
});
|
} else {
|
ElMessage({
|
message: error,
|
type: 'warning'
|
});
|
}
|
}).finally(() => {
|
loading.value = false;
|
resolve();
|
});
|
} else {
|
reject();
|
}
|
})
|
});
|
}
|
|
function getOtherQuery(query) {
|
return Object.keys(query).reduce((acc, cur) => {
|
if (cur !== 'redirect') {
|
acc[cur] = query[cur];
|
}
|
return acc;
|
}, {});
|
}
|
</script>
|
|
<style lang="scss">
|
/* 修复input 背景不协调 和光标变色 */
|
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
|
|
// $bg: #283443;
|
// $light_gray: #fff;
|
$cursor: #999;
|
// $input_bg: rgba(0, 0, 0, 0.1);
|
// $input_color: #000;
|
|
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
|
.login-container .el-input input {
|
color: $cursor;
|
}
|
}
|
|
/* reset element-plus css */
|
.login-container {
|
.el-input {
|
height: 47px;
|
width: 85%;
|
|
.el-input__wrapper,
|
input {
|
background: transparent;
|
border: 0px;
|
-webkit-appearance: none;
|
border-radius: 0px;
|
box-shadow: none;
|
}
|
|
input {
|
padding: 12px 5px 12px 15px;
|
color: #fff;
|
height: 47px;
|
caret-color: $cursor;
|
|
&:-webkit-autofill {
|
box-shadow: 0 0 0px 1000px rgba(255, 255, 255, 0.1) inset !important;
|
-webkit-text-fill-color: #fff !important;
|
}
|
}
|
}
|
|
.el-form-item {
|
border: 1px solid #247CF7;
|
background: rgba(0, 0, 0, 0.1);
|
// border-radius: 5px;
|
color: #454545;
|
}
|
}
|
</style>
|
|
<style lang="scss" scoped>
|
$bg: #2d3a4b;
|
$dark_gray: #889aa4;
|
$light_gray: #eee;
|
|
.login-container {
|
height: 100%;
|
width: 100%;
|
background: url("@/assets/images/bg-login1.png"),
|
url("@/assets/images/bg-login0.jpg");
|
background-size: 100% 100%;
|
background-repeat: no-repeat;
|
overflow: hidden;
|
// &::before {
|
// content: "";
|
// position: absolute;
|
// top: 0;
|
// left: 0;
|
// width: 100%;
|
// height: 100%;
|
// background: url("@/assets/images/bg-login1.png");
|
// }
|
|
.login-wrap {
|
position: relative;
|
// width: 80vh;
|
width: 450px;
|
height: 47vh;
|
left: 50%;
|
top: 50%;
|
transform: translate(-51%, -58%);
|
|
// max-width: 100%;
|
// margin: 260px 10% 0 auto;
|
// margin: 260px auto 0;
|
// transform: translate(clamp(0px, calc(36vw - 50%), 50vw), 0);
|
padding: 8px;
|
overflow: hidden;
|
// background-color: #1d4167;
|
// background: rgba(255, .255, 255, 0.2);
|
// border: 2px solid #0d3c68;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
.login-form {
|
// display: none;
|
// background: #fff;
|
// width: 46vh;
|
width: 100%;
|
// padding: 36px 70px 36px;
|
// border: 2px solid #064ec3;
|
}
|
.input-item {
|
margin-bottom: 28px;
|
}
|
}
|
.el_row {
|
width: 100%;
|
}
|
|
.site-title {
|
font-size: 46px;
|
font-weight: 700;
|
color: #0ff;
|
position: absolute;
|
left: 0;
|
top: 12%;
|
transform: translate(clamp(0px, calc(24vw - 50%), 50vw), -50%);
|
display: flex;
|
align-items: center;
|
|
.logo {
|
position: relative;
|
width: 5.5rem;
|
height: 2.5rem;
|
margin-right: 24px;
|
img {
|
width: 100%;
|
height: 100%;
|
object-fit: contain;
|
// mask-image: linear-gradient(#fff, #fff);
|
// mask-size: cover;
|
// mask-repeat: no-repeat;
|
}
|
&::after {
|
position: absolute;
|
content: '';
|
top: 50%;
|
right: -12px;
|
width: 2px;
|
height: 80%;
|
transform: translateY(-50%);
|
background: #0ff;
|
}
|
}
|
}
|
|
.tips {
|
font-size: 14px;
|
color: #fff;
|
margin-bottom: 10px;
|
|
span {
|
&:first-of-type {
|
margin-right: 16px;
|
}
|
}
|
}
|
|
.img-hm {
|
position: absolute;
|
width: clamp(500px, 50vw, 800px);
|
height: clamp(300px, 80vh, 80vh);
|
background: url(@/assets/images/img-hm.png) center center / contain no-repeat;
|
left: 0;
|
top: 20%;
|
transform: translate(clamp(0px, calc(24vw - 50%), 50vw), 0);
|
}
|
|
.svg-container {
|
padding: 6px 5px 6px 15px;
|
color: #fff;
|
vertical-align: middle;
|
width: 30px;
|
display: inline-block;
|
&.pos {
|
position: absolute;
|
left: 0;
|
top: 0;
|
font-size: 20px;
|
padding-left: 10px;
|
& + :deep(.el-col .el-input__wrapper) {
|
padding-left: 41px;
|
}
|
}
|
}
|
|
.title-container {
|
position: relative;
|
|
.title {
|
font-size: 38px;
|
color: #fff;
|
// margin: 0px auto 40px auto;
|
margin-bottom: 30px;
|
margin-top: 0;
|
text-align: center;
|
letter-spacing: 0.2em;
|
// font-weight: bold;
|
font-weight: normal;
|
}
|
}
|
|
.show-pwd {
|
position: absolute;
|
right: 10px;
|
top: 7px;
|
font-size: 16px;
|
color: #fff;
|
cursor: pointer;
|
user-select: none;
|
}
|
|
.thirdparty-button {
|
position: absolute;
|
right: 0;
|
bottom: 6px;
|
}
|
|
.tools-container {
|
position: absolute;
|
bottom: 0;
|
right: 0;
|
background-color: #ffffff;
|
}
|
|
.tools-container .tools-item {
|
padding: 8px;
|
width: 40px;
|
height: 40px;
|
cursor: pointer;
|
|
.face {
|
display: inline-block;
|
width: 100%;
|
height: 100%;
|
background: url("data:image/svg+xml,%3csvg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' %3e%3cpath d='M161.6 153.1h128.7V73.3H99.7c-8.3 0-15.1 6.7-15.1 15.1V286h76.9V153.1z m692.7 132.8h76.9V88.3c0-8.3-6.7-15.1-15.1-15.1H725.9V153h128.3v132.9zM605 449.2s140.1 88.3 161.6 22.2c0-148.1-115.8-268-258.5-268s-258.5 119.9-258.5 268C386.9 521.9 605 449.2 605 449.2z m161.6 134.1h-43.2s1 59.4-53.8 78C668.4 693.9 615 829 508.7 829c-106.2 0-160.9-135.1-162.2-167.7-55-18.9-52.5-78-52.5-78h-44.5s-1.6 78 64.6 100.6c1.6 38.2 66.2 189.9 193.9 189.9s192.6-151.4 193.9-189.9c66.3-22.5 64.7-100.6 64.7-100.6zM161.9 738.1H84.6v197.6c0 8.3 6.7 15.1 15.1 15.1h190.2V871h-128V738.1z m692.4 132.8H725.9v79.8h190.2c8.3 0 15.1-6.7 15.1-15.1V738.1h-76.9v132.8zM945 520H79c-8.2 0-15 6.7-15 15v2.2c0 8.2 6.7 15 15 15h866c8.2 0 15-6.7 15-15V535c0-8.3-6.7-15-15-15z' fill='%23333333'%3e%3c/path%3e%3c/svg%3e") center center / contain no-repeat;
|
}
|
|
.ukey {
|
display: inline-block;
|
width: 100%;
|
height: 100%;
|
background: url("data:image/svg+xml,%3csvg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' %3e%3cpath d='M456.26 247.11a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m160 0a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m72-64h-352v248h352z m79.9 357.5h-53.7a8 8 0 0 0-6.6 3.5l-81 118.2a157.35 157.35 0 0 0-8.2 15.6h-0.9v-129.2a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v274.4a8 8 0 0 0 8 8h45.9a8 8 0 0 0 8-8V689h0.9a90.25 90.25 0 0 0 7.7 15.2L712 827.71a8.19 8.19 0 0 0 6.6 3.4h58.3a7.84 7.84 0 0 0 4.7-1.6 8 8 0 0 0 1.7-11.2l-103-139.1 94.3-125.8a8.37 8.37 0 0 0 1.6-4.8 8 8 0 0 0-8.04-8z m-459.3 0.1h-46.1a8 8 0 0 0-8 8v160.8q0 126.6 116.6 126.6 120.9 0 120.8-129.9v-157.5a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v164q0 69.9-56.2 69.9-57.15 0-57.2-72.6v-161.3a8 8 0 0 0-8-8z m419.4-429.6a32 32 0 0 1 32 31.47v288.53c65.54 0 118.93 51.06 120 114.09v357.91a8 8 0 0 1-7.75 8H152.26a8 8 0 0 1-8-7.75V547.11c0-63.26 52.73-115 118-116h2v-288a32 32 0 0 1 31.47-32h432.53z' fill='%230000ff'%3e%3c/path%3e%3c/svg%3e") center center / contain no-repeat;
|
}
|
|
&.state-default .ukey {
|
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' %3e%3cpath d='M456.26 247.11a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m160 0a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m72-64h-352v248h352z m79.9 357.5h-53.7a8 8 0 0 0-6.6 3.5l-81 118.2a157.35 157.35 0 0 0-8.2 15.6h-0.9v-129.2a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v274.4a8 8 0 0 0 8 8h45.9a8 8 0 0 0 8-8V689h0.9a90.25 90.25 0 0 0 7.7 15.2L712 827.71a8.19 8.19 0 0 0 6.6 3.4h58.3a7.84 7.84 0 0 0 4.7-1.6 8 8 0 0 0 1.7-11.2l-103-139.1 94.3-125.8a8.37 8.37 0 0 0 1.6-4.8 8 8 0 0 0-8.04-8z m-459.3 0.1h-46.1a8 8 0 0 0-8 8v160.8q0 126.6 116.6 126.6 120.9 0 120.8-129.9v-157.5a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v164q0 69.9-56.2 69.9-57.15 0-57.2-72.6v-161.3a8 8 0 0 0-8-8z m419.4-429.6a32 32 0 0 1 32 31.47v288.53c65.54 0 118.93 51.06 120 114.09v357.91a8 8 0 0 1-7.75 8H152.26a8 8 0 0 1-8-7.75V547.11c0-63.26 52.73-115 118-116h2v-288a32 32 0 0 1 31.47-32h432.53z' fill='%23808080'%3e%3c/path%3e%3c/svg%3e")
|
}
|
|
&.state-error .ukey {
|
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' %3e%3cpath d='M456.26 247.11a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m160 0a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m72-64h-352v248h352z m79.9 357.5h-53.7a8 8 0 0 0-6.6 3.5l-81 118.2a157.35 157.35 0 0 0-8.2 15.6h-0.9v-129.2a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v274.4a8 8 0 0 0 8 8h45.9a8 8 0 0 0 8-8V689h0.9a90.25 90.25 0 0 0 7.7 15.2L712 827.71a8.19 8.19 0 0 0 6.6 3.4h58.3a7.84 7.84 0 0 0 4.7-1.6 8 8 0 0 0 1.7-11.2l-103-139.1 94.3-125.8a8.37 8.37 0 0 0 1.6-4.8 8 8 0 0 0-8.04-8z m-459.3 0.1h-46.1a8 8 0 0 0-8 8v160.8q0 126.6 116.6 126.6 120.9 0 120.8-129.9v-157.5a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v164q0 69.9-56.2 69.9-57.15 0-57.2-72.6v-161.3a8 8 0 0 0-8-8z m419.4-429.6a32 32 0 0 1 32 31.47v288.53c65.54 0 118.93 51.06 120 114.09v357.91a8 8 0 0 1-7.75 8H152.26a8 8 0 0 1-8-7.75V547.11c0-63.26 52.73-115 118-116h2v-288a32 32 0 0 1 31.47-32h432.53z' fill='%23ff0000'%3e%3c/path%3e%3c/svg%3e");
|
}
|
}
|
|
.tools-container .tools-item:hover {
|
background-color: #e4e4e4;
|
}
|
|
.tools-container .iconfont {
|
font-size: 22px;
|
color: #0080ff;
|
}
|
|
.tools-container .state-default .iconfont {
|
color: #808080;
|
}
|
|
.tools-container .state-error .iconfont {
|
color: #ff0000;
|
}
|
|
:deep(.dialog-center) {
|
box-sizing: content-box;
|
}
|
|
|
@media only screen and (max-width: 470px) {
|
.thirdparty-button {
|
display: none;
|
}
|
}
|
}
|
</style>
|