物联网问题解决,只差最后测试完善
This commit is contained in:
@@ -21,16 +21,16 @@
|
||||
|
||||
<div class="main-container" style="margin-top: 10px">
|
||||
<el-table :data="form.tableData" style="width: 100%" border>
|
||||
<el-table-column label="项圈编号" prop="sn" />
|
||||
<el-table-column label="项圈编号" prop="deviceId" />
|
||||
<el-table-column label="设备电量" prop="battery">
|
||||
<template #default="scope"> {{ scope.row.battery }}% </template>
|
||||
<template #default="scope"> {{ calculateBatteryPercentage(scope.row.battery) }}% </template>
|
||||
</el-table-column>
|
||||
<el-table-column label="设备温度" prop="temperature">
|
||||
<template #default="scope"> {{ scope.row.temperature }}°C</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="delivery_number" label="所属运单号" />
|
||||
<el-table-column prop="license_plate" label="车牌号" />
|
||||
<el-table-column prop="uptime" label="绑定时间" />
|
||||
<el-table-column prop="deliveryNumber" label="运单号" />
|
||||
<el-table-column prop="carNumber" label="车牌号" />
|
||||
<el-table-column prop="uptime" label="更新时间" />
|
||||
<el-table-column label="操作" width="180">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" @click="showLocationDialog(scope.row)">定位</el-button>
|
||||
@@ -46,7 +46,7 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { collarList } from '~/api/hardware.js';
|
||||
import { iotDeviceQueryList } from '~/api/hardware.js';
|
||||
import LocationDialog from './locationDialog.vue';
|
||||
import TrackDialog from './trackDialog.vue';
|
||||
|
||||
@@ -63,21 +63,66 @@ const form = reactive({
|
||||
endNo: '',
|
||||
});
|
||||
|
||||
// 计算电量百分比:3V为100%,2.4V为0%
|
||||
const calculateBatteryPercentage = (voltage) => {
|
||||
if (!voltage || voltage === '' || voltage === '0') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const voltageValue = parseFloat(voltage);
|
||||
if (isNaN(voltageValue)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 线性插值计算:3V = 100%, 2.4V = 0%
|
||||
const minVoltage = 2.4;
|
||||
const maxVoltage = 3.0;
|
||||
|
||||
if (voltageValue >= maxVoltage) {
|
||||
return 100;
|
||||
} else if (voltageValue <= minVoltage) {
|
||||
return 0;
|
||||
} else {
|
||||
const percentage = ((voltageValue - minVoltage) / (maxVoltage - minVoltage)) * 100;
|
||||
return Math.round(percentage);
|
||||
}
|
||||
};
|
||||
|
||||
const getList = async () => {
|
||||
const { pageSize, pageNum, sn, startNo, endNo } = form;
|
||||
// 为了获取所有项圈设备,使用更大的pageSize
|
||||
const params = {
|
||||
pageSize,
|
||||
pageNum,
|
||||
pageSize: 100, // 使用更大的页面大小确保能获取所有设备
|
||||
pageNum: 1,
|
||||
sn,
|
||||
startNo,
|
||||
endNo,
|
||||
};
|
||||
const res = await collarList(params);
|
||||
const { data = {}, code } = res;
|
||||
const { rows = [], total = 0 } = data;
|
||||
if (code === 200) {
|
||||
form.tableData = rows;
|
||||
form.total = total;
|
||||
|
||||
try {
|
||||
const res = await iotDeviceQueryList(params);
|
||||
const { data = {}, code } = res;
|
||||
|
||||
if (code === 200) {
|
||||
// 后端已经过滤了organName为'牛只运输跟踪系统'的数据
|
||||
// 前端根据设备类型过滤项圈数据(type=4)
|
||||
const allData = data.rows || [];
|
||||
const filteredData = allData.filter(item => item.type === 4);
|
||||
|
||||
form.tableData = filteredData;
|
||||
form.total = filteredData.length;
|
||||
|
||||
// 重新计算分页,因为我们现在显示的是过滤后的数据
|
||||
form.pageNum = 1; // 重置到第一页
|
||||
} else {
|
||||
console.error('API调用失败:', res.msg);
|
||||
form.tableData = [];
|
||||
form.total = 0;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('API调用异常:', error);
|
||||
form.tableData = [];
|
||||
form.total = 0;
|
||||
}
|
||||
};
|
||||
const searchClick = async () => {
|
||||
|
||||
Reference in New Issue
Block a user