@taole/dev-helper 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/open-diandian.umd.js +116 -2
- package/open-diandian/index.js +116 -2
- package/package.json +1 -1
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
const appInfoMap = {
|
|
9
9
|
'wx6cd4c28b58e8737f': { // 点点开黑
|
|
10
10
|
app_name: '点点开黑',
|
|
11
|
+
openinstall_app_key: 'qrsz57',
|
|
12
|
+
openinstall_script: 'https://res.opstatistics.com/openinstall-qrsz57.js',
|
|
11
13
|
link_ios: "com.tuwan.diandian://openPage",
|
|
12
14
|
link_android: "intent://diandain:8888/splash#Intent;scheme=taole;package=com.tuwan.yw;S.browser_fallback_url=https://sj.qq.com/myapp/detail.htm?apkName=com.tuwan.yw;end",
|
|
13
15
|
link_harmony: "taole://diandain:8888/splash",
|
|
@@ -33,6 +35,58 @@
|
|
|
33
35
|
fallback_fin_5s: 'https://sj.qq.com/appdetail/com.tuwan.game.werewolf',
|
|
34
36
|
},
|
|
35
37
|
};
|
|
38
|
+
// OpenInstall 初始化对应页面访问,多个组件共用同一个实例。
|
|
39
|
+
const openInstallInstances = new Map();
|
|
40
|
+
function resolveOpenInstallData() {
|
|
41
|
+
const data = {};
|
|
42
|
+
const match = window.location.search.substr(1).match(/(^|&)bizInfo=([^&]*)(&|$)/i);
|
|
43
|
+
let bizInfo = match && match[2];
|
|
44
|
+
if (bizInfo) {
|
|
45
|
+
try {
|
|
46
|
+
bizInfo = decodeURIComponent(bizInfo);
|
|
47
|
+
} catch (error) {}
|
|
48
|
+
try {
|
|
49
|
+
bizInfo = JSON.parse(bizInfo);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
bizInfo = null;
|
|
52
|
+
}
|
|
53
|
+
data.bizInfo = (bizInfo && bizInfo.data) || '';
|
|
54
|
+
data.bizShowTime = Date.now();
|
|
55
|
+
data.url = window.location.href;
|
|
56
|
+
}
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
function resolveOpenInstall(appInfo) {
|
|
60
|
+
const key = appInfo && appInfo.openinstall_app_key;
|
|
61
|
+
if (!key || !appInfo.openinstall_script) {
|
|
62
|
+
return Promise.reject(new Error('OpenInstall is not configured for this app'));
|
|
63
|
+
}
|
|
64
|
+
if (openInstallInstances.has(key)) return openInstallInstances.get(key);
|
|
65
|
+
const promise = new Promise((resolve, reject) => {
|
|
66
|
+
const timer = setTimeout(() => reject(new Error('OpenInstall initialization timed out')), 10000);
|
|
67
|
+
const fail = error => { clearTimeout(timer); reject(error); };
|
|
68
|
+
const initialize = () => {
|
|
69
|
+
try {
|
|
70
|
+
if (!window.OpenInstall) throw new Error('OpenInstall SDK is unavailable');
|
|
71
|
+
new window.OpenInstall({ appKey: key, onready: function () { clearTimeout(timer); resolve(this); } },
|
|
72
|
+
resolveOpenInstallData());
|
|
73
|
+
} catch (error) { fail(error); }
|
|
74
|
+
};
|
|
75
|
+
if (window.OpenInstall) {
|
|
76
|
+
initialize();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const script = document.createElement('script');
|
|
80
|
+
script.src = appInfo.openinstall_script;
|
|
81
|
+
script.charset = 'UTF-8';
|
|
82
|
+
script.onload = initialize;
|
|
83
|
+
script.onerror = () => { script.remove(); fail(new Error('load OpenInstall error')); };
|
|
84
|
+
document.head.appendChild(script);
|
|
85
|
+
});
|
|
86
|
+
openInstallInstances.set(key, promise);
|
|
87
|
+
promise.catch(() => { if (openInstallInstances.get(key) === promise) openInstallInstances.delete(key); });
|
|
88
|
+
return promise;
|
|
89
|
+
}
|
|
36
90
|
function resolveTwKit() {
|
|
37
91
|
if (window.twKit) {
|
|
38
92
|
return;
|
|
@@ -56,7 +110,7 @@
|
|
|
56
110
|
return class extends HTMLElement {
|
|
57
111
|
// fallback-time: 3000, 跳转fallback链接的延迟时间,单位毫秒 不传或者传0等价于3000ms
|
|
58
112
|
static get observedAttributes() {
|
|
59
|
-
return ['appid', 'extinfo', 'debug', 'scene', 'fallback-time'];
|
|
113
|
+
return ['appid', 'extinfo', 'debug', 'scene', 'fallback-time', 'openinstall'];
|
|
60
114
|
}
|
|
61
115
|
constructor() {
|
|
62
116
|
super();
|
|
@@ -84,6 +138,10 @@
|
|
|
84
138
|
this._clipboardText = '';
|
|
85
139
|
this._clipboardTextPs = null;
|
|
86
140
|
this._clipboardTextTimer = null;
|
|
141
|
+
this._openInstall = null;
|
|
142
|
+
this._openInstallPromise = null;
|
|
143
|
+
this._openInstallKey = '';
|
|
144
|
+
this._openInstallPending = false;
|
|
87
145
|
}
|
|
88
146
|
_log(...args) {
|
|
89
147
|
if (this._debug) {
|
|
@@ -97,6 +155,8 @@
|
|
|
97
155
|
connectedCallback() {
|
|
98
156
|
this._log("connectedCallback");
|
|
99
157
|
this._isConnected = true;
|
|
158
|
+
this._updateTagAttr();
|
|
159
|
+
this._initOpenInstall();
|
|
100
160
|
if (this._isWechat) {
|
|
101
161
|
this._genTemplate();
|
|
102
162
|
if (!this._openAppTag) {
|
|
@@ -130,6 +190,10 @@
|
|
|
130
190
|
bubbles: true,
|
|
131
191
|
composed: true,
|
|
132
192
|
}));
|
|
193
|
+
if (this._useOpenInstall()) {
|
|
194
|
+
this._wakeupOpenInstall();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
133
197
|
if (this._isHarmony || this._isSceneLink()) {
|
|
134
198
|
this._showOpenInBrowserHint();
|
|
135
199
|
return;
|
|
@@ -216,7 +280,12 @@
|
|
|
216
280
|
this._initClipboardText();
|
|
217
281
|
}
|
|
218
282
|
}
|
|
219
|
-
_handleAlinkClick() {
|
|
283
|
+
_handleAlinkClick(event) {
|
|
284
|
+
if (this._useOpenInstall()) {
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
this._wakeupOpenInstall();
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
220
289
|
this._writeClickboard();
|
|
221
290
|
if (this._alink_link != this._alink_fallback) {
|
|
222
291
|
this._log("this._alink is clicked");
|
|
@@ -237,6 +306,7 @@
|
|
|
237
306
|
disconnectedCallback() {
|
|
238
307
|
this._log("disconnectedCallback");
|
|
239
308
|
this._isConnected = false;
|
|
309
|
+
this._openInstallPending = false;
|
|
240
310
|
if (this._openAppTag) {
|
|
241
311
|
this._openAppTag.remove();
|
|
242
312
|
this._openAppTag = null;
|
|
@@ -257,6 +327,40 @@
|
|
|
257
327
|
this._fin5sVisHandler = null;
|
|
258
328
|
}
|
|
259
329
|
}
|
|
330
|
+
_useOpenInstall() {
|
|
331
|
+
return this.hasAttribute('openinstall') && !!(this._appInfo && this._appInfo.openinstall_app_key);
|
|
332
|
+
}
|
|
333
|
+
_initOpenInstall() {
|
|
334
|
+
if (!this._isConnected || this._isApp || !this._isMobile || !this._useOpenInstall()) return;
|
|
335
|
+
const key = this._appInfo.openinstall_app_key;
|
|
336
|
+
if (this._openInstallKey === key && this._openInstallPromise) return;
|
|
337
|
+
this._openInstallKey = key;
|
|
338
|
+
this._openInstall = null;
|
|
339
|
+
const promise = resolveOpenInstall(this._appInfo);
|
|
340
|
+
this._openInstallPromise = promise;
|
|
341
|
+
promise.then(instance => {
|
|
342
|
+
if (this._openInstallPromise !== promise) return;
|
|
343
|
+
this._openInstall = instance;
|
|
344
|
+
if (this._openInstallPending && this._isConnected && this._useOpenInstall()) {
|
|
345
|
+
this._openInstallPending = false;
|
|
346
|
+
instance.wakeupOrInstall();
|
|
347
|
+
}
|
|
348
|
+
}).catch(error => {
|
|
349
|
+
if (this._openInstallPromise !== promise) return;
|
|
350
|
+
this._openInstallPromise = null;
|
|
351
|
+
this._openInstallPending = false;
|
|
352
|
+
this._log('OpenInstall initialization failed', error);
|
|
353
|
+
this.dispatchEvent(new CustomEvent('openinstallerror', { detail: { error }, bubbles: true, composed: true }));
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
_wakeupOpenInstall() {
|
|
357
|
+
if (this._openInstall) {
|
|
358
|
+
this._openInstall.wakeupOrInstall();
|
|
359
|
+
} else {
|
|
360
|
+
this._openInstallPending = true;
|
|
361
|
+
this._initOpenInstall();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
260
364
|
_initClipboardText() {
|
|
261
365
|
// 延迟20ms执行,如果20ms后卸载了,直接不执行了
|
|
262
366
|
this._clipboardTextTimer = setTimeout(() => {
|
|
@@ -375,6 +479,12 @@
|
|
|
375
479
|
this._debug = this.getAttribute('debug') !== null;
|
|
376
480
|
this._appid = this.getAttribute('appid') || this._defaultAppid;
|
|
377
481
|
this._appInfo = appInfoMap[this._appid];
|
|
482
|
+
if (this._openInstallKey && (!this._appInfo || this._openInstallKey !== this._appInfo.openinstall_app_key)) {
|
|
483
|
+
this._openInstallKey = '';
|
|
484
|
+
this._openInstall = null;
|
|
485
|
+
this._openInstallPromise = null;
|
|
486
|
+
this._openInstallPending = false;
|
|
487
|
+
}
|
|
378
488
|
var fallbackTime = this.getAttribute('fallback-time');
|
|
379
489
|
if (fallbackTime == null || fallbackTime === '' || isNaN(Number(fallbackTime))) {
|
|
380
490
|
this._fallbackTime = 3000;
|
|
@@ -386,6 +496,10 @@
|
|
|
386
496
|
console.error('open-diandian: appid not supported', this._appid);
|
|
387
497
|
return;
|
|
388
498
|
}
|
|
499
|
+
if (this._isConnected) {
|
|
500
|
+
if (!this._useOpenInstall()) this._openInstallPending = false;
|
|
501
|
+
this._initOpenInstall();
|
|
502
|
+
}
|
|
389
503
|
this._log('open-diandian: appInfo', this._appInfo);
|
|
390
504
|
if (this._isIOS) {
|
|
391
505
|
this._alink_fallback = this._appInfo.fallback_link_ios;
|
package/open-diandian/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const appInfoMap = {
|
|
4
4
|
'wx6cd4c28b58e8737f': { // 点点开黑
|
|
5
5
|
app_name: '点点开黑',
|
|
6
|
+
openinstall_app_key: 'qrsz57',
|
|
7
|
+
openinstall_script: 'https://res.opstatistics.com/openinstall-qrsz57.js',
|
|
6
8
|
link_ios: "com.tuwan.diandian://openPage",
|
|
7
9
|
link_android: "intent://diandain:8888/splash#Intent;scheme=taole;package=com.tuwan.yw;S.browser_fallback_url=https://sj.qq.com/myapp/detail.htm?apkName=com.tuwan.yw;end",
|
|
8
10
|
link_harmony: "taole://diandain:8888/splash",
|
|
@@ -28,6 +30,58 @@ const appInfoMap = {
|
|
|
28
30
|
fallback_fin_5s: 'https://sj.qq.com/appdetail/com.tuwan.game.werewolf',
|
|
29
31
|
},
|
|
30
32
|
}
|
|
33
|
+
// OpenInstall 初始化对应页面访问,多个组件共用同一个实例。
|
|
34
|
+
const openInstallInstances = new Map();
|
|
35
|
+
function resolveOpenInstallData() {
|
|
36
|
+
const data = {};
|
|
37
|
+
const match = window.location.search.substr(1).match(/(^|&)bizInfo=([^&]*)(&|$)/i);
|
|
38
|
+
let bizInfo = match && match[2];
|
|
39
|
+
if (bizInfo) {
|
|
40
|
+
try {
|
|
41
|
+
bizInfo = decodeURIComponent(bizInfo);
|
|
42
|
+
} catch (error) {}
|
|
43
|
+
try {
|
|
44
|
+
bizInfo = JSON.parse(bizInfo);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
bizInfo = null;
|
|
47
|
+
}
|
|
48
|
+
data.bizInfo = (bizInfo && bizInfo.data) || '';
|
|
49
|
+
data.bizShowTime = Date.now();
|
|
50
|
+
data.url = window.location.href;
|
|
51
|
+
}
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
function resolveOpenInstall(appInfo) {
|
|
55
|
+
const key = appInfo && appInfo.openinstall_app_key;
|
|
56
|
+
if (!key || !appInfo.openinstall_script) {
|
|
57
|
+
return Promise.reject(new Error('OpenInstall is not configured for this app'));
|
|
58
|
+
}
|
|
59
|
+
if (openInstallInstances.has(key)) return openInstallInstances.get(key);
|
|
60
|
+
const promise = new Promise((resolve, reject) => {
|
|
61
|
+
const timer = setTimeout(() => reject(new Error('OpenInstall initialization timed out')), 10000);
|
|
62
|
+
const fail = error => { clearTimeout(timer); reject(error); };
|
|
63
|
+
const initialize = () => {
|
|
64
|
+
try {
|
|
65
|
+
if (!window.OpenInstall) throw new Error('OpenInstall SDK is unavailable');
|
|
66
|
+
new window.OpenInstall({ appKey: key, onready: function () { clearTimeout(timer); resolve(this); } },
|
|
67
|
+
resolveOpenInstallData());
|
|
68
|
+
} catch (error) { fail(error); }
|
|
69
|
+
};
|
|
70
|
+
if (window.OpenInstall) {
|
|
71
|
+
initialize();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const script = document.createElement('script');
|
|
75
|
+
script.src = appInfo.openinstall_script;
|
|
76
|
+
script.charset = 'UTF-8';
|
|
77
|
+
script.onload = initialize;
|
|
78
|
+
script.onerror = () => { script.remove(); fail(new Error('load OpenInstall error')); };
|
|
79
|
+
document.head.appendChild(script);
|
|
80
|
+
});
|
|
81
|
+
openInstallInstances.set(key, promise);
|
|
82
|
+
promise.catch(() => { if (openInstallInstances.get(key) === promise) openInstallInstances.delete(key); });
|
|
83
|
+
return promise;
|
|
84
|
+
}
|
|
31
85
|
function resolveTwKit() {
|
|
32
86
|
if (window.twKit) {
|
|
33
87
|
return;
|
|
@@ -51,7 +105,7 @@ function createOpenDiandianElementClass() {
|
|
|
51
105
|
return class extends HTMLElement {
|
|
52
106
|
// fallback-time: 3000, 跳转fallback链接的延迟时间,单位毫秒 不传或者传0等价于3000ms
|
|
53
107
|
static get observedAttributes() {
|
|
54
|
-
return ['appid', 'extinfo', 'debug', 'scene', 'fallback-time'];
|
|
108
|
+
return ['appid', 'extinfo', 'debug', 'scene', 'fallback-time', 'openinstall'];
|
|
55
109
|
}
|
|
56
110
|
constructor() {
|
|
57
111
|
super();
|
|
@@ -79,6 +133,10 @@ function createOpenDiandianElementClass() {
|
|
|
79
133
|
this._clipboardText = '';
|
|
80
134
|
this._clipboardTextPs = null;
|
|
81
135
|
this._clipboardTextTimer = null;
|
|
136
|
+
this._openInstall = null;
|
|
137
|
+
this._openInstallPromise = null;
|
|
138
|
+
this._openInstallKey = '';
|
|
139
|
+
this._openInstallPending = false;
|
|
82
140
|
}
|
|
83
141
|
_log(...args) {
|
|
84
142
|
if (this._debug) {
|
|
@@ -92,6 +150,8 @@ function createOpenDiandianElementClass() {
|
|
|
92
150
|
connectedCallback() {
|
|
93
151
|
this._log("connectedCallback")
|
|
94
152
|
this._isConnected = true;
|
|
153
|
+
this._updateTagAttr();
|
|
154
|
+
this._initOpenInstall();
|
|
95
155
|
if (this._isWechat) {
|
|
96
156
|
this._genTemplate();
|
|
97
157
|
if (!this._openAppTag) {
|
|
@@ -125,6 +185,10 @@ function createOpenDiandianElementClass() {
|
|
|
125
185
|
bubbles: true,
|
|
126
186
|
composed: true,
|
|
127
187
|
}));
|
|
188
|
+
if (this._useOpenInstall()) {
|
|
189
|
+
this._wakeupOpenInstall();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
128
192
|
if (this._isHarmony || this._isSceneLink()) {
|
|
129
193
|
this._showOpenInBrowserHint();
|
|
130
194
|
return;
|
|
@@ -211,7 +275,12 @@ function createOpenDiandianElementClass() {
|
|
|
211
275
|
this._initClipboardText();
|
|
212
276
|
}
|
|
213
277
|
}
|
|
214
|
-
_handleAlinkClick() {
|
|
278
|
+
_handleAlinkClick(event) {
|
|
279
|
+
if (this._useOpenInstall()) {
|
|
280
|
+
event.preventDefault();
|
|
281
|
+
this._wakeupOpenInstall();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
215
284
|
this._writeClickboard();
|
|
216
285
|
if (this._alink_link != this._alink_fallback) {
|
|
217
286
|
this._log("this._alink is clicked");
|
|
@@ -232,6 +301,7 @@ function createOpenDiandianElementClass() {
|
|
|
232
301
|
disconnectedCallback() {
|
|
233
302
|
this._log("disconnectedCallback")
|
|
234
303
|
this._isConnected = false;
|
|
304
|
+
this._openInstallPending = false;
|
|
235
305
|
if (this._openAppTag) {
|
|
236
306
|
this._openAppTag.remove();
|
|
237
307
|
this._openAppTag = null;
|
|
@@ -252,6 +322,40 @@ function createOpenDiandianElementClass() {
|
|
|
252
322
|
this._fin5sVisHandler = null;
|
|
253
323
|
}
|
|
254
324
|
}
|
|
325
|
+
_useOpenInstall() {
|
|
326
|
+
return this.hasAttribute('openinstall') && !!(this._appInfo && this._appInfo.openinstall_app_key);
|
|
327
|
+
}
|
|
328
|
+
_initOpenInstall() {
|
|
329
|
+
if (!this._isConnected || this._isApp || !this._isMobile || !this._useOpenInstall()) return;
|
|
330
|
+
const key = this._appInfo.openinstall_app_key;
|
|
331
|
+
if (this._openInstallKey === key && this._openInstallPromise) return;
|
|
332
|
+
this._openInstallKey = key;
|
|
333
|
+
this._openInstall = null;
|
|
334
|
+
const promise = resolveOpenInstall(this._appInfo);
|
|
335
|
+
this._openInstallPromise = promise;
|
|
336
|
+
promise.then(instance => {
|
|
337
|
+
if (this._openInstallPromise !== promise) return;
|
|
338
|
+
this._openInstall = instance;
|
|
339
|
+
if (this._openInstallPending && this._isConnected && this._useOpenInstall()) {
|
|
340
|
+
this._openInstallPending = false;
|
|
341
|
+
instance.wakeupOrInstall();
|
|
342
|
+
}
|
|
343
|
+
}).catch(error => {
|
|
344
|
+
if (this._openInstallPromise !== promise) return;
|
|
345
|
+
this._openInstallPromise = null;
|
|
346
|
+
this._openInstallPending = false;
|
|
347
|
+
this._log('OpenInstall initialization failed', error);
|
|
348
|
+
this.dispatchEvent(new CustomEvent('openinstallerror', { detail: { error }, bubbles: true, composed: true }));
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
_wakeupOpenInstall() {
|
|
352
|
+
if (this._openInstall) {
|
|
353
|
+
this._openInstall.wakeupOrInstall();
|
|
354
|
+
} else {
|
|
355
|
+
this._openInstallPending = true;
|
|
356
|
+
this._initOpenInstall();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
255
359
|
_initClipboardText() {
|
|
256
360
|
// 延迟20ms执行,如果20ms后卸载了,直接不执行了
|
|
257
361
|
this._clipboardTextTimer = setTimeout(() => {
|
|
@@ -370,6 +474,12 @@ function createOpenDiandianElementClass() {
|
|
|
370
474
|
this._debug = this.getAttribute('debug') !== null;
|
|
371
475
|
this._appid = this.getAttribute('appid') || this._defaultAppid;
|
|
372
476
|
this._appInfo = appInfoMap[this._appid];
|
|
477
|
+
if (this._openInstallKey && (!this._appInfo || this._openInstallKey !== this._appInfo.openinstall_app_key)) {
|
|
478
|
+
this._openInstallKey = '';
|
|
479
|
+
this._openInstall = null;
|
|
480
|
+
this._openInstallPromise = null;
|
|
481
|
+
this._openInstallPending = false;
|
|
482
|
+
}
|
|
373
483
|
var fallbackTime = this.getAttribute('fallback-time');
|
|
374
484
|
if (fallbackTime == null || fallbackTime === '' || isNaN(Number(fallbackTime))) {
|
|
375
485
|
this._fallbackTime = 3000;
|
|
@@ -381,6 +491,10 @@ function createOpenDiandianElementClass() {
|
|
|
381
491
|
console.error('open-diandian: appid not supported', this._appid);
|
|
382
492
|
return;
|
|
383
493
|
}
|
|
494
|
+
if (this._isConnected) {
|
|
495
|
+
if (!this._useOpenInstall()) this._openInstallPending = false;
|
|
496
|
+
this._initOpenInstall();
|
|
497
|
+
}
|
|
384
498
|
this._log('open-diandian: appInfo', this._appInfo);
|
|
385
499
|
if (this._isIOS) {
|
|
386
500
|
this._alink_fallback = this._appInfo.fallback_link_ios;
|