解绑设备
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
|
||||
import 'package:vbvs_app/controller/mh_controller/device.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
@@ -19,7 +20,6 @@ class DeviceListModel {
|
||||
//设备列表
|
||||
List<dynamic> deviceList = [];
|
||||
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
String? keyword;
|
||||
@JsonKey(ignore: true)
|
||||
@@ -70,4 +70,35 @@ class DeviceListController extends GetControllerEx<DeviceListModel> {
|
||||
}
|
||||
return ApiResponse(code: -1, msg: "未知错误".tr); // Default return statement
|
||||
}
|
||||
|
||||
//解绑设备
|
||||
Future<String> unbindDevice(Map<dynamic, dynamic> device) async {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.device_bind;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
String msg = '';
|
||||
int type = device['bind_type'];
|
||||
await requestWithLog(
|
||||
logTitle: '解绑设备',
|
||||
method: MyHttpMethod.delete,
|
||||
queryUrl: queryUrl,
|
||||
data: {"mac": device['mac'], "uid": device['uid']},
|
||||
onSuccess: (res) {
|
||||
if (type == 1) {
|
||||
msg = '解绑成功'.tr;
|
||||
} else {
|
||||
msg = '删除成功'.tr;
|
||||
}
|
||||
},
|
||||
onFailure: (res) {
|
||||
if (type == 1) {
|
||||
msg = '解绑失败'.tr;
|
||||
} else {
|
||||
msg = '删除失败'.tr;
|
||||
}
|
||||
},
|
||||
);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/src/form_data.dart' as formdata;
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
|
||||
part 'mhdevice_share_controller.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class MHDeviceShareModel {
|
||||
String? phone;
|
||||
String? account;
|
||||
int? type = 1;
|
||||
|
||||
String? msg;
|
||||
int? show = 0;
|
||||
|
||||
int? code = 0;
|
||||
int limit = AppConstants.limit;
|
||||
int offset = 0;
|
||||
bool isLoading = false;
|
||||
@@ -37,86 +46,91 @@ class MHDeviceShareController extends GetControllerEx<MHDeviceShareModel> {
|
||||
attr = GetModel(MHDeviceShareModel()).obs;
|
||||
}
|
||||
|
||||
// RxString account = "".obs;
|
||||
// RxString msg = "".obs;
|
||||
// RxInt code = 0.obs;
|
||||
@override
|
||||
void onInit() {
|
||||
Future<void> onInit() async {
|
||||
super.onInit();
|
||||
model.shareUser = [
|
||||
{
|
||||
'userName': '张三',
|
||||
'opType': 1, // 允许控制
|
||||
},
|
||||
{
|
||||
'userName': '李四',
|
||||
'opType': 2, // 仅查看
|
||||
},
|
||||
{
|
||||
'userName': '王五',
|
||||
'opType': 1,
|
||||
},
|
||||
];
|
||||
update(); // 刷新UI
|
||||
await shareDeviceList(Get.arguments["mac"]);
|
||||
}
|
||||
|
||||
// Future<String> sendInvite(String? phone, String mac) async {
|
||||
// if (phone == null || phone.isEmpty) {
|
||||
// return "手机号不能为空";
|
||||
// }
|
||||
// if (!MyUtils.isValidPhoneNumber(phone)) {
|
||||
// return "手机号格式不正确";
|
||||
// }
|
||||
// var type = model.type;
|
||||
// try {
|
||||
// var aa = await ApiService.requestNoInfo.post("/api/device/info/share",
|
||||
// data: formdata.FormData.fromMap(
|
||||
// {"mac": mac, "tel": phone, "type": type}));
|
||||
// return "";
|
||||
// } catch (e) {
|
||||
// if (e is DioError) {
|
||||
// // 返回 DioError 的 message 属性
|
||||
// return e.message!;
|
||||
// } else {
|
||||
// // 处理其他类型的错误
|
||||
// return e.toString();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Future<ApiResponse> shareDevice(String mac) async {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "请求失败".tr);
|
||||
EasyDartModule.logger.info("分享设备");
|
||||
DailyLogUtils.writeLog("分享设备");
|
||||
try {
|
||||
model.account = model.account!.trim();
|
||||
if (model.account == null || model.account!.isEmpty) {
|
||||
apiResponse.msg = "请输入手机号".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (!MyUtils.isValidPhoneNumber(model.account!) &&
|
||||
!MyUtils.isValidEmail(model.account!)) {
|
||||
apiResponse.msg = '请输入正确的手机号'.tr;
|
||||
return apiResponse;
|
||||
}
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.device_share;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
String? language = "";
|
||||
if (languageController.selectLanguage != null) {
|
||||
language = languageController.selectLanguage.value!.language_code;
|
||||
}
|
||||
if (language != null && language.isNotEmpty) {
|
||||
if (queryUrl.contains("?")) {
|
||||
queryUrl += "&lang=$language";
|
||||
} else {
|
||||
queryUrl += "?lang=$language";
|
||||
}
|
||||
}
|
||||
var data = {"type": model.type, "userName": model.account, "mac": mac};
|
||||
var response =
|
||||
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(data));
|
||||
if (response != null) {
|
||||
var responseData =
|
||||
response.data is String ? jsonDecode(response.data) : response.data;
|
||||
ApiResponse res =
|
||||
ApiResponse.fromJson(responseData, (object) => object);
|
||||
if (res.code != HttpStatusCodes.ok) {
|
||||
if (res.msg == null || res.msg!.isEmpty) {
|
||||
res.msg = apiResponse.msg;
|
||||
}
|
||||
} else {
|
||||
if (res.msg == null || res.msg!.isEmpty) {
|
||||
res.msg = "操作成功".tr;
|
||||
}
|
||||
}
|
||||
if (res.code != HttpStatusCodes.ok) {
|
||||
model.msg = res.msg!;
|
||||
}
|
||||
model.code = res.code!;
|
||||
updateAll();
|
||||
return res;
|
||||
} else {
|
||||
return ApiResponse(code: -1, msg: "服务器.失败".tr);
|
||||
}
|
||||
} catch (e) {
|
||||
EasyDartModule.logger.info("分享设备失败:${e.toString()}");
|
||||
DailyLogUtils.writeLog("分享设备失败:${e.toString()}");
|
||||
return ApiResponse(code: -1, msg: "服务器.失败".tr);
|
||||
}
|
||||
}
|
||||
|
||||
// Future<void> initData() async {
|
||||
// //todo 请求分享列表
|
||||
// var deviceController = Get.find<GlobalController>();
|
||||
// var query = {
|
||||
// "mac": deviceController.model.deviceMain['mac'],
|
||||
// };
|
||||
// var data = await ApiService.request
|
||||
// .get("/api/device/info/share", data: formdata.FormData.fromMap(query));
|
||||
|
||||
// if (data.data["data"] != null) {
|
||||
// try {
|
||||
// List<dynamic> tmp = data.data["data"] as List<dynamic>;
|
||||
// model.shareUser = tmp;
|
||||
// } catch (e) {
|
||||
// print(e);
|
||||
// }
|
||||
// } else {
|
||||
// model.shareUser = [];
|
||||
// }
|
||||
// updateAll();
|
||||
// }
|
||||
|
||||
// //保存
|
||||
// saveShareDevice(Map shareInfo, RxInt type) async {
|
||||
// return await ApiService.request.put("/api/device/info/share",
|
||||
// data: formdata.FormData.fromMap({
|
||||
// "mac": shareInfo['mac'],
|
||||
// "tel": shareInfo['tel'],
|
||||
// "type": type.value
|
||||
// }));
|
||||
// }
|
||||
|
||||
// //删除
|
||||
// deleteShare(Map shareInfo) async {
|
||||
// return await ApiService.request.delete("/api/device/info/share",
|
||||
// data: formdata.FormData.fromMap(
|
||||
// {"mac": shareInfo['mac'], "tel": shareInfo['tel']}));
|
||||
// }
|
||||
shareDeviceList(String mac) async {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.device_share;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?mac=$mac";
|
||||
await requestWithLog(
|
||||
logTitle: '分享用户列表',
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) => {
|
||||
model.shareUser = res.data,
|
||||
updateAll(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ part of 'mhdevice_share_controller.dart';
|
||||
|
||||
MHDeviceShareModel _$MHDeviceShareModelFromJson(Map<String, dynamic> json) =>
|
||||
MHDeviceShareModel()
|
||||
..phone = json['phone'] as String?
|
||||
..account = json['account'] as String?
|
||||
..type = (json['type'] as num?)?.toInt()
|
||||
..msg = json['msg'] as String?
|
||||
..show = (json['show'] as num?)?.toInt()
|
||||
@@ -21,7 +21,7 @@ MHDeviceShareModel _$MHDeviceShareModelFromJson(Map<String, dynamic> json) =>
|
||||
|
||||
Map<String, dynamic> _$MHDeviceShareModelToJson(MHDeviceShareModel instance) =>
|
||||
<String, dynamic>{
|
||||
'phone': instance.phone,
|
||||
'phone': instance.account,
|
||||
'type': instance.type,
|
||||
'msg': instance.msg,
|
||||
'show': instance.show,
|
||||
|
||||
Reference in New Issue
Block a user