Skip to content

Commit 88781d0

Browse files
committed
refactor(datetimerange): 优化 array DateTimeRange 选择时间区间
1 parent 1ca9f21 commit 88781d0

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Created by Liu.Jun on 2020/9/16 10:25.
3+
*/
4+
5+
import vueProps from '../../props';
6+
import Widget from '../../../fieldComponents/Widget';
7+
import { getWidgetConfig } from '../../../common/formUtils';
8+
import WIDGET_MAP from '../../../config/WIDGET_MAP';
9+
10+
export default {
11+
name: 'ArrayFieldDateRange',
12+
props: vueProps,
13+
functional: true,
14+
render(h, context) {
15+
const { schema, uiSchema } = context.props;
16+
const widgetConfig = getWidgetConfig({
17+
schema,
18+
uiSchema: {
19+
'ui:widget': WIDGET_MAP.formats[schema.format],
20+
...uiSchema
21+
}
22+
});
23+
24+
return h(
25+
Widget,
26+
{
27+
props: {
28+
...context.props,
29+
...widgetConfig
30+
}
31+
}
32+
);
33+
}
34+
};

packages/lib/src/JsonSchemaForm/fields/ArrayField/index.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import vueProps from '../props';
77
import getDefaultFormState from '../../common/schema/getDefaultFormState';
88

99
import {
10-
allowAdditionalItems, getWidgetConfig, isFixedItems, isMultiSelect
10+
allowAdditionalItems, isFixedItems, isMultiSelect
1111
} from '../../common/formUtils';
1212
import { getPathVal, setPathVal } from '../../common/vueUtils';
1313
import { genId, lowerCase } from '../../common/utils';
@@ -19,7 +19,7 @@ import * as arrayMethods from '../../common/arrayUtils';
1919
import ArrayFieldNormal from './arrayTypes/ArrayFieldNormal';
2020
import ArrayFieldMultiSelect from './arrayTypes/ArrayFieldMultiSelect';
2121
import ArrayFieldTuple from './arrayTypes/ArrayFieldTuple';
22-
import WIDGET_MAP from '../../config/WIDGET_MAP';
22+
import ArrayFieldDateRange from './arrayTypes/ArrayFieldDateRange';
2323

2424
export default {
2525
name: 'ArrayField',
@@ -151,24 +151,13 @@ export default {
151151
}
152152

153153
// 特殊处理date datetime format
154-
if (schema.format && WIDGET_MAP.formats[schema.format]) {
155-
const widgetConfig = getWidgetConfig({
156-
schema,
157-
uiSchema: {
158-
'ui:widget': WIDGET_MAP.formats[schema.format],
159-
...uiSchema
154+
if (schema.format) {
155+
return h(ArrayFieldDateRange, {
156+
props: this.$props,
157+
class: {
158+
[lowerCase(ArrayFieldDateRange.name)]: true
160159
}
161160
});
162-
163-
return h(
164-
Widget,
165-
{
166-
props: {
167-
...this.$props,
168-
...widgetConfig
169-
}
170-
}
171-
);
172161
}
173162

174163
// https://json-schema.org/understanding-json-schema/reference/array.html#list-validation

0 commit comments

Comments
 (0)