Skip to content

Commit

Permalink
fix Time component
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtanglove committed Nov 12, 2020
1 parent 7b5c938 commit df2d912
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
17 changes: 14 additions & 3 deletions src/pages/Quark/components/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import React, { useEffect } from 'react';
import ProForm from '@ant-design/pro-form';
import ProCard from '@ant-design/pro-card';
import FormItem from './FormItem';
import { history } from 'umi';
import { post } from '@/services/action';
import moment from 'moment';
import {
Form as AntForm,
message,
Expand All @@ -18,6 +19,18 @@ const Form: React.FC<Form> = (props:any) => {

const [form] = AntForm.useForm();

useEffect(() => {
let initialValues = props.form.initialValues;
props.form.items.map((item:any) => {
if(item.component === 'time') {
if(initialValues.hasOwnProperty(item.name)) {
initialValues[item.name] = moment(initialValues[item.name],item.format);
}
}
})
form.setFieldsValue(initialValues);
}, []);

const onFinish = async (values: any) => {
const result = await post({
actionUrl: props.form.api,
Expand Down Expand Up @@ -52,7 +65,6 @@ const Form: React.FC<Form> = (props:any) => {
onFinish={async (values) => { onFinish(values) }}
style={props.form.style ? props.form.style : {margin:'25px',width:'100%'}}
colon={props.form.colon}
initialValues={props.form.initialValues}
labelAlign={props.form.labelAlign}
name={props.form.name}
preserve={props.form.preserve}
Expand All @@ -75,7 +87,6 @@ const Form: React.FC<Form> = (props:any) => {
onFinish={async (values) => { onFinish(values) }}
style={props.form.style}
colon={props.form.colon}
initialValues={props.form.initialValues}
labelAlign={props.form.labelAlign}
name={props.form.name}
preserve={props.form.preserve}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Quark/components/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
ProFormDatePicker,
ProFormDateTimePicker,
ProFormDateRangePicker,
ProFormDateTimeRangePicker
ProFormDateTimeRangePicker,
ProFormTimePicker
} from '@ant-design/pro-form';
import { createFromIconfontCN,PlusOutlined } from '@ant-design/icons';
import {
Expand Down
16 changes: 14 additions & 2 deletions src/pages/Quark/components/ModalForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { useModel, history } from 'umi';
import { get, post } from '@/services/action';
import moment from 'moment';
import {
Form,
Button,
Expand All @@ -17,6 +18,18 @@ const ModalForm: React.FC<any> = (props:any) => {
scriptUrl: initialState.settings.iconfontUrl,
});

useEffect(() => {
let initialValues = props.form.initialValues;
props.form.items.map((item:any) => {
if(item.component === 'time') {
if(initialValues.hasOwnProperty(item.name)) {
initialValues[item.name] = moment(initialValues[item.name],item.format);
}
}
})
form.setFieldsValue(initialValues);
}, []);

const [formComponent, setFormComponentState] = useState({
api:null,
style:undefined,
Expand Down Expand Up @@ -146,7 +159,6 @@ const ModalForm: React.FC<any> = (props:any) => {
form={form}
style={formComponent.style}
colon={formComponent.colon}
initialValues={formComponent.initialValues}
labelAlign={formComponent.labelAlign}
name={formComponent.name}
preserve={formComponent.preserve}
Expand Down
15 changes: 14 additions & 1 deletion src/pages/Quark/components/TabForm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react';
import React, { useEffect } from 'react';
import ProCard from '@ant-design/pro-card';
import FormItem from './FormItem';
import { history } from 'umi';
import { post } from '@/services/action';
import moment from 'moment';
import {
Form,
message,
Expand All @@ -18,6 +19,18 @@ export interface Form {
const TabForm: React.FC<Form> = (props:any) => {
const [form] = Form.useForm();

useEffect(() => {
let initialValues = props.form.initialValues;
props.form.items.map((item:any) => {
if(item.component === 'time') {
if(initialValues.hasOwnProperty(item.name)) {
initialValues[item.name] = moment(initialValues[item.name],item.format);
}
}
})
form.setFieldsValue(initialValues);
}, []);

const onFinish = async (values: any) => {
const result = await post({
actionUrl: props.form.api,
Expand Down

0 comments on commit df2d912

Please sign in to comment.