| | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { |
| | | ProForm, |
| | | ProFormDigit, |
| | | ProFormText, |
| | | ProFormSelect, |
| | | ProFormDateTimePicker |
| | | } from '@ant-design/pro-components'; |
| | | import { Form, Modal } from 'antd'; |
| | | import { FormattedMessage, useIntl } from '@umijs/max'; |
| | | import moment from 'moment'; |
| | | import Http from '@/utils/http'; |
| | | |
| | | const Edit = (props) => { |
| | | const intl = useIntl(); |
| | | const [form] = Form.useForm(); |
| | | const { } = props; |
| | | |
| | | useEffect(() => { |
| | | form.resetFields(); |
| | | form.setFieldsValue({ |
| | | ...props.values |
| | | }) |
| | | }, [form, props]) |
| | | |
| | | const handleCancel = () => { |
| | | props.onCancel(); |
| | | }; |
| | | |
| | | const handleOk = () => { |
| | | form.submit(); |
| | | } |
| | | |
| | | const handleFinish = async (values) => { |
| | | props.onSubmit({ ...values }); |
| | | } |
| | | |
| | | return ( |
| | | <> |
| | | <Modal |
| | | title={ |
| | | Object.keys(props.values).length > 0 |
| | | ? intl.formatMessage({ id: 'page.edit', defaultMessage: '编辑' }) |
| | | : intl.formatMessage({ id: 'page.add', defaultMessage: '添加' }) |
| | | } |
| | | width={640} |
| | | forceRender |
| | | destroyOnClose |
| | | open={props.open} |
| | | onCancel={handleCancel} |
| | | onOk={handleOk} |
| | | > |
| | | <ProForm |
| | | form={form} |
| | | submitter={false} |
| | | onFinish={handleFinish} |
| | | layout="horizontal" |
| | | grid={true} |
| | | > |
| | | <ProFormDigit |
| | | name="id" |
| | | disabled |
| | | hidden={true} |
| | | /> |
| | | <ProForm.Group> |
| | | <ProFormText |
| | | name="name" |
| | | label="名称" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | rules={[{ required: true, message: "名称不能为空!" }]} |
| | | /> |
| | | <ProFormSelect |
| | | name="status" |
| | | label="状态" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | options={[ |
| | | { label: '正常', value: 1 }, |
| | | { label: '禁用', value: 0 }, |
| | | ]} |
| | | /> |
| | | </ProForm.Group> |
| | | <ProForm.Group> |
| | | <ProFormDateTimePicker |
| | | name="createTime" |
| | | label="添加时间" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | transform={(value) => moment(value).toISOString()} |
| | | /> |
| | | <ProFormDateTimePicker |
| | | name="updateTime" |
| | | label="修改时间" |
| | | colProps={{ md: 12, xl: 12 }} |
| | | transform={(value) => moment(value).toISOString()} |
| | | /> |
| | | </ProForm.Group> |
| | | |
| | | </ProForm> |
| | | </Modal> |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | export default Edit; |
| | | import React, { useState, useRef, useEffect } from 'react';
|
| | | import {
|
| | | ProForm,
|
| | | ProFormDigit,
|
| | | ProFormText,
|
| | | ProFormSelect,
|
| | | ProFormDateTimePicker
|
| | | } from '@ant-design/pro-components';
|
| | | import { Form, Modal } from 'antd';
|
| | | import { FormattedMessage, useIntl } from '@umijs/max';
|
| | | import moment from 'moment';
|
| | | import Http from '@/utils/http';
|
| | |
|
| | | const Edit = (props) => {
|
| | | const intl = useIntl();
|
| | | const [form] = Form.useForm();
|
| | | const { } = props;
|
| | |
|
| | | useEffect(() => {
|
| | | form.resetFields();
|
| | | form.setFieldsValue({
|
| | | ...props.values
|
| | | })
|
| | | }, [form, props])
|
| | |
|
| | | const handleCancel = () => {
|
| | | props.onCancel();
|
| | | };
|
| | |
|
| | | const handleOk = () => {
|
| | | form.submit();
|
| | | }
|
| | |
|
| | | const handleFinish = async (values) => {
|
| | | props.onSubmit({ ...values });
|
| | | }
|
| | |
|
| | | return (
|
| | | <>
|
| | | <Modal
|
| | | title={
|
| | | Object.keys(props.values).length > 0
|
| | | ? intl.formatMessage({ id: 'page.edit', defaultMessage: '编辑' })
|
| | | : intl.formatMessage({ id: 'page.add', defaultMessage: '添加' })
|
| | | }
|
| | | width={640}
|
| | | forceRender
|
| | | destroyOnClose
|
| | | open={props.open}
|
| | | onCancel={handleCancel}
|
| | | onOk={handleOk}
|
| | | >
|
| | | <ProForm
|
| | | form={form}
|
| | | submitter={false}
|
| | | onFinish={handleFinish}
|
| | | layout="horizontal"
|
| | | grid={true}
|
| | | >
|
| | | <ProFormDigit
|
| | | name="id"
|
| | | disabled
|
| | | hidden={true}
|
| | | />
|
| | | <ProForm.Group>
|
| | | <ProFormText
|
| | | name="name"
|
| | | label="名称"
|
| | | colProps={{ md: 12, xl: 12 }}
|
| | | rules={[{ required: true, message: "名称不能为空!" }]}
|
| | | />
|
| | | <ProFormSelect
|
| | | name="status"
|
| | | label="状态"
|
| | | colProps={{ md: 12, xl: 12 }}
|
| | | options={[
|
| | | { label: '正常', value: 1 },
|
| | | { label: '禁用', value: 0 },
|
| | | ]}
|
| | | />
|
| | | </ProForm.Group>
|
| | | <ProForm.Group>
|
| | | <ProFormDateTimePicker
|
| | | name="createTime"
|
| | | label="添加时间"
|
| | | colProps={{ md: 12, xl: 12 }}
|
| | | transform={(value) => moment(value).toISOString()}
|
| | | />
|
| | | <ProFormDateTimePicker
|
| | | name="updateTime"
|
| | | label="修改时间"
|
| | | colProps={{ md: 12, xl: 12 }}
|
| | | transform={(value) => moment(value).toISOString()}
|
| | | />
|
| | | </ProForm.Group>
|
| | |
|
| | | </ProForm>
|
| | | </Modal>
|
| | | </>
|
| | | )
|
| | | }
|
| | |
|
| | | export default Edit;
|