energy/example/dev-test/ipc-event/resources/ipc-event.html
2023-03-11 14:24:22 +08:00

180 lines
6.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ipc-event</title>
<style>
button {
margin: 5px;
}
</style>
<script type="application/javascript">
let idx = 0;
let si = null;
function autoIpcEmit() {
if (si != null) {
clearInterval(si)
si = null
idx = 0
return
}
si = setInterval(ipcEmit, 1)
// for(let i=0;i<100000;i++){
// ipcEmit();
// }
if (si != null) {
let time = document.getElementById("time").value - 0
if (time > 0) {
setTimeout(function () {
clearInterval(si)
si = null
}, time)
}
}
}
function ipcEmit() {
idx++;
let objectValueArray = [
100, 200, "数组里的字符串", 66996.99,
]
let objectValue = {
"stringField": "stringFieldValue",
"intField": 1000,
"arrayField": objectValueArray,
"doubleField": 999991.102,
"booleanField": true,
}
let arrayValue = [
100, 200, "数组里的字符串", 66996.99, objectValue, true, false
]
let ok = ipc.emit("testEmitName", ["stringValue", idx, true, 1999.66 + idx, "字符串?", 29999.66 + idx, objectValue, arrayValue, 8888888888888 + idx, null, undefined],
/*function (result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13) {
//msg('testEmitName 回调函数执行了', result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12);
//第2个返回值是 ArrayBuffer 类型,字节数组
let result2ArrayBuffer = new Uint8Array(result2);
let result2Decode = new TextDecoder()//中文转码,不乱码
let decodedString = result2Decode.decode(result2ArrayBuffer);
// msg('result1', JSON.stringify(result1));
// msg('result2 字符串-字节数组:', decodedString);
// msg('result3', JSON.stringify(result3));
// msg('result4', JSON.stringify(result4));
// msg('result5', JSON.stringify(result5));
// msg('result6', JSON.stringify(result6));
// msg('result7', JSON.stringify(result7));
// msg('result8', JSON.stringify(result8));
// msg('result9', JSON.stringify(result9));
// msg('result10', JSON.stringify(result10));
// msg('result11', JSON.stringify(result11));
// msg('result12', JSON.stringify(result12));
// msg('result13', JSON.stringify(result13));
console.log('result1', result1)
console.log('result2', result2)
console.log('result3', result3)
console.log('result4', result4)
console.log('result5', result5)
console.log('result6', result6)
console.log('result7', result7)
console.log('result8', result8)
console.log('result9', result9)
console.log('result10', result10)
console.log('result11', result11)
console.log('result12', result12)
console.log('result13', result13)
}*/);
//msg('ipc.emit ok?', ok);
//let ok1 = ipc.emit([]);
// msg('ipc.emit ok?', ok1);
}
function testInArgs() {
let map = {
"key1": "value1value1value1value1",
"key2": "value2value2value2vaaaaaaalue2",
"key3": "value3value3value3",
"key4": 1231,
"key5": 1231.33,
"key6": true,
"subObj": {
"StringField": "StringFieldStringFieldStringField",
"IntField": 3333333,
"BoolField": true,
"FloatField": 1006588.666
}
}
let args8 = {
"key1": "value1value1value1value1",
"key2": "value2value2value2vaaaaaaalue2",
"key3": "value3value3value3"
}
let arr = ["adsfsadf", "fffffff"]
let args10 = [1111111.1111, 222222.222]
ipc.emit("testInArgs", ["字符串参数", 123123, true, arr, map, map, {"structMap": map}, args8, 9999999.99999, args10]);
}
function testResultArgs() {
ipc.emit("testResultArgs", [6666], function (r1) {
msg('r1', r1)
})
}
ipc.on('onTestName1', function (param1, param2, param3) {
});
ipc.on('onTestName2', function (param1, param2, param3) {
});
function bindFunc() {
energy.funcName();
}
function bindField() {
clearMsg();
msg('stringField', energy.stringField);
msg('intField', energy.intField);
msg('doubleField', energy.doubleField);
msg('boolField', energy.boolField);
}
</script>
</head>
<body style="margin: 0px;padding: 0px;">
<p>
<h3>process-message</h3></p>
<p><a target="_blank" href="ipc-event.html">open</a></p>
<p>
<button onclick="ipcEmit()">ipcEmit</button>
<button onclick="autoIpcEmit()">自动-ipcEmit</button>
<input id="time" value="0">
<br>
<button onclick="testInArgs()">testInArgs</button>
<button onclick="testResultArgs()">testResultArgs</button>
<br>
<button onclick="bindFunc()">bindFunc</button>
<button onclick="bindField()">bindField</button>
</p>
<p id="msgHtml"></p>
</body>
<script type="application/javascript">
let msgHtml = document.getElementById("msgHtml");
function msg(...vvv) {
let str = msgHtml.innerHTML;
for (let i = 0; i < vvv.length; i++) {
str = str + " " + vvv[i];
}
str += "<br>";
msgHtml.innerHTML = str;
}
function clearMsg() {
msgHtml.innerHTML = "";
}
msg("ipc-event: 页面加载完成...");
</script>
</html>