网页 手机端 初版
This commit is contained in:
parent
cef3227375
commit
87b3157e14
|
|
@ -1,20 +1,102 @@
|
||||||
class JavaScriptString {
|
class JavaScriptString {
|
||||||
/// 点击监听
|
/// 点击监听
|
||||||
static String clickEventkJSString =
|
static String clickEventJSString =
|
||||||
'''document.addEventListener('click', function(event) {
|
'''document.addEventListener('click', function(event) {
|
||||||
var x = event.clientX;
|
var x = event.clientX;
|
||||||
var y = event.clientY;
|
var y = event.clientY;
|
||||||
|
|
||||||
console.log('点击坐标:x=' + x + ', y=' + y);
|
console.log('点击坐标:x=' + x + ', y=' + y);
|
||||||
window.flutter_inappwebview.callHandler('Click', x, y);
|
window.flutter_inappwebview.callHandler('click', x, y);
|
||||||
|
|
||||||
});''';
|
});''';
|
||||||
|
|
||||||
|
/// 触摸监听
|
||||||
|
static String touchendEventJSString =
|
||||||
|
'''document.addEventListener('touchend', function(event) {
|
||||||
|
var x = event.changedTouches[0].clientX;
|
||||||
|
var y = event.changedTouches[0].clientY;
|
||||||
|
|
||||||
|
// 获取目标元素
|
||||||
|
var target = event.target;
|
||||||
|
|
||||||
|
// 获取目标元素的class和id
|
||||||
|
var targetClass = target.className;
|
||||||
|
var targetId = target.id;
|
||||||
|
|
||||||
|
console.log('Class: ' + targetClass);
|
||||||
|
console.log('Id: ' + targetId);
|
||||||
|
|
||||||
|
console.log('触摸坐标:x=' + x + ', y=' + y);
|
||||||
|
window.flutter_inappwebview.callHandler('touchend', x, y);
|
||||||
|
|
||||||
|
});''';
|
||||||
|
|
||||||
|
/// 退出登录
|
||||||
|
static String loginOutJsString = '''
|
||||||
|
\$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: "/api/logout.do",
|
||||||
|
success: function(t) {
|
||||||
|
"index.html" != location.pathname ? window.location.href = "index.html" : location.reload()
|
||||||
|
},
|
||||||
|
error: function(t) {
|
||||||
|
var e = \$.parseJSON(t.responseText + "");
|
||||||
|
alert(e.msg, 2)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
''';
|
||||||
|
|
||||||
/// 模拟点击
|
/// 模拟点击
|
||||||
static String clickJSString(int x, int y) {
|
static String clickJSString(int x, int y) {
|
||||||
return 'document.elementFromPoint($x, $y).click();';
|
return 'document.elementFromPoint($x, $y).click();';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 模拟触摸
|
||||||
|
static String touchendJsString(int x, int y) {
|
||||||
|
return '''
|
||||||
|
|
||||||
|
''';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 模拟触摸
|
||||||
|
static String getClassTouchendJsString(int x, int y) {
|
||||||
|
return '''
|
||||||
|
try{
|
||||||
|
// 获取鼠标点击位置的坐标
|
||||||
|
var x = $x;
|
||||||
|
var y = $y;
|
||||||
|
|
||||||
|
// 创建一个touchstart事件
|
||||||
|
var touchstartEvent = new TouchEvent('touchstart', {
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true,
|
||||||
|
view: window,
|
||||||
|
changedTouches: [new Touch({ identifier: Date.now(), target: document.body, clientX: x, clientY: y })],
|
||||||
|
targetTouches: [new Touch({ identifier: Date.now(), target: document.body, clientX: x, clientY: y })]
|
||||||
|
});
|
||||||
|
|
||||||
|
// touchstartEvent
|
||||||
|
document.body.dispatchEvent(touchstartEvent);
|
||||||
|
|
||||||
|
// 创建一个touchend事件
|
||||||
|
var touchendEvent = new TouchEvent('touchend', {
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true,
|
||||||
|
view: window,
|
||||||
|
changedTouches: [new Touch({ identifier: Date.now(), target: document.body, clientX: x, clientY: y })],
|
||||||
|
targetTouches: [new Touch({ identifier: Date.now(), target: document.body, clientX: x, clientY: y })]
|
||||||
|
});
|
||||||
|
|
||||||
|
// 触发touchend事件
|
||||||
|
document.body.dispatchEvent(touchendEvent);
|
||||||
|
|
||||||
|
} catch (t) {
|
||||||
|
console.log('模拟触摸错误 -- ' + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
''';
|
||||||
|
}
|
||||||
|
|
||||||
/// 输入
|
/// 输入
|
||||||
static String inputJsString(int value) {
|
static String inputJsString(int value) {
|
||||||
return '''
|
return '''
|
||||||
|
|
@ -24,7 +106,7 @@ var inputEvent = new Event('input', {
|
||||||
cancelable: true,
|
cancelable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
var inputElement = document.querySelector(".bet-money");
|
var inputElement = document.querySelector(".input");
|
||||||
|
|
||||||
inputElement.value = "$value";
|
inputElement.value = "$value";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
import 'package:web_synchronization_tool/main_page.dart';
|
import 'package:web_synchronization_tool/main_page.dart';
|
||||||
import 'package:web_synchronization_tool/windows/windows_main_page.dart';
|
import 'package:web_synchronization_tool/windows/windows_main_page.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
|
|
||||||
|
// await InAppWebViewController.setWebContentsDebuggingEnabled(true);
|
||||||
|
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
import 'package:web_synchronization_tool/web_widget.dart';
|
import 'package:web_synchronization_tool/web_widget.dart';
|
||||||
|
|
@ -16,22 +17,35 @@ class _MainPageState extends State<MainPage> {
|
||||||
late InAppWebViewController mainController;
|
late InAppWebViewController mainController;
|
||||||
late InAppWebViewController controller;
|
late InAppWebViewController controller;
|
||||||
|
|
||||||
|
bool asyncState = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 注入点击监听
|
@override
|
||||||
addClickEventJS(){
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
|
||||||
final clickJsUS = UserScript(groupName: 'click',source: JavaScriptString.clickEventkJSString, injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START);
|
WebStorageManager.instance().deleteAllData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 注入触摸监听
|
||||||
|
addTouchendEventJS(){
|
||||||
|
|
||||||
|
final clickJsUS = UserScript(groupName: 'touchend',source: JavaScriptString.touchendEventJSString, injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START);
|
||||||
mainController.addUserScript(userScript: clickJsUS);
|
mainController.addUserScript(userScript: clickJsUS);
|
||||||
|
|
||||||
mainController.addJavaScriptHandler(handlerName: 'Click', callback: (args){
|
mainController.addJavaScriptHandler(handlerName: 'touchend', callback: (args){
|
||||||
controller.evaluateJavascript(source: JavaScriptString.clickJSString(args.first, args.last) );
|
if (asyncState){
|
||||||
|
int x = double.parse(args.first.toString()).toInt();
|
||||||
|
int y = double.parse(args.last.toString()).toInt();
|
||||||
|
controller.evaluateJavascript(source: JavaScriptString.clickJSString(x, y) );
|
||||||
|
// controller.evaluateJavascript(source: JavaScriptString.touchendJsString(x, y) );
|
||||||
|
// controller.evaluateJavascript(source: JavaScriptString.getClassTouchendJsString(x, y) );
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -40,6 +54,7 @@ class _MainPageState extends State<MainPage> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Column(
|
body: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
height: 50,
|
height: 50,
|
||||||
|
|
@ -49,7 +64,7 @@ class _MainPageState extends State<MainPage> {
|
||||||
children: [
|
children: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
controller.evaluateJavascript(source: JavaScriptString.clickJSString(600, 280) );
|
controller.evaluateJavascript(source: JavaScriptString.clickJSString(50, 100) );
|
||||||
},
|
},
|
||||||
child: const Text('模拟点击测试')),
|
child: const Text('模拟点击测试')),
|
||||||
TextButton(
|
TextButton(
|
||||||
|
|
@ -58,12 +73,15 @@ class _MainPageState extends State<MainPage> {
|
||||||
controller.evaluateJavascript(source: JavaScriptString.inputJsString(45) );
|
controller.evaluateJavascript(source: JavaScriptString.inputJsString(45) );
|
||||||
},
|
},
|
||||||
child: const Text('模拟输入测试')),
|
child: const Text('模拟输入测试')),
|
||||||
const SizedBox(
|
Row(
|
||||||
width: 50,
|
children: [
|
||||||
child: TextField(
|
const Text('同步'),
|
||||||
keyboardType: TextInputType.number,
|
Switch(value: asyncState, onChanged: (value){
|
||||||
decoration: InputDecoration(prefixText: '网页数量'),
|
setState(() {
|
||||||
),
|
asyncState = value;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -75,19 +93,30 @@ class _MainPageState extends State<MainPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget pageViewWidget() {
|
Widget pageViewWidget() {
|
||||||
return PageView(
|
return Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
KeepAlivePage(
|
Expanded(
|
||||||
child: WebWidget(controlerCallBack: (_mainController) {
|
child: Container(
|
||||||
mainController = _mainController;
|
color: Colors.yellow,
|
||||||
|
child: KeepAlivePage(
|
||||||
addClickEventJS();
|
child: WebWidget(controlerCallBack: (_mainController) {
|
||||||
}),
|
mainController = _mainController;
|
||||||
|
|
||||||
|
addTouchendEventJS();
|
||||||
|
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
KeepAlivePage(
|
Expanded(
|
||||||
child: WebWidget(controlerCallBack: (_controller) {
|
child: Container(
|
||||||
controller = _controller;
|
color: Colors.blue,
|
||||||
}),
|
child: KeepAlivePage(
|
||||||
|
child: WebWidget(controlerCallBack: (_controller) {
|
||||||
|
controller = _controller;
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,19 @@ class _WebWidgetState extends State<WebWidget> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InAppWebView(
|
return InAppWebView(
|
||||||
initialUrlRequest:
|
initialUrlRequest:
|
||||||
URLRequest(url: WebUri('http://www.df6831.com/game/')),
|
URLRequest(url: WebUri('http://www.df6831.com')),
|
||||||
initialSettings: InAppWebViewSettings(initialScale: 200,loadWithOverviewMode: false,useWideViewPort: false),
|
initialSettings: InAppWebViewSettings(
|
||||||
|
initialScale: 180,
|
||||||
|
loadWithOverviewMode: false,
|
||||||
|
useWideViewPort: false,
|
||||||
|
preferredContentMode: UserPreferredContentMode.MOBILE,
|
||||||
|
cacheEnabled: false, //启用缓存
|
||||||
|
clearSessionCache: true,//清除会话缓存
|
||||||
|
databaseEnabled:false, // 启用数据库
|
||||||
|
domStorageEnabled: false,//启用 dom 存储
|
||||||
|
incognito: true, //隐身模式
|
||||||
|
sharedCookiesEnabled: false, // 共享Cookie
|
||||||
|
),
|
||||||
onWebViewCreated: (_controller) {
|
onWebViewCreated: (_controller) {
|
||||||
widget.controlerCallBack(_controller);
|
widget.controlerCallBack(_controller);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class _WindowsPageState extends State<WindowsPage> {
|
||||||
});
|
});
|
||||||
|
|
||||||
mainController.addScriptToExecuteOnDocumentCreated(
|
mainController.addScriptToExecuteOnDocumentCreated(
|
||||||
JavaScriptString.clickEventkJSString).then((value){
|
JavaScriptString.clickEventJSString).then((value){
|
||||||
print(value);
|
print(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue