alarm-detail.vue
7.52 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
<template>
<view class="alarm-detail-page">
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<view class="alarm-detail-column">
<view class="u-flex detail-column">
<view class="column-line" v-for="(item,index) in alarmDetail" :key="index">
<view class="column">
<text class="text-org-bold">{{item.label}}</text>
<text class="text-device-muted text-clip alarm-text"
:style="{color:hasColor.includes(item.label)?'#DE4437':''}">
{{item.label===hasColor[0]? setAlarmStatus(item.value):item.label===hasColor[1]?setAlarmSeverity(item.value):
item.label==='告警值:'?formatAlarmValueText:item.label==='告警条件:'?formatAlarmConditionText
:item.label==='告警设备:'?formatDeviceText:item.value}}
</text>
</view>
<view class="bottom-line"></view>
</view>
</view>
</view>
<!-- #ifdef MP -->
<view class="handle-result text-org-bold" style="">处理结果</view>
<view class="hanle-main">
<u--form :label-style="{ 'font-size': '0rpx' }" style="padding-left: 26rpx;" labelPosition="left"
:model="formModel" ref="form1">
<u-form-item label="." prop="result" ref="item3">
<view style="position: relative;left: -60rpx;">
<u--textarea border="none" height="96" placeholder="请输入处理结果" v-model="formModel.result" count>
</u--textarea>
</view>
</u-form-item>
</u--form>
</view>
<!-- #endif -->
<!-- #ifdef APP-PLUS -->
<view class="handle-result text-org-bold">处理结果</view>
<view class="hanle-main">
<view>
<u--textarea border="none" height="96" placeholder="请输入处理结果" v-model="formModel.result" count>
</u--textarea>
</view>
</view>
<!-- #endif -->
<view class="bottom-button">
<view v-if="handleText.includes(alarmDetail[7].value)" class="u-flex button-item">
<u-button @click="handleSubmit" type="primary" shape="circle" text="处理"></u-button>
</view>
<view v-if="clearText.includes(alarmDetail[7].value)" class="u-flex button-item">
<u-button @click="handleRemove" type="error" shape="circle" text="清除"></u-button>
</view>
</view>
</view>
</template>
<script>
import {
mapActions
} from 'vuex'
import api from '@/api/index.js'
import {
alarmSeverity,
alarmStatus,
operationNumberOrDate,
operationString,
operationBoolean
} from '@/pages/alarm/config/data.js';
import {
useShowToast,
useNavigateBack
} from '@/plugins/utils.js'
export default {
data() {
return {
handleText: ['ACTIVE_UNACK', 'CLEARED_UNACK'],
clearText: ['ACTIVE_UNACK', 'ACTIVE_ACK'],
hasColor: ['告警级别:', '告警状态:'],
alarmSeverity,
alarmStatus,
operationNumberOrDate,
operationString,
operationBoolean,
formModel: {
result: ''
},
detailId: '',
alarmDetail: [],
formatDeviceText: '',
formatAlarmValueText: '',
formatAlarmConditionText: '',
};
},
onLoad(e) {
if (e.data !== null) {
let params = JSON.parse(decodeURIComponent(e.data));
const {deviceName,severity,organizationName,details,type,createdTime,status,id} = params
this.detailId = id
this.alarmDetail = [{label: '告警场景:',value: type},{label: '告警级别:',value: severity},{label: '所属组织:',value: organizationName},{label: '告警设备:',value: ''},{label: '告警条件:',value: ''},{label: '告警值:',value: ''},{label: '告警时间:',value: createdTime},{label: '告警状态:',value: status},]
this.formatAlarmDevice(details)
this.formatAlarmValue(details)
this.formatAlarmCondition(details)
}
// 隐藏原生的tabbar
uni.hideTabBar();
},
methods: {
...mapActions(['updateBadgeTotal']),
setAlarmStatus(value) {
return this.alarmSeverity.find(item => item.value === value).label
},
setAlarmSeverity(value) {
return this.alarmStatus.find(item => item.value === value).label
},
returnPrevPage(title) {
useShowToast(title)
let pages = getCurrentPages(); //获取所有页面栈实例列表
let nowPage = pages[pages.length - 1]; //当前页页面实例
let prevPage = pages[pages.length - 2]; //上一页页面实例
prevPage.$vm.detailStatus = true;
},
async handleSubmit() {
if (this.formModel.result == '') return uni.$u.toast('请输入处理结果');
const res = await api.alarmApi.postAlarmAckApi(this.detailId)
if (res == '') {
this.returnPrevPage('处理成功~')
setTimeout(() => {
useNavigateBack(1)
}, 500);
}
},
async handleRemove() {
const res = await api.alarmApi.postAlarmClearApi(this.detailId)
if (res == '') {
this.returnPrevPage('清除成功~')
setTimeout(async () => {
useNavigateBack(1)
const res = await uni.$u.http.get('/yt/homepage/app?login=true');
if (res) {
//异步实时更新告警徽标数
await this.updateBadgeTotal(res.totalAlarm?.activedAlarm);
}
}, 500);
}
},
//告警值处理
async formatAlarmValue(e) {
const keys = Object.keys(e)
const dataFormat = await this.handleAlarmDetailFormat(keys);
const values = keys.reduce((acc, curr) => {
dataFormat.forEach((dataItem => {
if (dataItem.tbDeviceId === curr) {
const findAttribute = dataItem.attribute.find(findItem => findItem.identifier === e[curr].key)
acc.push(
`${findAttribute.name}:${e[curr].realValue}${!findAttribute.detail?.dataType?.specs?.unit?.key?'':findAttribute.detail?.dataType?.specs?.unit?.key}`
)
}
}))
return acc
}, [])
this.formatAlarmValueText = values.join(',')
},
//告警条件处理
formatAlarmCondition(e) {
const keys = Object.keys(e)
const values = keys.reduce((acc, curr) => {
acc.push({
login: e[curr].logic,
logicValue: e[curr].logicValue
})
return acc
}, [])
const operation = [...operationNumberOrDate, ...operationString, ...operationBoolean]
const format = values.map(item => {
const findOperation = operation.find(findItem => findItem.value === item.login)?.symbol
return findOperation + item.logicValue
})
this.formatAlarmConditionText = format.filter(Boolean).join(',')
},
//告警设备处理
async formatAlarmDevice(e) {
const keys = Object.keys(e)
const dataFormat = await this.handleAlarmDetailFormat(keys);
if (!dataFormat) this.formatDeviceText = ''
if (Array.isArray(dataFormat) && dataFormat.length === 0) this.formatDeviceText = ''
this.formatDeviceText = dataFormat.map(item => item.name).join(',')
},
async handleAlarmDetailFormat(keys) {
const temp = [];
for (let item of keys) {
if (item === 'key' || item === 'data') return; //旧数据则终止
const deviceDetailRes = await api.deviceApi.getDeviceDetail(item);
const { deviceProfileId } = deviceDetailRes;
if (!deviceProfileId) return;
const attributeRes = await api.deviceApi.getAttribute(deviceProfileId);
const dataFormat = this.handleDataFormat(deviceDetailRes, attributeRes);
temp.push(dataFormat);
}
return temp;
},
handleDataFormat(deviceDetail, attributes) {
const { name,tbDeviceId } = deviceDetail;
const attribute = attributes.map((item) => ({
identifier: item.identifier,
name: item.name,
detail: item.detail
}));
return {
name,
tbDeviceId,
attribute,
};
}
}
};
</script>
<style lang="scss" scoped>
@import './static/alarmDetail.scss';
/deep/ .u-button--primary {
background-color: #377dff !important;
border-color: #377dff !important;
}
</style>