This commit is contained in:
wyf
2025-08-14 09:52:10 +08:00
parent 5e9111ca41
commit bc4a07c4fa
21 changed files with 394 additions and 86 deletions

View File

@@ -11,6 +11,7 @@ import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
import 'package:vbvs_app/controller/mh_controller/device_list_controller.dart';
import 'package:vbvs_app/pages/main_bottom/component/main_page_b_bottom_change.dart';
import 'package:vbvs_app/pages/mh_page/homepage/component/HomeDeviceStausWidget.dart';
import 'package:vbvs_app/pages/mh_page/test/WebviewTestModel.dart';
class DeviceInfoWidget extends GetView {
@@ -151,8 +152,10 @@ class DeviceInfoWidget extends GetView {
try {
WebviewTestController webviewTestController =
Get.find();
webviewTestController.web.jsbridge?.dart
.switchLanguage(mhLanguageController.selectLanguage.value!.language_code);
webviewTestController.web.jsbridge?.dart
.switchLanguage(mhLanguageController
.selectLanguage.value!.language_code);
await checkBlueToothPermissin();
webviewTestController.web.jsbridge?.dart
.pageActive(false);
// await Future.delayed(Duration(seconds: 1));

View File

@@ -132,7 +132,7 @@ class _MHTBlueteethDevicePageState extends State<MHTBlueteethDevicePage> {
if (!alreadyGranted) {
// 弹出自定义提示
showPermissionInfoDialog(
Get.context!, CommonVariables().permissionInfo);
Get.context!, CommonVariables().bluetoothpermissionInfo);
dialogShown = true;
await Future.delayed(const Duration(milliseconds: 300));

View File

@@ -1,12 +1,16 @@
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/CommonVariables.dart';
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/CustomCard.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';
import 'package:vbvs_app/pages/common/selectDialog.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';
@@ -91,6 +95,7 @@ class _HomeDeviceStausWidgetState extends State<HomeDeviceStausWidget> {
webviewTestController.web.jsbridge?.dart.switchLanguage(
mhLanguageController
.selectLanguage.value!.language_code);
await checkBlueToothPermissin();
webviewTestController.web.jsbridge?.dart
.pageActive(false);
await Future.delayed(Duration(seconds: 1));
@@ -128,3 +133,140 @@ class _HomeDeviceStausWidgetState extends State<HomeDeviceStausWidget> {
);
}
}
// Future<Map> checkBlueToothPermissin() async {
// UserInfoController userInfoController = Get.find();
// bool show = false;
// Map data = {};
// var bluetoothScanGranted;
// var bluetoothConnectGranted;
// var locationGranted;
// try {
// // 如果没初始化过,就检查并请求权限
// if (userInfoController.initLocationpermission != 1) {
// bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
// bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
// locationGranted = await Permission.location.isGranted;
// // 如果权限没全部授予
// if (!bluetoothScanGranted ||
// !bluetoothConnectGranted ||
// !locationGranted) {
// show = true;
// // 同屏显示权限说明弹窗(阻塞等待用户点击确认)
// showPermissionInfoDialog(
// Get.context!,
// CommonVariables().bluetoothpermissionInfo,
// );
// // 再请求权限
// await [
// Permission.bluetoothScan,
// Permission.bluetoothConnect,
// Permission.location,
// ].request();
// // 再次检查最新权限状态
// bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
// bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
// locationGranted = await Permission.location.isGranted;
// }
// }
// // 通知 web 端
// data = {
// 'bluetoothScanGranted': bluetoothScanGranted,
// 'bluetoothConnectGranted': bluetoothConnectGranted,
// 'locationGranted': locationGranted,
// };
// WebviewTestController webviewTestController = Get.find();
// // webviewTestController.web.jsbridge?.dart.updatePermission(data);
// } catch (e) {
// ef.log("蓝牙权限:$e");
// } finally {
// if (show) {
// Navigator.of(Get.context!, rootNavigator: true).pop();
// }
// }
// // 标记初始化完成
// userInfoController.initLocationpermission = 1;
// return data;
// }
Future<Map> checkBlueToothPermissin() async {
UserInfoController userInfoController = Get.find();
bool show = false;
Map data = {};
var bluetoothScanGranted;
var bluetoothConnectGranted;
var locationGranted;
try {
// 先显示权限说明弹窗(同屏显示)
bool bluetoothScanPermanentlyDenied =
await Permission.bluetoothScan.isPermanentlyDenied;
bool bluetoothConnectPermanentlyDenied =
await Permission.bluetoothConnect.isPermanentlyDenied;
bool locationPermanentlyDenied =
await Permission.location.isPermanentlyDenied;
if (bluetoothScanPermanentlyDenied ||
bluetoothConnectPermanentlyDenied ||
locationPermanentlyDenied) {
return data; // 直接返回,不再弹窗申请
}
if (userInfoController.initLocationpermission == 1) {
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
locationGranted = await Permission.location.isGranted;
data = {
'bluetoothScanGranted': bluetoothScanGranted,
'bluetoothConnectGranted': bluetoothConnectGranted,
'locationGranted': locationGranted,
};
return data;
}
showPermissionInfoDialog(
Get.context!,
CommonVariables().bluetoothpermissionInfo,
);
show = true;
// 检查并请求权限
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
locationGranted = await Permission.location.isGranted;
if (!bluetoothScanGranted || !bluetoothConnectGranted || !locationGranted) {
await [
Permission.bluetoothScan,
Permission.bluetoothConnect,
Permission.location,
].request();
// 更新权限状态
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
locationGranted = await Permission.location.isGranted;
}
data = {
'bluetoothScanGranted': bluetoothScanGranted,
'bluetoothConnectGranted': bluetoothConnectGranted,
'locationGranted': locationGranted,
};
// 通知 web 端
WebviewTestController webviewTestController = Get.find();
// webviewTestController.web.jsbridge?.dart.updatePermission(data);
} catch (e) {
ef.log("蓝牙权限:$e");
} finally {
if (show) {
Navigator.of(Get.context!, rootNavigator: true).pop();
}
}
userInfoController.initLocationpermission = 1;
return data;
}

View File

@@ -16,6 +16,7 @@ import 'package:vbvs_app/controller/user_info_controller.dart';
import 'package:vbvs_app/model/WebSocketMessage.dart';
import 'package:vbvs_app/pages/main_bottom/component/main_page_b_bottom_change.dart';
import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.dart';
import 'package:vbvs_app/pages/mh_page/homepage/component/HomeDeviceStausWidget.dart';
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
class WebviewTestModel {
@@ -225,6 +226,27 @@ class WebviewTestController extends GetControllerEx<WebviewTestModel> {
}
return true;
});
bridge.sdk.updatePermisson((args) async {
ef.log('获取权限: $args[0]');
try {
if (MainPageBBottomChange.getCurrentIndex() != 2) {
return false;
}
Map data = await checkBlueToothPermissin();
if (data == null || data.isEmpty) {
return false;
}
if (!data['bluetoothScanGranted'] ||
!data['bluetoothConnectGranted'] ||
!data['locationGranted']) {
return false;
}
return true;
} catch (e) {
ef.log("[网页加载失败]:$e");
}
return true;
});
// bridge.sdk.bluetoothConnect((args) async {
// ef.log('[蓝牙连接失败]: $args[0]');
// try {
@@ -540,7 +562,8 @@ class WebviewTestView extends GetComponent<WebviewTestController> {
child: Obx(() {
int? aa = MainPageBBottomChange.getCurrentIndex();
print(aa);
return (controller.ready.value && (MainPageBBottomChange.getCurrentIndex() == 2))
// return (controller.ready.value && (MainPageBBottomChange.getCurrentIndex() == 2))
return (controller.ready.value)
? controller.web.build()
: Center(child: CircularProgressIndicator());
}),