|
@@ -1,42 +1,77 @@
|
|
|
<template>
|
|
|
<div class="login">
|
|
|
- <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
|
|
- <img src="../assets/images/comlo.png" class="comlogo">
|
|
|
+ <el-form
|
|
|
+ ref="loginForm"
|
|
|
+ :model="loginForm"
|
|
|
+ :rules="loginRules"
|
|
|
+ class="login-form"
|
|
|
+ >
|
|
|
+ <img src="../assets/images/comlo.png" class="comlogo" />
|
|
|
<span class="title">智能制造平台</span>
|
|
|
<el-form-item prop="username">
|
|
|
- <p style="line-height: 12px;">用户名</p>
|
|
|
- <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号" show-password>
|
|
|
+ <p style="line-height: 12px">用户名</p>
|
|
|
+ <el-input
|
|
|
+ v-model="loginForm.username"
|
|
|
+ type="text"
|
|
|
+ auto-complete="off"
|
|
|
+ placeholder="账号"
|
|
|
+ show-password
|
|
|
+ >
|
|
|
<!-- <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> -->
|
|
|
</el-input>
|
|
|
</el-form-item>
|
|
|
<el-form-item prop="password">
|
|
|
- <p style="line-height: 12px;">密码</p>
|
|
|
- <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码"
|
|
|
- @keyup.enter.native="handleLogin" show-password>
|
|
|
+ <p style="line-height: 12px">密码</p>
|
|
|
+ <el-input
|
|
|
+ v-model="loginForm.password"
|
|
|
+ type="password"
|
|
|
+ auto-complete="off"
|
|
|
+ placeholder="密码"
|
|
|
+ @keyup.enter.native="handleLogin"
|
|
|
+ show-password
|
|
|
+ >
|
|
|
<!-- <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">
|
|
|
- <div style="line-height: 12px;">验证码</div>
|
|
|
- <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%"
|
|
|
- @keyup.enter.native="handleLogin" show-password>
|
|
|
+ <div style="line-height: 12px">验证码</div>
|
|
|
+ <el-input
|
|
|
+ v-model="loginForm.code"
|
|
|
+ auto-complete="off"
|
|
|
+ placeholder="验证码"
|
|
|
+ style="width: 63%"
|
|
|
+ @keyup.enter.native="handleLogin"
|
|
|
+ show-password
|
|
|
+ >
|
|
|
<!-- <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;" class="a">在这个设备上记住我</el-checkbox>
|
|
|
-
|
|
|
- <el-form-item style="width:100%;">
|
|
|
- <el-button :loading="loading" size="medium" type="primary" style="width:100%;"
|
|
|
- @click.native.prevent="handleLogin">
|
|
|
+ <el-checkbox
|
|
|
+ v-model="loginForm.rememberMe"
|
|
|
+ style="margin: 0px 0px 25px 0px"
|
|
|
+ class="a"
|
|
|
+ >在这个设备上记住我</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>
|
|
|
- <div style="float: right;" v-if="register">
|
|
|
- <router-link class="link-type" :to="'/register'">立即注册</router-link>
|
|
|
+ <div style="float: right" v-if="register">
|
|
|
+ <router-link class="link-type" :to="'/register'"
|
|
|
+ >立即注册</router-link
|
|
|
+ >
|
|
|
</div>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
@@ -50,7 +85,7 @@
|
|
|
<script>
|
|
|
import { getCodeImg } from "@/api/login";
|
|
|
import Cookies from "js-cookie";
|
|
|
-import { encrypt, decrypt } from '@/utils/jsencrypt'
|
|
|
+import { encrypt, decrypt } from "@/utils/jsencrypt";
|
|
|
|
|
|
export default {
|
|
|
name: "Login",
|
|
@@ -62,23 +97,23 @@ export default {
|
|
|
password: "admin123",
|
|
|
rememberMe: false,
|
|
|
code: "",
|
|
|
- uuid: ""
|
|
|
+ uuid: "",
|
|
|
},
|
|
|
loginRules: {
|
|
|
username: [
|
|
|
- { required: true, trigger: "blur", message: "请输入您的账号" }
|
|
|
+ { required: true, trigger: "blur", message: "请输入您的账号" },
|
|
|
],
|
|
|
password: [
|
|
|
- { required: true, trigger: "blur", message: "请输入您的密码" }
|
|
|
+ { required: true, trigger: "blur", message: "请输入您的密码" },
|
|
|
],
|
|
|
- code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
|
|
+ code: [{ required: true, trigger: "change", message: "请输入验证码" }],
|
|
|
},
|
|
|
loading: false,
|
|
|
// 验证码开关
|
|
|
captchaEnabled: true,
|
|
|
// 注册开关
|
|
|
register: false,
|
|
|
- redirect: undefined
|
|
|
+ redirect: undefined,
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
@@ -86,18 +121,19 @@ export default {
|
|
|
handler: function (route) {
|
|
|
this.redirect = route.query && route.query.redirect;
|
|
|
},
|
|
|
- immediate: true
|
|
|
- }
|
|
|
+ immediate: true,
|
|
|
+ },
|
|
|
},
|
|
|
created() {
|
|
|
this.getCode();
|
|
|
this.getCookie();
|
|
|
},
|
|
|
methods: {
|
|
|
- forgetEvent(){},
|
|
|
+ forgetEvent() {},
|
|
|
getCode() {
|
|
|
- getCodeImg().then(res => {
|
|
|
- this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
|
|
+ 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;
|
|
@@ -107,43 +143,51 @@ export default {
|
|
|
getCookie() {
|
|
|
const username = Cookies.get("username");
|
|
|
const password = Cookies.get("password");
|
|
|
- const rememberMe = Cookies.get('rememberMe')
|
|
|
+ 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)
|
|
|
+ password:
|
|
|
+ password === undefined ? this.loginForm.password : decrypt(password),
|
|
|
+ rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
|
|
};
|
|
|
},
|
|
|
handleLogin() {
|
|
|
- this.$refs.loginForm.validate(valid => {
|
|
|
+ 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 });
|
|
|
+ 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');
|
|
|
+ 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();
|
|
|
- }
|
|
|
- });
|
|
|
+ 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">
|
|
|
-.comlogo{
|
|
|
+.comlogo {
|
|
|
width: 90px;
|
|
|
margin-right: 15px;
|
|
|
}
|
|
@@ -159,11 +203,9 @@ export default {
|
|
|
.title {
|
|
|
margin: 0px 30px 30px auto;
|
|
|
text-align: center;
|
|
|
- color:#07448a;
|
|
|
+ color: #07448a;
|
|
|
font-size: 26px;
|
|
|
font-weight: bolder;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
.login-form {
|
|
@@ -220,8 +262,7 @@ export default {
|
|
|
.login-code-img {
|
|
|
height: 38px;
|
|
|
}
|
|
|
-.a{
|
|
|
+.a {
|
|
|
float: left;
|
|
|
}
|
|
|
-
|
|
|
</style>
|