修改设备别名接口+UI
This commit is contained in:
@@ -4,6 +4,7 @@ abstract class DeviceHttpDatasource {
|
||||
Future<List<DeviceEntity>> getUserDevices(String username);
|
||||
Future<int> bindDevice(String deviceId, String deviceAlias);
|
||||
Future<int> unbindDevice(String deviceId, String deviceName);
|
||||
Future<int> updateDeviceName(String deviceId, String deviceName);
|
||||
Future<int> switchDevice(String platform, String deviceId);
|
||||
|
||||
Future<dynamic> getDeviceLocation(String username) async {}
|
||||
|
||||
@@ -92,7 +92,27 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
throw Exception(data['msg']);
|
||||
}
|
||||
|
||||
return data['data'];
|
||||
return data['data'] == true ? 1 : 0; // 根据接口返回的布尔值转换为 int
|
||||
}
|
||||
|
||||
Future<int> updateDeviceName(String deviceId, String deviceName) async {
|
||||
final response = await dio.post(
|
||||
'/forward/device/updateDeviceAlias',
|
||||
data: {"deviceId": deviceId, "deviceAlias": deviceName},
|
||||
);
|
||||
print('修改别名响应: ${response}'); // 调试输出响应数据
|
||||
|
||||
final data = response.data;
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络错误');
|
||||
}
|
||||
|
||||
if (data['code'] != 200) {
|
||||
throw Exception(data['msg']);
|
||||
}
|
||||
|
||||
return data['data'] == true ? 1 : 0; // 根据接口返回的布尔值转换为 int
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -61,6 +61,19 @@ class DeviceRepositoryImpl implements DeviceRepository {
|
||||
return Left(DeviceFailure(cleanMessage));
|
||||
}
|
||||
}
|
||||
@override
|
||||
Future<Either<DeviceFailure, int>> updateDeviceName(String deviceId, String deviceName) async {
|
||||
try {
|
||||
var result = await _deviceHttpDatasource.updateDeviceName(deviceId, deviceName);
|
||||
return Right(result);
|
||||
} on DioException catch (e) {
|
||||
final String serverMessage = e.response?.data['msg'] ?? "网络连接异常";
|
||||
return Left(DeviceFailure(serverMessage));
|
||||
} catch (e) {
|
||||
final cleanMessage = e.toString().replaceFirst('Exception: ', '');
|
||||
return Left(DeviceFailure(cleanMessage));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<DeviceFailure, int>> switchDevice(
|
||||
|
||||
Reference in New Issue
Block a user