From 137c28d0f0b58fa63996753e461a2c4566f6061f Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Tue, 10 Mar 2026 15:58:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E9=AB=98=E6=B8=85=E5=9C=BA?= =?UTF-8?q?=E7=AB=99=E5=9C=B0=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/router/route_paths.dart | 4 +- .../home/presentation/pages/dj_page.dart | 82 +++++++++++++++++++ .../pages/running_status_page.dart | 3 - .../home/presentation/routes/home_routes.dart | 16 ++-- .../widgets/map/testmap_pages.dart | 3 + .../presentation/widgets/path_list_pages.dart | 2 + 6 files changed, 93 insertions(+), 17 deletions(-) create mode 100644 lib/features/home/presentation/pages/dj_page.dart diff --git a/lib/core/router/route_paths.dart b/lib/core/router/route_paths.dart index 66faa290..4afeb465 100644 --- a/lib/core/router/route_paths.dart +++ b/lib/core/router/route_paths.dart @@ -13,9 +13,7 @@ class RoutePaths { static const remoteControl = '/home/remote_control'; static const routePlan = '/home/route_plan'; static const runningStatus = '/home/running_status'; + static const djMap = '/home/dj_map'; static const machineDetails = '/machine_details/machine_details'; - - - } diff --git a/lib/features/home/presentation/pages/dj_page.dart b/lib/features/home/presentation/pages/dj_page.dart new file mode 100644 index 00000000..cd1f5dc1 --- /dev/null +++ b/lib/features/home/presentation/pages/dj_page.dart @@ -0,0 +1,82 @@ +import 'dart:convert'; +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; +import 'package:maibu_satabot_v2/core/router/route_paths.dart'; +import 'package:webview_flutter/webview_flutter.dart'; + +class DjPage extends StatefulWidget { + const DjPage({super.key}); + + @override + State createState() => _DjPageState(); +} + +class _DjPageState extends State { + late final WebViewController controller; + + @override + void initState() { + super.initState(); + + final url = "https://pvs.satabot.com/?platform=flutter&t=${DateTime.now().millisecondsSinceEpoch}"; + + controller = WebViewController() + ..setJavaScriptMode(JavaScriptMode.unrestricted) + // 监听 H5 消息 + ..addJavaScriptChannel( + 'MapChannel', + onMessageReceived: (JavaScriptMessage message) { + _handleJsMessage(message.message); + }, + ) + // 加载网页 + ..loadRequest(Uri.parse(url)); + } + + /// 处理 H5 返回的数据 + void _handleJsMessage(String msg) { + debugPrint("H5消息: $msg"); + + try { + final data = jsonDecode(msg); + + final action = data["action"]; + final page = data["page"]; + + if (action == "navigate") { + if (page == "gaode") { + _openGaode(); + } + + if (page == "StatusFragment") { + context.go(RoutePaths.routePlan); + } + } + } catch (e) { + debugPrint("解析H5消息失败: $e"); + } + } + + /// 打开高德地图页面 + void _openGaode() { + context.go(RoutePaths.routePlan); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + leading: IconButton( + icon: const Icon(Icons.arrow_back, color: Colors.white), + onPressed: () { + context.go(RoutePaths.home); + }, + ), + title: const Text("路径规划", style: TextStyle(color: Colors.white)), + backgroundColor: const Color(0xFF1677FF), + foregroundColor: Colors.white, + ), + body: WebViewWidget(controller: controller), + ); + } +} diff --git a/lib/features/home/presentation/pages/running_status_page.dart b/lib/features/home/presentation/pages/running_status_page.dart index baccec63..e975864e 100644 --- a/lib/features/home/presentation/pages/running_status_page.dart +++ b/lib/features/home/presentation/pages/running_status_page.dart @@ -961,9 +961,6 @@ class _RunningStatusPageState extends State { ), // 新增:AppBar底部阴影优化 shadowColor: Colors.black12, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.only(bottomLeft: Radius.circular(12), bottomRight: Radius.circular(12)), - ), ); } diff --git a/lib/features/home/presentation/routes/home_routes.dart b/lib/features/home/presentation/routes/home_routes.dart index 9463f82e..4575ee5e 100644 --- a/lib/features/home/presentation/routes/home_routes.dart +++ b/lib/features/home/presentation/routes/home_routes.dart @@ -1,5 +1,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; +import 'package:maibu_satabot_v2/features/home/presentation/pages/dj_page.dart'; import 'package:maibu_satabot_v2/features/home/presentation/pages/home_page.dart'; import '../../../../core/di/injection.dart'; @@ -22,13 +23,11 @@ class HomeRoutes { child: const RemoteControlPage(), ), ), - GoRoute( - path: RoutePaths.routePlan, - builder: (context, state) => const RoutePlanPage(), - ), + GoRoute(path: RoutePaths.routePlan, builder: (context, state) => const RoutePlanPage()), + GoRoute(path: RoutePaths.djMap, builder: (context, state) => const DjPage()), GoRoute( path: RoutePaths.runningStatus, - // builder: (context, state) => const RunningStatusPage(), + // builder: (context, state) => const RunningStatusPage(), builder: (context, state) => BlocProvider( create: (_) => sl(), // 从 GetIt 获取单例 child: const RunningStatusPage(), @@ -39,11 +38,6 @@ class HomeRoutes { /// 2. 首页 Tab 分支(带导航栏) /// 仅保留真正的首页入口 static StatefulShellBranch get branch => StatefulShellBranch( - routes: [ - GoRoute( - path: RoutePaths.home, - builder: (context, state) => const HomePage(), - ), - ], + routes: [GoRoute(path: RoutePaths.home, builder: (context, state) => const HomePage())], ); } diff --git a/lib/features/home/presentation/widgets/map/testmap_pages.dart b/lib/features/home/presentation/widgets/map/testmap_pages.dart index 3a9f58d6..6115e15a 100644 --- a/lib/features/home/presentation/widgets/map/testmap_pages.dart +++ b/lib/features/home/presentation/widgets/map/testmap_pages.dart @@ -9,6 +9,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:geolocator/geolocator.dart'; +import 'package:go_router/go_router.dart'; import 'package:http/http.dart' as http; import 'package:latlong2/latlong.dart'; import 'package:maibu_satabot_v2/components/confrim_dialog.dart'; @@ -18,6 +19,7 @@ import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart'; import 'package:maibu_satabot_v2/core/di/injection.dart'; import 'package:maibu_satabot_v2/core/network/net_message_dispatcher.dart'; import 'package:maibu_satabot_v2/core/network/protocol_decoder.dart'; +import 'package:maibu_satabot_v2/core/router/route_paths.dart'; import 'package:maibu_satabot_v2/features/devices/data/models/device_add_path_point_model.dart' as work_area_model; import 'package:maibu_satabot_v2/features/devices/data/models/device_work_area_param_model.dart' as work_area_model; import 'package:maibu_satabot_v2/features/devices/data/repositories/generate_path_repository_Impl.dart'; @@ -2175,6 +2177,7 @@ class _MapPageEnterpriseState extends State { }); }, onDjShow: (bool isOpen) { + if (isOpen) context.go(RoutePaths.djMap); setState(() { isDjMapShow = isOpen; }); diff --git a/lib/features/home/presentation/widgets/path_list_pages.dart b/lib/features/home/presentation/widgets/path_list_pages.dart index d8388321..745197c9 100644 --- a/lib/features/home/presentation/widgets/path_list_pages.dart +++ b/lib/features/home/presentation/widgets/path_list_pages.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; +import 'package:maibu_satabot_v2/core/router/route_paths.dart'; import 'package:maibu_satabot_v2/features/home/presentation/widgets/common/enum.dart'; class VerticalFloatMenu extends StatefulWidget {