Skip to content

Commit 34d4af7

Browse files
committed
Add 'enter' event for login & format login.vue
1 parent 69742b9 commit 34d4af7

File tree

1 file changed

+70
-52
lines changed

1 file changed

+70
-52
lines changed

web/src/view/login/login.vue

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,31 @@
33
<vue-particle-line></vue-particle-line>
44
<el-main class="login-box">
55
<h1 class="title-1">
6-
<img class="logo" :src="require('@/assets/logo.png')" alt="" srcset="">
6+
<img
7+
class="logo"
8+
:src="require('@/assets/logo.png')"
9+
alt=""
10+
srcset=""
11+
/>
712
</h1>
8-
<el-form :model="loginForm" :rules="rules" ref="loginForm">
13+
<el-form :model="loginForm" :rules="rules" ref="loginForm" @keyup.enter.native="submitForm">
914
<el-form-item prop="username">
10-
<el-input placeholder="请输入用户名" v-model="loginForm.username"></el-input>
15+
<el-input
16+
placeholder="请输入用户名"
17+
v-model="loginForm.username"
18+
></el-input>
1119
</el-form-item>
1220
<el-form-item prop="password">
1321
<el-input
14-
:type="lock==='lock'?'password':'text'"
22+
:type="lock === 'lock' ? 'password' : 'text'"
1523
placeholder="请输入密码"
1624
v-model="loginForm.password"
1725
>
18-
<i :class="'el-input__icon el-icon-' + lock" @click="changeLock" slot="suffix"></i>
26+
<i
27+
:class="'el-input__icon el-icon-' + lock"
28+
@click="changeLock"
29+
slot="suffix"
30+
></i>
1931
</el-input>
2032
</el-form-item>
2133
<el-form-item style="position:relative">
@@ -25,7 +37,13 @@
2537
placeholder="请输入验证码"
2638
maxlength="10"
2739
/>
28-
<img v-if="picPath" :src="path + picPath" alt="请输入验证码" @click="loginVefify()" class="vPic">
40+
<img
41+
v-if="picPath"
42+
:src="path + picPath"
43+
alt="请输入验证码"
44+
@click="loginVefify()"
45+
class="vPic"
46+
/>
2947
</el-form-item>
3048
<el-form-item>
3149
<el-button @click="submitForm" style="width:100%">登 录</el-button>
@@ -37,79 +55,79 @@
3755
</template>
3856

3957
<script>
40-
import { mapActions } from 'vuex'
41-
import { captcha } from '@/api/user'
42-
const path = process.env.VUE_APP_BASE_API
58+
import { mapActions } from "vuex";
59+
import { captcha } from "@/api/user";
60+
const path = process.env.VUE_APP_BASE_API;
4361
export default {
44-
name: 'Login',
62+
name: "Login",
4563
data() {
4664
const checkUsername = (rule, value, callback) => {
4765
if (value.length < 5 || value.length > 12) {
48-
return callback(new Error('请输入正确的用户名'))
66+
return callback(new Error("请输入正确的用户名"));
4967
} else {
50-
callback()
68+
callback();
5169
}
52-
}
70+
};
5371
const checkPassword = (rule, value, callback) => {
5472
if (value.length < 6 || value.length > 12) {
55-
return callback(new Error('请输入正确的密码'))
73+
return callback(new Error("请输入正确的密码"));
5674
} else {
57-
callback()
75+
callback();
5876
}
59-
}
77+
};
6078
6179
return {
62-
lock: 'lock',
80+
lock: "lock",
6381
loginForm: {
64-
username: '',
65-
password: '',
66-
captcha:'',
67-
captchaId: '',
82+
username: "",
83+
password: "",
84+
captcha: "",
85+
captchaId: "",
6886
},
6987
rules: {
70-
username: [{ validator: checkUsername, trigger: 'blur' }],
71-
password: [{ validator: checkPassword, trigger: 'blur' }]
88+
username: [{ validator: checkUsername, trigger: "blur" }],
89+
password: [{ validator: checkPassword, trigger: "blur" }],
7290
},
73-
path:path,
74-
logVerify:'',
75-
picPath:''
76-
}
91+
path: path,
92+
logVerify: "",
93+
picPath: "",
94+
};
7795
},
7896
created() {
79-
this.loginVefify()
97+
this.loginVefify();
8098
},
8199
methods: {
82-
...mapActions('user', ['LoginIn']),
100+
...mapActions("user", ["LoginIn"]),
83101
async login() {
84-
await this.LoginIn(this.loginForm)
102+
await this.LoginIn(this.loginForm);
85103
},
86104
async submitForm() {
87-
this.$refs.loginForm.validate(async v => {
105+
this.$refs.loginForm.validate(async (v) => {
88106
if (v) {
89-
this.login()
90-
this.loginVefify()
107+
this.login();
108+
this.loginVefify();
91109
} else {
92110
this.$message({
93-
type: 'error',
94-
message: '请正确填写登录信息',
95-
showClose: true
96-
})
97-
this.loginVefify()
98-
return false
111+
type: "error",
112+
message: "请正确填写登录信息",
113+
showClose: true,
114+
});
115+
this.loginVefify();
116+
return false;
99117
}
100-
})
118+
});
101119
},
102120
changeLock() {
103-
this.lock === 'lock' ? (this.lock = 'unlock') : (this.lock = 'lock')
121+
this.lock === "lock" ? (this.lock = "unlock") : (this.lock = "lock");
104122
},
105123
loginVefify() {
106-
captcha({}).then(ele=>{
107-
this.picPath = ele.data.picPath
108-
this.loginForm.captchaId = ele.data.captchaId
109-
})
110-
}
111-
}
112-
}
124+
captcha({}).then((ele) => {
125+
this.picPath = ele.data.picPath;
126+
this.loginForm.captchaId = ele.data.captchaId;
127+
});
128+
},
129+
},
130+
};
113131
</script>
114132

115133
<style scoped lang="scss">
@@ -121,16 +139,16 @@ export default {
121139
position: absolute;
122140
left: 50%;
123141
margin-left: -22vw;
124-
top:5vh;
125-
.logo{
142+
top: 5vh;
143+
.logo {
126144
height: 35vh;
127145
width: 35vh;
128146
}
129147
}
130-
.vPic{
148+
.vPic {
131149
position: absolute;
132150
right: 10px;
133-
bottom: 0px; // 适配ie
151+
bottom: 0px; // 适配ie
134152
}
135153
}
136154
</style>

0 commit comments

Comments
 (0)