<template>
|
<div
|
class="login-container"
|
:style="{
|
backgroundSize: 'cover',
|
backgroundImage:
|
'url(' + require('@/assets/images/login_bg.gif') + ')',
|
}"
|
>
|
<div class="login-information">
|
<el-form
|
ref="loginForm"
|
:model="loginForm"
|
:rules="loginRules"
|
class="login-form"
|
auto-complete="on"
|
label-position="left"
|
>
|
<el-form-item prop="account">
|
<el-input
|
ref="account"
|
v-model="loginForm.account"
|
placeholder="请输入用户名"
|
name="account"
|
type="text"
|
tabindex="1"
|
auto-complete="on"
|
:style="{height:38}"
|
>
|
<i slot="prefix" class="el-input__icon">
|
<img src="@/assets/images/user.png" alt width="14px" height="14px">
|
</i>
|
</el-input>
|
</el-form-item>
|
<br>
|
<el-form-item prop="password">
|
<el-input
|
:key="passwordType"
|
ref="password"
|
v-model="loginForm.password"
|
:type="passwordType"
|
placeholder="请输入密码"
|
name="password"
|
tabindex="2"
|
auto-complete="on"
|
@keyup.enter.native="handleLogin"
|
>
|
<i slot="prefix" class="el-input__icon">
|
<img src="@/assets/images/psd.png" alt width="14px" height="14px">
|
</i>
|
</el-input>
|
<span class="show-pwd" @click="showPwd">
|
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
|
</span>
|
</el-form-item>
|
<br>
|
<el-button
|
:loading="loading"
|
type="primary"
|
style="width: 100%; margin-bottom: 30px; fontsize: 18px !important;"
|
@click.native.prevent="handleLogin"
|
>登 录</el-button>
|
</el-form>
|
|
</div>
|
</div>
|
</template>
|
|
<script>
|
// import { validUsername } from '@/utils/validate'
|
// import axios from 'axios'
|
import Cookies from 'js-cookie'
|
import { Encrypt } from '@/utils/AES.js'
|
import { getMenus } from '@/router/dynamicRouter.js'
|
// import store from '@/store'
|
import { getToken, removeToken } from '@/utils/auth'
|
|
export default {
|
name: 'Login',
|
data() {
|
// const validateUsername = (rule, value, callback) => {
|
// if (!validUsername(value)) {
|
// callback(new Error('Please enter the correct user name'))
|
// } else {
|
// callback()
|
// }
|
// }
|
// const validatePassword = (rule, value, callback) => {
|
// if (value.length < 6) {
|
// callback(new Error('The password can not be less than 6 digits'))
|
// } else {
|
// callback()
|
// }
|
// }
|
return {
|
loginForm: {
|
account: '',
|
password: ''
|
},
|
loginRules: {
|
account: [
|
{ required: true, trigger: 'blur', message: '用户名不能为空' }
|
],
|
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
|
},
|
loading: false,
|
passwordType: 'password',
|
redirect: undefined,
|
bg: {
|
// backgroundImage: 'url(' + require('@/assets/images/bg.jpg') + ')',
|
background: 'url(' + require('@/assets/images/login_bg1.gif') + ')' + 'no-repeat top center'
|
}
|
}
|
},
|
watch: {
|
$route: {
|
handler: function(route) {
|
this.redirect = route.query && ''
|
},
|
immediate: true
|
}
|
},
|
methods: {
|
showPwd() {
|
if (this.passwordType === 'password') {
|
this.passwordType = ''
|
} else {
|
this.passwordType = 'password'
|
}
|
this.$nextTick(() => {
|
this.$refs.password.focus()
|
})
|
},
|
handleLogin() {
|
Cookies.set('monitorPointName', this.loginForm.account)
|
this.$refs.loginForm.validate(valid => {
|
if (valid) {
|
this.loginForm.password = Encrypt(this.loginForm.password)
|
this.loading = true
|
this.$store
|
.dispatch('user/login', this.loginForm)
|
.then((res) => {
|
new Promise((resolve, reject) => {
|
getMenus()
|
resolve()
|
}).then(() => {
|
setTimeout(() => {
|
const menusLen = this.$router.options.routes.length
|
if (menusLen === 4) {
|
this.$message.warning('该账号无菜单权限!')
|
this.loginForm.password = ''
|
if (getToken()) {
|
removeToken()
|
}
|
this.loading = false
|
} else {
|
console.log('路由跳转')
|
this.$router.push({ path: this.redirect || '/' })
|
this.loading = false
|
}
|
}, 500)
|
})
|
})
|
.catch(err => {
|
this.loading = false
|
console.log(err)
|
this.loginForm.password = ''
|
this.$message.error(window.loginInfo)
|
})
|
} else {
|
console.log('校验失败')
|
return false
|
}
|
})
|
}
|
}
|
}
|
</script>
|
<style lang="scss">
|
/* 修复input 背景不协调 和光标变色 */
|
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
|
|
$bg: #283443;
|
$light_gray: #fff;
|
$cursor: #fff;
|
|
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
|
.login-container .el-input input {
|
color: $cursor;
|
}
|
}
|
/* reset element-ui css */
|
.login-container {
|
.el-input {
|
|
input {
|
background: #1171b4;
|
border: 1px solid #6eeffc;
|
|
}
|
}
|
|
.el-button--primary {
|
span {
|
font-size: 20px;
|
}
|
}
|
}
|
</style>
|
|
<style lang="scss" scoped>
|
$bg: #2d3a4b;
|
$dark_gray: #889aa4;
|
$light_gray: #eee;
|
|
.login-information {
|
height: 58%;
|
background-repeat: no-repeat;
|
width: 30%;
|
position: relative;
|
left: 52%;
|
top: 30%;
|
color: white;
|
background: url('../../assets/images/logininformation.png');
|
background-size: 100% 100%;
|
}
|
|
.login-container {
|
height: 100%;
|
|
background-size: cover;
|
|
.login-form {
|
position: absolute;
|
width: 60%;
|
height: 200px;
|
color: white;
|
top: 32%;
|
left: 21%;
|
}
|
|
.svg-container {
|
padding: 6px 5px 6px 15px;
|
color: $dark_gray;
|
vertical-align: middle;
|
width: 30px;
|
display: inline-block;
|
}
|
|
.show-pwd {
|
position: absolute;
|
right: 10px;
|
top: 3px;
|
font-size: 16px;
|
color: $dark_gray;
|
cursor: pointer;
|
user-select: none;
|
}
|
}
|
</style>
|