|
@@ -132,68 +132,59 @@ export default {
|
|
|
methods: {
|
|
methods: {
|
|
|
async fetchRooms() {
|
|
async fetchRooms() {
|
|
|
try {
|
|
try {
|
|
|
- // 获取所有房间
|
|
|
|
|
- const response = await axios.get('/api/rooms');
|
|
|
|
|
- console.log('API 返回的房间数据:', response.data);
|
|
|
|
|
|
|
+ const response = await axios.get('/api/all-rooms-with-devices');
|
|
|
|
|
+ console.log('API 返回的房间和设备数据:', response.data);
|
|
|
|
|
|
|
|
- // 遍历每个房间,获取绑定的设备信息
|
|
|
|
|
- for (const room of response.data) {
|
|
|
|
|
- const deviceResponse = await axios.get(
|
|
|
|
|
- `/api/devices-by-room?roomId=${room.id}`
|
|
|
|
|
- );
|
|
|
|
|
- console.log(`房间 ${room.id} 的设备数据:`, deviceResponse.data);
|
|
|
|
|
|
|
+ // 处理房间数据
|
|
|
|
|
+ this.rooms = response.data.map(room => {
|
|
|
|
|
+ const roomData = {
|
|
|
|
|
+ id: room.id,
|
|
|
|
|
+ room_name: room.room_name,
|
|
|
|
|
+ orientation: room.orientation,
|
|
|
|
|
+ hasBoundDevices: room.devices.length > 0,
|
|
|
|
|
+ deviceCount: room.devices.length,
|
|
|
|
|
+ onlineDeviceCount: room.devices.filter(d => d.status === 'online').length,
|
|
|
|
|
+ temperature: null,
|
|
|
|
|
+ switchStatus: null,
|
|
|
|
|
+ occupancy: '未绑定人体传感器',
|
|
|
|
|
+ temperatureDeviceStatus: 'offline',
|
|
|
|
|
+ humanSensorStatus: 'offline',
|
|
|
|
|
+ hasTemperatureDevice: false,
|
|
|
|
|
+ hasHumanSensor: false
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- // 初始化设备状态
|
|
|
|
|
- room.hasBoundDevices = deviceResponse.data.length > 0;
|
|
|
|
|
- room.deviceCount = deviceResponse.data.length; // 绑定设备数量
|
|
|
|
|
- room.onlineDeviceCount = deviceResponse.data.filter(
|
|
|
|
|
- (device) => device.status === 'online'
|
|
|
|
|
- ).length; // 在线设备数量
|
|
|
|
|
-
|
|
|
|
|
- room.temperature = null;
|
|
|
|
|
- room.switchStatus = null;
|
|
|
|
|
- room.occupancy = '未绑定人体传感器';
|
|
|
|
|
- room.temperatureDeviceStatus = 'offline'; // 温度传感器状态
|
|
|
|
|
- room.humanSensorStatus = 'offline'; // 人体传感器状态
|
|
|
|
|
- room.hasTemperatureDevice = false; // 是否绑定温度传感器
|
|
|
|
|
- room.hasHumanSensor = false; // 是否绑定人体传感器
|
|
|
|
|
-
|
|
|
|
|
- // 遍历设备,判断设备类型和状态
|
|
|
|
|
- for (const device of deviceResponse.data) {
|
|
|
|
|
|
|
+ // 处理设备信息
|
|
|
|
|
+ room.devices.forEach(device => {
|
|
|
if (device.device_id.includes('ESP32-')) {
|
|
if (device.device_id.includes('ESP32-')) {
|
|
|
- // 继电器温度传感器
|
|
|
|
|
- room.hasTemperatureDevice = true;
|
|
|
|
|
- room.temperature = device.temperature || null;
|
|
|
|
|
- room.switchStatus = device.switch_status || null;
|
|
|
|
|
- room.temperatureDeviceStatus = device.status; // 设备状态
|
|
|
|
|
|
|
+ roomData.hasTemperatureDevice = true;
|
|
|
|
|
+ roomData.temperature = device.temperature || null;
|
|
|
|
|
+ roomData.switchStatus = device.switch_status || null;
|
|
|
|
|
+ roomData.temperatureDeviceStatus = device.status;
|
|
|
} else if (device.device_id.includes('24G-')) {
|
|
} else if (device.device_id.includes('24G-')) {
|
|
|
- // 人体传感器
|
|
|
|
|
- room.hasHumanSensor = true;
|
|
|
|
|
- room.humanSensorStatus = device.status; // 设备状态
|
|
|
|
|
- if (device.status === 'online') {
|
|
|
|
|
- room.occupancy = device.level_status === 'high' ? '有人' : '无人';
|
|
|
|
|
- } else {
|
|
|
|
|
- room.occupancy = '人体存在掉线';
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ roomData.hasHumanSensor = true;
|
|
|
|
|
+ roomData.humanSensorStatus = device.status;
|
|
|
|
|
+ roomData.occupancy = device.status === 'online'
|
|
|
|
|
+ ? (device.level_status === 'high' ? '有人' : '无人')
|
|
|
|
|
+ : '人体存在掉线';
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果没有绑定温度传感器,则显示"未绑定设备"
|
|
|
|
|
- if (!room.hasTemperatureDevice) {
|
|
|
|
|
- room.temperature = null;
|
|
|
|
|
- room.switchStatus = null;
|
|
|
|
|
- room.temperatureDeviceStatus = 'offline';
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果没有绑定人体传感器,则显示"未绑定人体传感器"
|
|
|
|
|
- if (!room.hasHumanSensor) {
|
|
|
|
|
- room.occupancy = '未绑定人体传感器';
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- this.rooms = response.data;
|
|
|
|
|
|
|
+ return roomData;
|
|
|
|
|
+ });
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('获取房间数据失败:', error);
|
|
console.error('获取房间数据失败:', error);
|
|
|
|
|
+ if (error.response) {
|
|
|
|
|
+ // 服务器返回了非2xx的响应
|
|
|
|
|
+ console.error('响应数据:', error.response.data);
|
|
|
|
|
+ console.error('状态码:', error.response.status);
|
|
|
|
|
+ console.error('响应头:', error.response.headers);
|
|
|
|
|
+ } else if (error.request) {
|
|
|
|
|
+ // 请求已发出但没有收到响应
|
|
|
|
|
+ console.error('请求:', error.request);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 其他错误
|
|
|
|
|
+ console.error('错误信息:', error.message);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
// 根据房间号解析楼层
|
|
// 根据房间号解析楼层
|
|
@@ -269,22 +260,34 @@ body {
|
|
|
.floor-content {
|
|
.floor-content {
|
|
|
display: flex;
|
|
display: flex;
|
|
|
gap: 10px;
|
|
gap: 10px;
|
|
|
- /* 缩小东西边房间的间距 */
|
|
|
|
|
|
|
+ flex-wrap: nowrap; /* 确保不换行 */
|
|
|
|
|
+ overflow-x: auto; /* 添加水平滚动条 */
|
|
|
|
|
+ padding-bottom: 10px; /* 为滚动条留出空间 */
|
|
|
}
|
|
}
|
|
|
.room-list {
|
|
.room-list {
|
|
|
display: flex;
|
|
display: flex;
|
|
|
- flex-wrap: wrap;
|
|
|
|
|
- justify-content: space-between;
|
|
|
|
|
|
|
+ gap: 10px;
|
|
|
|
|
+ flex-wrap: nowrap; /* 确保不换行 */
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.room-card {
|
|
.room-card {
|
|
|
- flex: 0 0 calc(50% - 10px); /* 每行显示两个房间卡片,减去间距 */
|
|
|
|
|
|
|
+ flex: 0 0 200px; /* 固定卡片宽度 */
|
|
|
margin-bottom: 10px;
|
|
margin-bottom: 10px;
|
|
|
|
|
+ padding: 10px;
|
|
|
|
|
+ border: 1px solid #ddd;
|
|
|
|
|
+ border-radius: 8px;
|
|
|
|
|
+ background-color: white;
|
|
|
|
|
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* 响应式设计 */
|
|
|
@media (max-width: 768px) {
|
|
@media (max-width: 768px) {
|
|
|
|
|
+ .floor-content {
|
|
|
|
|
+ flex-wrap: wrap; /* 在小屏幕上换行 */
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
.room-card {
|
|
.room-card {
|
|
|
- flex: 0 0 100%; /* 在手机上每行显示一个房间卡片 */
|
|
|
|
|
|
|
+ flex: 1 1 100%; /* 在小屏幕上占满宽度 */
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
@media (max-width: 768px) {
|
|
@media (max-width: 768px) {
|