<template>
|
<el-row class="login">
|
<el-col :sm="24" :md="12" class="login-name">
|
新疆维吾尔自治区特种作业<br/>安全生产知识和管理能力考核平台
|
</el-col>
|
<el-col :sm="24" :md="12" class="login-box">
|
<div class="login-card">
|
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
<h3 class="title">登录系统</h3>
|
<el-form-item prop="username">
|
<el-input
|
v-model="loginForm.username"
|
type="text"
|
auto-complete="off"
|
placeholder="账号"
|
>
|
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
|
</el-input>
|
</el-form-item>
|
<el-form-item prop="password">
|
<el-input
|
v-model="loginForm.password"
|
type="password"
|
auto-complete="off"
|
placeholder="密码"
|
show-password
|
@keyup.enter.native="handleLogin"
|
>
|
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
</el-input>
|
</el-form-item>
|
<el-form-item prop="code" v-if="captchaEnabled">
|
<el-input
|
v-model="loginForm.code"
|
auto-complete="off"
|
placeholder="验证码"
|
style="width: 63%"
|
@keyup.enter.native="handleLogin"
|
>
|
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
</el-input>
|
<div class="login-code">
|
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
</div>
|
</el-form-item>
|
<el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;color: #ccc">记住密码</el-checkbox>
|
<div style="display: flex;justify-content: space-between;align-items: center">
|
<div style="width: 100%">
|
<el-button
|
class="btn-cont"
|
:loading="loading"
|
size="medium"
|
type="primary"
|
@click.native.prevent="handleLogin"
|
>
|
<span v-if="!loading">登 录</span>
|
<span v-else>登 录 中...</span>
|
</el-button>
|
</div>
|
</div>
|
<div style="float: right;" v-if="register">
|
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
</div>
|
|
</el-form>
|
</div>
|
</el-col>
|
<!-- 底部 -->
|
<!-- <div class="el-login-footer">-->
|
<!-- <span>技术支持:中国科学院</span>-->
|
<!-- </div>-->
|
</el-row>
|
</template>
|
|
<script>
|
import { getCodeImg } from "@/api/login";
|
import Cookies from "js-cookie";
|
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
|
export default {
|
name: "Login",
|
data() {
|
return {
|
codeUrl: "",
|
loginForm: {
|
username: "",
|
password: "",
|
rememberMe: false,
|
code: "",
|
uuid: ""
|
},
|
loginRules: {
|
username: [
|
{ required: true, trigger: "blur", message: "请输入您的账号" }
|
],
|
password: [
|
{ required: true, trigger: "blur", message: "请输入您的密码" }
|
],
|
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
},
|
loading: false,
|
// 验证码开关
|
captchaEnabled: true,
|
// 注册开关
|
register: false,
|
redirect: undefined
|
};
|
},
|
watch: {
|
$route: {
|
handler: function(route) {
|
console.log(route,'route')
|
this.redirect = route.query && route.query.redirect;
|
// this.redirect = '/notCoalMine/nPeopleManage'
|
},
|
immediate: true
|
}
|
},
|
created() {
|
this.getCode();
|
this.getCookie();
|
},
|
methods: {
|
getCode() {
|
getCodeImg().then(res => {
|
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
if (this.captchaEnabled) {
|
this.codeUrl = "data:image/gif;base64," + res.img;
|
this.loginForm.uuid = res.uuid;
|
}
|
});
|
},
|
getCookie() {
|
const username = Cookies.get("username")
|
const password = Cookies.get("password")
|
const rememberMe = Cookies.get('rememberMe')
|
this.loginForm = {
|
username: username === undefined ? this.loginForm.username : username,
|
password: password === undefined ? this.loginForm.password : decrypt(password),
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
};
|
},
|
handleLogin() {
|
this.$refs.loginForm.validate(valid => {
|
if (valid) {
|
this.loading = true;
|
if (this.loginForm.rememberMe) {
|
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
} else {
|
Cookies.remove("username");
|
Cookies.remove("password");
|
Cookies.remove('rememberMe');
|
}
|
this.$store.dispatch("Login", this.loginForm).then(() => {
|
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
}).catch(() => {
|
this.loading = false;
|
if (this.captchaEnabled) {
|
this.getCode();
|
}
|
});
|
}
|
});
|
}
|
}
|
};
|
</script>
|
|
<style rel="stylesheet/scss" lang="scss">
|
@font-face {
|
font-family: "AliMa";
|
src: url("../assets/styles/AlimamaShuHeiTi-Bold.ttf");
|
font-style: normal;
|
font-weight: normal;
|
}
|
.login{
|
width: 100%;
|
height: 100%;
|
background: url("../assets/images/login-background.jpg") no-repeat center;
|
background-size: cover;
|
justify-content: center;
|
align-items: center;
|
display: flex;
|
flex-wrap: wrap;
|
position: relative;
|
box-sizing: border-box;
|
}
|
|
@keyframes floatDown {
|
100% {
|
transform: translateY(-80px);
|
opacity: 100%;
|
-webkit-opacity: 100%
|
}
|
}
|
|
.login-name{
|
display: flex;
|
opacity: 0;
|
-webkit-opacity: 0;
|
animation: floatDown ease 0.6s forwards;
|
justify-content: center;
|
align-items: center;
|
font-family: 'AliMa';
|
color: #fff;
|
font-size: 3rem;
|
text-align: center;
|
line-height: 1.6;
|
transform: translateY(-120px);
|
text-shadow: -10px 10px 20px rgba(0,0,0,.4);
|
}
|
|
@keyframes floatUp {
|
100% {
|
transform: translateY(-40px);
|
opacity: 100%;
|
-webkit-opacity: 100%
|
}
|
}
|
|
.login-box{
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
|
.login-card{
|
width: 500px;
|
padding: 30px;
|
border-radius: 16px;
|
background-color: rgba(40,40,40,.4);
|
backdrop-filter: blur(6px);
|
-webkit-backdrop-filter: blur(6px);
|
border: 1px solid rgba(255,255,255,.6);
|
max-width: 100%;
|
box-sizing: border-box;
|
box-shadow: 0 10px 20px rgba(0,0,0,.05);
|
opacity: 0;
|
-webkit-opacity: 0;
|
animation: floatUp ease 0.6s forwards;
|
}
|
.login-form {
|
width: 100%;
|
box-sizing: border-box;
|
|
.title{
|
margin: 0 0 30px;
|
text-align: center;
|
color: #fff;
|
font-size: 1.4rem;
|
letter-spacing: 8px;
|
}
|
|
.el-form-item{
|
margin-bottom: 30px;
|
}
|
|
.el-input {
|
height: 48px;
|
input {
|
height: 48px;
|
}
|
.el-input__prefix{
|
display: flex;
|
left: 15px;
|
align-items: center;
|
}
|
}
|
|
.el-input__inner{
|
padding-left: 45px;
|
}
|
|
.input-icon {
|
height: 42px;
|
width: 16px;
|
margin-left: 0;
|
}
|
}
|
}
|
|
.login-tip {
|
font-size: 13px;
|
text-align: center;
|
color: #bfbfbf;
|
}
|
.login-code {
|
width: 33%;
|
height: 48px;
|
float: right;
|
.login-code-img {
|
display: inline-block;
|
width: 100%;
|
padding-left: 12px;
|
cursor: pointer;
|
vertical-align: middle;
|
}
|
}
|
|
.el-form-item--default{
|
margin-bottom: 15px;
|
}
|
|
::v-deep(.el-form-item__content){
|
display: flex;
|
justify-content: space-between;
|
}
|
|
.login-btn {
|
width: 100%;
|
font-size: 1.2em;
|
padding: 0.6em 0.8em;
|
border-radius: 0.5em;
|
border: none;
|
background-color: #2563EB;
|
color: #fff;
|
cursor: pointer;
|
box-shadow: 2px 2px 3px #000000b4;
|
}
|
|
.btn-cont {
|
width: 100%;
|
height: 48px;
|
padding: 3px;
|
background: #03a9f4;
|
border-radius: 0.6em;
|
box-sizing: border-box;
|
font-size: 18px;
|
}
|
</style>
|