@taole/dev-helper 0.1.24 → 0.1.26
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 +55 -27
- package/open-diandian/index.js +55 -27
- package/package.json +1 -1
|
@@ -37,6 +37,25 @@
|
|
|
37
37
|
};
|
|
38
38
|
// OpenInstall 初始化对应页面访问,多个组件共用同一个实例。
|
|
39
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
|
+
}
|
|
40
59
|
function resolveOpenInstall(appInfo) {
|
|
41
60
|
const key = appInfo && appInfo.openinstall_app_key;
|
|
42
61
|
if (!key || !appInfo.openinstall_script) {
|
|
@@ -50,7 +69,7 @@
|
|
|
50
69
|
try {
|
|
51
70
|
if (!window.OpenInstall) throw new Error('OpenInstall SDK is unavailable');
|
|
52
71
|
new window.OpenInstall({ appKey: key, onready: function () { clearTimeout(timer); resolve(this); } },
|
|
53
|
-
|
|
72
|
+
resolveOpenInstallData());
|
|
54
73
|
} catch (error) { fail(error); }
|
|
55
74
|
};
|
|
56
75
|
if (window.OpenInstall) {
|
|
@@ -208,9 +227,7 @@
|
|
|
208
227
|
return;
|
|
209
228
|
}
|
|
210
229
|
this._log('open-diandian: final fallback go', this._alink_fin_5s);
|
|
211
|
-
|
|
212
|
-
lnkFinal.href = this._alink_fin_5s;
|
|
213
|
-
lnkFinal.click();
|
|
230
|
+
this._openFallbackLink(this._alink_fin_5s);
|
|
214
231
|
}, 5000);
|
|
215
232
|
}
|
|
216
233
|
});
|
|
@@ -242,11 +259,7 @@
|
|
|
242
259
|
if (document.hidden) {
|
|
243
260
|
if (this._clickLink) {
|
|
244
261
|
this._log("open app successfully");
|
|
245
|
-
|
|
246
|
-
clearTimeout(this._alink_click_timer);
|
|
247
|
-
this._alink_click_timer = null;
|
|
248
|
-
}
|
|
249
|
-
this._clickLink = false;
|
|
262
|
+
this._cancelLaunchFallback();
|
|
250
263
|
}
|
|
251
264
|
}
|
|
252
265
|
});
|
|
@@ -262,32 +275,44 @@
|
|
|
262
275
|
}
|
|
263
276
|
}
|
|
264
277
|
_handleAlinkClick(event) {
|
|
278
|
+
this._writeClickboard();
|
|
279
|
+
this._cancelLaunchFallback();
|
|
280
|
+
if (this._alink_link === this._alink_fallback) {
|
|
281
|
+
// 没有可用的拉端链接,点击本身就是兜底。
|
|
282
|
+
if (this._useOpenInstall()) {
|
|
283
|
+
event.preventDefault();
|
|
284
|
+
this._wakeupOpenInstall();
|
|
285
|
+
}
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// 先使用原链接拉端,页面没有隐藏才执行兜底。
|
|
289
|
+
this._clickLink = true;
|
|
290
|
+
this._alink_click_timer = setTimeout(() => {
|
|
291
|
+
this._cancelLaunchFallback();
|
|
292
|
+
if (!this._isConnected || document.hidden) return;
|
|
293
|
+
this._log('open app timed out, run fallback');
|
|
294
|
+
this._openFallbackLink(this._alink_fallback);
|
|
295
|
+
}, this._fallbackTime);
|
|
296
|
+
}
|
|
297
|
+
_cancelLaunchFallback() {
|
|
298
|
+
clearTimeout(this._alink_click_timer);
|
|
299
|
+
this._alink_click_timer = null;
|
|
300
|
+
this._clickLink = false;
|
|
301
|
+
}
|
|
302
|
+
_openFallbackLink(href) {
|
|
265
303
|
if (this._useOpenInstall()) {
|
|
266
|
-
event.preventDefault();
|
|
267
304
|
this._wakeupOpenInstall();
|
|
268
305
|
return;
|
|
269
306
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
// 端外使用scheme打开app,3秒内如果页面有隐藏过,那么认为拉端成功了,否则跳转到fallback链接
|
|
274
|
-
if (this._alink_click_timer) {
|
|
275
|
-
clearTimeout(this._alink_click_timer);
|
|
276
|
-
}
|
|
277
|
-
this._clickLink = true;
|
|
278
|
-
this._alink_click_timer = setTimeout(() => {
|
|
279
|
-
this._log("3s timeout, open app failed, jump to fallback link");
|
|
280
|
-
this._alink_click_timer = null;
|
|
281
|
-
var tmplnk = document.createElement("a");
|
|
282
|
-
tmplnk.href = this._alink_fallback;
|
|
283
|
-
tmplnk.click();
|
|
284
|
-
}, this._fallbackTime);
|
|
285
|
-
}
|
|
307
|
+
const link = document.createElement('a');
|
|
308
|
+
link.href = href;
|
|
309
|
+
link.click();
|
|
286
310
|
}
|
|
287
311
|
disconnectedCallback() {
|
|
288
312
|
this._log("disconnectedCallback");
|
|
289
313
|
this._isConnected = false;
|
|
290
314
|
this._openInstallPending = false;
|
|
315
|
+
this._cancelLaunchFallback();
|
|
291
316
|
if (this._openAppTag) {
|
|
292
317
|
this._openAppTag.remove();
|
|
293
318
|
this._openAppTag = null;
|
|
@@ -501,7 +526,10 @@
|
|
|
501
526
|
this._openAppTag.setAttribute('appid', this._appid);
|
|
502
527
|
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
503
528
|
} else if (this._alink) {
|
|
504
|
-
|
|
529
|
+
// 开启 OpenInstall 时,由组件统一触发兜底,避免 Android Intent 直接跳转。
|
|
530
|
+
this._alink.href = this._useOpenInstall() && this._alink_link.startsWith('intent:')
|
|
531
|
+
? this._alink_link.replace(/;S\.browser_fallback_url=[^;]*/, '')
|
|
532
|
+
: this._alink_link;
|
|
505
533
|
}
|
|
506
534
|
}
|
|
507
535
|
};
|
package/open-diandian/index.js
CHANGED
|
@@ -32,6 +32,25 @@ const appInfoMap = {
|
|
|
32
32
|
}
|
|
33
33
|
// OpenInstall 初始化对应页面访问,多个组件共用同一个实例。
|
|
34
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
|
+
}
|
|
35
54
|
function resolveOpenInstall(appInfo) {
|
|
36
55
|
const key = appInfo && appInfo.openinstall_app_key;
|
|
37
56
|
if (!key || !appInfo.openinstall_script) {
|
|
@@ -45,7 +64,7 @@ function resolveOpenInstall(appInfo) {
|
|
|
45
64
|
try {
|
|
46
65
|
if (!window.OpenInstall) throw new Error('OpenInstall SDK is unavailable');
|
|
47
66
|
new window.OpenInstall({ appKey: key, onready: function () { clearTimeout(timer); resolve(this); } },
|
|
48
|
-
|
|
67
|
+
resolveOpenInstallData());
|
|
49
68
|
} catch (error) { fail(error); }
|
|
50
69
|
};
|
|
51
70
|
if (window.OpenInstall) {
|
|
@@ -203,9 +222,7 @@ function createOpenDiandianElementClass() {
|
|
|
203
222
|
return;
|
|
204
223
|
}
|
|
205
224
|
this._log('open-diandian: final fallback go', this._alink_fin_5s);
|
|
206
|
-
|
|
207
|
-
lnkFinal.href = this._alink_fin_5s;
|
|
208
|
-
lnkFinal.click();
|
|
225
|
+
this._openFallbackLink(this._alink_fin_5s);
|
|
209
226
|
}, 5000);
|
|
210
227
|
}
|
|
211
228
|
});
|
|
@@ -237,11 +254,7 @@ function createOpenDiandianElementClass() {
|
|
|
237
254
|
if (document.hidden) {
|
|
238
255
|
if (this._clickLink) {
|
|
239
256
|
this._log("open app successfully");
|
|
240
|
-
|
|
241
|
-
clearTimeout(this._alink_click_timer);
|
|
242
|
-
this._alink_click_timer = null;
|
|
243
|
-
}
|
|
244
|
-
this._clickLink = false;
|
|
257
|
+
this._cancelLaunchFallback();
|
|
245
258
|
}
|
|
246
259
|
}
|
|
247
260
|
});
|
|
@@ -257,32 +270,44 @@ function createOpenDiandianElementClass() {
|
|
|
257
270
|
}
|
|
258
271
|
}
|
|
259
272
|
_handleAlinkClick(event) {
|
|
273
|
+
this._writeClickboard();
|
|
274
|
+
this._cancelLaunchFallback();
|
|
275
|
+
if (this._alink_link === this._alink_fallback) {
|
|
276
|
+
// 没有可用的拉端链接,点击本身就是兜底。
|
|
277
|
+
if (this._useOpenInstall()) {
|
|
278
|
+
event.preventDefault();
|
|
279
|
+
this._wakeupOpenInstall();
|
|
280
|
+
}
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
// 先使用原链接拉端,页面没有隐藏才执行兜底。
|
|
284
|
+
this._clickLink = true;
|
|
285
|
+
this._alink_click_timer = setTimeout(() => {
|
|
286
|
+
this._cancelLaunchFallback();
|
|
287
|
+
if (!this._isConnected || document.hidden) return;
|
|
288
|
+
this._log('open app timed out, run fallback');
|
|
289
|
+
this._openFallbackLink(this._alink_fallback);
|
|
290
|
+
}, this._fallbackTime);
|
|
291
|
+
}
|
|
292
|
+
_cancelLaunchFallback() {
|
|
293
|
+
clearTimeout(this._alink_click_timer);
|
|
294
|
+
this._alink_click_timer = null;
|
|
295
|
+
this._clickLink = false;
|
|
296
|
+
}
|
|
297
|
+
_openFallbackLink(href) {
|
|
260
298
|
if (this._useOpenInstall()) {
|
|
261
|
-
event.preventDefault();
|
|
262
299
|
this._wakeupOpenInstall();
|
|
263
300
|
return;
|
|
264
301
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
// 端外使用scheme打开app,3秒内如果页面有隐藏过,那么认为拉端成功了,否则跳转到fallback链接
|
|
269
|
-
if (this._alink_click_timer) {
|
|
270
|
-
clearTimeout(this._alink_click_timer);
|
|
271
|
-
}
|
|
272
|
-
this._clickLink = true;
|
|
273
|
-
this._alink_click_timer = setTimeout(() => {
|
|
274
|
-
this._log("3s timeout, open app failed, jump to fallback link");
|
|
275
|
-
this._alink_click_timer = null;
|
|
276
|
-
var tmplnk = document.createElement("a");
|
|
277
|
-
tmplnk.href = this._alink_fallback;
|
|
278
|
-
tmplnk.click();
|
|
279
|
-
}, this._fallbackTime);
|
|
280
|
-
}
|
|
302
|
+
const link = document.createElement('a');
|
|
303
|
+
link.href = href;
|
|
304
|
+
link.click();
|
|
281
305
|
}
|
|
282
306
|
disconnectedCallback() {
|
|
283
307
|
this._log("disconnectedCallback")
|
|
284
308
|
this._isConnected = false;
|
|
285
309
|
this._openInstallPending = false;
|
|
310
|
+
this._cancelLaunchFallback();
|
|
286
311
|
if (this._openAppTag) {
|
|
287
312
|
this._openAppTag.remove();
|
|
288
313
|
this._openAppTag = null;
|
|
@@ -496,7 +521,10 @@ function createOpenDiandianElementClass() {
|
|
|
496
521
|
this._openAppTag.setAttribute('appid', this._appid);
|
|
497
522
|
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
498
523
|
} else if (this._alink) {
|
|
499
|
-
|
|
524
|
+
// 开启 OpenInstall 时,由组件统一触发兜底,避免 Android Intent 直接跳转。
|
|
525
|
+
this._alink.href = this._useOpenInstall() && this._alink_link.startsWith('intent:')
|
|
526
|
+
? this._alink_link.replace(/;S\.browser_fallback_url=[^;]*/, '')
|
|
527
|
+
: this._alink_link;
|
|
500
528
|
}
|
|
501
529
|
}
|
|
502
530
|
};
|