From 447ace2c802ee85bda58ef16d70af50bb1fce841 Mon Sep 17 00:00:00 2001 From: zzy Date: Wed, 24 Aug 2022 16:33:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wallet/components/AddWalletModal.tsx | 97 +++++++++++++++++ .../Wallet/components/EditWalletModal.tsx | 101 ++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 src/pages/Recharge/Wallet/components/AddWalletModal.tsx create mode 100644 src/pages/Recharge/Wallet/components/EditWalletModal.tsx diff --git a/src/pages/Recharge/Wallet/components/AddWalletModal.tsx b/src/pages/Recharge/Wallet/components/AddWalletModal.tsx new file mode 100644 index 0000000..c043339 --- /dev/null +++ b/src/pages/Recharge/Wallet/components/AddWalletModal.tsx @@ -0,0 +1,97 @@ +// 创建弹窗 +import React, { useRef } from 'react'; +import { createForm, onFieldReact, FormPathPattern, Field } from '@formily/core'; +import { FormProvider, createSchemaField } from '@formily/react'; +import { getCoinTypeList } from '@/services/recharge/coinType'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, Select } from '@formily/antd'; +import { action } from '@formily/reactive'; + +interface AddWalletModalPropsType extends ModalProps { + onOk: (val: any) => void; + onCancel: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Select, + }, +}); + +const useAsyncDataSource = ( + pattern: FormPathPattern, + service: (field: Field) => Promise<{ label: string; value: any }[]>, +) => { + onFieldReact(pattern, (field) => { + service(field).then( + action.bound((data) => { + field.dataSource = data; + }), + ); + }); +}; + +const form = createForm({ + effects: () => { + // eslint-disable-next-line react-hooks/rules-of-hooks + useAsyncDataSource('name', async (field) => { + const list = await getCoinTypeList({ page: 1, page_size: 10 }); + const option = []; + for (let index = 0; index < list.items.length; index++) { + const element = list.items[index]; + const item = { + label: element.name, + value: element.name, + }; + option.push(item); + } + return option; + }); + }, +}); + +const AddWalletModal = ({ onOk, onCancel, ...rest }: AddWalletModalPropsType) => { + const handleOk = () => { + const formState = form.getFormState(); + onOk(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + + + + + + + + {/*
*/} + + {/*
*/} +
+ ); +}; + +export default AddWalletModal; diff --git a/src/pages/Recharge/Wallet/components/EditWalletModal.tsx b/src/pages/Recharge/Wallet/components/EditWalletModal.tsx new file mode 100644 index 0000000..11632bd --- /dev/null +++ b/src/pages/Recharge/Wallet/components/EditWalletModal.tsx @@ -0,0 +1,101 @@ +// 修改弹窗 +import React, { useRef, useEffect } from 'react'; +import { createForm, onFieldReact, FormPathPattern, Field } from '@formily/core'; +import { getCoinTypeList } from '@/services/recharge/coinType'; +import { FormProvider, createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, Select } from '@formily/antd'; +import { action } from '@formily/reactive'; + +interface EditWalletModalPropsType extends ModalProps { + editModalData: any; + onOk: (val: any) => void; + onCancel: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Select, + }, +}); + +const EditWalletModal = ({ onOk, onCancel, editModalData, ...rest }: EditWalletModalPropsType) => { + const useAsyncDataSource = ( + pattern: FormPathPattern, + service: (field: Field) => Promise<{ label: string; value: any }[]>, + ) => { + onFieldReact(pattern, (field) => { + service(field).then( + action.bound((data) => { + field.dataSource = data; + }), + ); + }); + }; + + const form = createForm({ + effects: () => { + // eslint-disable-next-line react-hooks/rules-of-hooks + useAsyncDataSource('name', async (field) => { + const list = await getCoinTypeList({ page: 1, page_size: 10 }); + const option = []; + for (let index = 0; index < list.items.length; index++) { + const element = list.items[index]; + const item = { + label: element.name, + value: element.name, + }; + option.push(item); + } + return option; + }); + }, + }); + + useEffect(() => { + form.setInitialValues(editModalData); + }); + + const handleOk = () => { + const formState = form.getFormState(); + onOk(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + +
+ + + + + +
+
+ ); +}; + +export default EditWalletModal;