import { defineComponent } from 'vue' import { Col, Popup, Row, Image as VanImage, Loading, Field, Toast } from 'vant' import styles from './index.module.less' import request from '@/helpers/request' import { state } from '@/state' export default defineComponent({ name: 'imgCode', props: { value: Boolean, phone: [String, Number], onClose: { type: Function, // (...args: any[]) => any) | undefined default: () => {} }, onSendCode: { type: Function, default: () => {} } }, data() { let origin = window.location.origin let suffix = state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher' return { isSuffix: suffix, showStatus: false, identifyingCode: origin + suffix + '/code/getImageCode?phone=' + this.phone, code: null } }, mounted() { this.showStatus = this.value }, watch: { value(val: any) { this.showStatus = val }, code(val: any) { if (val.length >= 4) { this.checkVerifyLoginImage() } } }, methods: { async updateIdentifyingCode() { // 刷新token let origin = window.location.origin this.identifyingCode = `${origin}${ this.isSuffix }/code/getImageCode?phone=${this.phone}&token=${Math.random()}` }, async checkVerifyLoginImage() { try { if ((this as any).code.length < 4) { return } await request.post(`${this.isSuffix}/code/verifyImageCode`, { requestType: 'form', data: { phone: this.phone, code: this.code } }) await request.post(`${this.isSuffix}/code/sendSmsCode`, { requestType: 'form', data: { mobile: this.phone, type: 'LOGIN' } }) Toast('验证码已发送') this.onClose() this.onSendCode() } catch { this.updateIdentifyingCode() } } }, render() { return ( // @ts-ignore { this.onClose() }} closeable closeIcon="close" >

输入图形验证码

this.updateIdentifyingCode()} // @ts-ignore vSlots={{ loading: () => }} /> this.updateIdentifyingCode()} > 看不清?换一换
) } })