更新web实时数据
This commit is contained in:
@@ -38,8 +38,8 @@
|
|||||||
<application
|
<application
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launchermh"
|
||||||
android:label="太和e护"
|
android:label="眠花糖"
|
||||||
android:enableOnBackInvokedCallback="true"
|
android:enableOnBackInvokedCallback="true"
|
||||||
>
|
>
|
||||||
<activity
|
<activity
|
||||||
|
|||||||
@@ -31,10 +31,11 @@ class SleepdateWidget extends StatelessWidget {
|
|||||||
color: isSelected ? highlightColor : Colors.transparent, // 使用传入的颜色
|
color: isSelected ? highlightColor : Colors.transparent, // 使用传入的颜色
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsetsDirectional.fromSTEB(10.rpx, 10.rpx, 10.rpx, 10.rpx),
|
padding:
|
||||||
|
EdgeInsetsDirectional.fromSTEB(10.rpx, 10.rpx, 10.rpx, 10.rpx),
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color(0xFFDC1C1C),
|
color: Color(0xFF757575),
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
|||||||
@@ -1,16 +1,29 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:vbvs_app/pages/common/bezier_bottom_navigation_bar.dart';
|
import 'package:vbvs_app/pages/common/bezier_bottom_navigation_bar.dart';
|
||||||
import 'package:vbvs_app/pages/mh_page/MattressControl.dart';
|
import 'package:vbvs_app/pages/mh_page/MattressControl.dart';
|
||||||
import 'package:vbvs_app/pages/mh_page/device_list.dart';
|
|
||||||
import 'package:vbvs_app/pages/mh_page/homepage/mht_sleep_report_page.dart';
|
import 'package:vbvs_app/pages/mh_page/homepage/mht_sleep_report_page.dart';
|
||||||
import 'package:vbvs_app/pages/mh_page/homepage/new_Home_page.dart';
|
import 'package:vbvs_app/pages/mh_page/homepage/new_Home_page.dart';
|
||||||
import 'package:vbvs_app/pages/mh_page/new_mine_page.dart';
|
import 'package:vbvs_app/pages/mh_page/new_mine_page.dart';
|
||||||
|
|
||||||
class MainPageBBottomChange extends StatefulWidget {
|
class MainPageBBottomChange extends StatefulWidget {
|
||||||
|
// 全局 key,用于静态访问 _HomePageState
|
||||||
|
static final GlobalKey<_HomePageState> globalKey = GlobalKey<_HomePageState>();
|
||||||
|
|
||||||
|
MainPageBBottomChange({Key? key}) : super(key: globalKey);
|
||||||
|
|
||||||
|
// 静态方法:外部调用,跳转 tab
|
||||||
|
static void jumpTo(int index) {
|
||||||
|
final state = globalKey.currentState;
|
||||||
|
if (state != null) {
|
||||||
|
state.switchTab(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_HomePageState createState() => _HomePageState();
|
_HomePageState createState() => _HomePageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _HomePageState extends State<MainPageBBottomChange>
|
class _HomePageState extends State<MainPageBBottomChange>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
int selectedIndex = 0;
|
int selectedIndex = 0;
|
||||||
@@ -95,4 +108,23 @@ class _HomePageState extends State<MainPageBBottomChange>
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void switchTab(int index) {
|
||||||
|
final begin = currentPosition;
|
||||||
|
final end = index.toDouble();
|
||||||
|
|
||||||
|
_positionAnimation = Tween<double>(begin: begin, end: end).animate(
|
||||||
|
CurvedAnimation(parent: _controller, curve: Curves.easeOut),
|
||||||
|
)..addListener(() {
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
_controller.forward(from: 0.0);
|
||||||
|
currentPosition = end;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
selectedIndex = index;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,9 +138,9 @@ class _MattressControlPageState extends State<MattressControlPage> {
|
|||||||
|
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: WebviewTestView(
|
child: WebviewTestView(
|
||||||
oncreate: (widget) {
|
// oncreate: (widget) {
|
||||||
return WebviewTestController();
|
// return WebviewTestController();
|
||||||
},
|
// },
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
))));
|
))));
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import 'package:vbvs_app/common/color/appConstants.dart';
|
|||||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||||
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
||||||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||||||
|
import 'package:vbvs_app/pages/main_bottom/component/main_page_b_bottom_change.dart';
|
||||||
|
import 'package:vbvs_app/pages/mh_page/test/WebviewTestModel.dart';
|
||||||
|
|
||||||
class HomeDeviceStausWidget extends StatefulWidget {
|
class HomeDeviceStausWidget extends StatefulWidget {
|
||||||
final deviceStatus;
|
final deviceStatus;
|
||||||
@@ -72,10 +74,25 @@ class _HomeDeviceStausWidgetState extends State<HomeDeviceStausWidget> {
|
|||||||
CustomCard(
|
CustomCard(
|
||||||
gradientDirection: GradientDirection.vertical,
|
gradientDirection: GradientDirection.vertical,
|
||||||
borderRadius: 10.rpx,
|
borderRadius: 10.rpx,
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
// 点击回调逻辑放这里
|
try {
|
||||||
TopSlideNotification.show(context,text: "功能开发中...".tr);
|
var device = widget.deviceStatus;
|
||||||
|
WebviewTestController webviewTestController = Get.find();
|
||||||
|
var future = webviewTestController.web.jsbridge?.dart
|
||||||
|
.appToHtmlDevice(device);
|
||||||
|
|
||||||
|
Future.delayed(Duration(seconds: 5), () {
|
||||||
|
TopSlideNotification.show(context, text: "控制界面初始化中,请稍后再试".tr);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
await future; // 等待最终完成(即使超过 5 秒)
|
||||||
|
MainPageBBottomChange.jumpTo(2);
|
||||||
|
} catch (e) {
|
||||||
|
print("发生异常: $e");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
colors:
|
colors:
|
||||||
AppConstants().mhtButtongradientColors, // 你原本没有渐变,单色即可
|
AppConstants().mhtButtongradientColors, // 你原本没有渐变,单色即可
|
||||||
enableGradient: true, // 关闭渐变
|
enableGradient: true, // 关闭渐变
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
|
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:easyweb/easyweb.dart';
|
||||||
import 'package:ef/ef.dart';
|
import 'package:ef/ef.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:easyweb/base/minisdk.dart';
|
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||||
import 'package:easydevice/easydevice.dart';
|
|
||||||
import 'package:vbvs_app/common/util/FitTool.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/controller/user_info_controller.dart';
|
||||||
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
|
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
|
||||||
import 'package:vbvs_app/pages/mh_page/room_picker.dart';
|
|
||||||
|
|
||||||
class WebviewTestModel {
|
class WebviewTestModel {
|
||||||
WebviewTestModel();
|
WebviewTestModel();
|
||||||
@@ -18,12 +24,16 @@ class WebviewTestModel {
|
|||||||
|
|
||||||
class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
||||||
var selectDevice = {};
|
var selectDevice = {};
|
||||||
|
var lastSelectDevice = {};
|
||||||
var bluetooth = 0;
|
var bluetooth = 0;
|
||||||
|
List personList = [];
|
||||||
|
List instantData = [];
|
||||||
|
|
||||||
WebviewTestController() : super(WebviewTestModel()) {
|
WebviewTestController() : super(WebviewTestModel()) {
|
||||||
web = WebviewHelper(
|
web = WebviewHelper(
|
||||||
jsbridge: buildsdk(
|
jsbridge: buildsdk(
|
||||||
father: this,
|
// father: this,
|
||||||
clientId: '494641114',
|
// clientId: '494641114',
|
||||||
// dbgserverUrl: 'ws://192.168.1.2:9001',
|
// dbgserverUrl: 'ws://192.168.1.2:9001',
|
||||||
),
|
),
|
||||||
settings: buildsettings(),
|
settings: buildsettings(),
|
||||||
@@ -51,8 +61,23 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
bridge.sdk.selectDevice((args) async {
|
bridge.sdk.selectDevice((args) async {
|
||||||
ef.log('selectDevice: $args');
|
try {
|
||||||
selectDevice = args[0];
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询人员信息
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
bridge.sdk.updateBlueToothStatus((args) async {
|
bridge.sdk.updateBlueToothStatus((args) async {
|
||||||
@@ -70,6 +95,30 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
|||||||
.toList();
|
.toList();
|
||||||
return allDevices;
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
web
|
web
|
||||||
//.file(
|
//.file(
|
||||||
@@ -91,6 +140,117 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
|
|||||||
late WebviewHelper web;
|
late WebviewHelper web;
|
||||||
var ready = false.obs;
|
var ready = false.obs;
|
||||||
var cnt = 0.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("未知数据格式");
|
||||||
|
}
|
||||||
|
print("aaa");
|
||||||
|
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
|
//EasyFlutter End
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ dependencies:
|
|||||||
easyweb:
|
easyweb:
|
||||||
git:
|
git:
|
||||||
url: https://gitea.wslpc.real.he-info.cn:94/flutter/easyweb.git
|
url: https://gitea.wslpc.real.he-info.cn:94/flutter/easyweb.git
|
||||||
ref: main
|
ref: e86d515f77
|
||||||
archive: ^4.0.0
|
archive: ^4.0.0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user