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) return if (!mobileReg.test(this.form.mobile)) { return uni.showToast({ title: '请输入正确手机号', icon: 'error' }) } 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) } }, // 手机号授权登录 async getPhoneNumber(event) { try { let me = this console.log(event) if (event.detail.errMsg === 'getPhoneNumber:ok') { uni.showLoading({ title: '正在登录...', mask: true }); let params = { code: event.detail.code } const res = await Apis.PostWechatLogin(params) 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.error(error) } }, }