|
@@ -81,6 +81,13 @@
|
|
|
<option value="北">北</option>
|
|
<option value="北">北</option>
|
|
|
</select>
|
|
</select>
|
|
|
<button class="modal-button" @click="saveEditedRoom">保存</button>
|
|
<button class="modal-button" @click="saveEditedRoom">保存</button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ v-if="editRoom.device_count === 0"
|
|
|
|
|
+ class="delete-button"
|
|
|
|
|
+ @click="deleteRoom(editRoom.id)"
|
|
|
|
|
+ >
|
|
|
|
|
+ 删除房间
|
|
|
|
|
+ </button>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
@@ -166,6 +173,7 @@ export default {
|
|
|
description: '',
|
|
description: '',
|
|
|
floor: null,
|
|
floor: null,
|
|
|
orientation: '',
|
|
orientation: '',
|
|
|
|
|
+ device_count: 0,
|
|
|
},
|
|
},
|
|
|
hasHumanSensor: false, // 是否有人体传感器
|
|
hasHumanSensor: false, // 是否有人体传感器
|
|
|
hasRelayInRoom: false, // 是否有继电器
|
|
hasRelayInRoom: false, // 是否有继电器
|
|
@@ -253,14 +261,17 @@ export default {
|
|
|
// 重新获取设备列表以更新界面
|
|
// 重新获取设备列表以更新界面
|
|
|
await this.toggleDevices(this.roomId);
|
|
await this.toggleDevices(this.roomId);
|
|
|
} else {
|
|
} else {
|
|
|
- this.message = '绑定继电器时出错';
|
|
|
|
|
|
|
+ const result = await response.json();
|
|
|
|
|
+ this.message = result.message || '绑定继电器时出错';
|
|
|
this.messageType = 'error';
|
|
this.messageType = 'error';
|
|
|
console.error('绑定继电器时出错');
|
|
console.error('绑定继电器时出错');
|
|
|
}
|
|
}
|
|
|
|
|
+ this.autoHideMessage();
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
this.message = '绑定设备时出错';
|
|
this.message = '绑定设备时出错';
|
|
|
this.messageType = 'error';
|
|
this.messageType = 'error';
|
|
|
console.error('绑定设备时出错:', error);
|
|
console.error('绑定设备时出错:', error);
|
|
|
|
|
+ this.autoHideMessage();
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -287,6 +298,102 @@ async toggleDevices(roomId) {
|
|
|
console.error('Error fetching devices:', error);
|
|
console.error('Error fetching devices:', error);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
+ async addNewRoom() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await fetch('/api/rooms', {
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
|
|
+ },
|
|
|
|
|
+ body: JSON.stringify({
|
|
|
|
|
+ room_name: this.newRoomName,
|
|
|
|
|
+ description: this.newRoomDescription,
|
|
|
|
|
+ floor: this.newRoomFloor,
|
|
|
|
|
+ orientation: this.newRoomOrientation,
|
|
|
|
|
+ }),
|
|
|
|
|
+ });
|
|
|
|
|
+ if (response.ok) {
|
|
|
|
|
+ const result = await response.json();
|
|
|
|
|
+ this.message = result.message || '房间新增成功';
|
|
|
|
|
+ this.messageType = 'success';
|
|
|
|
|
+ await this.fetchRooms();
|
|
|
|
|
+ this.showModal = false;
|
|
|
|
|
+ this.newRoomName = '';
|
|
|
|
|
+ this.newRoomDescription = '';
|
|
|
|
|
+ this.newRoomFloor = null;
|
|
|
|
|
+ this.newRoomOrientation = '';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const result = await response.json();
|
|
|
|
|
+ this.message = result.message || '新增房间时出错';
|
|
|
|
|
+ this.messageType = 'error';
|
|
|
|
|
+ console.error('新增房间时出错');
|
|
|
|
|
+ }
|
|
|
|
|
+ this.autoHideMessage();
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.message = '新增房间时出错';
|
|
|
|
|
+ this.messageType = 'error';
|
|
|
|
|
+ console.error('新增房间时出错:', error);
|
|
|
|
|
+ this.autoHideMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ async saveEditedRoom() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await fetch(`/api/rooms/${this.editRoom.id}`, {
|
|
|
|
|
+ method: 'PUT',
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
|
|
+ },
|
|
|
|
|
+ body: JSON.stringify(this.editRoom),
|
|
|
|
|
+ });
|
|
|
|
|
+ if (response.ok) {
|
|
|
|
|
+ const result = await response.json();
|
|
|
|
|
+ this.message = result.message || '房间信息更新成功';
|
|
|
|
|
+ this.messageType = 'success';
|
|
|
|
|
+ await this.fetchRooms();
|
|
|
|
|
+ this.showEditModal = false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const result = await response.json();
|
|
|
|
|
+ this.message = result.message || '更新房间信息时出错';
|
|
|
|
|
+ this.messageType = 'error';
|
|
|
|
|
+ console.error('更新房间信息时出错');
|
|
|
|
|
+ }
|
|
|
|
|
+ this.autoHideMessage();
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.message = '更新房间信息时出错';
|
|
|
|
|
+ this.messageType = 'error';
|
|
|
|
|
+ console.error('更新房间信息时出错:', error);
|
|
|
|
|
+ this.autoHideMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ async deleteRoom(roomId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await fetch(`/api/rooms/${roomId}`, {
|
|
|
|
|
+ method: 'DELETE',
|
|
|
|
|
+ });
|
|
|
|
|
+ if (response.ok) {
|
|
|
|
|
+ this.message = '房间删除成功';
|
|
|
|
|
+ this.messageType = 'success';
|
|
|
|
|
+ await this.fetchRooms();
|
|
|
|
|
+ this.showEditModal = false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const result = await response.json();
|
|
|
|
|
+ this.message = result.message || '删除房间时出错';
|
|
|
|
|
+ this.messageType = 'error';
|
|
|
|
|
+ console.error('删除房间时出错');
|
|
|
|
|
+ }
|
|
|
|
|
+ this.autoHideMessage();
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.message = '删除房间时出错';
|
|
|
|
|
+ this.messageType = 'error';
|
|
|
|
|
+ console.error('删除房间时出错:', error);
|
|
|
|
|
+ this.autoHideMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ autoHideMessage() {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.message = '';
|
|
|
|
|
+ }, 2000);
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
</script>
|
|
</script>
|
|
@@ -699,4 +806,24 @@ async toggleDevices(roomId) {
|
|
|
background: linear-gradient(135deg, #1e88e5, #42a5f5); /* 渐变背景 */
|
|
background: linear-gradient(135deg, #1e88e5, #42a5f5); /* 渐变背景 */
|
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* 阴影效果 */
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* 阴影效果 */
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+/* 删除按钮样式 */
|
|
|
|
|
+.delete-button {
|
|
|
|
|
+ background: linear-gradient(135deg, #f44336, #e57373);
|
|
|
|
|
+ color: white;
|
|
|
|
|
+ border: none;
|
|
|
|
|
+ padding: 10px 20px;
|
|
|
|
|
+ border-radius: 6px;
|
|
|
|
|
+ font-size: 16px;
|
|
|
|
|
+ font-weight: 500;
|
|
|
|
|
+ cursor: pointer;
|
|
|
|
|
+ transition: all 0.3s ease;
|
|
|
|
|
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
|
|
|
+ margin-top: 10px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.delete-button:hover {
|
|
|
|
|
+ background: linear-gradient(135deg, #e53935, #d32f2f);
|
|
|
|
|
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
|
|
|
|
+}
|
|
|
</style>
|
|
</style>
|