| 
									
										
										
										
											2024-04-06 16:35:02 +08:00
										 |  |  | import 'package:common/utils/toast_utils.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-05 18:10:38 +08:00
										 |  |  | import 'package:web_synchronization_tool/windows/number_tool.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-03 21:53:27 +08:00
										 |  |  | import 'package:web_synchronization_tool/windows/socket_tool.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  | import 'package:web_synchronization_tool/windows/synchronization_web_tool.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-05 18:10:38 +08:00
										 |  |  | import 'package:web_synchronization_tool/windows/windowsJs.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  | import 'package:webview_windows/webview_windows.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WebGridController { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Function(WebviewController controller)? addWebControllerBlack; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   addWebController(WebviewController controller) { | 
					
						
							|  |  |  |     if (addWebControllerBlack != null) { | 
					
						
							|  |  |  |       addWebControllerBlack!(controller); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WebGridWidget extends StatefulWidget { | 
					
						
							|  |  |  |   const WebGridWidget({super.key, required this.controller}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   final WebGridController controller; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<WebGridWidget> createState() => _WebGridWidgetState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _WebGridWidgetState extends State<WebGridWidget> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   List<WebviewController> controllers = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   bool initDone = false; | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     controllerInit(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |   /// 控制器初始化
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   Future controllerInit() async { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (var i = 0; i< 10 ; i++) { | 
					
						
							|  |  |  |       var controller = WebviewController(); | 
					
						
							|  |  |  |       await controller.initialize(); | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |       controller.loadUrl('https://www.df6831.com/'); | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // controller.executeScript(WindowsJs.zoom(35));
 | 
					
						
							|  |  |  |       // controller.addScriptToExecuteOnDocumentCreated(WindowsJs.onloadZoom(35));
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       controllers.add(controller); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SynchronizationWebTool.getInstance().setChildController(controllers); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setState(() { | 
					
						
							|  |  |  |       initDone = true; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return GridView.builder( | 
					
						
							|  |  |  |       gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( | 
					
						
							|  |  |  |           crossAxisCount: 5, // 两列
 | 
					
						
							|  |  |  |           crossAxisSpacing: 8.0, // 水平间距
 | 
					
						
							|  |  |  |           mainAxisSpacing: 8.0, // 垂直间距
 | 
					
						
							|  |  |  |           childAspectRatio: 0.9), | 
					
						
							|  |  |  |       itemBuilder: (BuildContext context, int index) { | 
					
						
							|  |  |  |         return Stack( | 
					
						
							|  |  |  |           children: [ | 
					
						
							|  |  |  |             Webview(controllers[index]), | 
					
						
							|  |  |  |             TextButton( | 
					
						
							|  |  |  |               style: ButtonStyle( | 
					
						
							|  |  |  |                   overlayColor: MaterialStateProperty.resolveWith( | 
					
						
							|  |  |  |                       (states) => Colors.transparent)), | 
					
						
							|  |  |  |               onPressed: () { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 var controller = controllers[index]; | 
					
						
							|  |  |  |                 // controller.executeScript(WindowsJs.zoom(100));
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 10:37:41 +08:00
										 |  |  |                 // showAnimationDialog(
 | 
					
						
							|  |  |  |                 //     context: context,
 | 
					
						
							|  |  |  |                 //     // barrierDismissible: false,
 | 
					
						
							|  |  |  |                 //     child: ShowWebWidget(controller: controller,));
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // Navigator.push(context, MaterialPageRoute(builder: (context)=> ShowWebWidget(controller: controller,) ));
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 Navigator.of(context).push(PageRouteBuilder( | 
					
						
							|  |  |  |                   opaque: false, // 设置路由本身透明
 | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |                   pageBuilder: (BuildContext context, _, __) => ShowWebWidget(controller: controller,main: index == 0,), | 
					
						
							| 
									
										
										
										
											2024-04-03 10:37:41 +08:00
										 |  |  |                 )); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |               }, | 
					
						
							|  |  |  |               child: Container(), | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       itemCount: controllers.length, // 生成20个瀑布流瓦片
 | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  | class ShowWebWidget extends StatefulWidget { | 
					
						
							|  |  |  |   const ShowWebWidget({super.key, required this.controller, this.main = false}); | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   final WebviewController controller; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |   final bool main; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<ShowWebWidget> createState() => _ShowWebWidgetState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _ShowWebWidgetState extends State<ShowWebWidget> { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 21:53:27 +08:00
										 |  |  |    /// 网址
 | 
					
						
							|  |  |  |    TextEditingController urlController = TextEditingController(); | 
					
						
							| 
									
										
										
										
											2024-04-05 18:10:38 +08:00
										 |  |  |    /// 总金额
 | 
					
						
							|  |  |  |    TextEditingController numController = TextEditingController(); | 
					
						
							| 
									
										
										
										
											2024-04-03 21:53:27 +08:00
										 |  |  |    /// 服务器ip
 | 
					
						
							|  |  |  |    TextEditingController ipController = TextEditingController(); | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void dispose() { | 
					
						
							|  |  |  |     super.dispose(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // widget.controller.clearCache();
 | 
					
						
							|  |  |  |     // widget.controller.clearCookies();
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2024-04-03 10:37:41 +08:00
										 |  |  |     return Scaffold( | 
					
						
							|  |  |  |       backgroundColor: Colors.transparent, | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |       appBar: AppBar( | 
					
						
							|  |  |  |         title: getTitleWidget(), | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2024-04-03 10:37:41 +08:00
										 |  |  |       body: Center( | 
					
						
							|  |  |  |         child: SizedBox( | 
					
						
							|  |  |  |           width: 1400, | 
					
						
							|  |  |  |           height: 900, | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |           child: Webview(widget.controller), | 
					
						
							| 
									
										
										
										
											2024-04-03 10:37:41 +08:00
										 |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |   Widget getTitleWidget(){ | 
					
						
							|  |  |  |     if (widget.main == false) return input(); | 
					
						
							|  |  |  |     return Row( | 
					
						
							|  |  |  |       children: [ | 
					
						
							| 
									
										
										
										
											2024-04-05 18:10:38 +08:00
										 |  |  |         inputNumber(), | 
					
						
							|  |  |  |         Row( | 
					
						
							|  |  |  |           children: [ | 
					
						
							|  |  |  |             const Text('同步'), | 
					
						
							|  |  |  |             Switch( | 
					
						
							|  |  |  |                 value: SynchronizationWebTool.getInstance().webSync, | 
					
						
							|  |  |  |                 onChanged: (value) { | 
					
						
							|  |  |  |                   setState(() { | 
					
						
							|  |  |  |                     SynchronizationWebTool.getInstance().webSync = value; | 
					
						
							|  |  |  |                     if (value){ // 打开同步获取 从机
 | 
					
						
							|  |  |  |                       SocketUtils.getInstance().sendGetChilds(); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   }); | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-04-03 21:53:27 +08:00
										 |  |  |         input(), | 
					
						
							|  |  |  |         ipSet() | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |       ], | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 21:53:27 +08:00
										 |  |  |   /// 跳转网址
 | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |   input(){ | 
					
						
							|  |  |  |     return Row( | 
					
						
							|  |  |  |       children: [ | 
					
						
							| 
									
										
										
										
											2024-04-03 21:53:27 +08:00
										 |  |  |         SizedBox(width: 400, child: TextField(style: const TextStyle(fontSize: 14),controller: urlController,)), | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |         TextButton(onPressed: (){ | 
					
						
							| 
									
										
										
										
											2024-04-03 21:53:27 +08:00
										 |  |  |           String url = urlController.text; | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |           // if (!url.startsWith("https://") ) {
 | 
					
						
							|  |  |  |           //   url = "https://$url";
 | 
					
						
							|  |  |  |           // }
 | 
					
						
							|  |  |  |           widget.controller.loadUrl(url); | 
					
						
							|  |  |  |         }, child: const Text('跳转',style: TextStyle(fontSize: 14),)) | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 21:53:27 +08:00
										 |  |  |   ipSet(){ | 
					
						
							|  |  |  |     ipController.text = SocketUtils.getInstance().url; | 
					
						
							|  |  |  |     return Row( | 
					
						
							|  |  |  |       children: [ | 
					
						
							|  |  |  |         SizedBox(width: 100, child: TextField(style: const TextStyle(fontSize: 14),controller: ipController,)), | 
					
						
							|  |  |  |         TextButton(onPressed: (){ | 
					
						
							|  |  |  |           SocketUtils.getInstance().url = ipController.text; | 
					
						
							|  |  |  |           SocketUtils.getInstance().connect(); | 
					
						
							|  |  |  |         }, child: const Text('保存服务器ip',style: TextStyle(fontSize: 14),)) | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-05 18:10:38 +08:00
										 |  |  |   /// 输入总金额
 | 
					
						
							|  |  |  |   inputNumber(){ | 
					
						
							|  |  |  |     return Row( | 
					
						
							|  |  |  |       children: [ | 
					
						
							|  |  |  |         SizedBox(width: 100, child: TextField(style: const TextStyle(fontSize: 14),controller: numController,)), | 
					
						
							|  |  |  |         TextButton( | 
					
						
							|  |  |  |             onPressed: () { | 
					
						
							|  |  |  |               try{ | 
					
						
							|  |  |  |                 int num = int.parse(numController.text); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 int chidNum = SocketUtils.getInstance().childrenIp.length + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (num <= chidNum * 10){ | 
					
						
							| 
									
										
										
										
											2024-04-06 16:35:02 +08:00
										 |  |  |                   numController.text = '不能小于${chidNum*10}'; | 
					
						
							|  |  |  |                   ToastUtils.showToast('金额不能太小'); | 
					
						
							| 
									
										
										
										
											2024-04-05 18:10:38 +08:00
										 |  |  |                   return; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 int maxNum = num ~/ chidNum; | 
					
						
							|  |  |  |                 SocketUtils.getInstance().sendInpuMessage(maxNum); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // 本地处理
 | 
					
						
							|  |  |  |                 List<int> nums = NumberTool().randomNum(maxNum); | 
					
						
							|  |  |  |                 widget.controller.executeScript(WindowsJs.inputJs(nums.first)); | 
					
						
							|  |  |  |                 nums.removeAt(0); | 
					
						
							|  |  |  |                 SynchronizationWebTool.getInstance().input(nums); | 
					
						
							|  |  |  |               }catch(e){ | 
					
						
							| 
									
										
										
										
											2024-04-06 16:35:02 +08:00
										 |  |  |                 ToastUtils.showToast('请输入数字'); | 
					
						
							| 
									
										
										
										
											2024-04-05 18:10:38 +08:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             child: const Text('填入总金额')), | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |