<template>
|
<div class="login-container">
|
<div class='login-bg'>
|
<div class='bg-title'>企业信息查询系统</div>
|
<div class='bg-pic'></div>
|
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
|
<div class="loginCenter">
|
<!-- <div class="logo">-->
|
<!-- LOGO-->
|
<!-- </div>-->
|
<div class="title-container">
|
<h3 class="title">欢迎登录</h3>
|
</div>
|
|
<el-form-item prop="username">
|
<span class="svg-container">
|
<svg-icon icon-class="user" />
|
</span>
|
<el-input ref="username" v-model="loginForm.username" placeholder="用户名" name="username" type="text" tabindex="1" auto-complete="off" />
|
</el-form-item>
|
|
<el-form-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="密码"
|
name="password"
|
tabindex="2"
|
auto-complete="off"
|
@keyup.enter.native="handleLogin"
|
/>
|
<span class="show-pwd" @click="showPwd">
|
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
|
</span>
|
</el-form-item>
|
|
<el-button class="loginBtn" :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">登录</el-button>
|
</div>
|
|
</el-form>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import { validUsername } from '@/utils/validate';
|
import md5 from 'js-md5';
|
import { getConfigData } from '@/api/serverconfig';
|
|
export default {
|
name: 'Login',
|
data() {
|
const validateUsername = (rule, value, callback) => {
|
if (!validUsername(value)) {
|
callback(new Error('用户名不能为空'));
|
} else {
|
callback();
|
}
|
};
|
const validatePassword = (rule, value, callback) => {
|
if (!value.length) {
|
callback(new Error('密码不能为空'));
|
} else {
|
callback();
|
}
|
};
|
return {
|
loginForm: {
|
username: '',
|
password: ''
|
},
|
loginRules: {
|
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
|
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
|
},
|
loading: false,
|
passwordType: 'password',
|
redirect: undefined
|
};
|
},
|
watch: {
|
$route: {
|
handler: function(route) {
|
this.redirect = route.query && route.query.redirect;
|
},
|
immediate: true
|
}
|
},
|
methods: {
|
showPwd() {
|
if (this.passwordType === 'password') {
|
this.passwordType = '';
|
} else {
|
this.passwordType = 'password';
|
}
|
this.$nextTick(() => {
|
this.$refs.password.focus();
|
});
|
},
|
handleLogin() {
|
this.$refs.loginForm.validate(valid => {
|
if (valid) {
|
this.loading = true;
|
this.$store
|
.dispatch('user/login', {
|
username: this.loginForm.username,
|
password: this.loginForm.password
|
})
|
.then(async res => {
|
if (!res || !res.result) {
|
this.$message(res.msg || '用户名或密码不正确', 'error', 5 * 1000);
|
this.loading = false;
|
return;
|
}
|
|
await this.setConfigDataToStorage();
|
this.setInfo(this.loginForm.username,this.loginForm.password)
|
this.$router.push({ path: '/management' });
|
this.loading = false;
|
})
|
.catch(() => {
|
this.loading = false;
|
});
|
} else {
|
console.log('error submit!!');
|
return false;
|
}
|
});
|
},
|
setInfo(name,password){
|
localStorage.removeItem('name');
|
localStorage.removeItem('password');
|
localStorage.setItem("name",name)
|
localStorage.setItem("password",password)
|
},
|
async setConfigDataToStorage() {
|
localStorage.removeItem('configdata');
|
const response = await getConfigData();
|
if (response && response.result) {
|
const list = response.data.list;
|
localStorage.setItem('configdata', JSON.stringify(list));
|
}
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss">
|
/* 修复input 背景不协调 和光标变色 */
|
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
|
@keyframes right {
|
100%{
|
transform: translateX(50px);
|
opacity: 1;
|
-webkit-opacity: 1;
|
}
|
}
|
|
@keyframes left {
|
100%{
|
transform: translateX(-60px);
|
opacity: 1;
|
-webkit-opacity: 1;
|
}
|
}
|
|
$bg: #283443;
|
$light_gray: black;
|
$cursor: black;
|
|
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
|
.login-container .el-input input {
|
color: $cursor;
|
}
|
}
|
|
/* reset element-ui css */
|
.login-container {
|
.el-input {
|
display: inline-block;
|
height: 47px;
|
width: 85%;
|
|
input {
|
background: transparent;
|
border: 0px;
|
-webkit-appearance: none;
|
border-radius: 0px;
|
padding: 12px 5px 12px 15px;
|
color: $light_gray;
|
height: 47px;
|
caret-color: $cursor;
|
|
&:-webkit-autofill {
|
box-shadow: 0 0 0px 1000px #fff inset !important;
|
-webkit-text-fill-color: $cursor !important;
|
// opacity: 0.1;
|
}
|
}
|
}
|
|
.el-form-item {
|
border: 1px solid rgba(0, 0, 0, 0.1);
|
background: rgba(255, 255, 255, 0.1);
|
border-radius: 5px;
|
color: black;
|
margin-bottom: 40px;
|
}
|
}
|
</style>
|
|
<style lang="scss" scoped>
|
$bg: #2d3a4b;
|
$dark_gray: #889aa4;
|
$light_gray: rgb(20, 133, 254);
|
|
.loginCenter{
|
width:80%;
|
height:100%;
|
display: flex;
|
flex-direction: column;
|
|
}
|
.login-container {
|
min-height: 100%;
|
width: 100%;
|
position: relative;
|
// background-color: $bg;
|
background: url('../../assets/bg.png') no-repeat center;
|
background-size: 100% 100%;
|
overflow: hidden;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
|
.login-bg{
|
position: relative;
|
|
.bg-title{
|
font-size: 52px;
|
font-weight: bolder;
|
color: #fff;
|
margin-bottom: 20px;
|
margin-left: 60px;
|
opacity: 0;
|
-webkit-opacity: 0;
|
text-shadow: 0 8px 16px rgba(38,97,251,.8);
|
animation: right .6s ease-in-out forwards;
|
}
|
|
.bg-pic{
|
width: 1200px;
|
height: 441px;
|
background: url('../../assets/login-form-bg.png') no-repeat center;
|
background-size: 100% 100%;
|
filter: drop-shadow(0 15px 30px rgba(0, 0, 0, 0.2));
|
-webkit-filter: drop-shadow(0 15px 30px rgba(0, 0, 0, 0.2));
|
}
|
}
|
|
.login-form {
|
width: 480px;
|
height: 100%;
|
position: absolute;
|
right: -60px;
|
top: 0;
|
border-radius: 16px;
|
z-index: 9999;
|
max-width: 100%;
|
/*padding: 160px 35px 0;*/
|
margin: 0 auto;
|
overflow: hidden;
|
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
|
background-color: rgba(255,255,255,0);
|
backdrop-filter: blur(4px);
|
-webkit-backdrop-filter: blur(4px);
|
border: 2px solid rgba(255,255,255,.2);
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
opacity: 0;
|
-webkit-opacity: 0;
|
animation: left .6s ease-in-out forwards;
|
|
.el-form-item{
|
background: #fff;
|
box-shadow: 3px 3px 8px rgba(0,0,0,.1), -3px -3px 8px rgba(255,255,255,.2);
|
border: 2px solid #fff;
|
}
|
}
|
|
.tips {
|
font-size: 14px;
|
color: #fff;
|
margin-bottom: 10px;
|
|
span {
|
&:first-of-type {
|
margin-right: 16px;
|
}
|
}
|
}
|
|
.svg-container {
|
padding: 6px 5px 6px 15px;
|
color: $dark_gray;
|
vertical-align: middle;
|
width: 30px;
|
display: inline-block;
|
}
|
|
.title-container {
|
position: relative;
|
|
.title {
|
font-size: 32px;
|
color: #fff;
|
margin: 80px auto 50px;
|
font-weight: bold;
|
}
|
}
|
|
.show-pwd {
|
position: absolute;
|
right: 10px;
|
top: 7px;
|
font-size: 16px;
|
color: $dark_gray;
|
cursor: pointer;
|
user-select: none;
|
}
|
}
|
.loginBtn{
|
background: linear-gradient(90deg, rgb(17, 171, 255) 0%, rgb(17, 171, 255) 0%, rgb(60, 79, 252) 100%, rgb(60, 79, 252) 100%);
|
border-radius: 150px;
|
width: 300px;
|
height: 50px;
|
margin-top: 20px;
|
font-size: 18px;
|
box-shadow: 3px 3px 8px rgba(0,0,0,.1), -2px -2px 6px rgba(255,255,255,.1);
|
|
&:active{
|
background: linear-gradient(-90deg, rgb(17, 171, 255) 0%, rgb(17, 171, 255) 0%, rgb(60, 79, 252) 100%, rgb(60, 79, 252) 100%);
|
box-shadow: -2px -2px 6px rgba(255,255,255,.1) inset,3px 3px 8px rgba(0,0,0,.1) inset;
|
}
|
}
|
.loginInput{
|
border-width: 0px;
|
width: 300px;
|
height: 50px;
|
display: flex;
|
font-family: 'FontAwesome', sans-serif;
|
font-weight: 400;
|
font-style: normal;
|
font-size: 20px;
|
color: transparent;
|
text-align: right;
|
}
|
.logo{
|
margin:0 auto;
|
width: 100px;
|
height: 100px;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
}
|
</style>
|