// components/phone-input/phone-input.js import { imgServerUrl } from '../../config/config.js' import { testPhone } from '../../utils/util' Component({ /** * 组件的属性列表 */ properties: { // 标题 title: { type: String, value: '' }, // 是否为登陆 is_login: { type: Boolean, value: false } }, /** * 组件的初始数据 */ data: { imgServerUrl: imgServerUrl, iphone: '', // 电话号码 disabled: false, //样式控制 focus: true }, /** * 组件的方法列表 */ methods: { // 清除输入 clear() { this.setData({ iphone: '' }) }, // 手机号输入 bindPhoneInput(e) { if (e.detail.value.length === 11) { const disabled = testPhone(e.detail.value) if (disabled) { this.setData({ iphone: e.detail.value, disabled, focus: false }) } else { wx.showToast({ icon: 'none', title: '号码格式错误', }) } } else { this.setData({ disabled: false }) } }, // 发送验证码 toSend() { const { iphone, disabled } = this.data; if (disabled) { this.triggerEvent('done', { phone: iphone }) } else { wx.showToast({ icon: 'none', title: '请输入正确的手机号', }) } } } })