吉安感知网项目-前端
chenyao
6 days ago c2e0774ce8fecf5ef512afa3ff6125fd2f5377b9
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
<template>
    <div class="left-container" :class="{ collapsed: collapsedModel }">
        <div class="wrapper">
            <TitleTemplate>异常情况告警</TitleTemplate>
 
            <div class="category-container">
                <div class="category-item" v-for="(item, ind) in categoryList" :key="ind"
                    @click="activeIdModel = item.id" :class="{ active: activeIdModel === item.id }">
                    {{ item.name }}
                    <span class="badge" v-if="item.badge">{{ item.badge }}</span>
                </div>
            </div>
 
            <div class="content">
                <RealWarning
                    v-if="activeIdModel === 1"
                    :data="realWarningData"
                    :loading="realWarningLoading"
                    @signal="emit('real-warning-signal', $event)"
                    @counter="emit('real-warning-counter', $event)"
                    @favorite="emit('real-warning-favorite', $event)"
                />
                <EquipmentWarning v-else-if="activeIdModel === 2" />
                <HistoryWarning v-else />
            </div>
        </div>
 
        <div class="collapse-btn" @click="toggleCollapse">
            <span class="arrow" :class="collapsedModel ? 'right' : 'left'"></span>
        </div>
    </div>
</template>
 
<script setup>
import TitleTemplate from './templateComponents/TitleTemplate.vue'
import EquipmentWarning from './EquipmentWarning.vue'
import HistoryWarning from './HistoryWarning.vue'
import { alarmStatisticsApi } from '@/api/dataCockpit'
import { computed, onMounted, ref } from 'vue'
import RealWarning from './RealWarning.vue'
 
const props = defineProps({
    activeId: {
        type: Number,
        default: 1
    },
    collapsed: {
        type: Boolean,
        default: false
    },
    realWarningData: {
        type: Array,
        default: () => []
    },
    realWarningLoading: {
        type: Boolean,
        default: false
    }
})
 
const emit = defineEmits([
    'update:activeId',
    'update:collapsed',
    'real-warning-signal',
    'real-warning-counter',
    'real-warning-favorite'
])
 
const activeIdModel = computed({
    get: () => props.activeId,
    set: (val) => emit('update:activeId', val)
})
 
const collapsedModel = computed({
    get: () => props.collapsed,
    set: (val) => emit('update:collapsed', val)
})
 
const categoryList = ref([
    {
        id: 1,
        name: '实时告警',
        badge: 0,
        component: RealWarning
    },
    {
        id: 2,
        name: '设备告警',
        badge: 0,
        component: EquipmentWarning
    },
    {
        id: 3,
        name: '历史告警',
        badge: 0,
        component: HistoryWarning
    }
])
 
const toggleCollapse = () => {
    collapsedModel.value = !collapsedModel.value
}
 
const updateBadges = async () => {
    const res = await alarmStatisticsApi()
    const data = res?.data?.data || {}
    const realTotal = data.realTimeAlarmCount ?? 0
    const historyTotal = data.historyAlarmCount ?? 0
    const deviceTotal = data.deviceAlarmCount ?? 0
    categoryList.value = categoryList.value.map((item) => {
        if (item.id === 1) return { ...item, badge: realTotal }
        if (item.id === 2) return { ...item, badge: deviceTotal }
        if (item.id === 3) return { ...item, badge: historyTotal }
        return item
    })
}
 
onMounted(() => {
    updateBadges()
})
</script>
 
<style lang="scss" scoped>
.left-container {
    position: relative;
    transition: transform 0.3s ease-in-out;
 
    &.collapsed {
        transform: translateX(calc(-100% - 17px - 32px));
    }
}
 
.collapse-btn {
    position: absolute;
    bottom: 454px;
    left: 300px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    z-index: 10;
    transform: translateY(50%);
 
    .arrow {
        width: 36px;
        height: 36px;
        background: url('@/assets/images/dataCockpit/left-btn.png') center / 100% 100% no-repeat;
    }
 
    &:hover {
        background: rgba(40, 79, 227, 0.6);
    }
}
 
.category-container {
    position: relative;
    display: flex;
    justify-content: space-between;
 
    &::after {
        content: '';
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 1px;
        background: #333355;
    }
 
    .category-item {
        position: relative;
        width: 0;
        flex: 1;
        margin-left: 26px;
        height: 68px;
        line-height: 68px;
 
        font-family: Source Code Pro, Source Code Pro;
        font-weight: 400;
        font-size: 14px;
        color: #86909C;
        text-align: center;
        font-style: normal;
        text-transform: none;
        cursor: pointer;
 
        &:first-child {
            margin-left: 0;
        }
 
        &.active {
            font-weight: normal;
            color: #FFFFFF;
        }
 
        &::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 0;
        }
 
        &.active::after {
            height: 3px;
            background: #284FE3;
            box-shadow: 0px 3px 2px 0px rgba(15, 89, 255, 0.1), 0px 7px 5px 0px rgba(15, 89, 255, 0.15), 0px 13px 10px 0px rgba(15, 89, 255, 0.18), 0px 22px 18px 0px rgba(15, 89, 255, 0.21), 0px 42px 33px 0px rgba(15, 89, 255, 0.26), 0px 100px 80px 0px rgba(15, 89, 255, 0.36);
            border-radius: 5px 5px 0px 0px;
            z-index: 9;
        }
 
        .badge {
            position: absolute;
            top: 16px;
            right: -4px;
            min-width: 18px;
            line-height: 18px;
            font-size: 12px;
            color: #FFFFFF;
            background: #FF3B30;
            border-radius: 50%;
            text-align: center;
            box-shadow: 0px 2px 6px rgba(255, 59, 48, 0.6);
            pointer-events: none;
        }
    }
}
 
.content {
    height: 0;
    flex: 1;
    margin-top: 20px;
    overflow: hidden;
}
</style>