config.ts
5.14 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import moment, { Moment } from 'moment';
import { getPacketIntervalByRange, getPacketIntervalByValue, intervalOption } from './helper';
import { FormSchema } from '/@/components/Form';
import { ColEx } from '/@/components/Form/src/types';
import { useGridLayout } from '/@/hooks/component/useGridLayout';
export enum QueryWay {
LATEST = 'latest',
TIME_PERIOD = 'timePeriod',
}
export enum SchemaFiled {
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',
}
export enum AggregateDataEnum {
MIN = 'MIN',
MAX = 'MAX',
AVG = 'AVG',
SUM = 'SUM',
COUNT = 'COUNT',
NONE = 'NONE',
}
export const defaultSchemas: FormSchema[] = [
{
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.START_TS,
label: '最后数据',
component: 'Select',
ifShow({ values }) {
return values[SchemaFiled.WAY] === QueryWay.LATEST;
},
componentProps({ formActionType }) {
const { setFieldsValue } = formActionType;
return {
options: intervalOption,
onChange() {
setFieldsValue({ [SchemaFiled.INTERVAL]: null });
},
getPopupContainer: () => document.body,
};
},
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;
let dates: Moment[] = [];
return {
showTime: {
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
},
onCalendarChange(value: Moment[]) {
dates = value;
},
disabledDate(current: Moment) {
if (!dates || dates.length === 0 || !current) {
return false;
}
const diffDate = current.diff(dates[0], 'years', true);
return Math.abs(diffDate) > 1;
},
onChange() {
dates = [];
setFieldsValue({ [SchemaFiled.INTERVAL]: null });
},
getPopupContainer: () => document.body,
};
},
colProps: useGridLayout(2, 2, 2, 2, 2, 2) as unknown as ColEx,
},
{
field: SchemaFiled.AGG,
label: '数据聚合功能',
component: 'Select',
// defaultValue: AggregateDataEnum.NONE,
componentProps: {
getPopupContainer: () => document.body,
options: [
{ label: '最小值', value: AggregateDataEnum.MIN },
{ label: '最大值', value: AggregateDataEnum.MAX },
{ label: '平均值', value: AggregateDataEnum.AVG },
{ label: '求和', value: AggregateDataEnum.SUM },
{ label: '计数', value: AggregateDataEnum.COUNT },
{ label: '空', value: AggregateDataEnum.NONE },
],
},
},
{
field: SchemaFiled.INTERVAL,
label: '分组间隔',
component: 'Select',
dynamicRules: ({ model }) => {
return [
{
required: model[SchemaFiled.AGG] !== AggregateDataEnum.NONE,
message: '分组间隔为必填项',
type: 'number',
},
];
},
ifShow({ values }) {
return values[SchemaFiled.AGG] !== AggregateDataEnum.NONE;
},
componentProps({ formModel, formActionType }) {
const options =
formModel[SchemaFiled.WAY] === QueryWay.LATEST
? getPacketIntervalByValue(formModel[SchemaFiled.START_TS])
: getPacketIntervalByRange(formModel[SchemaFiled.DATE_RANGE]);
if (formModel[SchemaFiled.AGG] !== AggregateDataEnum.NONE) {
formActionType.setFieldsValue({ [SchemaFiled.LIMIT]: null });
}
return {
options,
getPopupContainer: () => document.body,
};
},
},
{
field: SchemaFiled.LIMIT,
label: '最大条数',
component: 'InputNumber',
// defaultValue: 7,
ifShow({ values }) {
return values[SchemaFiled.AGG] === AggregateDataEnum.NONE;
},
helpMessage: ['根据查询条件,查出的数据条数不超过这个值'],
componentProps() {
return {
max: 50000,
min: 7,
getPopupContainer: () => document.body,
};
},
},
];