提交 34d4af7b 编写于 作者: G Granty1

Add 'enter' event for login & format login.vue

上级 69742b93
...@@ -3,19 +3,31 @@ ...@@ -3,19 +3,31 @@
<vue-particle-line></vue-particle-line> <vue-particle-line></vue-particle-line>
<el-main class="login-box"> <el-main class="login-box">
<h1 class="title-1"> <h1 class="title-1">
<img class="logo" :src="require('@/assets/logo.png')" alt="" srcset=""> <img
class="logo"
:src="require('@/assets/logo.png')"
alt=""
srcset=""
/>
</h1> </h1>
<el-form :model="loginForm" :rules="rules" ref="loginForm"> <el-form :model="loginForm" :rules="rules" ref="loginForm" @keyup.enter.native="submitForm">
<el-form-item prop="username"> <el-form-item prop="username">
<el-input placeholder="请输入用户名" v-model="loginForm.username"></el-input> <el-input
placeholder="请输入用户名"
v-model="loginForm.username"
></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="password"> <el-form-item prop="password">
<el-input <el-input
:type="lock==='lock'?'password':'text'" :type="lock === 'lock' ? 'password' : 'text'"
placeholder="请输入密码" placeholder="请输入密码"
v-model="loginForm.password" v-model="loginForm.password"
> >
<i :class="'el-input__icon el-icon-' + lock" @click="changeLock" slot="suffix"></i> <i
:class="'el-input__icon el-icon-' + lock"
@click="changeLock"
slot="suffix"
></i>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item style="position:relative"> <el-form-item style="position:relative">
...@@ -25,7 +37,13 @@ ...@@ -25,7 +37,13 @@
placeholder="请输入验证码" placeholder="请输入验证码"
maxlength="10" maxlength="10"
/> />
<img v-if="picPath" :src="path + picPath" alt="请输入验证码" @click="loginVefify()" class="vPic"> <img
v-if="picPath"
:src="path + picPath"
alt="请输入验证码"
@click="loginVefify()"
class="vPic"
/>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button @click="submitForm" style="width:100%">登 录</el-button> <el-button @click="submitForm" style="width:100%">登 录</el-button>
...@@ -37,79 +55,79 @@ ...@@ -37,79 +55,79 @@
</template> </template>
<script> <script>
import { mapActions } from 'vuex' import { mapActions } from "vuex";
import { captcha } from '@/api/user' import { captcha } from "@/api/user";
const path = process.env.VUE_APP_BASE_API const path = process.env.VUE_APP_BASE_API;
export default { export default {
name: 'Login', name: "Login",
data() { data() {
const checkUsername = (rule, value, callback) => { const checkUsername = (rule, value, callback) => {
if (value.length < 5 || value.length > 12) { if (value.length < 5 || value.length > 12) {
return callback(new Error('请输入正确的用户名')) return callback(new Error("请输入正确的用户名"));
} else { } else {
callback() callback();
} }
} };
const checkPassword = (rule, value, callback) => { const checkPassword = (rule, value, callback) => {
if (value.length < 6 || value.length > 12) { if (value.length < 6 || value.length > 12) {
return callback(new Error('请输入正确的密码')) return callback(new Error("请输入正确的密码"));
} else { } else {
callback() callback();
} }
} };
return { return {
lock: 'lock', lock: "lock",
loginForm: { loginForm: {
username: '', username: "",
password: '', password: "",
captcha:'', captcha: "",
captchaId: '', captchaId: "",
}, },
rules: { rules: {
username: [{ validator: checkUsername, trigger: 'blur' }], username: [{ validator: checkUsername, trigger: "blur" }],
password: [{ validator: checkPassword, trigger: 'blur' }] password: [{ validator: checkPassword, trigger: "blur" }],
}, },
path:path, path: path,
logVerify:'', logVerify: "",
picPath:'' picPath: "",
} };
}, },
created() { created() {
this.loginVefify() this.loginVefify();
}, },
methods: { methods: {
...mapActions('user', ['LoginIn']), ...mapActions("user", ["LoginIn"]),
async login() { async login() {
await this.LoginIn(this.loginForm) await this.LoginIn(this.loginForm);
}, },
async submitForm() { async submitForm() {
this.$refs.loginForm.validate(async v => { this.$refs.loginForm.validate(async (v) => {
if (v) { if (v) {
this.login() this.login();
this.loginVefify() this.loginVefify();
} else { } else {
this.$message({ this.$message({
type: 'error', type: "error",
message: '请正确填写登录信息', message: "请正确填写登录信息",
showClose: true showClose: true,
}) });
this.loginVefify() this.loginVefify();
return false return false;
} }
}) });
}, },
changeLock() { changeLock() {
this.lock === 'lock' ? (this.lock = 'unlock') : (this.lock = 'lock') this.lock === "lock" ? (this.lock = "unlock") : (this.lock = "lock");
}, },
loginVefify() { loginVefify() {
captcha({}).then(ele=>{ captcha({}).then((ele) => {
this.picPath = ele.data.picPath this.picPath = ele.data.picPath;
this.loginForm.captchaId = ele.data.captchaId this.loginForm.captchaId = ele.data.captchaId;
}) });
} },
} },
} };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
...@@ -121,16 +139,16 @@ export default { ...@@ -121,16 +139,16 @@ export default {
position: absolute; position: absolute;
left: 50%; left: 50%;
margin-left: -22vw; margin-left: -22vw;
top:5vh; top: 5vh;
.logo{ .logo {
height: 35vh; height: 35vh;
width: 35vh; width: 35vh;
} }
} }
.vPic{ .vPic {
position: absolute; position: absolute;
right: 10px; right: 10px;
bottom: 0px; // 适配ie bottom: 0px; // 适配ie
} }
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册