class JavaScriptString { /// 点击监听 static String clickEventJSString = '''document.addEventListener('click', function(event) { var x = event.clientX; var y = event.clientY; console.log('点击坐标:x=' + x + ', y=' + 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) { 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) { return ''' var inputEvent = new Event('input', { bubbles: true, cancelable: true, }); var inputElement = document.querySelector(".input"); inputElement.value = "$value"; inputElement.dispatchEvent(inputEvent); '''; } }