Files
shgx_tz_mes_backend_sync/ZR.Vue/src/views/login.vue

212 lines
5.9 KiB
Vue
Raw Normal View History

2021-08-23 16:57:25 +08:00
<template>
<div class="login">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
2021-12-10 08:29:11 +08:00
<h3 class="title">{{title}}</h3>
2021-08-23 16:57:25 +08:00
<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="密码" @keyup.enter.native="handleLogin">
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
</el-input>
</el-form-item>
2021-12-01 16:56:46 +08:00
<el-form-item prop="code" v-if="showCaptcha != 'off'">
2021-08-23 16:57:25 +08:00
<el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin" ref="codeTxt">
<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:0px 0px 25px 0px;">记住密码</el-checkbox>
<el-form-item style="width:100%;">
<el-button :loading="loading" size="medium" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
<span v-if="!loading"> </span>
<span v-else> 中...</span>
</el-button>
</el-form-item>
</el-form>
<!-- 底部 -->
2021-09-26 17:01:52 +08:00
<div class="el-login-footer">
2021-10-11 11:17:42 +08:00
<span>Copyright ©2021 izhaorui.cn All Rights Reserved.</span>
2021-09-26 17:01:52 +08:00
</div>
2021-08-23 16:57:25 +08:00
</div>
</template>
<script>
2021-09-10 10:44:17 +08:00
import { getCodeImg } from "@/api/system/login";
2021-08-23 16:57:25 +08:00
import Cookies from "js-cookie";
2021-12-01 16:56:46 +08:00
// import { encrypt, decrypt } from "@/utils/jsencrypt";
2021-11-06 12:51:43 +08:00
import defaultSettings from "@/settings";
2021-08-23 16:57:25 +08:00
export default {
name: "Login",
data() {
return {
codeUrl: "",
cookiePassword: "",
loginForm: {
username: "",
password: "",
rememberMe: false,
code: "",
uuid: "",
},
2021-10-11 11:17:42 +08:00
title: defaultSettings.title,
2021-08-23 16:57:25 +08:00
loginRules: {
username: [
{ required: true, trigger: "blur", message: "用户名不能为空" },
],
password: [
{ required: true, trigger: "blur", message: "密码不能为空" },
],
code: [
{ required: true, trigger: "change", message: "验证码不能为空" },
],
},
2021-12-01 16:56:46 +08:00
showCaptcha: '',
2021-08-23 16:57:25 +08:00
loading: false,
redirect: undefined,
};
},
watch: {
$route: {
handler: function (route) {
this.redirect = route.query && route.query.redirect;
},
immediate: true,
},
},
created() {
this.getCode();
this.getCookie();
2021-12-01 16:56:46 +08:00
this.getConfigKey("sys.account.captchaOnOff").then((response) => {
this.showCaptcha = response.data;
});
2021-08-23 16:57:25 +08:00
},
methods: {
getCode() {
// this.loginForm.code = "";
2021-08-23 16:57:25 +08:00
getCodeImg().then((res) => {
this.codeUrl = "data:image/gif;base64," + res.data.img;
this.loginForm.uuid = res.data.uuid;
this.$forceUpdate();
2021-08-23 16:57:25 +08:00
});
},
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,
2021-11-06 12:51:43 +08:00
password: password === undefined ? this.loginForm.password : password,
2021-08-23 16:57:25 +08:00
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", 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(() => {
2022-03-31 13:42:50 +08:00
this.msgSuccess("登录成功");
2021-08-23 16:57:25 +08:00
this.$router.push({ path: this.redirect || "/" });
})
.catch((error) => {
this.$message(error.msg);
this.loading = false;
this.getCode();
this.$refs.codeTxt.focus();
});
} else {
console.log("未完成");
}
});
},
},
};
</script>
2022-03-23 15:26:43 +08:00
<style scoped rel="stylesheet/scss" lang="scss">
2021-08-23 16:57:25 +08:00
.login {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
2021-12-15 12:53:04 +08:00
background-image: url("../assets/image/login-background.jpg");
2021-08-23 16:57:25 +08:00
background-size: cover;
2021-12-15 12:53:04 +08:00
// background-color: rgba(56, 157, 170, 0.82);
2021-08-23 16:57:25 +08:00
}
.title {
margin: 0px auto 30px auto;
text-align: center;
2021-10-09 15:14:34 +08:00
// color: #707070;
color: #fff;
2021-08-23 16:57:25 +08:00
}
.login-form {
border-radius: 6px;
2021-10-09 15:14:34 +08:00
// background: #ffffff;
2021-11-06 12:51:43 +08:00
background-color: hsla(0, 0%, 100%, 0.3);
2022-03-04 21:48:04 +08:00
width: 310px;
2021-08-23 16:57:25 +08:00
padding: 25px 25px 5px 25px;
.el-input {
height: 38px;
input {
height: 38px;
}
}
.input-icon {
height: 39px;
width: 14px;
margin-left: 2px;
}
}
.login-tip {
font-size: 13px;
text-align: center;
color: #bfbfbf;
}
.login-code {
width: 33%;
height: 38px;
float: right;
img {
cursor: pointer;
vertical-align: middle;
}
}
.el-login-footer {
height: 40px;
line-height: 40px;
position: fixed;
bottom: 0;
width: 100%;
text-align: center;
color: #fff;
font-family: Arial;
font-size: 12px;
letter-spacing: 1px;
}
.login-code-img {
height: 38px;
}
</style>