index.vue
10.5 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<template>
<div>
<a-card class="content">
<!-- 查询条件 start-->
<a-row>
<a-col :flex="1" style="margin-top: 4px">
<a-form :model="searchModel" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }" label-align="left" auto-label-width>
<a-row :gutter="12">
<!--设备名称-->
<!--<a-col :span="8">-->
<!--<a-form-item field="catalogId" :label="$t('power.energy.device.name')">-->
<!--<a-tree-select v-model="searchModel.deviceId" :data="renderDeviceData" placeholder="全部设备" :fieldNames="{-->
<!--key: 'id', title: 'deviceName', children: 'children'-->
<!--}" :allow-search="true" :allow-clear="true" :filter-tree-node="filterTreeNode"-->
<!--@clear="handleDeviceClear" @change="handleDeviceChange"></a-tree-select>-->
<!--</a-form-item>-->
<!--</a-col>-->
<!--能源类型-->
<a-col :span="8">
<a-form-item field="stationType" :label="$t('global.energy')">
<a-select v-model="searchModel.stationType" :placeholder="$t('global.pleaseSelect')" allow-clear>
<a-option :key="0" :label="'全部类型'" :value="Number(-100)" />
<a-option v-for="dict in sys_station_type" :key="dict.value" :label="dict.label" :value="Number(dict.value)" />
</a-select>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="state" :label="$t('pv.alarm.list.eventStatus')">
<a-select v-model="searchModel.triggerStatus" @clear="handleTriggerStatusClear" placeholder="全部状态" allow-clear>
<a-option key="-10" label="全部状态" value="-10"></a-option>
<a-option v-for="dict in sys_trigger_status" :key="dict.value" :label="dict.label" :value="dict.value"></a-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="time" :label="$t('pv.alarm.list.selectDate')">
<a-range-picker v-model="searchModel.time" />
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-col>
<a-divider style="height: 35px" direction="vertical" />
<a-col :flex="'86px'" style="text-align: right">
<a-space :size="18">
<a-button type="primary" @click="onSearch">
<template #icon>
<icon-search />
</template>
{{ $t('global.search') }}
</a-button>
</a-space>
</a-col>
</a-row>
<!-- 查询条件 end-->
<a-divider style="margin-top: 0" />
<!-- 表格 start-->
<a-table
row-key="id"
:loading="loading"
:bordered="{ wrapper: true, cell: true }"
:pagination="pagination"
:columns="(tabColumns as TableColumnData[])"
:data="renderData"
@page-change="onPageChange"
@page-size-change="onPageSizeChange"
>
</a-table>
<!-- 表格 end-->
</a-card>
<!-- 图表 start -->
<a-card class="general-card" style="margin-top: 12px" :title="$t('pv.alarm.list.levelStatistics')">
<CutomChart :options="chartLevelData" autoresize height="460px" />
</a-card>
<a-card class="general-card" style="margin-top: 12px" :title="$t('pv.alarm.list.typeStatistics')">
<CutomChart :options="chartCategoryData" autoresize height="460px" />
</a-card>
<!-- 图表 end -->
</div>
</template>
<script lang="ts" setup>
import { computed, ref, reactive, getCurrentInstance } from 'vue';
import { BasePagination } from '@/api/common';
import { TableColumnData } from '@arco-design/web-vue';
import useLoading from '@/hooks/loading';
import dayjs from 'dayjs';
import { onMounted } from 'vue';
import { getCategoryStaticList, getLevelStaticList, getStatisticlist } from '@/api/system/trigger';
import { handleChartData } from '@/utils/charts';
import { StationTypeEnum, listFusionGroup } from '@/api/system/device';
import { processSelectable } from '@/utils/ruoyi';
const props = defineProps({
stationType: {
type: Number,
default: StationTypeEnum.power,
},
});
//加载中
const { loading, setLoading } = useLoading(true);
//******* 这里编写动态获取下拉列表 start ******
const proxy = getCurrentInstance()?.appContext.config.globalProperties;
const { sys_alaram_level, sys_trigger_status, sys_station_type } = proxy?.useDict('sys_alaram_level', 'sys_trigger_status', 'sys_station_type');
//******* 这里编写动态获取下拉列表 end ******
//表格数据
const renderData = ref<any>([]);
//设备数据
const renderDeviceData = ref<any>([
{
id: 0,
deviceSn: '0',
selectable: true,
isGroup: 0,
deviceName: '全部设备',
children: [],
},
]);
//报警类型数据-下拉框
const renderAlarmCategoryData = ref<any>([
{
id: 0,
triggerName: '全部类型',
triggerSn: 'all',
},
]);
//报警类型数据-下拉框-自定义字段
const alarmCategoryfieldNames = { value: 'id', label: 'triggerName' };
//表格分页配置
const pagination: any = reactive({ ...BasePagination() });
//报警级别统计图
const chartLevelData = ref<any>([]);
//报警类型统计图
const chartCategoryData = ref<any>([]);
const customColumns = ref<any>([]);
//设置表格列
const tabColumns = computed<TableColumnData[]>(() => customColumns.value);
var dateNow = dayjs().format('YYYY-MM-DD');
var dateBefore = dayjs().format('YYYY-MM-01');
//报警事件查询项
const searchModel = ref({
id: 0,
//设备名称
deviceId: 0,
//事件状态
triggerStatus: '-10',
// 选择日期
time: [dateBefore, dateNow],
// 能源类型
stationType: props.stationType,
});
/**
* 搜索
*/
const onSearch = async () => {
await fetchData();
await fetchLevelData();
await fetchCategoryData();
};
/**
* 表格页码发生变化
* @param val
*/
const onPageChange = async (val: number) => {
pagination.current = val;
await fetchData();
};
/**
* 表格每页数量发生变化
* @param val
*/
const onPageSizeChange = async (val: number) => {
pagination.pageSize = val;
await fetchData();
};
/**
* 设备搜索
* @param searchValue
* @param nodeData
*/
const filterTreeNode = (searchValue: any, nodeData: any) => {
return nodeData.deviceName.toLowerCase().indexOf(searchValue.toLowerCase()) > -1;
};
/**
* 选择设备
*/
const handleDeviceChange = (val: any) => {
if (searchModel.value.deviceId) {
console.log(val);
}
};
/**
* 设备清空
*/
const handleDeviceClear = () => {
searchModel.value.deviceId = 0;
};
/**
* 事件状态清空
*/
const handleTriggerStatusClear = () => {
searchModel.value.triggerStatus = '-10';
};
/**
* 获取设备列表
*/
const fetchDeviceData = async () => {
try {
let param = {
stationType: props.stationType,
};
const res = await listFusionGroup(param);
processSelectable(res.data);
renderDeviceData.value[0].children = res.data;
} catch (err) {
// you can report use errorHandler or other
} finally {
}
};
/**
* 查询数据
*/
const fetchData = async () => {
setLoading(true);
try {
const res: any = await getStatisticlist({
deviceId: searchModel.value.deviceId > 0 ? searchModel.value.deviceId : '',
triggerStatus: searchModel.value.triggerStatus != '-10' ? searchModel.value.triggerStatus : '',
// 能源类型
stationType: searchModel.value.stationType != -100 ? searchModel.value.stationType : '',
params: {
beginTime: searchModel.value.time[0],
endTime: searchModel.value.time[1],
},
});
renderData.value= [];
if (res.code == 200) {
pagination.total = res.total;
if (res.rows && res.rows.length > 0) {
let columns: TableColumnData[] = [];
let data: any = [];
res.rows.forEach((item: any, index: number) => {
let info: any = {};
item.forEach((cItem: any, cIndex: number) => {
if (index == 0) {
columns.push({
title: cItem.key,
dataIndex: cItem.key,
align: cIndex <= 1 ? 'left' : 'center',
});
}
info[cItem.key] = cItem.value;
});
data.push(info);
});
customColumns.value = columns;
renderData.value = data;
}
}
} catch (err) {
// you can report use errorHandler or other
} finally {
setLoading(false);
}
};
/**
* 报警级别统计图
*/
const fetchLevelData = async () => {
try {
let res = await getLevelStaticList({
stationType: searchModel.value.stationType != -100 ? searchModel.value.stationType : '',
beginTime: searchModel.value.time[0],
endTime: searchModel.value.time[1],
triggerStatus: searchModel.value.triggerStatus != '-10' ? searchModel.value.triggerStatus : '',
});
if (res.code == 200) {
chartLevelData.value = handleChartData(res.data);
} else {
chartLevelData.value = [];
}
} catch (ex) {
} finally {
}
};
/**
* 报警类型统计图
*/
const fetchCategoryData = async () => {
try {
let res = await getCategoryStaticList({
stationType: searchModel.value.stationType != -100 ? searchModel.value.stationType : '',
beginTime: searchModel.value.time[0],
endTime: searchModel.value.time[1],
triggerStatus: searchModel.value.triggerStatus != '-10' ? searchModel.value.triggerStatus : '',
});
if (res.code == 200) {
chartCategoryData.value = handleChartData(res.data);
} else {
chartCategoryData.value = [];
}
} catch (ex) {
} finally {
}
};
/**
* 首次加载
*/
onMounted(async () => {
fetchDeviceData();
await fetchData();
await fetchLevelData();
await fetchCategoryData();
});
</script>
<style lang="less" scoped>
.row-mp-30 {
margin-top: 30px;
padding-right: 30px;
}
.main-chart {
height: 400px;
padding: 0px;
margin: 0px;
}
</style>