1212 <span class =" icon secret-icon" ></span >
1313 <input type =" password" v-model =" account.password" autocomplete =" off" placeholder =" 请填写用户登录密码" />
1414 </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 >
1519 <button class =" submit-btn" type =" submit" >登录</button >
1620 </form >
1721 </div >
2226import { reactive , ref , onMounted , getCurrentInstance } from ' vue'
2327import { useStore } from ' vuex'
2428import { useRouter } from ' vue-router'
29+ import axios from ' lin/plugin/axios'
2530import UserModel from ' @/lin/model/user'
2631import Utils from ' @/lin/util/util'
2732import Config from ' @/config'
2833
2934export default {
3035 setup () {
36+ let tag = ' '
3137 const wait = 2000 // 2000ms之内不能重复发起请求
3238 const loading = ref (false )
39+ const captchaImage = ref (' ' )
3340 const store = useStore ()
3441 const router = useRouter ()
3542 const throttleLogin = ref (null )
@@ -38,16 +45,17 @@ export default {
3845 const account = reactive ({
3946 username: ' ' ,
4047 password: ' ' ,
48+ captcha: ' ' ,
4149 })
4250
4351 /**
4452 * 根据账号密码登录,拿到 token 并储存
4553 */
4654 const login = async () => {
47- const { username , password } = account
55+ const { username , password , captcha } = account
4856 try {
4957 loading .value = true
50- await UserModel .getToken (username, password)
58+ await UserModel .getToken (username, password, captcha, tag )
5159 await getInformation ()
5260 loading .value = false
5361 router .push (Config .defaultRoute )
@@ -60,6 +68,16 @@ export default {
6068 }
6169 }
6270
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+
6381 /**
6482 * 获取并更新当前管理员信息
6583 */
@@ -78,12 +96,14 @@ export default {
7896 * 节流登录
7997 */
8098 onMounted (() => {
99+ getCaptcha ()
81100 throttleLogin .value = Utils .throttle (login, wait)
82101 })
83102
84103 return {
85104 account,
86105 loading,
106+ captchaImage,
87107 throttleLogin,
88108 }
89109 },
@@ -130,6 +150,7 @@ export default {
130150 width : 100% ;
131151
132152 .form-item {
153+ position : relative ;
133154 width : 100% ;
134155 height : 40px ;
135156 box-sizing : border-box ;
@@ -145,6 +166,13 @@ export default {
145166 padding-left : 74px ;
146167 box-sizing : border-box ;
147168 }
169+
170+ .captcha {
171+ position : absolute ;
172+ width : 80px ;
173+ right : 30px ;
174+ top : -22px ;
175+ }
148176 }
149177
150178 .form-item.nickname {
0 commit comments