now、+1day、-2weeks、+1hours、+2years
这种相对值用法,同时支持变量如\\${start_date}
';
+const dateTooltip =
+ '支持例如: now、+3days、-2weeks、+1hour、+2years
等(minute|min|hour|day|week|month|year|weekday|second|millisecond)这种相对值用法';
export class DateControlPlugin extends BasePlugin {
// 关联渲染器名字
@@ -312,28 +313,31 @@ export class DateControlPlugin extends BasePlugin {
}),
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema,
- label: tipedLabel(
- '默认值',
- '支持 now、+1day、-2weeks、+1hours、+2years
等这种相对值用法'
- )
+ header: '表达式或相对值',
+ DateTimeType: FormulaDateType.IsDate,
+ label: tipedLabel('默认值', dateTooltip)
}),
getSchemaTpl('valueFormula', {
name: 'minDate',
+ header: '表达式或相对值',
+ DateTimeType: FormulaDateType.IsDate,
rendererSchema: {
...context?.schema,
value: context?.schema.minDate
},
needDeleteProps: ['minDate'], // 避免自我限制
- label: tipedLabel('最小值', tipedLabelText)
+ label: tipedLabel('最小值', dateTooltip)
}),
getSchemaTpl('valueFormula', {
name: 'maxDate',
+ header: '表达式或相对值',
+ DateTimeType: FormulaDateType.IsDate,
rendererSchema: {
...context?.schema,
value: context?.schema.maxDate
},
needDeleteProps: ['maxDate'], // 避免自我限制
- label: tipedLabel('最大值', tipedLabelText)
+ label: tipedLabel('最大值', dateTooltip)
}),
getSchemaTpl('placeholder', {
pipeIn: defaultValue('请选择日期')
diff --git a/packages/amis-editor/src/plugin/Form/InputDateRange.tsx b/packages/amis-editor/src/plugin/Form/InputDateRange.tsx
index d2ab4e4b7..e427ab6ed 100644
--- a/packages/amis-editor/src/plugin/Form/InputDateRange.tsx
+++ b/packages/amis-editor/src/plugin/Form/InputDateRange.tsx
@@ -4,6 +4,7 @@ import {BasePlugin, BaseEventContext} from 'amis-editor-core';
import {ValidatorTag} from '../../validator';
import {getEventControlConfig} from '../../renderer/event-control/helper';
+import {FormulaDateType} from '../../renderer/FormulaControl';
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
const DateType: {
@@ -59,8 +60,10 @@ const DateType: {
}
};
-const tipedLabelText =
- '支持 now、+1day、-2weeks、+1hours、+2years
这种相对值用法,同时支持变量如\\${start_date}
';
+const dateTooltip =
+ '支持例如: now、+3days、-2weeks、+1hour、+2years
等(minute|hour|day|week|month|year|weekday|second|millisecond)这种相对值用法';
+const rangTooltip =
+ '支持例如: 3days、2weeks、1hour、2years
等(minute|hour|day|week|month|year|weekday|second|millisecond)这种相对值用法';
export class DateRangeControlPlugin extends BasePlugin {
// 关联渲染器名字
@@ -247,63 +250,65 @@ export class DateRangeControlPlugin extends BasePlugin {
}),
getSchemaTpl('valueFormula', {
- /* 备注: 待 amis 日期组件优化
- rendererSchema: {
- ...context?.schema,
- size: 'full', // 备注:目前样式还有问题,需要在amis端进行优化
- mode: "inline"
- },
- mode: 'vertical',
- */
rendererSchema: {
- type: 'input-date'
+ ...context?.schema,
+ size: 'full',
+ mode: 'inline'
},
- label: tipedLabel(
- '默认值',
- '支持 now、+1day、-2weeks、+1hours、+2years
等这种相对值用法'
- )
+ mode: 'vertical',
+ header: '表达式或相对值',
+ DateTimeType: FormulaDateType.IsDate,
+ label: tipedLabel('默认值', dateTooltip)
}),
getSchemaTpl('valueFormula', {
name: 'minDate',
+ header: '表达式或相对值',
+ DateTimeType: FormulaDateType.IsDate,
rendererSchema: {
...context?.schema,
value: context?.schema.minDate,
type: 'input-date'
},
needDeleteProps: ['minDate'], // 避免自我限制
- label: tipedLabel('最小值', tipedLabelText)
+ label: tipedLabel('最小值', dateTooltip)
}),
getSchemaTpl('valueFormula', {
name: 'maxDate',
+ header: '表达式或相对值',
+ DateTimeType: FormulaDateType.IsDate,
rendererSchema: {
...context?.schema,
value: context?.schema.maxDate,
type: 'input-date'
},
needDeleteProps: ['maxDate'], // 避免自我限制
- label: tipedLabel('最大值', tipedLabelText)
+ label: tipedLabel('最大值', dateTooltip)
}),
getSchemaTpl('valueFormula', {
name: 'minDuration',
+ header: '表达式或相对值',
+ DateTimeType: FormulaDateType.IsRange,
rendererSchema: {
...context?.schema,
value: context?.schema.minDuration,
type: 'input-text'
},
needDeleteProps: ['minDuration'], // 避免自我限制
- label: tipedLabel('最小跨度', '例如 2days')
+ label: tipedLabel('最小跨度', rangTooltip)
}),
getSchemaTpl('valueFormula', {
name: 'maxDuration',
+ header: '表达式或相对值',
+ DateTimeType: FormulaDateType.IsRange,
rendererSchema: {
...context?.schema,
value: context?.schema.maxDuration,
type: 'input-text'
},
needDeleteProps: ['maxDuration'], // 避免自我限制
- label: tipedLabel('最大跨度', '例如 1year')
+ label: tipedLabel('最大跨度', rangTooltip)
}),
getSchemaTpl('dateShortCutControl', {
mode: 'normal',
diff --git a/packages/amis-editor/src/renderer/FormulaControl.tsx b/packages/amis-editor/src/renderer/FormulaControl.tsx
index 2c4591c5d..55b2b1de5 100644
--- a/packages/amis-editor/src/renderer/FormulaControl.tsx
+++ b/packages/amis-editor/src/renderer/FormulaControl.tsx
@@ -15,7 +15,7 @@ import omit from 'lodash/omit';
import cx from 'classnames';
import {FormItem, Button, InputBox, Icon, ResultBox} from 'amis';
import {FormulaExec, isExpression} from 'amis';
-import {PickerContainer} from 'amis';
+import {PickerContainer, relativeValueRe} from 'amis';
import {FormulaEditor} from 'amis-ui/lib/components/formula/Editor';
import {autobind} from 'amis-editor-core';
@@ -27,6 +27,13 @@ import type {
import {dataMapping, FormControlProps} from 'amis-core';
import type {BaseEventContext} from 'amis-editor-core';
import {EditorManager} from 'amis-editor-core';
+
+export enum FormulaDateType {
+ NotDate, // 不是时间类
+ IsDate, // 日期时间类
+ IsRange // 日期时间范围类
+}
+
export interface FormulaControlProps extends FormControlProps {
manager?: EditorManager;
@@ -95,6 +102,14 @@ export interface FormulaControlProps extends FormControlProps {
* 是否使用外部的Form数据
*/
useExternalFormData?: boolean;
+
+ /**
+ * 是否是日期类组件使用formulaControl
+ * 日期类 值 使用表达式时,支持 now、+1day、-2weeks、+1hours、+2years等这种相对值写法,不会最外层包裹 ${}
+ * 日期类 跨度值 使用表达式时,支持 1day、2weeks、1hours、2years等这种相对值写法,不会最外层包裹 ${}
+ * 默认为 FormulaDateType.NotDate
+ */
+ DateTimeType?: FormulaDateType;
}
interface FormulaControlState {
@@ -109,7 +124,8 @@ export default class FormulaControl extends React.Component<
FormulaControlState
> {
static defaultProps: Partial