2026-03-10 15:58:52 +08:00
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import 'package:go_router/go_router.dart';
|
2026-11-21 14:26:18 +08:00
|
|
|
|
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
|
|
|
|
|
import 'package:maibu_satabot_v2/core/env/server_configuration.dart';
|
2026-04-24 15:24:43 +08:00
|
|
|
|
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
2026-03-10 15:58:52 +08:00
|
|
|
|
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
|
|
|
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class DjPage extends StatefulWidget {
|
2026-11-06 08:41:44 +08:00
|
|
|
|
/// 从横屏页(如「地图与区域编辑」)push 进来时为 true:
|
|
|
|
|
|
/// 退出统一用 pop 回来源页。若用 context.go() 整栈替换,
|
|
|
|
|
|
/// 来源页 await push 的 Future 永不完成,横屏恢复不会执行,
|
|
|
|
|
|
/// 页面会被锁死在竖屏。首页进入时保持原 go() 行为。
|
|
|
|
|
|
final bool exitToPop;
|
|
|
|
|
|
|
|
|
|
|
|
const DjPage({super.key, this.exitToPop = false});
|
2026-03-10 15:58:52 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<DjPage> createState() => _DjPageState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _DjPageState extends State<DjPage> {
|
|
|
|
|
|
late final WebViewController controller;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
2026-11-21 14:26:18 +08:00
|
|
|
|
final url = EnvConfig.address(ServerService.stationWeb).replace(
|
|
|
|
|
|
queryParameters: {
|
|
|
|
|
|
'platform': 'flutter',
|
|
|
|
|
|
't': DateTime.now().millisecondsSinceEpoch.toString(),
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
2026-03-10 15:58:52 +08:00
|
|
|
|
|
|
|
|
|
|
controller = WebViewController()
|
|
|
|
|
|
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
|
|
|
|
|
..addJavaScriptChannel(
|
|
|
|
|
|
'MapChannel',
|
|
|
|
|
|
onMessageReceived: (JavaScriptMessage message) {
|
|
|
|
|
|
_handleJsMessage(message.message);
|
|
|
|
|
|
},
|
|
|
|
|
|
)
|
2026-11-21 14:26:18 +08:00
|
|
|
|
..loadRequest(url);
|
2026-03-10 15:58:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 处理 H5 返回的数据
|
|
|
|
|
|
void _handleJsMessage(String msg) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
final data = jsonDecode(msg);
|
|
|
|
|
|
|
|
|
|
|
|
final action = data["action"];
|
|
|
|
|
|
final page = data["page"];
|
|
|
|
|
|
|
|
|
|
|
|
if (action == "navigate") {
|
2026-11-06 08:41:44 +08:00
|
|
|
|
// 编辑器入口:H5 发出任何跳转都视为「场站已选好」,pop 回横屏编辑页
|
|
|
|
|
|
if (widget.exitToPop) {
|
|
|
|
|
|
if (context.canPop()) context.pop();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-03-10 15:58:52 +08:00
|
|
|
|
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: () {
|
2026-11-06 08:41:44 +08:00
|
|
|
|
// 编辑器入口:pop 回来源页(触发对方 await 完成→恢复横屏)
|
|
|
|
|
|
if (widget.exitToPop && context.canPop()) {
|
|
|
|
|
|
context.pop();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
context.go(RoutePaths.home);
|
|
|
|
|
|
}
|
2026-03-10 15:58:52 +08:00
|
|
|
|
},
|
|
|
|
|
|
),
|
2026-04-24 15:24:43 +08:00
|
|
|
|
title: Text(AppLocalizations.of(context).translate('route_planning.title'), style: const TextStyle(color: Colors.white)),
|
2026-03-10 15:58:52 +08:00
|
|
|
|
backgroundColor: const Color(0xFF1677FF),
|
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
|
),
|
|
|
|
|
|
body: WebViewWidget(controller: controller),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|