import Apis from '@/common/apis/index' let codeStatus = false const mobileReg = /^1[3456789]\d{9}$/ export default { inputMobile(event) { this.form.mobile = event.detail.value }, inputCode(event) { this.form.sms_code = event.detail.value }, async sendCode() { if (codeStatus || !this.form.mobile) return try { const that = this uni.showLoading({ title: '发送中...' }); await Apis.GetVerificationCode({ mobile: this.form.mobile }) uni.hideLoading(); codeStatus = true let num = 60 loop() const time = setInterval(() => { loop() }, 1000) function loop() { num-- if (num <= 0) { num = '重新获取' clearInterval(time) codeStatus = false } that.timeNum = num } } catch (error) { console.log(error) } }, async login() { try { for (let key in this.form) { if (!this.form[key]) { let keyname = { mobile: '手机号', sms_code: '验证码' } [key] uni.showToast({ title: `请输入${keyname}`, duration: 2000, icon: 'error' }); return } } uni.showLoading({ title: '登录中...' }); const res = await Apis.PostSmsLogin(this.form) uni.hideLoading(); if (res.data.token) { uni.setStorageSync('token', res.data.token) uni.setStorageSync('userInfo', res.data.user) uni.switchTab({ url: '../index/index' }) } } catch (error) { console.log(error) } }, }