Commit 47bc416d authored by 前端-许佳敏's avatar 前端-许佳敏

fix: 修复发送验证码无法正常操作

parent 7cea348f
......@@ -11,6 +11,10 @@ const FLAG_SIZE = 60
const IMG_WIDTH = 352
const IMG_HEIGHT = 180
// 国家前缀 暂时写死
const prefixCode = '+86'
const Phone = (props) => {
const { value, form, schema } = props
const {text, isActive, start} = useCountDown({
......@@ -18,6 +22,7 @@ const Phone = (props) => {
minTime: 0,
initText: '获取验证码',
onEnd: () => {
instanceRef.current.canIUseSms = false
form.setFieldState('phone', state => {
state.smsLoading = instanceRef.current.canIUseSms
})
......@@ -74,10 +79,39 @@ const Phone = (props) => {
}
}, [isShowValidate, isActive])
const validatePhoneRequest = async () => {
return new Promise(async (resolve, reject) => {
try {
const { code } = await PublicApi.getMemberRegisterPhoneCheck({
countryCode: prefixCode,
phone: form.getFieldValue('phone')
}, { ctlType: 'none', useCache: true, ttl: 60 * 1000 })
if (code !== 1000) {
form.setFieldState('phone', state => {
state.errors = ['手机号已存在']
resolve(false)
godEvent.emit('SHOW_PHONE_VALIDATE', false)
})
} else {
resolve(true)
}
} catch(err) {
console.log(err)
resolve(false)
}
})
}
const handleClickSms = async () => {
const validateState = await form.validate('phone')
// 注册页手机号字段
const validatePhoneState = await form.validate('phone')
// 忘记密码 手机号或邮箱字段
const validateAccountState = await form.validate('account')
const phoneAsyncValidate = await validatePhoneRequest()
// 手机号未通过校验
if (validateState.errors > 0) {
if (validatePhoneState.errors > 0 || validateAccountState.errors > 0 || !phoneAsyncValidate) {
return false
}
......
......@@ -48,24 +48,24 @@ const useLinkageValidateEffects = () => {
})
})
onFieldValidateEnd$('phone').subscribe(fieldState => {
if (fieldState.valid && !fieldState.smsLoading) {
// 校验手机号格式通过时, 需请求接口判断手机号是否存在数据库
PublicApi.getMemberRegisterPhoneCheck({
countryCode: prefixCode,
phone: fieldState.value
}, { ctlType: 'none', useCache: true, ttl: 60 * 1000 }).then(({ code, data }) => {
if (code !== 1000) {
setFieldState('phone', state => {
state.errors = ['手机号已存在']
eventEmitter.emit('SHOW_PHONE_VALIDATE', false)
})
} else {
eventEmitter.emit('SHOW_PHONE_VALIDATE', true)
}
})
} else {
eventEmitter.emit('SHOW_PHONE_VALIDATE', false)
}
// if (fieldState.valid && !fieldState.smsLoading) {
// // 校验手机号格式通过时, 需请求接口判断手机号是否存在数据库
// PublicApi.getMemberRegisterPhoneCheck({
// countryCode: prefixCode,
// phone: fieldState.value
// }, { ctlType: 'none', useCache: true, ttl: 60 * 1000 }).then(({ code, data }) => {
// if (code !== 1000) {
// setFieldState('phone', state => {
// state.errors = ['手机号已存在']
// eventEmitter.emit('SHOW_PHONE_VALIDATE', false)
// })
// } else {
// eventEmitter.emit('SHOW_PHONE_VALIDATE', true)
// }
// })
// } else {
// eventEmitter.emit('SHOW_PHONE_VALIDATE', false)
// }
})
onFieldValueChange$('*(confirmPassword)').subscribe(fieldState => {
const selfValue = fieldState.value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment