config.ts
3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import moment from 'moment';
import { FormSchema } from '/@/components/Form';
import { ColEx } from '/@/components/Form/src/types';
import { useGridLayout } from '/@/hooks/component/useGridLayout';
import { intervalOption } from '/@/views/device/localtion/cpns/TimePeriodForm/helper';
export enum QueryWay {
LATEST = 'latest',
TIME_PERIOD = 'timePeriod',
}
export enum SchemaFiled {
DEVICE_ID = 'deviceId',
WAY = 'way',
TIME_PERIOD = 'timePeriod',
KEYS = 'keys',
DATE_RANGE = 'dataRange',
START_TS = 'startTs',
END_TS = 'endTs',
INTERVAL = 'interval',
LIMIT = 'limit',
AGG = 'agg',
ORDER_BY = 'orderBy',
PAGE_SIZE = 'pageSize',
}
export enum AggregateDataEnum {
MIN = 'MIN',
MAX = 'MAX',
AVG = 'AVG',
SUM = 'SUM',
COUNT = 'COUNT',
NONE = 'NONE',
}
export const formSchema = (): FormSchema[] => {
return [
{
field: SchemaFiled.WAY,
label: '查询方式',
component: 'RadioGroup',
defaultValue: QueryWay.LATEST,
componentProps({ formActionType }) {
const { setFieldsValue } = formActionType;
return {
options: [
{ label: '最后', value: QueryWay.LATEST },
{ label: '时间段', value: QueryWay.TIME_PERIOD },
],
onChange(event: ChangeEvent) {
(event.target as HTMLInputElement).value === QueryWay.LATEST
? setFieldsValue({
[SchemaFiled.DATE_RANGE]: [],
[SchemaFiled.START_TS]: null,
[SchemaFiled.END_TS]: null,
})
: setFieldsValue({ [SchemaFiled.START_TS]: null });
},
getPopupContainer: () => document.body,
};
},
},
{
field: SchemaFiled.PAGE_SIZE,
label: '分页条数',
component: 'InputNumber',
defaultValue: 20,
ifShow: true,
componentProps() {
return {
min: 10,
max: 50000,
getPopupContainer: () => document.body,
};
},
},
{
field: SchemaFiled.START_TS,
label: '最后数据',
component: 'Select',
ifShow({ values }) {
return values[SchemaFiled.WAY] === QueryWay.LATEST;
},
defaultValue: 2592000000,
componentProps({ formActionType }) {
const { setFieldsValue } = formActionType;
return {
options: intervalOption,
onChange() {
setFieldsValue({ [SchemaFiled.INTERVAL]: null });
},
getPopupContainer: () => document.body,
};
},
colProps: useGridLayout(2, 2, 2, 2, 2, 2) as unknown as ColEx,
rules: [{ required: true, message: '最后数据为必选项', type: 'number' }],
},
{
field: SchemaFiled.DATE_RANGE,
label: '时间段',
component: 'RangePicker',
ifShow({ values }) {
return values[SchemaFiled.WAY] === QueryWay.TIME_PERIOD;
},
rules: [{ required: true, message: '时间段为必选项' }],
componentProps({ formActionType }) {
const { setFieldsValue } = formActionType;
return {
showTime: {
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
},
onChange() {
setFieldsValue({ [SchemaFiled.INTERVAL]: null });
},
getPopupContainer: () => document.body,
};
},
colProps: useGridLayout(2, 2, 2, 2, 2, 2) as unknown as ColEx,
},
{
field: SchemaFiled.LIMIT,
label: '最大条数',
component: 'InputNumber',
ifShow({ values }) {
return values[SchemaFiled.AGG] === AggregateDataEnum.NONE;
},
helpMessage: ['根据查询条件,查出的数据条数不超过这个值'],
componentProps() {
return {
max: 50000,
min: 7,
getPopupContainer: () => document.body,
};
},
},
];
};