吉安感知网项目-前端
shuishen
2026-01-27 98ff0df343bd4e5d2d5e138a02c6db2b7fa9696b
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
<!--
 * @Author       : yuan
 * @Date         : 2026-01-08 09:29:07
 * @LastEditors  : yuan
 * @LastEditTime : 2026-01-26 09:59:52
 * @FilePath     : \applications\drone-command\src\views\dataCockpit\components\RealWarning.vue
 * @Description  : 
 * Copyright 2026 OBKoro1, All Rights Reserved. 
 * 2026-01-08 09:29:07
-->
<template>
    <div
        class="real-warning"
        v-loading="loading"
        element-loading-background="rgba(5, 5, 15, 0.6)"
        element-loading-text="加载中..."
    >
        <div class="list-content">
            <EmptyState v-if="!realWarningData.length" />
            <RealTemplate
                v-else
                v-for="(item, ind) in realWarningData"
                :key="ind"
                :data="item"
                @signal="() => handleAction('signal', item)"
                @counter="() => handleAction('counter', item)"
                @favorite="() => handleFavorite(item)"
            />
        </div>
    </div>
</template>
 
<script setup>
import RealTemplate from './templateComponents/RealTemplate.vue'
import {
    alarmLogApi,
    alarmFavoriteRemoveApi,
    alarmFavoriteSaveApi,
    interferenceAndExpulsionApi
} from '@/api/dataCockpit'
import { onMounted, ref } from 'vue'
import EmptyState from './EmptyState.vue'
import { ElMessage } from 'element-plus'
 
const realWarningData = ref([])
const loading = ref(true)
const minLoadingMs = 400
 
const actionTextMap = {
    signal: '信号干扰',
    counter: '诱导驱离'
}
 
 
const getAlarmRecordId = (item) => item?.alarmRecordId ?? item?.id
const getFavoriteId = (item) =>
    item?.favoriteId ??
    item?.alarmFavoriteId ??
    item?.fwAlarmFavoriteId ??
    item?.favoriteRecordId ??
    getAlarmRecordId(item)
 
const isFavorited = (item) => {
    const value = item?.favorited ?? item?.isFavorite
    return value === 1 || value === '1' || value === true
}
 
const buildPayload = (type, item) => ({
    counterWay: type === 'signal' ? 1 : type === 'counter' ? 2 : '',
    alarmRecordId: getAlarmRecordId(item)
})
 
const handleAction = async (type, item) => {
    const actionText = actionTextMap[type] || '操作'
    try {
        const res = await interferenceAndExpulsionApi(buildPayload(type, item))
        if (res?.data?.success) {
            ElMessage({ type: 'success', message: actionText + '成功' })
            await fetchRealWarning()
        } else {
            ElMessage({ type: 'error', message: res?.data?.msg || actionText + '失败' })
        }
    } catch (error) {
        ElMessage({ type: 'error', message: actionText + '失败' })
    }
}
 
const handleFavorite = async (item) => {
    const alarmRecordId = getAlarmRecordId(item)
    if (!alarmRecordId) {
        ElMessage({ type: 'warning', message: '缺少告警记录ID' })
        return
    }
    const isFavorite = isFavorited(item)
    const actionText = isFavorite ? '取消关注' : '关注'
    try {
        const res = isFavorite
            ? await alarmFavoriteRemoveApi(getFavoriteId(item))
            : await alarmFavoriteSaveApi({ alarmRecordId })
        if (res?.data?.success) {
            ElMessage({ type: 'success', message: actionText + '成功' })
            await fetchRealWarning()
        } else {
            ElMessage({ type: 'error', message: res?.data?.msg || actionText + '失败' })
        }
    } catch (error) {
        ElMessage({ type: 'error', message: actionText + '失败' })
    }
}
 
const fetchRealWarning = async () => {
    const startAt = Date.now()
    loading.value = true
    try {
        const params = { current: 1, size: 20, alarmType: '1' }
        const res = await alarmLogApi(params)
        const records = res?.data?.data?.records ?? []
        realWarningData.value = records.map((record) => ({
            ...record,
            isFavorite:
                record?.isFavorite ??
                (record?.favorited === 1 || record?.favorited === '1')
        }))
    } finally {
        const elapsed = Date.now() - startAt
        if (elapsed < minLoadingMs) {
            await new Promise((resolve) => setTimeout(resolve, minLoadingMs - elapsed))
        }
        loading.value = false
    }
}
 
onMounted(() => {
    fetchRealWarning()
})
</script>
 
<style lang="scss" scoped>
.real-warning {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
 
.list-content {
    height: 0;
    flex: 1;
    overflow-y: auto;
}
</style>