index.vue
4.2 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
<script lang="ts" setup>
import { ref, unref } from 'vue';
import { AggregateDataEnum, formSchema, QueryWay, SchemaFiled } from './config';
import { useForm } from '/@/components/Form';
import { useModalInner } from '/@/components/Modal';
import { useGridLayout } from '/@/hooks/component/useGridLayout';
import { ColEx } from '/@/components/Form/src/types';
import { BasicForm } from '/@/components/Form';
import { BasicModal } from '/@/components/Modal';
import { nextTick } from 'vue';
import {
getPacketIntervalByRange,
getPacketIntervalByValue,
} from '/@/views/device/localtion/cpns/TimePeriodForm/helper';
const emit = defineEmits(['register', 'getAlarmForm', 'getHistoryForm']);
// const emit = defineEmits<{
// (event: 'getAlarmForm', data: WidgetDataType): void;
// }>();
const fontId = ref('');
const [registerModal, { closeModal }] = useModalInner(async (data) => {
fontId.value = unref(data).record.frontId;
method.updateSchema([
{
field: SchemaFiled.PAGE_SIZE,
ifShow: unref(fontId) !== 'StatisticsComponent7',
},
]);
if (unref(fontId) !== 'StatisticsComponent7') return;
await nextTick();
method.appendSchemaByField(
{
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 },
],
},
},
SchemaFiled.DATE_RANGE
);
method.appendSchemaByField(
{
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,
};
},
},
SchemaFiled.AGG
);
});
const [register, method] = useForm({
schemas: formSchema(),
baseColProps: useGridLayout(1) as unknown as ColEx,
showSubmitButton: false,
showResetButton: false,
rowProps: {
gutter: 10,
},
labelWidth: 120,
fieldMapToTime: [
[SchemaFiled.DATE_RANGE, [SchemaFiled.START_TS, SchemaFiled.END_TS], 'YYYY-MM-DD HH:ss:mm'],
],
});
const handleCancel = () => {
// destory()
};
const handleSubmit = async () => {
const values = method.getFieldsValue();
if (unref(fontId) == 'StatisticsComponent7') {
emit('getHistoryForm', values);
} else {
emit('getAlarmForm', values);
}
await nextTick();
closeModal();
};
</script>
<template>
<BasicModal
@register="registerModal"
@cancel="handleCancel"
@ok="handleSubmit"
:destroy-on-close="true"
:show-ok-btn="true"
cancel-text="关闭"
width="40%"
title="历史趋势"
>
<section
class="flex flex-col p-4 h-full w-full min-w-7/10"
style="color: #f0f2f5; background-color: #f0f2f5"
>
<section class="bg-white my-3 p-2">
<BasicForm @register="register" />
</section>
</section>
</BasicModal>
</template>
<style scoped></style>