diff --git a/src/views/AIPatrol/sensor/index.vue b/src/views/AIPatrol/sensor/index.vue index 567c0f4..9c5a6d0 100644 --- a/src/views/AIPatrol/sensor/index.vue +++ b/src/views/AIPatrol/sensor/index.vue @@ -78,21 +78,21 @@ const handleDelete = async (id) => { // 获取传感器状态样式 const getStatusStyle = (status) => { - if (!status) return { color: '#909399', text: '未知' } - return { - 1: { - color: '#67C23A', - text: '在线' - }, + const statusMap = { 0: { color: '#909399', text: '离线' }, + 1: { + color: '#67C23A', + text: '在线' + }, 2: { color: '#F56C6C', text: '异常' } - }[status.code] || { color: '#909399', text: status.text || '未知' } + } + return statusMap[status] || { color: '#909399', text: '未知' } } // 获取传感器类型信息 @@ -116,6 +116,41 @@ const formatValue = (value, unit = '') => { return `${value}${unit}` } +// 获取传感器类型名称 +const getSensorTypeName = (type, name) => { + if (name.includes('CS616')) return '土壤传感器' + if (name.includes('RK500-13')) return '水质传感器' + return '环境传感器' +} + +// 获取传感器数据项 +const getSensorDataItems = (sensor) => { + if (sensor.device_name.includes('CS616')) { + // 土壤传感器数据项 + return [ + { label: '温度', value: sensor.data?.temp, unit: '°C' }, + { label: '湿度', value: sensor.data?.humi, unit: '%' }, + { label: '土壤湿度', value: sensor.data?.soil_adc, unit: '' }, + { label: '光照强度', value: sensor.data?.light_adc, unit: '' } + ] + } else if (sensor.device_name.includes('RK500-13')) { + // 水质传感器数据项 + return [ + { label: '温度', value: sensor.data?.temp, unit: '°C' }, + { label: '湿度', value: sensor.data?.humi, unit: '%' }, + { label: '水质电导率', value: sensor.data?.soil_adc, unit: 'μS/cm' }, + { label: '光照强度', value: sensor.data?.light_adc, unit: '' } + ] + } + // 默认数据项 + return [ + { label: '温度', value: sensor.data?.temp, unit: '°C' }, + { label: '湿度', value: sensor.data?.humi, unit: '%' }, + { label: '光照强度', value: sensor.data?.light_adc, unit: '' }, + { label: '传感器值', value: sensor.data?.soil_adc, unit: '' } + ] +} + // 页面加载时获取数据 onMounted(() => { getSensorList() @@ -137,18 +172,18 @@ onMounted(() => { v-for="sensor in sensorList" :key="sensor.id" class="sensor-card" - :class="{ 'offline': sensor.status?.code === 0 }" + :class="{ 'offline': sensor.status === 0 }" >
- + {{ sensor.device_name }}
{{ getStatusStyle(sensor.status).text }} @@ -159,6 +194,10 @@ onMounted(() => { 设备编号 {{ sensor.device_code }}
+
+ 设备类型 + {{ getSensorTypeName(sensor.device_type, sensor.device_name) }} +
安装位置 {{ sensor.install_location || '暂无数据' }} @@ -166,28 +205,20 @@ onMounted(() => {
-
-
{{ formatValue(sensor.data?.temp, '°C') }}
-
温度
-
-
-
{{ formatValue(sensor.data?.humi, '%') }}
-
湿度
-
-
-
{{ formatValue(sensor.data?.light_adc) }}
-
光照强度
-
-
-
{{ formatValue(sensor.data?.soil_adc) }}
-
土壤湿度
+
+
{{ formatValue(item.value, item.unit) }}
+
{{ item.label }}