吉安感知网项目-前端
chenyao
just now 051e18f000cc438bc7dd972d3fe3cc9ea4f91b24
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
<template>
    <div class="scene-deployment">
        <div class="category-container">
            <div class="category-item" v-for="(item, ind) in categoryList" :key="ind">
                <div class="category-item-logo">
                    <img :src="item.logo" alt="">
                </div>
 
                <div class="category-item-content">
                    <span class="name">{{ item.name }}</span>
                    <span class="val">{{ item.val }}</span>
                </div>
            </div>
        </div>
 
        <div class="content" v-loading="loading" element-loading-background="rgba(5, 5, 15, 0.6)"
            element-loading-text="加载中...">
            <EmptyState v-if="!sceneList.length && !loading" />
            <div class="scene-card" v-else v-for="(item, index) in sceneList" :key="index" @click="emit('click', item)">
                <div class="card-header">
                    <el-tooltip class="title-tooltip" :content="item.sceneName || '-'" placement="top" effect="dark"
                        :show-after="200">
                        <span class="name">
                            {{ item.sceneName }}
                        </span>
                    </el-tooltip>
                </div>
 
                <div class="card-body">
                    <div class="row">
                        <span class="label">指挥点</span>
                        <span class="value">{{ formatPoint(item.longitude, item.latitude) }}</span>
                    </div>
                    <div class="rows">
                        <div class="col">
                            <span class="label">负责人</span>
                            <span class="value">{{ item.defenseLeader || '-' }}</span>
                        </div>
                        <div class="col">
                            <span class="label">电话</span>
                            <span class="value">{{ item.leaderPhone || '-' }}</span>
                        </div>
                    </div>
 
                    <div class="rows">
                        <div class="col">
                            <span class="label">区域数量</span>
                            <span class="value">{{ item.areaCount || 0 }}</span>
                        </div>
                        <div class="col">
                            <span class="label">设备数量</span>
                            <span class="value">{{ item.deviceCount || 0 }}</span>
                        </div>
                    </div>
 
                    <div class="row">
                        <span class="label">场景类型</span>
                        <span class="value">{{ getSceneTypeName(item.sceneType) }}</span>
                    </div>
                    <div class="row">
                        <span class="label">有效时间</span>
                    </div>
                    <div class="row">
                        <span class="value">{{ formatTimeRange(item.effectiveDateStart, item.effectiveDateEnd) }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
 
<script setup>
import { ref, onMounted } from 'vue'
import dayjs from 'dayjs'
import sceneLogo from '@/assets/images/dataCockpit/scene.png'
import areaLogo from '@/assets/images/dataCockpit/area.png'
import EmptyState from './EmptyState.vue'
import { newDefenseSceneManageList, sceneManageStatisticsApi } from '@/api/dataCockpit'
import { getDictionaryByCode } from '@/api/system/dictbiz'
 
const loading = ref(false)
const sceneTypeDict = ref([])
const loadingTimer = ref(null)
 
const categoryList = ref([
    {
        name: '场景',
        val: 0,
        logo: sceneLogo // 暂时复用
    },
    {
        name: '区域',
        val: 0,
        logo: areaLogo // 暂时复用
    }
])
 
const sceneList = ref([])
 
const formatPoint = (lng, lat) => {
    if (!lng || !lat) return '-'
    return `${lng}, ${lat}`
}
 
const formatTimeRange = (start, end) => {
    if (!start && !end) return '-'
    const s = start ? dayjs(start).format('YYYY-MM-DD HH:mm:ss') : '-'
    const e = end ? dayjs(end).format('YYYY-MM-DD HH:mm:ss') : '-'
    return `${s} ~ ${e}`
}
 
const getSceneTypeName = (code) => {
    const item = sceneTypeDict.value.find(i => i.dictKey === String(code))
    return item ? item.dictValue : (code || '-')
}
 
const fetchDict = async () => {
    try {
        const res = await getDictionaryByCode('CommandSceneType')
        if (res.data.code === 200) {
            sceneTypeDict.value = res.data.data.CommandSceneType || []
        }
    } catch (error) {
        console.error('获取场景类型字典失败:', error)
    }
}
 
const fetchStatistics = async () => {
    try {
        const params = {
            time: dayjs().format('YYYY-MM-DD HH:mm:ss')
        }
        const res = await sceneManageStatisticsApi(params)
        
        if (res.data.code === 200) {
            const { sceneManageCount, areaCount } = res.data.data
            categoryList.value[0].val = sceneManageCount || 0
            categoryList.value[1].val = areaCount || 0
        }
    } catch (error) {
        console.error('获取场景统计失败:', error)
    }
}
 
const emit = defineEmits(['click'])
 
const fetchList = async () => {
    // 只有超过200ms才显示loading,避免闪烁
    loadingTimer.value = setTimeout(() => {
        loading.value = true
    }, 200)
 
    try {
        const params = {
            time: dayjs().format('YYYY-MM-DD HH:mm:ss')
        }
        const res = await newDefenseSceneManageList(params)
        if (res.data.code === 200) {
            sceneList.value = res.data.data || []
        }
    } catch (error) {
        console.error('获取场景列表失败:', error)
    } finally {
        if (loadingTimer.value) clearTimeout(loadingTimer.value)
        loading.value = false
    }
}
 
onMounted(async () => {
    await fetchDict()
    fetchStatistics()
    fetchList()
})
</script>
 
<style lang="scss" scoped>
.scene-deployment {
    display: flex;
    flex-direction: column;
    height: 100%;
}
 
.category-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    box-sizing: border-box;
 
    .category-item {
        position: relative;
        width: 0;
        flex: 1;
        display: flex;
        height: 64px;
 
        &-logo {
            display: flex;
            align-items: center;
 
            img {
                width: 40px;
                height: 40px;
            }
        }
 
        &-content {
            width: 0;
            flex: 1;
            display: flex;
            flex-direction: column;
            border-bottom: 1px solid #6C6C89;
 
            span {
                margin-left: 8px;
            }
 
            .name {
                font-family: Open Sans, Open Sans;
                font-weight: 400;
                font-size: 16px;
                color: #C3C3DD;
                line-height: 20px;
                text-align: left;
                font-style: normal;
                text-transform: none;
            }
 
            .val {
                margin-top: 1rem;
                font-family: DinAB;
                font-weight: bold;
                font-size: 22px;
                color: #FFFFFF;
                line-height: 20px;
                text-align: left;
                font-style: normal;
                text-transform: none;
            }
        }
    }
}
 
