Commit ea90a54a authored by 张宏's avatar 张宏

3

parent cfc4a398
......@@ -146,8 +146,8 @@ class ServiceRoomCubit extends Cubit<ServiceRoomState> {
return Icons.devices_other;
}
/// 房间总电源开关
Future<void> toggleMainPower(bool value) async {
/// 房间总电源开关
Future<void> toggleMainPowerForSwitch(bool value) async {
if (state.isTogglingPower) return;
emit(state.copyWith(isTogglingPower: true));
try {
......@@ -164,6 +164,24 @@ class ServiceRoomCubit extends Cubit<ServiceRoomState> {
}
}
/// 房间总电源开关
Future<void> toggleMainPower(bool value) async {
if (state.isTogglingPower) return;
emit(state.copyWith(isTogglingPower: true));
try {
if (value) {
await _service.powerOn(deviceId: _roomId);
} else {
await _service.powerOff(deviceId: _roomId);
}
emit(state.copyWith(isTogglingPower: false, mainPowerOn: value));
} catch (e) {
emit(state.copyWith(isTogglingPower: false));
// Re-throw so the view can show error snackbar
rethrow;
}
}
/// 分设备电源开关
Future<void> toggleControlDevice(int index, bool value) async {
final devices = state.controlDevices;
......
......@@ -103,7 +103,7 @@ class ServiceRoomDetailView extends StatelessWidget {
controlDevices: state.controlDevices,
onMainPowerToggle: (value) async {
try {
await cubit.toggleMainPower(value);
await cubit.toggleMainPowerForSwitch(value);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
......@@ -128,7 +128,41 @@ class ServiceRoomDetailView extends StatelessWidget {
},
),
SizedBox(height: 20.h),
const RoomBottomButtons(),
RoomBottomButtons(
isProcessing: state.isTogglingPower,
onPowerOn: () async {
try {
await cubit.toggleMainPower(true);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('送电成功')),
);
}
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('送电失败: $e')),
);
}
}
},
onPowerOff: () async {
try {
await cubit.toggleMainPower(false);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('断电成功')),
);
}
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('断电失败: $e')),
);
}
}
},
),
SizedBox(height: 20.h),
],
),
......
......@@ -2,26 +2,42 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class RoomBottomButtons extends StatelessWidget {
const RoomBottomButtons({super.key});
final VoidCallback? onPowerOn;
final VoidCallback? onPowerOff;
final VoidCallback? onDeviceControl;
final bool isProcessing;
const RoomBottomButtons({
super.key,
this.onPowerOn,
this.onPowerOff,
this.onDeviceControl,
this.isProcessing = false,
});
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Container(
height: 88.h,
decoration: BoxDecoration(
color: const Color.fromRGBO(66, 165, 245, 1.0),
borderRadius: BorderRadius.circular(20.r),
),
child: Center(
child: Text(
'送电',
style: TextStyle(
color: Colors.white,
fontSize: 32.sp,
fontWeight: FontWeight.bold,
child: GestureDetector(
onTap: (onPowerOn != null && !isProcessing) ? onPowerOn : null,
child: Container(
height: 88.h,
decoration: BoxDecoration(
color: (onPowerOn != null && !isProcessing)
? const Color.fromRGBO(66, 165, 245, 1.0)
: const Color.fromRGBO(204, 204, 204, 1),
borderRadius: BorderRadius.circular(20.r),
),
child: Center(
child: Text(
'送电',
style: TextStyle(
color: Colors.white,
fontSize: 32.sp,
fontWeight: FontWeight.bold,
),
),
),
),
......@@ -29,23 +45,30 @@ class RoomBottomButtons extends StatelessWidget {
),
SizedBox(width: 12.w),
Expanded(
child: Container(
height: 88.h,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.r),
border: Border.all(
color: const Color.fromRGBO(66, 165, 245, 1.0),
width: 2.w,
child: GestureDetector(
onTap: (onPowerOff != null && !isProcessing) ? onPowerOff : null,
child: Container(
height: 88.h,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.r),
border: Border.all(
color: (onPowerOff != null && !isProcessing)
? const Color.fromRGBO(66, 165, 245, 1.0)
: const Color.fromRGBO(204, 204, 204, 1),
width: 2.w,
),
),
),
child: Center(
child: Text(
'断电',
style: TextStyle(
color: const Color.fromRGBO(66, 165, 245, 1.0),
fontSize: 32.sp,
fontWeight: FontWeight.bold,
child: Center(
child: Text(
'断电',
style: TextStyle(
color: (onPowerOff != null && !isProcessing)
? const Color.fromRGBO(66, 165, 245, 1.0)
: const Color.fromRGBO(100, 116, 139, 1),
fontSize: 32.sp,
fontWeight: FontWeight.bold,
),
),
),
),
......@@ -53,19 +76,22 @@ class RoomBottomButtons extends StatelessWidget {
),
SizedBox(width: 12.w),
Expanded(
child: Container(
height: 88.h,
decoration: BoxDecoration(
color: const Color.fromRGBO(200, 208, 220, 1.0),
borderRadius: BorderRadius.circular(20.r),
),
child: Center(
child: Text(
'设备控制',
style: TextStyle(
color: const Color.fromRGBO(100, 116, 139, 1.0),
fontSize: 32.sp,
fontWeight: FontWeight.bold,
child: GestureDetector(
onTap: onDeviceControl,
child: Container(
height: 88.h,
decoration: BoxDecoration(
color: const Color.fromRGBO(200, 208, 220, 1.0),
borderRadius: BorderRadius.circular(20.r),
),
child: Center(
child: Text(
'设备控制',
style: TextStyle(
color: const Color.fromRGBO(100, 116, 139, 1.0),
fontSize: 32.sp,
fontWeight: FontWeight.bold,
),
),
),
),
......
# 智慧酒店 App 接口对接方案
# 智慧酒店 App 接口对接方案
......@@ -217,12 +217,15 @@ class xxxBO extends Equatable {
| 客房服务看板-断电 |POST | /app/room/device/power/off | 已对接 | 客房服务看板-断电 | |
| 客房详情 |GET | /app/room/detail | 对接 | 客房详情 | |
| 客房详情 |GET | /app/room/detail | 对接 | 客房详情 | |
| 客房详情-房间总电源-switch开 |GET | /app/room/power/on | 未对接 | 客房详情-房间总电源-switch开 | |
| 客房详情-房间总电源-switch关 |POST | /app/room/power/off | 对接 | 客房详情-房间总电源-switch关 | |
| 客房详情-房间总电源-switch开 |POST | /app/room/power/on | 已对接 | 客房详情-房间总电源-switch开 | |
| 客房详情-房间总电源-switch关 |POST | /app/room/power/off | 对接 | 客房详情-房间总电源-switch关 | |
| 空调控制 |GET | /app/device/ac/status | 未对接 | 空调控制 | |
| 空调控制-相关操作 |POST | /app/device/ac/control | 未对接 | 空调控制-相关操作 | |
......@@ -230,6 +233,25 @@ class xxxBO extends Equatable {
### 3.2 接口详细定义
#### 空调控制-相关操作
**POST /app/device/ac/control**
```
求体:
{
"deviceId": 0, // 设备ID 必传
"powerOn": true, // 是否开机:true-开机,false-关机 可选
"targetTemperature": 16, // 目标温度(16°C ~ 30°C) 可选
"mode": "string", // 运行模式:cool-制冷,heat-制热,fan-送风,dry-除湿 可选
"fanSpeed": "string" // 风速:low-低速,medium-中速,high-高速,auto-自动 可选
}
应 data:
```
#### 空调控制
**GET /app/device/ac/status**
......@@ -316,7 +338,7 @@ class xxxBO extends Equatable {
#### 客房详情-房间总电源-switch开
**GET /app/room/power/on**
**POST /app/room/power/on**
```
求体:
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment