12
12
<span class =" icon secret-icon" ></span >
13
13
<input type =" password" v-model =" account.password" autocomplete =" off" placeholder =" 请填写用户登录密码" />
14
14
</div >
15
+ <div class =" form-item password" v-if =" captchaImage" >
16
+ <img class =" captcha" :src =" captchaImage" />
17
+ <input type =" password" v-model =" account.captcha" autocomplete =" off" placeholder =" 请填写验证码" />
18
+ </div >
15
19
<button class =" submit-btn" type =" submit" >登录</button >
16
20
</form >
17
21
</div >
22
26
import { reactive , ref , onMounted , getCurrentInstance } from ' vue'
23
27
import { useStore } from ' vuex'
24
28
import { useRouter } from ' vue-router'
29
+ import axios from ' lin/plugin/axios'
25
30
import UserModel from ' @/lin/model/user'
26
31
import Utils from ' @/lin/util/util'
27
32
import Config from ' @/config'
28
33
29
34
export default {
30
35
setup () {
36
+ let tag = ' '
31
37
const wait = 2000 // 2000ms之内不能重复发起请求
32
38
const loading = ref (false )
39
+ const captchaImage = ref (' ' )
33
40
const store = useStore ()
34
41
const router = useRouter ()
35
42
const throttleLogin = ref (null )
@@ -38,16 +45,17 @@ export default {
38
45
const account = reactive ({
39
46
username: ' ' ,
40
47
password: ' ' ,
48
+ captcha: ' ' ,
41
49
})
42
50
43
51
/**
44
52
* 根据账号密码登录,拿到 token 并储存
45
53
*/
46
54
const login = async () => {
47
- const { username , password } = account
55
+ const { username , password , captcha } = account
48
56
try {
49
57
loading .value = true
50
- await UserModel .getToken (username, password)
58
+ await UserModel .getToken (username, password, captcha, tag )
51
59
await getInformation ()
52
60
loading .value = false
53
61
router .push (Config .defaultRoute )
@@ -60,6 +68,16 @@ export default {
60
68
}
61
69
}
62
70
71
+ const getCaptcha = async () => {
72
+ axios ({
73
+ method: ' POST' ,
74
+ url: ' cms/user/captcha' ,
75
+ }).then (result => {
76
+ ;({ tag } = result)
77
+ captchaImage .value = result .image
78
+ })
79
+ }
80
+
63
81
/**
64
82
* 获取并更新当前管理员信息
65
83
*/
@@ -78,12 +96,14 @@ export default {
78
96
* 节流登录
79
97
*/
80
98
onMounted (() => {
99
+ getCaptcha ()
81
100
throttleLogin .value = Utils .throttle (login, wait)
82
101
})
83
102
84
103
return {
85
104
account,
86
105
loading,
106
+ captchaImage,
87
107
throttleLogin,
88
108
}
89
109
},
@@ -130,6 +150,7 @@ export default {
130
150
width : 100% ;
131
151
132
152
.form-item {
153
+ position : relative ;
133
154
width : 100% ;
134
155
height : 40px ;
135
156
box-sizing : border-box ;
@@ -145,6 +166,13 @@ export default {
145
166
padding-left : 74px ;
146
167
box-sizing : border-box ;
147
168
}
169
+
170
+ .captcha {
171
+ position : absolute ;
172
+ width : 80px ;
173
+ right : 30px ;
174
+ top : -22px ;
175
+ }
148
176
}
149
177
150
178
.form-item.nickname {
0 commit comments