.content {
    flex: 1;
    margin-top: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}
 
.scene-card {
    margin-top: 10px;
    padding: 10px;
    color: #fff;
    background: #191933;
    border-radius: 6px 6px 6px 6px;
    cursor: pointer;
 
    &:first-child {
        margin-top: 0;
    }
 
    &:hover {
        filter: brightness(1.05);
    }
 
    .card-header {
        display: flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
 
        .title-tooltip {
            flex: 1;
            min-width: 0;
            display: block;
        }
 
        .name {
            display: inline-block;
            max-width: 100%;
            font-family: Source Han Sans CN, Source Han Sans CN;
            font-weight: bold;
            font-size: 14px;
            color: #FFFFFF;
            text-align: left;
            font-style: normal;
            text-transform: none;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }
 
    .card-body {
        margin-top: 10px;
        display: flex;
        flex-direction: column;
 
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 400;
        font-size: 12px;
        color: #9E9EBA;
        text-align: left;
        font-style: normal;
        text-transform: none;
 
        .row {
            margin-top: 10px;
 
            line-height: 22px;
 
            .label {
                margin-right: 10px;
                color: #D4D5D7;
            }
 
            &:first-child {
                margin-top: 0;
            }
 
            &:last-child {
                margin-top: 0;
            }
        }
 
        .rows {
            margin-top: 10px;
 
            display: flex;
 
            .col {
                flex: 1;
 
                .label {
                    margin-right: 10px;
                    color: #D4D5D7;
                }
            }
        }
    }
}
</style>