Crunchy
2025-06-14 b25dac9ce64c5988a9e546c9c80413e9b666e4e2
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
<template>
    <div>
        <basic-container>
            <el-form label-width="100px" :inline="true">
                <el-form-item label="设备:" required>
                    <el-select v-model="search.deviceId" placeholder="请选择">
                        <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.name"
                            :value="item.device_id"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间:">
                    <el-date-picker
                        v-model="search.collectionTime"
                        type="datetime"
                        placeholder="选择日期时间"
                    >
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="searchFun">查询</el-button>
                </el-form-item>
            </el-form>
        </basic-container>
        <basic-container>
            <el-table
                :data="tableData"
                style="width: 100%"
                height="calc(100vh - 27vh)"
            >
                <el-table-column type="index" label="序号"></el-table-column>
                <el-table-column prop="collectionTime" label="采集时间">
                </el-table-column>
                <el-table-column label="设备名称">
                    <template slot-scope="scope">
                        <!-- 使用计算属性或方法查找匹配项 -->
                        {{ getMatchedName(scope.row.dataStream) }}
                    </template>
                </el-table-column>
                <el-table-column prop="dataStream" label="设备编号" >
                </el-table-column>
                <el-table-column prop="value" label="参数值"> </el-table-column>
            </el-table>
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="1"
                :page-sizes="[100, 200, 300, 400]"
                :page-size="search.size"
                layout="->, total, sizes, prev, pager, next, jumper"
                :total="search.total"
            >
            </el-pagination>
        </basic-container>
    </div>
</template>
 
<script>
import {
    getDeviceId,
    getEquipmentSensors,
    mqttPage
} from '@/api/equipment/equipment'
 
export default {
    data() {
        return {
            currentPage: 1,
            options: [],
            tableData: [],
            equipmentSensorsList: [],
            search: {
                size: 100,
                current: 1,
                total: 0,
                deviceId: null,
                collectionTime: null
            }
        }
    },
    // 初始化调用 查询设备 折线图数据
    async created() {
        await this.getDeviceIdFun()
        await this.getPage()
    },
    methods: {
        // 查找匹配的设备名称
        getMatchedName(dataStream) {
            // 遍历设备传感器列表
            const matchedItem = this.equipmentSensorsList.find((item) => {
                return item.dataStream === dataStream
            })
 
            // 返回匹配的中文名称或默认值
            return matchedItem ? matchedItem.nameCn : '未找到设备'
        },
        searchFun() {
            this.tableData = []
            this.getEquipmentSensors()
            this.getPage()
        },
        handleSizeChange(val) {
            this.search.size = val
            this.getPage()
        },
        handleCurrentChange(val) {
            this.search.current = val
            this.getPage()
        },
        // 获取设备下拉框
        async getDeviceIdFun() {
            await getDeviceId().then(async (res) => {
                this.options = res.data.data
                this.search.deviceId = this.options[0].device_id
                await this.getEquipmentSensors()
            })
        },
        getPage() {
            mqttPage(this.search).then((res) => {
                this.tableData = res.data.data.content
                this.search.total = res.data.data.totalElements
            })
        },
        async getEquipmentSensors() {
            await getEquipmentSensors({ deviceId: this.search.deviceId }).then(
                (response) => {
                    this.equipmentSensorsList = response.data.data
                }
            )
        }
    }
}
</script>
 
<style></style>