Commit 2bb62c82 authored by 前端-许佳敏's avatar 前端-许佳敏

fix:加入忘记密码校验

parent a5198e4a
......@@ -13,6 +13,8 @@ import { createFormActions } from '@formily/antd';
import { PublicApi } from '@/services/api';
const actions = createFormActions()
const prefixCode = '+86'
const GetBack: React.FC = () => {
const handleSubmit = async (value: any) => {
......@@ -45,6 +47,45 @@ const GetBack: React.FC = () => {
SubmitBtn
}}
effects={($, { setFieldState, getFieldState }) => {
$('onFieldInputChange', 'account').subscribe(fieldState => {
// 手动输入的时候 重置校验信息
setFieldState('account', state => {
state.errors = []
})
})
$('onFieldValidateEnd', 'account').subscribe(fieldState => {
if (fieldState.valid) {
if (PATTERN_MAPS.phone.test(fieldState.value)) {
// 校验手机号格式通过时, 需请求接口判断手机号是否存在数据库
PublicApi.getMemberRegisterPhoneCheck({
countryCode: prefixCode,
phone: fieldState.value
}, { ctlType: 'none', useCache: true, ttl: 60 * 1000 }).then(({ code, data }) => {
if (code === 1000) {
setFieldState('account', state => {
state.errors = ['手机号不存在, 请检查']
})
}
})
return ;
}
if (PATTERN_MAPS.email.test(fieldState.value)) {
// 校验邮箱格式通过时, 需请求接口判断邮箱是否存在数据库
PublicApi.getMemberRegisterEmailCheck({
email: fieldState.value
}, { ctlType: 'none', useCache: true, ttl: 60 * 1000 }).then(({ code, data }) => {
if (code === 1000) {
setFieldState('account', state => {
state.errors = ['邮箱不存在, 请检查']
})
}
})
return ;
}
}
})
$('onFieldValueChange', '*(password,confirmPassword)').subscribe(fieldState => {
const selfName = fieldState.name
const selfValue = fieldState.value
......
import { ISchema } from '@formily/antd';
import { ISchema, ISchemaFormActions } from '@formily/antd';
import { PATTERN_MAPS } from '@/constants/regExp';
import { GlobalConfig } from '@/global/config';
import { PublicApi } from '@/services/api';
......@@ -221,8 +221,12 @@ export const forgetPwdSchema: ISchema = {
],
"x-component-props": {
size: 'large',
smsFn: (form, setLoading, callback) => {
form.validate('account').then(() => {
smsFn: (form: ISchemaFormActions, setLoading, callback) => {
form.validate('account').then((res) => {
const state = form.getFieldState('account')
if (state.errors?.length > 0) {
return ;
}
const values = form.getFieldValue('account')
const isPhone = PATTERN_MAPS.phone.test(values)
const isEmail = PATTERN_MAPS.email.test(values)
......
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