Skip to content

Commit df2d912

Browse files
author
tangtanglove
committed
fix Time component
1 parent 7b5c938 commit df2d912

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

src/pages/Quark/components/Form.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import ProForm from '@ant-design/pro-form';
33
import ProCard from '@ant-design/pro-card';
44
import FormItem from './FormItem';
55
import { history } from 'umi';
66
import { post } from '@/services/action';
7+
import moment from 'moment';
78
import {
89
Form as AntForm,
910
message,
@@ -18,6 +19,18 @@ const Form: React.FC<Form> = (props:any) => {
1819

1920
const [form] = AntForm.useForm();
2021

22+
useEffect(() => {
23+
let initialValues = props.form.initialValues;
24+
props.form.items.map((item:any) => {
25+
if(item.component === 'time') {
26+
if(initialValues.hasOwnProperty(item.name)) {
27+
initialValues[item.name] = moment(initialValues[item.name],item.format);
28+
}
29+
}
30+
})
31+
form.setFieldsValue(initialValues);
32+
}, []);
33+
2134
const onFinish = async (values: any) => {
2235
const result = await post({
2336
actionUrl: props.form.api,
@@ -52,7 +65,6 @@ const Form: React.FC<Form> = (props:any) => {
5265
onFinish={async (values) => { onFinish(values) }}
5366
style={props.form.style ? props.form.style : {margin:'25px',width:'100%'}}
5467
colon={props.form.colon}
55-
initialValues={props.form.initialValues}
5668
labelAlign={props.form.labelAlign}
5769
name={props.form.name}
5870
preserve={props.form.preserve}
@@ -75,7 +87,6 @@ const Form: React.FC<Form> = (props:any) => {
7587
onFinish={async (values) => { onFinish(values) }}
7688
style={props.form.style}
7789
colon={props.form.colon}
78-
initialValues={props.form.initialValues}
7990
labelAlign={props.form.labelAlign}
8091
name={props.form.name}
8192
preserve={props.form.preserve}

src/pages/Quark/components/FormItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
ProFormDatePicker,
1212
ProFormDateTimePicker,
1313
ProFormDateRangePicker,
14-
ProFormDateTimeRangePicker
14+
ProFormDateTimeRangePicker,
15+
ProFormTimePicker
1516
} from '@ant-design/pro-form';
1617
import { createFromIconfontCN,PlusOutlined } from '@ant-design/icons';
1718
import {

src/pages/Quark/components/ModalForm.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import { useModel, history } from 'umi';
33
import { get, post } from '@/services/action';
4+
import moment from 'moment';
45
import {
56
Form,
67
Button,
@@ -17,6 +18,18 @@ const ModalForm: React.FC<any> = (props:any) => {
1718
scriptUrl: initialState.settings.iconfontUrl,
1819
});
1920

21+
useEffect(() => {
22+
let initialValues = props.form.initialValues;
23+
props.form.items.map((item:any) => {
24+
if(item.component === 'time') {
25+
if(initialValues.hasOwnProperty(item.name)) {
26+
initialValues[item.name] = moment(initialValues[item.name],item.format);
27+
}
28+
}
29+
})
30+
form.setFieldsValue(initialValues);
31+
}, []);
32+
2033
const [formComponent, setFormComponentState] = useState({
2134
api:null,
2235
style:undefined,
@@ -146,7 +159,6 @@ const ModalForm: React.FC<any> = (props:any) => {
146159
form={form}
147160
style={formComponent.style}
148161
colon={formComponent.colon}
149-
initialValues={formComponent.initialValues}
150162
labelAlign={formComponent.labelAlign}
151163
name={formComponent.name}
152164
preserve={formComponent.preserve}

src/pages/Quark/components/TabForm.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect } from 'react';
22
import ProCard from '@ant-design/pro-card';
33
import FormItem from './FormItem';
44
import { history } from 'umi';
55
import { post } from '@/services/action';
6+
import moment from 'moment';
67
import {
78
Form,
89
message,
@@ -18,6 +19,18 @@ export interface Form {
1819
const TabForm: React.FC<Form> = (props:any) => {
1920
const [form] = Form.useForm();
2021

22+
useEffect(() => {
23+
let initialValues = props.form.initialValues;
24+
props.form.items.map((item:any) => {
25+
if(item.component === 'time') {
26+
if(initialValues.hasOwnProperty(item.name)) {
27+
initialValues[item.name] = moment(initialValues[item.name],item.format);
28+
}
29+
}
30+
})
31+
form.setFieldsValue(initialValues);
32+
}, []);
33+
2134
const onFinish = async (values: any) => {
2235
const result = await post({
2336
actionUrl: props.form.api,

0 commit comments

Comments
 (0)