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

feat:修改密码

parent 8ce3c83d
...@@ -20,9 +20,11 @@ const Phone = (props) => { ...@@ -20,9 +20,11 @@ const Phone = (props) => {
const handleClickSms = () => { const handleClickSms = () => {
if (smsFn) { if (smsFn) {
smsFn(form, () => { smsFn(form, setLoading, () => {
start()
setLoading(false)
}) })
return ;
} }
form.validate('phone').then(result => { form.validate('phone').then(result => {
// 暂时写死, 需优化该组件 // 暂时写死, 需优化该组件
......
...@@ -7,6 +7,8 @@ import { IFormControllers, IFormButtonTypes } from 'god/dist/src/form-page' ...@@ -7,6 +7,8 @@ import { IFormControllers, IFormButtonTypes } from 'god/dist/src/form-page'
import './index.less' import './index.less'
import NiceForm from '@/components/NiceForm'; import NiceForm from '@/components/NiceForm';
import { forgetPwdSchema } from './schema'; import { forgetPwdSchema } from './schema';
import { PATTERN_MAPS } from '@/constants/regExp';
import { omit } from '@/utils';
const GetBack: React.FC = () => { const GetBack: React.FC = () => {
const [validButton, setValidButton] = useState(true) const [validButton, setValidButton] = useState(true)
...@@ -16,7 +18,9 @@ const GetBack: React.FC = () => { ...@@ -16,7 +18,9 @@ const GetBack: React.FC = () => {
} }
const handleSubmit = (value: any) => { const handleSubmit = (value: any) => {
console.log(value, 'handleSubmit') const { account } = value
const accountParams = PATTERN_MAPS.email.test(account) ? {email: account, ...omit(value, ['account'])} : { phone: account, ...omit(value, ['account']) }
console.log(accountParams)
} }
const getBcakForm: IFormControllers[] = [ const getBcakForm: IFormControllers[] = [
...@@ -100,6 +104,29 @@ const GetBack: React.FC = () => { ...@@ -100,6 +104,29 @@ const GetBack: React.FC = () => {
<div className={cx('getBackForm')}> <div className={cx('getBackForm')}>
<NiceForm <NiceForm
schema={forgetPwdSchema} schema={forgetPwdSchema}
onSubmit={handleSubmit}
effects={($, { setFieldState, getFieldState }) => {
$('onFieldValueChange', '*(password,confirmPassword)').subscribe(fieldState => {
const selfName = fieldState.name
const selfValue = fieldState.value
const otherName = selfName == 'password' ? 'confirmPassword' : 'password'
const otherValue = getFieldState(otherName, state => state.value)
setFieldState(otherName, state => {
if (selfValue && otherValue && selfValue !== otherValue) {
state.errors = ['两次密码输入不一致']
} else {
state.errors = ['']
}
})
setFieldState(selfName, state => {
if (selfValue && otherValue && selfValue !== otherValue) {
state.errors = ['两次密码输入不一致']
} else {
state.errors = ['']
}
})
})
}}
/> />
</div> </div>
</Row> </Row>
......
import { ISchema } from '@formily/antd'; import { ISchema } from '@formily/antd';
import { PATTERN_MAPS } from '@/constants/regExp'; import { PATTERN_MAPS } from '@/constants/regExp';
import { GlobalConfig } from '@/global/config'; import { GlobalConfig } from '@/global/config';
import { PublicApi } from '@/services/api';
export const registerStep0Schema: ISchema = { export const registerStep0Schema: ISchema = {
type: 'object', type: 'object',
...@@ -47,9 +48,12 @@ export const registerStep0Schema: ISchema = { ...@@ -47,9 +48,12 @@ export const registerStep0Schema: ISchema = {
}, },
password: { password: {
type: 'string', type: 'string',
required: true,
"x-rules": [ "x-rules": [
{ {
required: true,
message: '请输入密码'
},
{
pattern: PATTERN_MAPS.password, pattern: PATTERN_MAPS.password,
message: '请输入正确的密码' message: '请输入正确的密码'
} }
...@@ -62,9 +66,12 @@ export const registerStep0Schema: ISchema = { ...@@ -62,9 +66,12 @@ export const registerStep0Schema: ISchema = {
}, },
confirmPassword: { confirmPassword: {
type: 'string', type: 'string',
required: true,
"x-rules": [ "x-rules": [
{ {
required: true,
message: '请输入密码'
},
{
pattern: PATTERN_MAPS.password, pattern: PATTERN_MAPS.password,
message: '请输入正确的密码' message: '请输入正确的密码'
} }
...@@ -178,10 +185,14 @@ export const forgetPwdSchema: ISchema = { ...@@ -178,10 +185,14 @@ export const forgetPwdSchema: ISchema = {
full: true full: true
}, },
properties: { properties: {
email: { account: {
type: 'string', type: 'string',
"x-rules": [ "x-rules": [
{ {
required: true,
message: '请输入正确的邮箱/手机号'
},
{
pattern: PATTERN_MAPS.phoneAndEmail, pattern: PATTERN_MAPS.phoneAndEmail,
message: '请输入正确的邮箱/手机号' message: '请输入正确的邮箱/手机号'
}, },
...@@ -202,8 +213,78 @@ export const forgetPwdSchema: ISchema = { ...@@ -202,8 +213,78 @@ export const forgetPwdSchema: ISchema = {
} }
], ],
"x-component-props": { "x-component-props": {
size: 'large',
smsFn: (form, setLoading, callback) => {
form.validate('account').then(() => {
const values = form.getFieldValue('account')
const isPhone = PATTERN_MAPS.phone.test(values)
const isEmail = PATTERN_MAPS.email.test(values)
if (isPhone) {
setLoading(true)
PublicApi.postMemberRegisterPswSms({
countryCode: '+86',
phone: values
}).then(res => {
if (res.code === 1000) {
callback()
}
})
}
if (isEmail) {
setLoading(true)
PublicApi.postMemberRegisterPswEmail({
email: values
}).then(res => {
if (res.code === 1000) {
callback()
}
})
}
})
}
}
},
password: {
type: 'string',
"x-rules": [
{
required: true,
message: '请输入密码'
},
{
pattern: PATTERN_MAPS.password,
message: '请输入正确的密码'
}
],
"x-component-props": {
type: 'password',
placeholder: '请设置你的新密码',
size: 'large' size: 'large'
} }
},
confirmPassword: {
type: 'string',
"x-rules": [
{
required: true,
message: '请输入密码'
},
{
pattern: PATTERN_MAPS.password,
message: '请输入正确的密码'
}
],
"x-component-props": {
type: 'password',
placeholder: '请再次输入密码',
size: 'large',
}
},
submit: {
type: 'string',
"x-component": 'Submit'
} }
} }
} }
......
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