From 827d10360cc0ce5bc07810773b45c50e6862f3aa Mon Sep 17 00:00:00 2001 From: zzy Date: Thu, 18 Aug 2022 15:43:56 +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 --- .../Address/Components/AddAddressModal.tsx | 97 ++++++++++++++++ .../Address/Components/EditAddressModal.tsx | 106 ++++++++++++++++++ .../CoinType/Components/AddCoinTypeModal.tsx | 71 ++++++++++++ .../CoinType/Components/EditCoinTypeModal.tsx | 72 ++++++++++++ .../Account/Components/AddAccountModal.tsx | 84 ++++++++++++++ .../Account/Components/EditAccountModal.tsx | 82 ++++++++++++++ .../Notice/Components/AddNoticeModal.tsx | 69 ++++++++++++ .../Notice/Components/EditNoticeModal.tsx | 63 +++++++++++ 8 files changed, 644 insertions(+) create mode 100644 src/pages/Recharge/Address/Components/AddAddressModal.tsx create mode 100644 src/pages/Recharge/Address/Components/EditAddressModal.tsx create mode 100644 src/pages/Recharge/CoinType/Components/AddCoinTypeModal.tsx create mode 100644 src/pages/Recharge/CoinType/Components/EditCoinTypeModal.tsx create mode 100644 src/pages/System/Account/Components/AddAccountModal.tsx create mode 100644 src/pages/System/Account/Components/EditAccountModal.tsx create mode 100644 src/pages/System/Notice/Components/AddNoticeModal.tsx create mode 100644 src/pages/System/Notice/Components/EditNoticeModal.tsx diff --git a/src/pages/Recharge/Address/Components/AddAddressModal.tsx b/src/pages/Recharge/Address/Components/AddAddressModal.tsx new file mode 100644 index 0000000..dbd4a9d --- /dev/null +++ b/src/pages/Recharge/Address/Components/AddAddressModal.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 AddAddressModalPropsType 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('bc_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.bc_name, + value: element.bc_name, + }; + option.push(item); + } + return option; + }); + }, +}); + +const AddAddressModal = ({ onOk, onCancel, ...rest }: AddAddressModalPropsType) => { + const handleOk = () => { + const formState = form.getFormState(); + onOk(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + + + + + + + + {/*
*/} + + {/*
*/} +
+ ); +}; + +export default AddAddressModal; diff --git a/src/pages/Recharge/Address/Components/EditAddressModal.tsx b/src/pages/Recharge/Address/Components/EditAddressModal.tsx new file mode 100644 index 0000000..ca55c75 --- /dev/null +++ b/src/pages/Recharge/Address/Components/EditAddressModal.tsx @@ -0,0 +1,106 @@ +// 修改弹窗 +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 EditAddressModalPropsType extends ModalProps { + editModalData: any; + onOk: (val: any) => void; + onCancel: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Select, + }, +}); + +const EditAddressModal = ({ + onOk, + onCancel, + editModalData, + ...rest +}: EditAddressModalPropsType) => { + 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('bc_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.bc_name, + value: element.bc_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 EditAddressModal; diff --git a/src/pages/Recharge/CoinType/Components/AddCoinTypeModal.tsx b/src/pages/Recharge/CoinType/Components/AddCoinTypeModal.tsx new file mode 100644 index 0000000..798c15a --- /dev/null +++ b/src/pages/Recharge/CoinType/Components/AddCoinTypeModal.tsx @@ -0,0 +1,71 @@ +// 添加代币类型弹窗 +import React, { useRef } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, NumberPicker } from '@formily/antd'; + +interface AddCoinTypeModalPropsType extends ModalProps { + onOk: (val: any) => void; + onCancel: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + NumberPicker, + }, +}); + +const form = createForm({}); + +const AddCoinTypeModal = ({ onOk, onCancel, ...rest }: AddCoinTypeModalPropsType) => { + const handleOk = () => { + const formState = form.getFormState(); + onOk(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + +
+ + + + + + +
+
+ ); +}; + +export default AddCoinTypeModal; diff --git a/src/pages/Recharge/CoinType/Components/EditCoinTypeModal.tsx b/src/pages/Recharge/CoinType/Components/EditCoinTypeModal.tsx new file mode 100644 index 0000000..e61e366 --- /dev/null +++ b/src/pages/Recharge/CoinType/Components/EditCoinTypeModal.tsx @@ -0,0 +1,72 @@ +// 修改弹窗 +import React, { useRef, useEffect } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, Select } from '@formily/antd'; + +interface EditCoinTypeModalPropsType extends ModalProps { + editModalData: any; + onOk: (val: any) => void; + onCancel: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Select, + }, +}); + +const form = createForm({}); + +const EditCoinTypeModal = ({ + onOk, + onCancel, + editModalData, + ...rest +}: EditCoinTypeModalPropsType) => { + useEffect(() => { + form.setInitialValues(editModalData); + }); + + const handleOk = () => { + const formState = form.getFormState(); + onOk(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + +
+ + + + + +
+
+ ); +}; + +export default EditCoinTypeModal; diff --git a/src/pages/System/Account/Components/AddAccountModal.tsx b/src/pages/System/Account/Components/AddAccountModal.tsx new file mode 100644 index 0000000..9b07a1e --- /dev/null +++ b/src/pages/System/Account/Components/AddAccountModal.tsx @@ -0,0 +1,84 @@ +// 创建弹窗 +import React, { useRef } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, Select } from '@formily/antd'; +import { addUser } from '@/services/system/accountManage'; + +interface AddAccountModalPropsType extends ModalProps { + onCancel: () => void; + onOk: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Select, + }, +}); + +const form = createForm({}); + +const AddAccountModal = ({ onOk, onCancel, ...rest }: AddAccountModalPropsType) => { + const handleOk = async () => { + form.submit(async () => { + onOk(); + const formState = form.getFormState(); + formState.values.role = parseInt(formState.values.role); + await addUser(formState.values); + }); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + +
+ + + + + +
+
+ ); +}; + +export default AddAccountModal; diff --git a/src/pages/System/Account/Components/EditAccountModal.tsx b/src/pages/System/Account/Components/EditAccountModal.tsx new file mode 100644 index 0000000..44f66ba --- /dev/null +++ b/src/pages/System/Account/Components/EditAccountModal.tsx @@ -0,0 +1,82 @@ +// 创建弹窗 +import React, { useRef, useEffect } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, Select } from '@formily/antd'; +import { addUser, updateUser } from '@/services/system/accountManage'; + +interface AddUserModalPropsType extends ModalProps { + editModalData: any; + onCancel: () => void; + onOk: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Select, + }, +}); + +const form = createForm({}); + +const AddUserModal = ({ onOk, onCancel, editModalData, ...rest }: AddUserModalPropsType) => { + useEffect(() => { + form.setInitialValues(editModalData); + }); + + const handleOk = async () => { + onOk(); + const formState = form.getFormState(); + formState.values.role = parseInt(formState.values.role); + await updateUser(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + +
+ + + + + +
+
+ ); +}; + +export default AddUserModal; diff --git a/src/pages/System/Notice/Components/AddNoticeModal.tsx b/src/pages/System/Notice/Components/AddNoticeModal.tsx new file mode 100644 index 0000000..da5cb75 --- /dev/null +++ b/src/pages/System/Notice/Components/AddNoticeModal.tsx @@ -0,0 +1,69 @@ +// 添加代币类型弹窗 +import React, { useRef } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, Select } from '@formily/antd'; + +interface AddNoticeModalPropsType extends ModalProps { + onOk: (val: any) => void; + onCancel: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Select, + }, +}); + +const form = createForm({}); + +const AddNoticeModal = ({ onOk, onCancel, ...rest }: AddNoticeModalPropsType) => { + const handleOk = () => { + const formState = form.getFormState(); + formState.values.code = parseInt(formState.values.code); + onOk(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + +
+ + + + + +
+
+ ); +}; + +export default AddNoticeModal; diff --git a/src/pages/System/Notice/Components/EditNoticeModal.tsx b/src/pages/System/Notice/Components/EditNoticeModal.tsx new file mode 100644 index 0000000..7713f06 --- /dev/null +++ b/src/pages/System/Notice/Components/EditNoticeModal.tsx @@ -0,0 +1,63 @@ +// 修改弹窗 +import React, { useRef, useEffect } from 'react'; +import { createForm } from '@formily/core'; +import { createSchemaField } from '@formily/react'; +import Modal, { ModalProps } from '@/components/Modal'; +import { Form, FormItem, Input, Select } from '@formily/antd'; + +interface EditNoticeModalPropsType extends ModalProps { + editModalData: any; + onOk: (val: any) => void; + onCancel: () => void; +} + +const SchemaField = createSchemaField({ + components: { + FormItem, + Input, + Select, + }, +}); + +const form = createForm({}); + +const EditNoticeModal = ({ onOk, onCancel, editModalData, ...rest }: EditNoticeModalPropsType) => { + useEffect(() => { + form.setInitialValues(editModalData); + }); + + const handleOk = () => { + const formState = form.getFormState(); + onOk(formState.values); + }; + + const handleCancel = () => { + onCancel(); + }; + + return ( + +
+ + + + +
+
+ ); +}; + +export default EditNoticeModal;