吉安感知网项目-前端
chenyao
2 days ago c567cbca3b78a7e06a827acbab56a46657e31aa1
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
<template>
    <div class="history-warning" v-loading="loading" element-loading-background="rgba(5, 5, 15, 0.6)"
        element-loading-text="加载中...">
        <!-- 搜索区(设计稿红框) -->
        <div class="search-box">
            <!-- 关键字 -->
            <el-input v-model="query.keyword" class="command-input" placeholder="请输入数据名称" clearable
                @keyup.enter="onSearch" @clear="onSearch">
            </el-input>
 
            <!-- 日期范围 -->
            <el-date-picker v-model="query.dateRange" class="command-date-picker"
                popper-class="command-date-picker-popper" type="daterange" range-separator="~"
                start-placeholder="创建开始日期" end-placeholder="结束日期" format="YYYY年MM月DD日" value-format="YYYY-MM-DD"
                :clearable="true" @change="onSearch">
            </el-date-picker>
        </div>
 
        <!-- 列表 -->
        <div class="list-content">
            <EmptyState v-if="!filteredList.length" />
            <HistoryTemplate v-else v-for="(item, ind) in filteredList" :key="item.id || ind" :data="item"
                @click="onCardClick" />
        </div>
    </div>
</template>
 
<script setup>
import { dateRangeFormat } from '@ztzf/utils'
import { ref, computed, onMounted } from 'vue'
import HistoryTemplate from './templateComponents/HistoryTemplate.vue'
import { alarmLogApi } from '@/api/dataCockpit'
import EmptyState from './EmptyState.vue'
 
const historyWarningData = ref([])
const loading = ref(false)
const loadingTimer = ref(null)
 
// 查询条件:keyword + dateRange(YYYY-MM-DD数组)
const query = ref({
    keyword: '',
    dateRange: [] // [start, end]
})
 
const onSearch = () => {
    fetchHistoryWarning()
}
 
const onCardClick = (item) => {
    console.log('点击无人机卡片:', item.id)
}
 
const fetchHistoryWarning = async () => {
 
    // 只有超过200ms才显示loading,避免闪烁
    loadingTimer.value = setTimeout(() => {
        loading.value = true
    }, 200)
 
    try {
        const [startTime, endTime] = dateRangeFormat(query.value.dateRange) || []
        const keyword = (query.value.keyword || '').trim()
        const params = {
            current: 1,
            size: 20,
            alarmType: '2',
            startTime,
            endTime,
            droneName: keyword || undefined,
            droneSerialNo: keyword || undefined
        }
        const res = await alarmLogApi(params)
        const records = res?.data?.data?.records ?? []
        historyWarningData.value = records
    } finally {
        if (loadingTimer.value) clearTimeout(loadingTimer.value)
        loading.value = false
    }
}
 
const filteredList = computed(() => {
    return historyWarningData.value
})
 
onMounted(() => {
    fetchHistoryWarning()
})
</script>
 
<style scoped lang="scss">
.history-warning {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
 
    .search-box {
        display: flex;
        flex-direction: column;
        gap: 10px;
 
        ::v-deep(.command-date-picker) {
            width: 100% !important;
        }
    }
 
    .list-content {
        height: 0;
        flex: 1;
        overflow-y: auto;
    }
}
</style>