<!-- Description: 设备运维-设备数据查看 Author: 李亚光 Date: 2024-01-08 --> <script lang="ts" setup name="H5DeviceOperationData"> import { showToast } from 'vant' // 基本信息 const deviceInfo = ref({ devcode: '24102708', devTypeName: '燃气智能监测终端', tagNumber: 'N57C114', position: '示范区联络线中压A闸9', address: '百环花园调压站南侧', installDate: '2024-11-30', lon: '116.4159851074', lat: '39.9000473022', }) // 近期数据 const data = ref([ { logTime: '2024-05-18 17:05:01', value: '0.00', cell: '80' }, { logTime: '2024-07-18 13:02:11', value: '1.00', cell: '88' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '50' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '50' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '90' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '10' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '50' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '50' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '2' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '50' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '50' }, { logTime: '2024-09-18 17:05:01', value: '0.00', cell: '50' }, ]) // 查看位置 const locationRef = ref() const viewLocation = () => { if (!deviceInfo.value.lon || !deviceInfo.value.lat) { showToast('该位置缺少坐标信息'); return } locationRef.value.initDialog([deviceInfo.value.lon, deviceInfo.value.lat]) } // 计算滚动区域高度 const scrollHeight = ref(0) const calcHeight = () => { // 公共头部高度40 // 边距安全 30 // total区域 const totalAreaHeight = document.getElementById('base-info')?.offsetHeight // 查询结果头部 const searchHeaderHeight = document.getElementById('title')?.offsetHeight scrollHeight.value = window.innerHeight - 40 - 30 - (totalAreaHeight || 0) - (searchHeaderHeight || 0) - 14 } onMounted(() => { calcHeight() }) window.addEventListener('resize', () => { calcHeight() }) // 计算电池图标 const calcCellIcon = (cell: string) => { if (!cell) { return '' } if (Number(cell) <= 20) { return 'cell-20' } else if (Number(cell) > 20 && Number(cell) < 70) { return 'cell-40' } else if (Number(cell) >= 70) { return 'cell-70' } } // 计算电池电量进度 const calcCellWidth = (cell: string) => { if (!cell) { return '0' } else { return Number(cell) >= 85 ? `${89}%` : `${cell}%` } } // 计算电池颜色 const calcCellColor = (cell: string) => { if (!cell) { return '' } if (Number(cell) <= 20) { return 'cell-20-color' } else if (Number(cell) > 20 && Number(cell) < 70) { return 'cell-40-color' } else if (Number(cell) >= 70) { return 'cell-70-color' } } </script> <template> <div class="info-container"> <!-- 基本信息 --> <div id="base-info" class="search-info"> <div class="cell"> <div class="title">设备编号</div> <div class="value">{{ deviceInfo.devcode }}</div> </div> <div class="cell"> <div class="title">最近上报时间</div> <div class="value">{{ deviceInfo.installDate }}</div> </div> </div> <!-- 近期数据 --> <div class="search-result"> <div id="title" class="title"> <div class="symbol"></div> 近期数据 </div> <!-- 结果 --> <el-scrollbar :max-height="`${scrollHeight}px`" style="margin-top: 14px;"> <lazy-component> <div v-for="(item, index) in data" :key="index" :class="index !== 0 ? 'top-border' : ''" class="result-item"> <div class="cell"> <div class="title">{{ item.logTime }}</div> <div class="value"> <!-- 电池图标 --> <div class="cell-icon" :class="calcCellIcon(item.cell)"> <!-- 电池电量 --> <div style="height: 14px;" :style="{ width: `${calcCellWidth(item.cell)}` }" :class="calcCellColor(item.cell)"></div> <!-- 数字 --> <div class="cell-count">{{ item.cell }}</div> </div> </div> </div> <div class="cell"> <div class="title">燃气浓度</div> <div class="value">{{ item.value }}%LEL</div> </div> </div> </lazy-component> </el-scrollbar> </div> </div> </template> <style lang="scss" scoped> .cell-icon { position: relative; width: 30px; height: 18px; display: flex; align-items: center; padding-left: 2px; .cell-count { position: absolute; color: #000; text-align: center; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 0.8rem; align-items: center; } } .cell-70 { background: url('@/assets/icons/icon-cell-70.svg') no-repeat center center / cover; } .cell-70-color { background-color: rgb(37, 202, 37); } .cell-40 { background: url('@/assets/icons/icon-cell-40.svg') no-repeat center center / cover; } .cell-40-color { background-color: orange; } .cell-20 { background: url('@/assets/icons/icon-cell-20.svg') no-repeat center center / cover; } .cell-20-color { background-color: red; } .info-container { width: 100%; height: calc(100vh - 40px); overflow: hidden; color: #444; .search-info { background-color: #fff; width: 96%; margin: 0 auto; margin-top: 1vh; border-radius: 6px; padding: 4px; padding-top: 0.8rem; padding-bottom: 0.8rem; padding-left: 0.8rem; font-size: 1.1rem; .cell { display: flex; justify-content: space-between; padding-top: 6px; padding-bottom: 6px; padding-right: 14px; align-items: center; .value { color: #888; width: 80%; text-align: right; font-size: 1rem; vertical-align: middle; // display: flex; // flex-direction: column; // justify-content: center; display: flex; align-items: center; justify-content: flex-end; .location { display: inline-block; width: 22px; height: 22px; background: url('@/assets/icons/icon-location.svg') no-repeat center center / cover; vertical-align: middle; margin-left: 8px; } } .title { width: 20%; white-space: nowrap; font-weight: 500; } // .title, // .value { // white-space: nowrap; // overflow: hidden; // text-overflow: ellipsis; // } } } .search-result { background-color: #fff; width: 96%; margin: 0 auto; margin-top: 1vh; border-radius: 6px; padding: 4px; padding-left: 0.6rem; .title { display: flex; font-size: 1.1rem; .symbol { width: 4px; height: 22px; background-color: #0d76d4; border-radius: 4px; margin-right: 8px; } } .top-border { border-top: 1px solid #e4e7ed; // margin-top: 8px; } .result-item { .cell { display: flex; justify-content: space-between; padding-top: 6px; padding-bottom: 6px; padding-right: 18px; align-items: center; .value { color: #888; width: 80%; text-align: right; font-size: 1rem; vertical-align: middle; // display: flex; // flex-direction: column; // justify-content: center; display: flex; align-items: center; justify-content: flex-end; } .title { width: 20%; white-space: nowrap; } } } } } </style>