@taole/dev-helper 0.1.28 → 0.1.30
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/bin/dev-helper.js +1 -1
- package/dist/open-diandian.umd.js +67 -63
- package/open-diandian/index.js +67 -63
- package/package.json +1 -1
package/bin/dev-helper.js
CHANGED
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
this._debug = false;
|
|
118
118
|
this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
|
|
119
119
|
this._openAppTag = null;
|
|
120
|
-
this.
|
|
120
|
+
this._wechatFallbackRequest = null;
|
|
121
121
|
this._fallbackTime = 3000;
|
|
122
122
|
this._appid = '';
|
|
123
123
|
this._appInfo = null;
|
|
@@ -164,14 +164,6 @@
|
|
|
164
164
|
this._openAppTag = document.createElement('wx-open-launch-app');
|
|
165
165
|
this._openAppTag.style.background = "transparent";
|
|
166
166
|
this._openAppTag.style.opacity = 0;
|
|
167
|
-
this._openInstallButton = document.createElement('button');
|
|
168
|
-
this._openInstallButton.type = 'button';
|
|
169
|
-
this._openInstallButton.setAttribute('aria-label', '打开 App');
|
|
170
|
-
this._openInstallButton.style.width = '100%';
|
|
171
|
-
this._openInstallButton.style.height = '100%';
|
|
172
|
-
this._openInstallButton.addEventListener('click', () => {
|
|
173
|
-
if (this._useOpenInstall()) this._wakeupOpenInstall();
|
|
174
|
-
});
|
|
175
167
|
this._updateTagAttr();
|
|
176
168
|
|
|
177
169
|
var contentEle = document.createElement('div');
|
|
@@ -188,56 +180,13 @@
|
|
|
188
180
|
|
|
189
181
|
this._openAppTag.appendChild(scriptTag);
|
|
190
182
|
this._template.content.appendChild(this._openAppTag);
|
|
191
|
-
this._template.content.appendChild(this._openInstallButton);
|
|
192
183
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
193
184
|
shadow.appendChild(this._template.content);
|
|
194
185
|
this._log('open-diandian: wx-open-launch-app appended');
|
|
195
|
-
|
|
196
|
-
this._openAppTag.addEventListener('error', (e) => {
|
|
197
|
-
this.dispatchEvent(new CustomEvent('error', {
|
|
198
|
-
detail: e.detail, // 如需透传微信事件数据
|
|
199
|
-
bubbles: true,
|
|
200
|
-
composed: true,
|
|
201
|
-
}));
|
|
202
|
-
if (this._useOpenInstall()) return;
|
|
203
|
-
if (this._isHarmony || this._isSceneLink()) {
|
|
204
|
-
this._showOpenInBrowserHint();
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
var tmplnk = document.createElement("a");
|
|
208
|
-
tmplnk.href = this._alink_fallback;
|
|
209
|
-
tmplnk.click();
|
|
210
|
-
this._log('open-diandian: wx-open-launch-app error, go to fallback link', e, this._alink_fallback);
|
|
211
|
-
if (this._alink_fin_5s) {
|
|
212
|
-
this._cancelFinalFallback();
|
|
213
|
-
this._fin5sVisHandler = () => {
|
|
214
|
-
if (document.hidden) {
|
|
215
|
-
this._log('open-diandian: page hidden, fallback succeeded, cancel final fallback');
|
|
216
|
-
this._cancelFinalFallback();
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
document.addEventListener('visibilitychange', this._fin5sVisHandler);
|
|
220
|
-
this._log('open-diandian: schedule final fallback 5s later', this._alink_fin_5s);
|
|
221
|
-
this._fin5sTimer = setTimeout(() => {
|
|
222
|
-
this._fin5sTimer = null;
|
|
223
|
-
if (this._fin5sVisHandler) {
|
|
224
|
-
document.removeEventListener('visibilitychange', this._fin5sVisHandler);
|
|
225
|
-
this._fin5sVisHandler = null;
|
|
226
|
-
}
|
|
227
|
-
if (!this._isConnected) {
|
|
228
|
-
this._log('open-diandian: disconnected, skip final fallback');
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (document.hidden) {
|
|
232
|
-
this._log('open-diandian: page hidden when timer fired, skip final fallback');
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
this._log('open-diandian: final fallback go', this._alink_fin_5s);
|
|
236
|
-
this._openLink(this._alink_fin_5s);
|
|
237
|
-
}, 5000);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
186
|
+
this._openAppTag.addEventListener('error', this._handleWechatLaunchError.bind(this));
|
|
240
187
|
this._openAppTag.addEventListener('launch', (e) => {
|
|
188
|
+
this._wechatFallbackRequest = null;
|
|
189
|
+
this._cancelFinalFallback();
|
|
241
190
|
this._log('open-diandian: wx-open-launch-app launch', e);
|
|
242
191
|
this.dispatchEvent(new CustomEvent('launch', {
|
|
243
192
|
detail: e.detail, // 如需透传微信事件数据
|
|
@@ -280,6 +229,64 @@
|
|
|
280
229
|
this._initClipboardText();
|
|
281
230
|
}
|
|
282
231
|
}
|
|
232
|
+
async _handleWechatLaunchError(event) {
|
|
233
|
+
const openAppTag = event.currentTarget;
|
|
234
|
+
this.dispatchEvent(new CustomEvent('error', {
|
|
235
|
+
detail: event.detail,
|
|
236
|
+
bubbles: true,
|
|
237
|
+
composed: true,
|
|
238
|
+
}));
|
|
239
|
+
if (this._openAppTag !== openAppTag || this._wechatFallbackRequest) return;
|
|
240
|
+
|
|
241
|
+
if (this._useOpenInstall()) {
|
|
242
|
+
const request = { appid: this._appid, extinfo: this.getAttribute('extinfo') };
|
|
243
|
+
this._wechatFallbackRequest = request;
|
|
244
|
+
if (!this._openInstall) {
|
|
245
|
+
this._initOpenInstall();
|
|
246
|
+
if (this._openInstallPromise) {
|
|
247
|
+
// 初始化错误已由 _initOpenInstall 上报。
|
|
248
|
+
await this._openInstallPromise.catch(() => {});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (this._wechatFallbackRequest !== request) return;
|
|
252
|
+
this._wechatFallbackRequest = null;
|
|
253
|
+
if (document.hidden || this._appid !== request.appid || this.getAttribute('extinfo') !== request.extinfo) return;
|
|
254
|
+
|
|
255
|
+
if (this._useOpenInstall() && this._openInstall) {
|
|
256
|
+
try {
|
|
257
|
+
this._log('open-diandian: wx-open-launch-app error, try OpenInstall');
|
|
258
|
+
this._wakeupOpenInstall();
|
|
259
|
+
return;
|
|
260
|
+
} catch (error) {
|
|
261
|
+
this._log('open-diandian: OpenInstall wakeup failed', error);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (this._isHarmony || this._isSceneLink()) {
|
|
267
|
+
this._showOpenInBrowserHint();
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this._log('open-diandian: wx-open-launch-app error, go to fallback link', event, this._alink_fallback);
|
|
271
|
+
this._openLink(this._alink_fallback);
|
|
272
|
+
if (this._alink_fin_5s) {
|
|
273
|
+
this._cancelFinalFallback();
|
|
274
|
+
this._fin5sVisHandler = () => {
|
|
275
|
+
if (document.hidden) {
|
|
276
|
+
this._log('open-diandian: page hidden, fallback succeeded, cancel final fallback');
|
|
277
|
+
this._cancelFinalFallback();
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
document.addEventListener('visibilitychange', this._fin5sVisHandler);
|
|
281
|
+
this._log('open-diandian: schedule final fallback 5s later', this._alink_fin_5s);
|
|
282
|
+
this._fin5sTimer = setTimeout(() => {
|
|
283
|
+
this._cancelFinalFallback();
|
|
284
|
+
if (!this._isConnected || document.hidden) return;
|
|
285
|
+
this._log('open-diandian: final fallback go', this._alink_fin_5s);
|
|
286
|
+
this._openLink(this._alink_fin_5s);
|
|
287
|
+
}, 5000);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
283
290
|
_handleAlinkClick(event) {
|
|
284
291
|
const useOpenInstall = this._useOpenInstall();
|
|
285
292
|
if (useOpenInstall) {
|
|
@@ -317,12 +324,11 @@
|
|
|
317
324
|
disconnectedCallback() {
|
|
318
325
|
this._log("disconnectedCallback");
|
|
319
326
|
this._isConnected = false;
|
|
327
|
+
this._wechatFallbackRequest = null;
|
|
320
328
|
this._cancelLaunchFallback();
|
|
321
329
|
if (this._openAppTag) {
|
|
322
330
|
this._openAppTag.remove();
|
|
323
331
|
this._openAppTag = null;
|
|
324
|
-
this._openInstallButton.remove();
|
|
325
|
-
this._openInstallButton = null;
|
|
326
332
|
}
|
|
327
333
|
if (this._alink) {
|
|
328
334
|
this._alink.remove();
|
|
@@ -367,9 +373,10 @@
|
|
|
367
373
|
let data;
|
|
368
374
|
if (extinfo) {
|
|
369
375
|
try {
|
|
370
|
-
const
|
|
371
|
-
if (
|
|
372
|
-
|
|
376
|
+
const extInfo = JSON.parse(extinfo);
|
|
377
|
+
if (extInfo && typeof extInfo === 'object' && !Array.isArray(extInfo)) {
|
|
378
|
+
const { bizInfo = '' } = resolveOpenInstallData();
|
|
379
|
+
data = { bizInfo, extInfo };
|
|
373
380
|
}
|
|
374
381
|
} catch (error) {
|
|
375
382
|
this._log('invalid OpenInstall extinfo', error);
|
|
@@ -537,9 +544,6 @@
|
|
|
537
544
|
this._alink_fin_5s = this._appInfo.fallback_fin_5s || '';
|
|
538
545
|
}
|
|
539
546
|
if (this._openAppTag) {
|
|
540
|
-
const useOpenInstall = this._useOpenInstall();
|
|
541
|
-
this._openAppTag.style.display = useOpenInstall ? 'none' : '';
|
|
542
|
-
this._openInstallButton.hidden = !useOpenInstall;
|
|
543
547
|
this._openAppTag.setAttribute('appid', this._appid);
|
|
544
548
|
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
545
549
|
} else if (this._alink) {
|
package/open-diandian/index.js
CHANGED
|
@@ -112,7 +112,7 @@ function createOpenDiandianElementClass() {
|
|
|
112
112
|
this._debug = false;
|
|
113
113
|
this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
|
|
114
114
|
this._openAppTag = null;
|
|
115
|
-
this.
|
|
115
|
+
this._wechatFallbackRequest = null;
|
|
116
116
|
this._fallbackTime = 3000;
|
|
117
117
|
this._appid = '';
|
|
118
118
|
this._appInfo = null;
|
|
@@ -159,14 +159,6 @@ function createOpenDiandianElementClass() {
|
|
|
159
159
|
this._openAppTag = document.createElement('wx-open-launch-app');
|
|
160
160
|
this._openAppTag.style.background = "transparent";
|
|
161
161
|
this._openAppTag.style.opacity = 0;
|
|
162
|
-
this._openInstallButton = document.createElement('button');
|
|
163
|
-
this._openInstallButton.type = 'button';
|
|
164
|
-
this._openInstallButton.setAttribute('aria-label', '打开 App');
|
|
165
|
-
this._openInstallButton.style.width = '100%';
|
|
166
|
-
this._openInstallButton.style.height = '100%';
|
|
167
|
-
this._openInstallButton.addEventListener('click', () => {
|
|
168
|
-
if (this._useOpenInstall()) this._wakeupOpenInstall();
|
|
169
|
-
});
|
|
170
162
|
this._updateTagAttr();
|
|
171
163
|
|
|
172
164
|
var contentEle = document.createElement('div');
|
|
@@ -183,56 +175,13 @@ function createOpenDiandianElementClass() {
|
|
|
183
175
|
|
|
184
176
|
this._openAppTag.appendChild(scriptTag);
|
|
185
177
|
this._template.content.appendChild(this._openAppTag);
|
|
186
|
-
this._template.content.appendChild(this._openInstallButton);
|
|
187
178
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
188
179
|
shadow.appendChild(this._template.content);
|
|
189
180
|
this._log('open-diandian: wx-open-launch-app appended');
|
|
190
|
-
|
|
191
|
-
this._openAppTag.addEventListener('error', (e) => {
|
|
192
|
-
this.dispatchEvent(new CustomEvent('error', {
|
|
193
|
-
detail: e.detail, // 如需透传微信事件数据
|
|
194
|
-
bubbles: true,
|
|
195
|
-
composed: true,
|
|
196
|
-
}));
|
|
197
|
-
if (this._useOpenInstall()) return;
|
|
198
|
-
if (this._isHarmony || this._isSceneLink()) {
|
|
199
|
-
this._showOpenInBrowserHint();
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
var tmplnk = document.createElement("a");
|
|
203
|
-
tmplnk.href = this._alink_fallback;
|
|
204
|
-
tmplnk.click();
|
|
205
|
-
this._log('open-diandian: wx-open-launch-app error, go to fallback link', e, this._alink_fallback);
|
|
206
|
-
if (this._alink_fin_5s) {
|
|
207
|
-
this._cancelFinalFallback();
|
|
208
|
-
this._fin5sVisHandler = () => {
|
|
209
|
-
if (document.hidden) {
|
|
210
|
-
this._log('open-diandian: page hidden, fallback succeeded, cancel final fallback');
|
|
211
|
-
this._cancelFinalFallback();
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
document.addEventListener('visibilitychange', this._fin5sVisHandler);
|
|
215
|
-
this._log('open-diandian: schedule final fallback 5s later', this._alink_fin_5s);
|
|
216
|
-
this._fin5sTimer = setTimeout(() => {
|
|
217
|
-
this._fin5sTimer = null;
|
|
218
|
-
if (this._fin5sVisHandler) {
|
|
219
|
-
document.removeEventListener('visibilitychange', this._fin5sVisHandler);
|
|
220
|
-
this._fin5sVisHandler = null;
|
|
221
|
-
}
|
|
222
|
-
if (!this._isConnected) {
|
|
223
|
-
this._log('open-diandian: disconnected, skip final fallback');
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (document.hidden) {
|
|
227
|
-
this._log('open-diandian: page hidden when timer fired, skip final fallback');
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
this._log('open-diandian: final fallback go', this._alink_fin_5s);
|
|
231
|
-
this._openLink(this._alink_fin_5s);
|
|
232
|
-
}, 5000);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
181
|
+
this._openAppTag.addEventListener('error', this._handleWechatLaunchError.bind(this));
|
|
235
182
|
this._openAppTag.addEventListener('launch', (e) => {
|
|
183
|
+
this._wechatFallbackRequest = null;
|
|
184
|
+
this._cancelFinalFallback();
|
|
236
185
|
this._log('open-diandian: wx-open-launch-app launch', e);
|
|
237
186
|
this.dispatchEvent(new CustomEvent('launch', {
|
|
238
187
|
detail: e.detail, // 如需透传微信事件数据
|
|
@@ -275,6 +224,64 @@ function createOpenDiandianElementClass() {
|
|
|
275
224
|
this._initClipboardText();
|
|
276
225
|
}
|
|
277
226
|
}
|
|
227
|
+
async _handleWechatLaunchError(event) {
|
|
228
|
+
const openAppTag = event.currentTarget;
|
|
229
|
+
this.dispatchEvent(new CustomEvent('error', {
|
|
230
|
+
detail: event.detail,
|
|
231
|
+
bubbles: true,
|
|
232
|
+
composed: true,
|
|
233
|
+
}));
|
|
234
|
+
if (this._openAppTag !== openAppTag || this._wechatFallbackRequest) return;
|
|
235
|
+
|
|
236
|
+
if (this._useOpenInstall()) {
|
|
237
|
+
const request = { appid: this._appid, extinfo: this.getAttribute('extinfo') };
|
|
238
|
+
this._wechatFallbackRequest = request;
|
|
239
|
+
if (!this._openInstall) {
|
|
240
|
+
this._initOpenInstall();
|
|
241
|
+
if (this._openInstallPromise) {
|
|
242
|
+
// 初始化错误已由 _initOpenInstall 上报。
|
|
243
|
+
await this._openInstallPromise.catch(() => {});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (this._wechatFallbackRequest !== request) return;
|
|
247
|
+
this._wechatFallbackRequest = null;
|
|
248
|
+
if (document.hidden || this._appid !== request.appid || this.getAttribute('extinfo') !== request.extinfo) return;
|
|
249
|
+
|
|
250
|
+
if (this._useOpenInstall() && this._openInstall) {
|
|
251
|
+
try {
|
|
252
|
+
this._log('open-diandian: wx-open-launch-app error, try OpenInstall');
|
|
253
|
+
this._wakeupOpenInstall();
|
|
254
|
+
return;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
this._log('open-diandian: OpenInstall wakeup failed', error);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (this._isHarmony || this._isSceneLink()) {
|
|
262
|
+
this._showOpenInBrowserHint();
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this._log('open-diandian: wx-open-launch-app error, go to fallback link', event, this._alink_fallback);
|
|
266
|
+
this._openLink(this._alink_fallback);
|
|
267
|
+
if (this._alink_fin_5s) {
|
|
268
|
+
this._cancelFinalFallback();
|
|
269
|
+
this._fin5sVisHandler = () => {
|
|
270
|
+
if (document.hidden) {
|
|
271
|
+
this._log('open-diandian: page hidden, fallback succeeded, cancel final fallback');
|
|
272
|
+
this._cancelFinalFallback();
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
document.addEventListener('visibilitychange', this._fin5sVisHandler);
|
|
276
|
+
this._log('open-diandian: schedule final fallback 5s later', this._alink_fin_5s);
|
|
277
|
+
this._fin5sTimer = setTimeout(() => {
|
|
278
|
+
this._cancelFinalFallback();
|
|
279
|
+
if (!this._isConnected || document.hidden) return;
|
|
280
|
+
this._log('open-diandian: final fallback go', this._alink_fin_5s);
|
|
281
|
+
this._openLink(this._alink_fin_5s);
|
|
282
|
+
}, 5000);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
278
285
|
_handleAlinkClick(event) {
|
|
279
286
|
const useOpenInstall = this._useOpenInstall();
|
|
280
287
|
if (useOpenInstall) {
|
|
@@ -312,12 +319,11 @@ function createOpenDiandianElementClass() {
|
|
|
312
319
|
disconnectedCallback() {
|
|
313
320
|
this._log("disconnectedCallback")
|
|
314
321
|
this._isConnected = false;
|
|
322
|
+
this._wechatFallbackRequest = null;
|
|
315
323
|
this._cancelLaunchFallback();
|
|
316
324
|
if (this._openAppTag) {
|
|
317
325
|
this._openAppTag.remove();
|
|
318
326
|
this._openAppTag = null;
|
|
319
|
-
this._openInstallButton.remove();
|
|
320
|
-
this._openInstallButton = null;
|
|
321
327
|
}
|
|
322
328
|
if (this._alink) {
|
|
323
329
|
this._alink.remove();
|
|
@@ -362,9 +368,10 @@ function createOpenDiandianElementClass() {
|
|
|
362
368
|
let data;
|
|
363
369
|
if (extinfo) {
|
|
364
370
|
try {
|
|
365
|
-
const
|
|
366
|
-
if (
|
|
367
|
-
|
|
371
|
+
const extInfo = JSON.parse(extinfo);
|
|
372
|
+
if (extInfo && typeof extInfo === 'object' && !Array.isArray(extInfo)) {
|
|
373
|
+
const { bizInfo = '' } = resolveOpenInstallData();
|
|
374
|
+
data = { bizInfo, extInfo };
|
|
368
375
|
}
|
|
369
376
|
} catch (error) {
|
|
370
377
|
this._log('invalid OpenInstall extinfo', error);
|
|
@@ -532,9 +539,6 @@ function createOpenDiandianElementClass() {
|
|
|
532
539
|
this._alink_fin_5s = this._appInfo.fallback_fin_5s || '';
|
|
533
540
|
}
|
|
534
541
|
if (this._openAppTag) {
|
|
535
|
-
const useOpenInstall = this._useOpenInstall();
|
|
536
|
-
this._openAppTag.style.display = useOpenInstall ? 'none' : '';
|
|
537
|
-
this._openInstallButton.hidden = !useOpenInstall;
|
|
538
542
|
this._openAppTag.setAttribute('appid', this._appid);
|
|
539
543
|
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
540
544
|
} else if (this._alink) {
|