From 2efbe1ef0ab146698b3c3144a2f9e9cd4feff0d6 Mon Sep 17 00:00:00 2001 From: RickCole Date: Fri, 15 Jul 2022 17:50:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dinput-table=E4=B8=ADin?= =?UTF-8?q?put-date=E7=9B=B8=E5=AF=B9=E5=80=BC=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#4885)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复input-table中input-date相对值不生效问题 * fix: 修复input-table中input-date相对值不生效问题 --- .../amis/src/renderers/Form/InputTable.tsx | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/packages/amis/src/renderers/Form/InputTable.tsx b/packages/amis/src/renderers/Form/InputTable.tsx index 1a53f7e62..4c6d8d969 100644 --- a/packages/amis/src/renderers/Form/InputTable.tsx +++ b/packages/amis/src/renderers/Form/InputTable.tsx @@ -1,24 +1,31 @@ import React from 'react'; -import {FormItem, FormControlProps, FormBaseControl} from 'amis-core'; import { + FormItem, + FormControlProps, + FormBaseControl, createObject, getTree, getVariable, setVariable, - spliceTree + spliceTree, + filterDate, + isEffectiveApi, + filter, + dataMapping, + SimpleMap, + RendererData, + ActionObject, + Api, + Payload, + ApiObject } from 'amis-core'; -import {Button} from 'amis-ui'; -import {RendererData, ActionObject, Api, Payload, ApiObject} from 'amis-core'; -import {isEffectiveApi} from 'amis-core'; -import {filter} from 'amis-core'; +import {Button, Icon} from 'amis-ui'; import omit from 'lodash/omit'; -import {dataMapping} from 'amis-core'; import findIndex from 'lodash/findIndex'; -import {SimpleMap} from 'amis-core'; -import {Icon} from 'amis-ui'; import {TableSchema} from '../Table'; import {SchemaApi} from '../../Schema'; import find from 'lodash/find'; +import moment from 'moment'; export interface TableControlSchema extends FormBaseControl, @@ -466,7 +473,7 @@ export default class FormTable extends React.Component { } addItem(index: number) { - const {needConfirm, scaffold, columns} = this.props; + const {needConfirm, scaffold, columns, data} = this.props; const items = this.state.items.concat(); let value: any = { __isPlaceholder: true @@ -478,7 +485,27 @@ export default class FormTable extends React.Component { typeof column.value !== 'undefined' && typeof column.name === 'string' ) { - setVariable(value, column.name, column.value); + if ( + [ + 'input-date', + 'input-datetime', + 'input-time', + 'input-month', + 'input-quarter', + 'input-year' + ].includes(column.type) + ) { + const date = filterDate(column.value, data, column.format || 'X'); + setVariable( + value, + column.name, + (column.utc ? moment.utc(date) : date).format( + column.format || 'X' + ) + ); + } else { + setVariable(value, column.name, column.value); + } } }); }