-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
116 lines (95 loc) · 3.58 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="format-detection" content="telephone = no">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>测试</title>
<!-- <script type="text/javascript" src="hYi-sdk.js"></script>-->
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/751496032/[email protected]/hYi-sdk.js"></script>
<script type="text/javascript">
// window.config({debug: true})
// 使用方式一
function test1() {
takeNativeActionWithCallback("login", {
targetClassName: "com.xxx"
}, {
success: function (res) {
console.log("success res: " + JSON.stringify(res))
},
fail: function (res) {
console.log("fail res: " + JSON.stringify(res))
},
complete: function () {
console.log("complete res ")
}
})
}
// 使用方式二
function test2() {
window.takeNativeActionWithCallback("login",
{
targetClassName: "com.xxx222",
success: function (res) {
console.log("success res: " + JSON.stringify(res))
alert("success:登录成功")
handleLoginSuccess(res)
},
fail: function (res) {
console.log("fail res: " + JSON.stringify(res))
},
complete: function () {
console.log("complete res ")
setTimeout(function () {
alert("complete:完成登录")
}, 500)
}
})
}
function handleLoginSuccess(res) {
console.log("success res: " + JSON.stringify(res))
let element = document.createElement("div");
element.appendChild(document.createTextNode("userName: lili"));
document.querySelector('.loginContent').appendChild(element);
}
window.onload = function () {
let btn = document.querySelector('.btn')
btn.addEventListener('click', function () {
window.test2();
}, true)
let callbackBtn = document.querySelector('.callback')
callbackBtn.addEventListener('click', function () {
if (Object.keys(allCallbacks).length === 0) {
alert("没有回调函数")
return
}
Object.keys(allCallbacks).forEach(function (key) {
window.nativetoJsCallback(key, {result: "ok"})
if (key.startsWith(window.constants.CALLBACK_SUCCESS)) {
handleLoginSuccess({accountName: '测试'})
}
})
})
}
</script>
<style type="text/css">
img {
width: 100%;
margin-top: 10px;
}
</style>
</head>
<body>
<button class="btn">请求</button>
<button class="callback">手动回调</button>
<div class="loginContent"></div>
<div>
<img src="https://img0.baidu.com/it/u=1283434782,3467728248&fm=26&fmt=auto">
</div>
<div>
<img src="https://img2.baidu.com/it/u=2173052120,291691545&fm=26&fmt=auto">
</div>
</body>
</html>