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

feat:修改密码

parent 7d4f8798
import React, { useState, Fragment } from 'react';
import cx from 'classnames';
import { Row } from 'antd';
import { Link, Helmet } from 'umi'
import { Row, Button } from 'antd';
import { Link, Helmet, history } from 'umi'
import { FormPage, RiskCheck } from 'god'
import { IFormControllers, IFormButtonTypes } from 'god/dist/src/form-page'
import './index.less'
......@@ -9,90 +9,25 @@ import NiceForm from '@/components/NiceForm';
import { forgetPwdSchema } from './schema';
import { PATTERN_MAPS } from '@/constants/regExp';
import { omit } from '@/utils';
import { createFormActions } from '@formily/antd';
import { PublicApi } from '@/services/api';
const actions = createFormActions()
const GetBack: React.FC = () => {
const [validButton, setValidButton] = useState(true)
const finish = (value: any) => {
console.log(value, 'finish')
}
const handleSubmit = (value: any) => {
const handleSubmit = async (value: any) => {
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[] = [
{
type: 'Input',
name: 'phonemail',
span: 24,
inputProps: {
type: 'phonemail',
placeholder: '请输入您的邮箱/手机',
},
rules: [
{ required: true, message: '邮箱/手机为必填项!' }
]
},
// {
// span: 24,
// // @ts-ignore
// custom: () => <RiskCheck />
// },
{
type: 'Verification',
name: 'smsCode',
span: 24,
inputProps: {
const isEmail = PATTERN_MAPS.email.test(account)
const accountParams = isEmail ? {email: account, ...omit(value, ['account', 'confirmPassword'])} : { phone: account, ...omit(value, ['account', 'confirmPassword']) }
const submitFn = isEmail ? PublicApi.postMemberRegisterResetEmail : PublicApi.postMemberRegisterResetSms
}
},
{
type: 'Input',
name: 'password',
span: 24,
inputProps: {
type: 'password',
placeholder: '设置你的密码',
},
rules: [
{ required: true, message: '密码为必填项!' },
{ pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,20}$/, message: '密码长度8-20个字符,必须包含大小写字母和数字!' }
],
},
{
type: 'Input',
name: 'confirm',
span: 24,
dependencies: ['password'],
inputProps: {
type: 'password',
placeholder: '请再次输入密码',
},
rules: [
{ required: true, message: '请再次确认密码!' },
({ getFieldValue }) => ({
validator(rule, value) {
if (!value || getFieldValue('password') === value) {
return Promise.resolve();
}
return Promise.reject('两次的密码输入不一致!');
},
}),
]
},
]
const getBackButtons: IFormButtonTypes[] = [
{
text: '提交',
type: 'primary',
htmlType: 'submit',
block: true,
disabled: false,
const { code } = await submitFn(accountParams)
if (code === 1000) {
history.replace('/user/login')
}
]
}
const SubmitBtn = <Button type='primary' block htmlType='submit'>提交</Button>
return (
<Fragment>
......@@ -105,6 +40,10 @@ const GetBack: React.FC = () => {
<NiceForm
schema={forgetPwdSchema}
onSubmit={handleSubmit}
actions={actions}
expressionScope={{
SubmitBtn
}}
effects={($, { setFieldState, getFieldState }) => {
$('onFieldValueChange', '*(password,confirmPassword)').subscribe(fieldState => {
const selfName = fieldState.name
......@@ -128,6 +67,10 @@ const GetBack: React.FC = () => {
})
}}
/>
<p className={'formBox'}>
<Link className='back' to={'/user/login'}>返回登录页</Link>
</p>
</div>
</Row>
</Fragment>
......
......@@ -205,9 +205,12 @@ export const forgetPwdSchema: ISchema = {
smsCode: {
type: 'string',
"x-component": 'Phone',
required: true,
"x-rules": [
{
required: true,
message: '请输入验证码'
},
{
pattern: PATTERN_MAPS.smsCode,
message: '请输入正确的6位验证码'
}
......@@ -229,6 +232,8 @@ export const forgetPwdSchema: ISchema = {
if (res.code === 1000) {
callback()
}
}).finally(() => {
setLoading(false)
})
}
......@@ -240,6 +245,8 @@ export const forgetPwdSchema: ISchema = {
if (res.code === 1000) {
callback()
}
}).finally(() => {
setLoading(false)
})
}
})
......@@ -282,9 +289,12 @@ export const forgetPwdSchema: ISchema = {
size: 'large',
}
},
submit: {
VirtualChildren: {
type: 'string',
"x-component": 'Submit'
"x-component": 'VirtualChildren',
"x-component-props": {
children: "{{SubmitBtn}}"
}
}
}
}
......
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