<!-- Description: 设备运维-设备数据查看 Author: 李亚光 Date: 2024-01-08 --> <script lang="ts" setup name="H5DeviceOperationData"> import { showToast } from 'vant' import { getInfoListPage, getDeviceData } from '@/api/mobile/info' import { toHumpObject } from '@/utils/String' const $route = useRoute() // 基本信息 const devcode = ref('') const reportDate = ref('') const typeName = ref('') devcode.value = $route.query.devcode as string // 近期数据 const data = ref([]) const loading = ref(false) // 计算滚动区域高度 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() loading.value = true // 查询设备信息 getInfoListPage({ devCode: $route.query.devcode, offset: 1, limit: 1 }).then(res => { if (res.data.rows.length) { const device = res.data.rows[0] typeName.value = device.typeName getDeviceData({ devcode: device.devcode, typeName: device.typeName }).then(res1 => { data.value = res1.data.map((item: any) => toHumpObject(item)) // 上报时间 if (res1.data.length) { reportDate.value = res1.data[0].uptime } else { reportDate.value = '' } loading.value = false }).catch(() => { loading.value = false }) } else { data.value = [] reportDate.value = '' loading.value = false } }).catch(() => { loading.value = false }) }) window.addEventListener('resize', () => { calcHeight() }) onBeforeUnmount(() => { window.addEventListener('resize', () => { }) }) // 计算电池图标 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">{{ devcode }}</div> </div> <div class="cell"> <div class="title">最近上报时间</div> <div class="value">{{ reportDate }}</div> </div> </div> <!-- 近期数据 --> <div class="search-result"> <div id="title" class="title"> <div class="symbol"></div> 近期数据 </div> <!-- 结果 --> <el-scrollbar v-loading="loading" :max-height="`${scrollHeight}px`" style="margin-top: 14px;"> <lazy-component v-if="data.length"> <!-- 燃气智能终端 --> <template v-if="typeName.includes('燃气智能')"> <div v-for="(item, index) in data" :key="index" :class="index !== 0 ? 'top-border' : ''" class="result-item"> <div class="cell"> <div class="title">{{ item.uptime }}</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.strength }}%LEL</div> </div> </div> </template> <!-- 管网哨兵 --> <template v-if="typeName.includes('管网哨兵')"> <div v-for="(item, index) in data" :key="index" :class="index !== 0 ? 'top-border' : ''" class="result-item"> <div class="cell"> <div class="title">{{ item.uptime }}</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.gasval }}%LEL</div> </div> </div> </template> </lazy-component> <van-empty v-if="!data.length" description="暂无数据" /> <div v-if="data.length" class="to-top"> <van-back-top /> </div> </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>