index.vue
8.33 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
<script lang="ts" setup>
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { columns, searchFormSchema } from './config';
import { BasicModal, useModal } from '/@/components/Modal';
import { Input, Button } from 'ant-design-vue';
import { ref, computed, nextTick } from 'vue';
import { EyeOutlined } from '@ant-design/icons-vue';
import { EdgeDeviceItemType } from '/@/api/edgeManage/model/edgeInstance';
import { getDeviceAlarm, doBatchAckAlarm, doBatchClearAlarm } from '/@/api/device/deviceManager';
import { AlarmLogItem } from '/@/api/device/model/deviceConfigModel';
import { AlarmStatus } from '/@/enums/alarmEnum';
import { useMessage } from '/@/hooks/web/useMessage';
import { getDeviceDetail } from '/@/api/device/deviceManager';
import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
import {
operationBoolean,
operationNumber_OR_TIME,
operationString,
} from '/@/views/rule/linkedge/config/formatData';
import { clearOrAckAlarm } from '/@/api/device/deviceManager';
const props = defineProps({
recordData: {
type: Object as PropType<EdgeDeviceItemType>,
default: () => {},
},
});
defineEmits(['register']);
const outputData = ref<string>();
const { createMessage } = useMessage();
const [registerTable, { reload, getSelectRows, clearSelectedRowKeys, getRowSelection }] =
useTable({
columns,
api: getDeviceAlarm,
beforeFetch: (params) => {
const { status } = params;
const obj = {
...params,
deviceId: props?.recordData?.id?.id,
...{
status: status ? status.at(-1) : null,
},
};
return obj;
},
formConfig: {
labelWidth: 130,
schemas: searchFormSchema,
},
useSearchForm: true,
showIndexColumn: false,
clickToRowSelect: false,
showTableSetting: true,
bordered: true,
rowKey: 'id',
rowSelection: {
type: 'checkbox',
getCheckboxProps: (record: AlarmLogItem) => {
return {
disabled: record.status === AlarmStatus.CLEARED_ACK,
};
},
},
actionColumn: {
title: '操作',
slots: { customRender: 'action' },
fixed: 'right',
},
});
const [registerModal, { openModal, closeModal }] = useModal();
const findName = (item: Recordable, curr: Recordable) => {
return item.attribute.find((item) => item.identifier === curr?.key)?.name;
};
const findLogin = (curr: Recordable) => {
return [...operationNumber_OR_TIME, ...operationString, ...operationBoolean].find(
(item) => item.value === curr?.logic
)?.symbol;
};
const findAttribute = (item: Recordable, curr: Recordable) => {
item.attribute.find((findItem) => findItem.identifier === curr?.key);
};
const findValue = (item: Recordable, curr: Recordable) => {
return {
['触发属性']: findName(item, curr),
['触发条件']: `${findLogin(curr)}${curr?.logicValue}`,
['触发值']: `${curr?.realValue}${
(findAttribute(item, curr) as any)?.detail?.dataType?.specs?.unit?.key ?? ''
}`,
};
};
const handleAlarmText = (text: string) => (text === 'triggerData' ? '触发器' : '执行条件');
const handleViewDetail = async (record: Recordable) => {
await nextTick();
const { details } = record;
if (!details) return;
const deviceIdKeys = Object.keys(details);
const dataFormat = await handleAlarmDetailFormat(deviceIdKeys);
const mapDataFormat = deviceIdKeys.map((deviceKey: string) => {
const findDataFormat = dataFormat.find(
(dataItem: Recordable) => dataItem.tbDeviceId === deviceKey
);
const dataKeys = Object.keys(details[deviceKey]);
const data: any = dataKeys.map((dataItem: string) => {
if (dataItem !== 'triggerData' && dataItem !== 'conditionData') {
return findValue(findDataFormat, details[deviceKey]);
} else {
return {
[handleAlarmText(dataItem)]: findValue(findDataFormat, details[deviceKey][dataItem]),
};
}
});
const objectDataFormat = data.reduce((acc: Recordable, curr: Recordable) => {
return {
...acc,
...curr,
};
});
return {
[findDataFormat.name]: objectDataFormat,
};
});
const objectDataFormats = mapDataFormat.reduce((acc: Recordable, curr: Recordable) => {
return {
...acc,
...curr,
};
});
outputData.value = JSON.stringify(objectDataFormats, null, 2);
openModal(true);
};
const handleAlarmDetailFormat = async (keys: string[]) => {
const temp: Recordable = [];
for (let item of keys) {
if (item === 'key' || item === 'data') return []; //旧数据则终止
const deviceDetailRes = await getDeviceDetail(item);
const { deviceProfileId } = deviceDetailRes;
if (!deviceProfileId) return [];
const attributeRes = await getAttribute(deviceProfileId);
const dataFormat: Recordable = handleDataFormat(deviceDetailRes, attributeRes);
temp.push(dataFormat);
}
return temp;
};
const handleDataFormat = (deviceDetail: Recordable, attributes: Recordable) => {
const { name, tbDeviceId, alias } = deviceDetail;
const attribute = attributes.map((item) => ({
identifier: item.identifier,
name: item.name,
detail: item.detail,
}));
return {
name: alias || name,
tbDeviceId,
attribute,
};
};
const handleEventIsDone = async (record: Recordable) => {
if (!record.id) return;
await clearOrAckAlarm(record.id, false);
createMessage.success('操作成功');
reload();
};
const handleEventIsClear = async (record: Recordable) => {
if (!record.id) return;
await clearOrAckAlarm(record.id, true);
createMessage.success('操作成功');
reload();
};
const getCanBatchClear = computed(() => {
const rowSelection = getRowSelection();
const getRows: AlarmLogItem[] = getSelectRows();
return !rowSelection.selectedRowKeys?.length || !getRows.every((item) => !item.cleared);
});
const getCanBatchAck = computed(() => {
const rowSelection = getRowSelection();
const getRows: AlarmLogItem[] = getSelectRows();
return !rowSelection.selectedRowKeys?.length || !getRows.every((item) => !item.acknowledged);
});
const handleBatchClear = async () => {
const ids = getSelectRows<AlarmLogItem>().map((item) => item.id);
if (!ids.length) return;
await doBatchClearAlarm(ids);
createMessage.success('操作成功');
clearSelectedRowKeys();
reload();
};
const handleBatchAck = async () => {
const ids = getSelectRows<AlarmLogItem>().map((item) => item.id);
if (!ids.length) return;
await doBatchAckAlarm(ids);
createMessage.success('操作成功');
clearSelectedRowKeys();
reload();
};
</script>
<template>
<div>
<BasicTable @register="registerTable">
<template #details="{ record }">
<span class="cursor-pointer text-blue-500" @click="handleViewDetail(record)">
<EyeOutlined class="svg:text-blue-500" />
<span class="ml-2">查看告警详情</span>
</span>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '处理',
icon: 'ant-design:edit-outlined',
onClick: handleEventIsDone.bind(null, record),
ifShow: !record.acknowledged,
},
{
label: '清除',
icon: 'ant-design:close-circle-outlined',
onClick: handleEventIsClear.bind(null, record),
ifShow: !record.cleared,
},
]"
/>
</template>
<template #toolbar>
<a-button danger :disabled="getCanBatchClear" @click="handleBatchClear">
批量清除
</a-button>
<Button @click="handleBatchAck" type="primary" :disabled="getCanBatchAck">
<span>批量处理</span>
</Button>
</template>
</BasicTable>
<BasicModal title="告警详情" @register="registerModal" @ok="closeModal">
<Input.TextArea v-model:value="outputData" :autosize="true" />
</BasicModal>
</div>
</template>
<style>
.alarm-stauts-cascader {
.ant-cascader-menu {
height: fit-content;
}
}
</style>