251 lines
6.0 KiB
Vue
251 lines
6.0 KiB
Vue
<template>
|
|
<div class="login-container">
|
|
<div class="form-container">
|
|
<el-form
|
|
ref="loginForm"
|
|
:model="loginForm"
|
|
:rules="loginRules"
|
|
class="login-form"
|
|
auto-complete="on"
|
|
label-position="left"
|
|
>
|
|
<div class="logo-container">
|
|
<img src="@/assets/images/logo.png">
|
|
</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="on"
|
|
/>
|
|
</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="on"
|
|
/>
|
|
<!-- <span class="show-pwd" @click="showPwd">
|
|
<svg-icon
|
|
:icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
|
|
/>
|
|
</span> -->
|
|
</el-form-item>
|
|
|
|
<el-form-item prop="verifycode" style="background-color:transparent;border:0px">
|
|
<el-input v-model="loginForm.verifycode" style="width:50%" placeholder="验证码" tabindex="3" @keyup.enter.native="handleLogin" />
|
|
<img ref="verifyGif" :src="gifUrl" width="40%" style="float:right;cursor: pointer;" @click="getVerifycode">
|
|
</el-form-item>
|
|
<el-form-item prop="autoLogin" style="background-color:transparent;border:0px">
|
|
<a href="http://www.baidu.com" style="color:#1890FF;float: right;">忘记密码</a>
|
|
</el-form-item>
|
|
<div class="button-container">
|
|
<el-button
|
|
:loading="loading"
|
|
type="primary"
|
|
style="width: 70%; margin-bottom: 30px"
|
|
@click.native.prevent="handleLogin"
|
|
>登录</el-button>
|
|
</div>
|
|
</el-form>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { getGifCode } from '@/api/user'
|
|
|
|
export default {
|
|
name: 'Login',
|
|
data() {
|
|
const validateUsername = (rule, value, callback) => {
|
|
if (!value) {
|
|
callback(new Error('请输入用户名'))
|
|
} else {
|
|
callback()
|
|
}
|
|
}
|
|
const validatePassword = (rule, value, callback) => {
|
|
if (!value) {
|
|
callback(new Error('请输入密码'))
|
|
} else {
|
|
callback()
|
|
}
|
|
}
|
|
return {
|
|
loginForm: {
|
|
username: 'aiitxios',
|
|
password: 'xiosaiit',
|
|
verifycode: ''
|
|
},
|
|
loginRules: {
|
|
username: [
|
|
{ required: true, trigger: 'blur', validator: validateUsername }
|
|
],
|
|
password: [
|
|
{ required: true, trigger: 'blur', validator: validatePassword }
|
|
]
|
|
},
|
|
loading: false,
|
|
passwordType: 'password',
|
|
redirect: undefined,
|
|
gifUrl: ''
|
|
}
|
|
},
|
|
watch: {
|
|
$route: {
|
|
handler: function(route) {
|
|
console.log('route', route)
|
|
this.redirect = route.query && route.query.redirect
|
|
},
|
|
immediate: true
|
|
}
|
|
},
|
|
mounted() {
|
|
this.getVerifycode()
|
|
},
|
|
methods: {
|
|
getVerifycode() {
|
|
getGifCode().then(res => {
|
|
this.gifUrl = window.URL.createObjectURL(res)
|
|
}).catch()
|
|
},
|
|
handleLogin() {
|
|
this.$refs.loginForm.validate((valid) => {
|
|
if (valid) {
|
|
this.loading = true
|
|
this.$store
|
|
.dispatch('user/login', this.loginForm)
|
|
.then(() => {
|
|
this.$router.push({ path: this.redirect || '/' })
|
|
this.loading = false
|
|
})
|
|
.catch(() => {
|
|
this.loading = false
|
|
})
|
|
} else {
|
|
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;
|
|
}
|
|
}
|
|
</style>
|
|
|
|
<style lang="scss" scoped>
|
|
.login-container {
|
|
min-height: 100%;
|
|
width: 100%;
|
|
background: url("~@/assets/images/background.png") no-repeat;
|
|
background-size: 100% 100%;
|
|
overflow: hidden;
|
|
.form-container {
|
|
width: 650px;
|
|
max-width: 100%;
|
|
margin: 160px auto 0;
|
|
background-color: rgba(255, 255, 255, 0.2);
|
|
border-radius: 17px;
|
|
}
|
|
.login-form {
|
|
position: relative;
|
|
width: 520px;
|
|
max-width: 100%;
|
|
margin: 0 auto;
|
|
padding: 36px 0;
|
|
overflow: hidden;
|
|
.logo-container {
|
|
display: flex;
|
|
justify-content: center;
|
|
margin-bottom: 19px;
|
|
}
|
|
}
|
|
|
|
.svg-container {
|
|
padding: 6px 5px 6px 15px;
|
|
color: rgb(67, 142, 253);
|
|
vertical-align: middle;
|
|
width: 30px;
|
|
display: inline-block;
|
|
}
|
|
|
|
.title-container {
|
|
position: relative;
|
|
|
|
.title {
|
|
font-size: 30px;
|
|
color: #fff;
|
|
margin: 0px auto 24px auto;
|
|
text-align: center;
|
|
font-weight: bold;
|
|
}
|
|
}
|
|
|
|
.button-container{
|
|
display: flex;
|
|
justify-content: center;
|
|
}
|
|
|
|
::v-deep .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: black;
|
|
height: 47px;
|
|
&:-webkit-autofill {
|
|
box-shadow: 0 0 0px 1000px #fff inset !important;
|
|
}
|
|
}
|
|
}
|
|
|
|
.el-form-item {
|
|
margin: 23px auto;
|
|
width: 70%;
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
background: #fff;
|
|
color: #454545;
|
|
}
|
|
}
|
|
</style>
|