Browse Source

图形验证码

panhui 4 years ago
parent
commit
6734cf3bfb
1 changed files with 27 additions and 2 deletions
  1. 27 2
      src/views/account/Register.vue

+ 27 - 2
src/views/account/Register.vue

@@ -54,6 +54,20 @@
                         </van-button>
                     </template>
                 </van-field>
+                <van-field
+                    name="图形验证码"
+                    placeholder="请输入图形验证码"
+                    v-model="form.captcha"
+                    :maxlength="6"
+                    :rules="[{ required: true, message: '请输入图形验证码' }]"
+                >
+                    <template #left-icon>
+                        <img :src="require('@assets/svgs/login_icon_code.svg')" class="icon" />
+                    </template>
+                    <template #button>
+                        <van-image @click="getCode" :src="codeImg" width="68" height="32" fit="contain" />
+                    </template>
+                </van-field>
                 <van-field
                     type="password"
                     name="密码"
@@ -135,10 +149,13 @@ export default {
                 password: '',
                 password2: '',
                 code: '',
-                inviteCode: this.$store.state.inviteCode || ''
+                inviteCode: this.$store.state.inviteCode || '',
+                captchaKey: '',
+                captcha: ''
             },
             checked: false,
-            showInvite: true
+            showInvite: true,
+            codeImg: ''
         };
     },
     beforeRouteEnter(to, from) {
@@ -146,6 +163,12 @@ export default {
         console.log(to, from);
     },
     methods: {
+        getCode() {
+            this.$http.get('/captcha/get').then(res => {
+                this.form.captchaKey = res.key;
+                this.codeImg = res.image;
+            });
+        },
         sendPhone() {
             this.$refs.form.validate('手机号码').then(() => {
                 this.sendMsg(this.form.phone);
@@ -189,6 +212,8 @@ export default {
         } else {
             this.showInvite = true;
         }
+
+        this.getCode();
     }
 };
 </script>