Merge branch 'master' of http://git.it.real.he-info.cn:90/r/~enchantedwyf/vbvs_app
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart' as edm;
|
||||
import 'package:easydevice/easydevice.dart';
|
||||
import 'package:easyweb/base/easyws.dart';
|
||||
import 'package:easyweb/base/minisdk.dart';
|
||||
import 'package:easyweb/easyweb.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:easyweb/base/minisdk.dart';
|
||||
import 'package:easydevice/easydevice.dart';
|
||||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/requestWithLog.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
|
||||
|
||||
@@ -16,14 +23,18 @@ class WebviewTestModel {
|
||||
}
|
||||
|
||||
class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
var selectDevice;
|
||||
var bluetooth = false;
|
||||
var selectDevice = {};
|
||||
var lastSelectDevice = {};
|
||||
var bluetooth = 0;
|
||||
List personList = [];
|
||||
List instantData = [];
|
||||
|
||||
WebviewTestController() : super(WebviewTestModel()) {
|
||||
web = WebviewHelper(
|
||||
jsbridge: buildsdk(
|
||||
father: this,
|
||||
// father: this,
|
||||
// clientId: '494641114',
|
||||
//dbgserverUrl: 'ws://192.168.1.2:9001',
|
||||
// dbgserverUrl: 'ws://192.168.1.2:9001',
|
||||
),
|
||||
settings: buildsettings(),
|
||||
params: PlatformHeadlessInAppWebViewCreationParams(
|
||||
@@ -46,12 +57,32 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
bridge.sdk.updateDeviceRoute((args) async {
|
||||
ef.log('updateDeviceRoute: $args');
|
||||
selectDevice['blueToothStatus'] = bluetooth;
|
||||
Get.toNamed("$args[0]", arguments: selectDevice);
|
||||
Get.toNamed("${args[0]}", arguments: selectDevice);
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.selectDevice((args) async {
|
||||
<<<<<<< HEAD
|
||||
ef.log('selectDevice: $args');
|
||||
selectDevice = args[0];
|
||||
=======
|
||||
try {
|
||||
ef.log('selectDevice: $args');
|
||||
selectDevice = args[0];
|
||||
await queryPersonInfoByMac();
|
||||
if (selectDevice != null &&
|
||||
selectDevice.isNotEmpty &&
|
||||
selectDevice['mac'] != null &&
|
||||
(selectDevice['mac'] != args[0]['mac'])) {
|
||||
lastSelectDevice = selectDevice;
|
||||
}
|
||||
dealInstantData(selectDevice);
|
||||
} catch (e) {
|
||||
ef.log("[aaaa]$e");
|
||||
}
|
||||
|
||||
//查询人员信息
|
||||
|
||||
>>>>>>> 13eb25e1c30dcd81c87aa85bcb5306ca0931ed21
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.updateBlueToothStatus((args) async {
|
||||
@@ -59,6 +90,57 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
bluetooth = args[0];
|
||||
return true;
|
||||
});
|
||||
//sdk定义接口
|
||||
bridge.sdk.querySelectDevice((args) async {
|
||||
ef.log('updateBlueToothStatus: $args');
|
||||
// bluetooth = args[0];
|
||||
MHTHomeController deviceController = Get.find();
|
||||
final allDevices = deviceController.deviceList.values
|
||||
.expand((list) => list)
|
||||
.toList();
|
||||
return allDevices;
|
||||
});
|
||||
//请求token信息
|
||||
bridge.sdk.queryUserToken((args) async {
|
||||
ef.log('queryUserToken: $args');
|
||||
// bluetooth = args[0];
|
||||
return edm.EasyDartModule.dio.token;
|
||||
});
|
||||
//请求设备人员信息
|
||||
bridge.sdk.queryPersonInfo((args) async {
|
||||
ef.log('queryPersonInfo: $args');
|
||||
// bluetooth = args[0];
|
||||
return personList;
|
||||
});
|
||||
//请求实时体征数据
|
||||
bridge.sdk.queryInstantData((args) async {
|
||||
ef.log('queryInstantData: $args');
|
||||
// bluetooth = args[0];
|
||||
return instantData;
|
||||
});
|
||||
bridge.sdk.queryInstantData((args) async {
|
||||
ef.log('queryInstantData: $args');
|
||||
// bluetooth = args[0];
|
||||
return instantData;
|
||||
});
|
||||
bridge.sdk.startTimer((args) async {
|
||||
ef.log('queryInstantData: $args');
|
||||
MHTHomeController homeController = Get.find();
|
||||
homeController.startTimer(args);
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.cancelTimer((args) async {
|
||||
ef.log('queryInstantData: $args');
|
||||
MHTHomeController homeController = Get.find();
|
||||
homeController.cancelTimer(args);
|
||||
return true;
|
||||
});
|
||||
bridge.sdk.restoreTimer((args) async {
|
||||
ef.log('queryInstantData: $args');
|
||||
MHTHomeController homeController = Get.find();
|
||||
var data = await homeController.restoreTimer(args);
|
||||
return data;
|
||||
});
|
||||
});
|
||||
web
|
||||
//.file(
|
||||
@@ -80,6 +162,116 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||
late WebviewHelper web;
|
||||
var ready = false.obs;
|
||||
var cnt = 0.obs;
|
||||
|
||||
Future<void> queryPersonInfoByMac() async {
|
||||
UserInfoController userInfoController = Get.find();
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.person_info;
|
||||
String queryUrl =
|
||||
"${serviceAddress}${serviceName}${serviceApi}?mac=${selectDevice['mac']}";
|
||||
try {
|
||||
final res = await requestWithLog(
|
||||
logTitle: "查询设备绑定人员列表",
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) {
|
||||
personList = res.data;
|
||||
});
|
||||
} catch (e) {
|
||||
print("查询设备绑定列表失败: $e");
|
||||
}
|
||||
}
|
||||
|
||||
void dealInstantData(selectDevice) {
|
||||
//处理实时数据
|
||||
// edm.EasyDartModule.websocket.sendData(
|
||||
// jsonEncode(WebSocketMessage(path: "/vsbs/web/rt/marttress", type: 2)));
|
||||
lastSelectDevice;
|
||||
var ws;
|
||||
ws = Easyws(
|
||||
url: ServiceConstant.webSocketService,
|
||||
onData: (data) {
|
||||
ef.log("ws recv =>$data");
|
||||
try {
|
||||
var tmp;
|
||||
if (data is String) {
|
||||
tmp = jsonDecode(data); // 只有是 String 才 decode
|
||||
} else if (data is Map<String, dynamic>) {
|
||||
tmp = data; // 直接用
|
||||
} else {
|
||||
print("未知数据格式");
|
||||
}
|
||||
if (tmp['data'] != null && tmp['data'] is Map) {
|
||||
var newData = tmp['data'];
|
||||
var mac = newData['mac'];
|
||||
if (mac != null) {
|
||||
// 删除已有的同 mac 项
|
||||
instantData.removeWhere((element) => element['mac'] == mac);
|
||||
// 添加新的数据
|
||||
instantData.add(newData);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
ef.log("ws error =>$e");
|
||||
}
|
||||
},
|
||||
onStateChange: (x) {
|
||||
ef.log("ws =>$x");
|
||||
if (x == EasywsState.connected) {
|
||||
try {
|
||||
if (lastSelectDevice != null && lastSelectDevice.isNotEmpty) {
|
||||
List<String?> oldMacList = [
|
||||
lastSelectDevice['bind_mac_a'],
|
||||
lastSelectDevice['bind_mac_b'],
|
||||
];
|
||||
for (String? mac in oldMacList) {
|
||||
if (mac != null && mac.isNotEmpty) {
|
||||
bool success = ws.send({
|
||||
"type": 2,
|
||||
"path": "/vsbs/web/rt/marttress",
|
||||
"data": {"mac": mac},
|
||||
});
|
||||
if (success) {
|
||||
ef.log("✅ 已取消监听:$mac");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
ef.log("❌ 取消旧设备监听失败: $e");
|
||||
}
|
||||
try {
|
||||
// 2. 开始监听新设备(A/B 都监听)
|
||||
if (selectDevice != null && selectDevice.isNotEmpty) {
|
||||
List<String?> newMacList = [
|
||||
selectDevice['bind_mac_a'],
|
||||
selectDevice['bind_mac_b'],
|
||||
];
|
||||
for (String? mac in newMacList) {
|
||||
if (mac != null && mac.isNotEmpty) {
|
||||
bool success = ws.send({
|
||||
"type": 1,
|
||||
"path": "/vsbs/web/rt/marttress",
|
||||
"data": {"mac": mac},
|
||||
});
|
||||
if (success) {
|
||||
ef.log("✅ 开始监听新设备:$mac");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新记录
|
||||
lastSelectDevice = selectDevice;
|
||||
}
|
||||
} catch (e) {
|
||||
ef.log("❌ 监听新设备失败: $e");
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
ws.connect();
|
||||
}
|
||||
//EasyFlutter End
|
||||
}
|
||||
|
||||
@@ -90,7 +282,7 @@ class WebviewTestView extends GetComponent<WebviewTestController> {
|
||||
Widget build(BuildContext context) {
|
||||
UserInfoController userInfoController = Get.find();
|
||||
MHTHomeController deviceController = Get.find();
|
||||
deviceController.getDeviceList(group: 'room').then((x) {
|
||||
deviceController.getDeviceList().then((x) {
|
||||
if (controller.web.jsbridge!.inited) {
|
||||
//发送测试消息给webview
|
||||
controller.web.jsbridge!.dart
|
||||
|
||||
Reference in New Issue
Block a user