@taole/dev-helper 0.0.30 → 0.1.0

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.
@@ -5,20 +5,62 @@
5
5
 
6
6
  // const name = 'open-diandian';
7
7
  // 测试使用open-diandain-app标签
8
- // TODO: 后期可以考虑优化为根据域名自动选择appid
8
+ const appInfoMap = {
9
+ 'wx6cd4c28b58e8737f': { // 点点开黑
10
+ app_name: '点点开黑',
11
+ link_ios: "com.tuwan.diandian://openPage",
12
+ 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
+ fallback_link_ios: "https://apps.apple.com/cn/app/%E7%82%B9%E7%82%B9-%E8%AF%AD%E9%9F%B3%E5%BC%80%E9%BB%91/id1449564746",
14
+ fallback_link_android: 'https://sj.qq.com/myapp/detail.htm?apkName=com.tuwan.yw',
15
+ },
16
+ 'wx0e4a6eed634134ce': { // 兔小铲
17
+ app_name: '兔小铲',
18
+ link_ios: "", // 空缺,后期补充
19
+ link_android: "tuxiaochan://diandain:8888/splash",
20
+ fallback_link_ios: 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939',
21
+ fallback_link_android: 'https://m.malink.cn/s/rYNfAj',
22
+ },
23
+ 'wxcd28679e4d8c1792': { // 点点狼人
24
+ app_name: '点点狼人',
25
+ link_ios: "", // 空缺,后期补充
26
+ link_android: "tuxiaochan://diandain:8888/splash",
27
+ fallback_link_ios: 'https://apps.apple.com/mo/app/%E7%82%B9%E7%82%B9%E7%8B%BC%E4%BA%BA%E6%9D%80-%E8%AF%AD%E9%9F%B3%E7%A4%BE%E4%BA%A4%E6%8E%A8%E7%90%86%E6%B8%B8%E6%88%8F/id1557616226',
28
+ fallback_link_android: '',
29
+ },
30
+ };
31
+ function resolveTwKit(){
32
+ if(window.twKit){
33
+ return;
34
+ }
35
+ const script = document.createElement('script');
36
+ script.src = 'https://asset.tuwan.com/script/tw-kit/0.4.12/cdn/index.js';
37
+ document.head.appendChild(script);
38
+ return new Promise((resolve, reject) => {
39
+ script.onload = () => {
40
+ resolve();
41
+ };
42
+ script.onerror = () => {
43
+ reject(new Error('load tw-kit error'));
44
+ };
45
+ });
46
+ }
47
+ let id = 1;
9
48
  function defineTag() {
10
49
  customElements.define(
11
50
  "open-diandain-app",
12
51
  class extends HTMLElement {
13
52
  static get observedAttributes() {
14
- // 后期考虑去掉fallback_link_ios和fallback_link_android
15
- return ['appid', 'extinfo', 'fallback_link_ios', 'fallback_link_android'];
53
+ return ['appid', 'extinfo', 'debug'];
16
54
  }
17
55
  constructor() {
18
56
  super();
57
+ this._debug = false;
19
58
  this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
20
- this._txcAppid = 'wx0e4a6eed634134ce'; // 兔小铲
21
59
  this._openAppTag = null;
60
+ this._appid = '';
61
+ this._appInfo = null;
62
+ this._alink_fallback = '';
63
+ this._alink_link = '';
22
64
  this._template = null;
23
65
  this._alink = null;
24
66
  this._isApp = (window.AndroidJs && window.AndroidJs.publicInteraction) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.AndroidJs);
@@ -27,11 +69,24 @@
27
69
  this._isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
28
70
  this._isHarmony = /Harmony/i.test(navigator.userAgent);
29
71
  this._isMobile = this._isAndroid || this._isIOS || this._isHarmony;
72
+ this._isConnected = false;
73
+ this._id = id++;
74
+ this._clipboardText = '';
75
+ this._clipboardTextPs = null;
76
+ this._clipboardTextTimer = null;
77
+ }
78
+ _log(...args) {
79
+ if (this._debug) {
80
+ console.log('open-diandian:[' + this._id + ']', ...args);
81
+ }
30
82
  }
31
83
  attributeChangedCallback() {
84
+ this._log("attributeChangedCallback");
32
85
  this._updateTagAttr();
33
86
  }
34
87
  connectedCallback() {
88
+ this._log("connectedCallback");
89
+ this._isConnected = true;
35
90
  if (this._isWechat) {
36
91
  this._genTemplate();
37
92
  if (!this._openAppTag) {
@@ -57,13 +112,17 @@
57
112
  this._template.content.appendChild(this._openAppTag);
58
113
  this.attachShadow({ mode: 'open' });
59
114
  this.shadowRoot.appendChild(this._template.content);
60
- console.log('open-diandian: wx-open-launch-app appended');
115
+ this._log('open-diandian: wx-open-launch-app appended');
61
116
  // 监听打开app失败的情况,跳转fallback链接
62
117
  this._openAppTag.addEventListener('error', (e) => {
118
+ if (this._isHarmony) {
119
+ this._showOpenInBrowserHint();
120
+ return;
121
+ }
63
122
  var tmplnk = document.createElement("a");
64
123
  tmplnk.href = this._alink_fallback;
65
124
  tmplnk.click();
66
- console.log('open-diandian: wx-open-launch-app error', this._alink_fallback);
125
+ this._log('open-diandian: wx-open-launch-app error', this._alink_fallback);
67
126
  });
68
127
  } else {
69
128
  this._updateTagAttr();
@@ -79,19 +138,27 @@
79
138
  this.attachShadow({ mode: 'open' });
80
139
  this.shadowRoot.appendChild(this._template.content);
81
140
  this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
82
- console.log('open-diandian: open link appended');
141
+ this._log('open-diandian: open link appended');
83
142
  }
84
143
  this._updateTagAttr();
144
+ this._initClipboardText();
145
+ } else {
146
+ this._log('open-diandian: not supported pc platform');
85
147
  }
86
148
  }
87
149
  _handleAlinkClick() {
88
- setTimeout(() => {
89
- var tmplnk = document.createElement("a");
90
- tmplnk.href = this._alink_fallback;
91
- tmplnk.click();
92
- }, 1000);
150
+ this._writeClickboard();
151
+ if (this._alink_link != this._alink_fallback) {
152
+ setTimeout(() => {
153
+ var tmplnk = document.createElement("a");
154
+ tmplnk.href = this._alink_fallback;
155
+ tmplnk.click();
156
+ }, 1000);
157
+ }
93
158
  }
94
159
  disconnectedCallback() {
160
+ this._log("disconnectedCallback");
161
+ this._isConnected = false;
95
162
  if (this._openAppTag) {
96
163
  this._openAppTag.remove();
97
164
  this._openAppTag = null;
@@ -101,61 +168,118 @@
101
168
  this._alink = null;
102
169
  }
103
170
  }
171
+ _initClipboardText() {
172
+ // 延迟20ms执行,如果20ms后卸载了,直接不执行了
173
+ this._clipboardTextTimer = setTimeout(() => {
174
+ if(!this._isConnected){
175
+ this._log("not connected, no need to init clipboard text");
176
+ return;
177
+ }
178
+ const extinfo = this.getAttribute('extinfo') || '';
179
+ if(!extinfo){
180
+ this._log("extinfo is empty, no need to init clipboard text");
181
+ return;
182
+ }
183
+ this._log("initClipboardText");
184
+ if(!this._clipboardTextPs){
185
+ this._clipboardTextPs = new Promise(async (resolve, reject) => {
186
+ try {
187
+ await resolveTwKit();
188
+ const urlText = `https://${twKit.isTest ? 'y-test.tuwan.com' : 'y.tuwan.com'}/events/app_transfer_page?extinfo=` + encodeURIComponent(extinfo);
189
+ const shorUrl = await twKit.genShortUrl(urlText);
190
+ this._clipboardText = `【${this._appInfo.app_name}】 ${shorUrl} `;
191
+ this._log("initClipboardText success", this._clipboardText);
192
+ resolve();
193
+ } catch (error) {
194
+ this._log("initClipboardText error", error);
195
+ reject(error);
196
+ }
197
+ });
198
+ }
199
+ }, 25);
200
+ }
201
+ async _writeClickboard() {
202
+ const text = this._clipboardText;
203
+ if(!text){
204
+ this._log("clipboard text is empty, no need to write clipboard");
205
+ return;
206
+ }
207
+ if (!navigator.clipboard) {
208
+ const textarea = document.createElement("textarea");
209
+ textarea.value = text;
210
+ textarea.style.position = "fixed"; // 防止闪烁
211
+ document.body.appendChild(textarea);
212
+ textarea.focus();
213
+ textarea.select();
214
+ try {
215
+ document.execCommand("copy");
216
+ } catch (err) {
217
+ this._log('open-diandian: _writeClickboard error 1', err, text);
218
+ }
219
+ document.body.removeChild(textarea);
220
+ } else {
221
+ try {
222
+ await navigator.clipboard.writeText(text);
223
+ } catch (err) {
224
+ this._log('open-diandian: _writeClickboard error 2', err, text);
225
+ }
226
+ }
227
+ }
228
+ _showOpenInBrowserHint() { // 提示用户在浏览器中打开
229
+ this._log('open-diandian: showOpenInBrowserHint');
230
+ let _hHintDiv = document.getElementById('open-diandian-h-hint-div');
231
+ if (_hHintDiv) {
232
+ _hHintDiv.remove();
233
+ _hHintDiv = null;
234
+ }
235
+ // https://asset.tuwan.com/images/llqdk.png
236
+ _hHintDiv = document.createElement('div');
237
+ _hHintDiv.id = 'open-diandian-h-hint-div';
238
+ _hHintDiv.style.position = 'fixed';
239
+ _hHintDiv.style.top = '0';
240
+ _hHintDiv.style.left = '0';
241
+ _hHintDiv.style.width = '100%';
242
+ _hHintDiv.style.height = '100%';
243
+ _hHintDiv.style.zIndex = '100000';
244
+ _hHintDiv.style.backgroundImage = 'url(https://asset.tuwan.com/images/llqdk.png)';
245
+ _hHintDiv.style.backgroundRepeat = 'no-repeat';
246
+ _hHintDiv.style.backgroundSize = '80vw auto';
247
+ _hHintDiv.style.backgroundPosition = 'top right';
248
+ _hHintDiv.style.backgroundColor = 'rgba(0,0,0,0.5)';
249
+ _hHintDiv.onclick = function () {
250
+ _hHintDiv.remove();
251
+ _hHintDiv = null;
252
+ };
253
+ this._hHintDiv = _hHintDiv;
254
+ document.body.appendChild(this._hHintDiv);
255
+ }
104
256
  _genTemplate() {
105
257
  if (!this._template) {
106
258
  this._template = document.createElement('template');
107
259
  this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;opacity: 0;background:transparent;}</style>';
108
260
  }
109
261
  }
110
- _genFallbackLink() {
111
- const isDianDian = this.getAttribute('appid') === this._defaultAppid;
112
- const isTxc = this.getAttribute('appid') === this._txcAppid;
113
- if (isDianDian) {
114
- if (this._isIOS) {
115
- if (this.appid)
116
- this._alink_fallback = "https://apps.apple.com/cn/app/%E7%82%B9%E7%82%B9-%E8%AF%AD%E9%9F%B3%E5%BC%80%E9%BB%91/id1449564746";
117
- } else {
118
- var packageName = "com.tuwan.yw";
119
- this._alink_fallback = "https://sj.qq.com/myapp/detail.htm?apkName=" + packageName;
120
- }
121
- } else if (isTxc) {
122
- if (this._isIOS) {
123
- this._alink_fallback = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
124
- } else {
125
- this._alink_fallback = "https://m.malink.cn/s/rYNfAj";
126
- }
262
+ _updateTagAttr() {
263
+ this._debug = this.getAttribute('debug') !== null;
264
+ this._appid = this.getAttribute('appid') || this._defaultAppid;
265
+ this._appInfo = appInfoMap[this._appid];
266
+ if (!this._appInfo) {
267
+ console.error('open-diandian: appid not supported', this._appid);
268
+ return;
269
+ }
270
+ this._log('open-diandian: appInfo', this._appInfo);
271
+ if (this._isIOS) {
272
+ this._alink_fallback = this._appInfo.fallback_link_ios;
273
+ this._alink_link = this._appInfo.link_ios || this._alink_fallback;
127
274
  } else {
128
- if (this._isIOS) {
129
- this._alink_fallback = this.getAttribute('fallback_link_ios');
130
- } else {
131
- this._alink_fallback = this.getAttribute('fallback_link_android');
132
- }
275
+ this._alink_fallback = this._appInfo.fallback_link_android;
276
+ this._alink_link = this._appInfo.link_android || this._alink_fallback;
133
277
  }
134
- }
135
- _updateTagAttr() {
136
- this._genFallbackLink();
137
278
  if (this._openAppTag) {
138
- this._openAppTag.setAttribute('appid', this.getAttribute('appid') || this._defaultAppid);
279
+ this._openAppTag.setAttribute('appid', this._appid);
139
280
  this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
140
281
  } else if (this._alink) {
141
- const isDianDian = this.getAttribute('appid') === this._defaultAppid;
142
- const isTxc = this.getAttribute('appid') === this._txcAppid;
143
- if (isDianDian) {
144
- if (this._isIOS) {
145
- this._alink.href = "com.tuwan.diandian://openPage";
146
- } else {
147
- var packageName = "com.tuwan.yw";
148
- this._alink.href = "intent://diandain:8888/splash#Intent;scheme=taole;package=" + packageName + ";S.browser_fallback_url=" + this._alink_fallback + ";end";
149
- }
150
- } else if (isTxc) {
151
- if (this._isAndroid || this._isHarmony) {
152
- this._alink.href = "tuxiaochan://diandain:8888/splash";
153
- } else if (this._isIOS) { // ios 跳转appstore
154
- this._alink.href = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
155
- } else {
156
- this._alink.href = "https://m.malink.cn/s/rYNfAj";
157
- }
158
- }
282
+ this._alink.href = this._alink_link;
159
283
  }
160
284
  }
161
285
  },
@@ -173,7 +297,7 @@
173
297
  registerTdiv();
174
298
 
175
299
  // export default {
176
- // name
300
+ // name
177
301
  // }
178
302
 
179
303
  }));
@@ -1,19 +1,61 @@
1
1
  // const name = 'open-diandian';
2
2
  // 测试使用open-diandain-app标签
3
- // TODO: 后期可以考虑优化为根据域名自动选择appid
3
+ const appInfoMap = {
4
+ 'wx6cd4c28b58e8737f': { // 点点开黑
5
+ app_name: '点点开黑',
6
+ link_ios: "com.tuwan.diandian://openPage",
7
+ 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
+ fallback_link_ios: "https://apps.apple.com/cn/app/%E7%82%B9%E7%82%B9-%E8%AF%AD%E9%9F%B3%E5%BC%80%E9%BB%91/id1449564746",
9
+ fallback_link_android: 'https://sj.qq.com/myapp/detail.htm?apkName=com.tuwan.yw',
10
+ },
11
+ 'wx0e4a6eed634134ce': { // 兔小铲
12
+ app_name: '兔小铲',
13
+ link_ios: "", // 空缺,后期补充
14
+ link_android: "tuxiaochan://diandain:8888/splash",
15
+ fallback_link_ios: 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939',
16
+ fallback_link_android: 'https://m.malink.cn/s/rYNfAj',
17
+ },
18
+ 'wxcd28679e4d8c1792': { // 点点狼人
19
+ app_name: '点点狼人',
20
+ link_ios: "", // 空缺,后期补充
21
+ link_android: "tuxiaochan://diandain:8888/splash",
22
+ fallback_link_ios: 'https://apps.apple.com/mo/app/%E7%82%B9%E7%82%B9%E7%8B%BC%E4%BA%BA%E6%9D%80-%E8%AF%AD%E9%9F%B3%E7%A4%BE%E4%BA%A4%E6%8E%A8%E7%90%86%E6%B8%B8%E6%88%8F/id1557616226',
23
+ fallback_link_android: '',
24
+ },
25
+ }
26
+ function resolveTwKit(){
27
+ if(window.twKit){
28
+ return;
29
+ }
30
+ const script = document.createElement('script');
31
+ script.src = 'https://asset.tuwan.com/script/tw-kit/0.4.12/cdn/index.js';
32
+ document.head.appendChild(script);
33
+ return new Promise((resolve, reject) => {
34
+ script.onload = () => {
35
+ resolve();
36
+ }
37
+ script.onerror = () => {
38
+ reject(new Error('load tw-kit error'));
39
+ }
40
+ });
41
+ }
42
+ let id = 1;
4
43
  function defineTag() {
5
44
  customElements.define(
6
45
  "open-diandain-app",
7
46
  class extends HTMLElement {
8
47
  static get observedAttributes() {
9
- // 后期考虑去掉fallback_link_ios和fallback_link_android
10
- return ['appid', 'extinfo', 'fallback_link_ios', 'fallback_link_android'];
48
+ return ['appid', 'extinfo', 'debug'];
11
49
  }
12
50
  constructor() {
13
51
  super();
52
+ this._debug = false;
14
53
  this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
15
- this._txcAppid = 'wx0e4a6eed634134ce'; // 兔小铲
16
54
  this._openAppTag = null;
55
+ this._appid = '';
56
+ this._appInfo = null;
57
+ this._alink_fallback = '';
58
+ this._alink_link = '';
17
59
  this._template = null;
18
60
  this._alink = null;
19
61
  this._isApp = (window.AndroidJs && window.AndroidJs.publicInteraction) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.AndroidJs);
@@ -22,11 +64,24 @@ function defineTag() {
22
64
  this._isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
23
65
  this._isHarmony = /Harmony/i.test(navigator.userAgent);
24
66
  this._isMobile = this._isAndroid || this._isIOS || this._isHarmony;
67
+ this._isConnected = false;
68
+ this._id = id++;
69
+ this._clipboardText = '';
70
+ this._clipboardTextPs = null;
71
+ this._clipboardTextTimer = null;
72
+ }
73
+ _log(...args) {
74
+ if (this._debug) {
75
+ console.log('open-diandian:[' + this._id + ']', ...args);
76
+ }
25
77
  }
26
78
  attributeChangedCallback() {
79
+ this._log("attributeChangedCallback")
27
80
  this._updateTagAttr();
28
81
  }
29
82
  connectedCallback() {
83
+ this._log("connectedCallback")
84
+ this._isConnected = true;
30
85
  if (this._isWechat) {
31
86
  this._genTemplate();
32
87
  if (!this._openAppTag) {
@@ -52,13 +107,17 @@ function defineTag() {
52
107
  this._template.content.appendChild(this._openAppTag);
53
108
  this.attachShadow({ mode: 'open' });
54
109
  this.shadowRoot.appendChild(this._template.content);
55
- console.log('open-diandian: wx-open-launch-app appended');
110
+ this._log('open-diandian: wx-open-launch-app appended');
56
111
  // 监听打开app失败的情况,跳转fallback链接
57
112
  this._openAppTag.addEventListener('error', (e) => {
113
+ if (this._isHarmony) {
114
+ this._showOpenInBrowserHint();
115
+ return;
116
+ }
58
117
  var tmplnk = document.createElement("a");
59
118
  tmplnk.href = this._alink_fallback;
60
119
  tmplnk.click();
61
- console.log('open-diandian: wx-open-launch-app error', this._alink_fallback);
120
+ this._log('open-diandian: wx-open-launch-app error', this._alink_fallback);
62
121
  });
63
122
  } else {
64
123
  this._updateTagAttr();
@@ -74,19 +133,27 @@ function defineTag() {
74
133
  this.attachShadow({ mode: 'open' });
75
134
  this.shadowRoot.appendChild(this._template.content);
76
135
  this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
77
- console.log('open-diandian: open link appended');
136
+ this._log('open-diandian: open link appended');
78
137
  }
79
138
  this._updateTagAttr();
139
+ this._initClipboardText();
140
+ } else {
141
+ this._log('open-diandian: not supported pc platform');
80
142
  }
81
143
  }
82
144
  _handleAlinkClick() {
83
- setTimeout(() => {
84
- var tmplnk = document.createElement("a");
85
- tmplnk.href = this._alink_fallback;
86
- tmplnk.click();
87
- }, 1000);
145
+ this._writeClickboard();
146
+ if (this._alink_link != this._alink_fallback) {
147
+ setTimeout(() => {
148
+ var tmplnk = document.createElement("a");
149
+ tmplnk.href = this._alink_fallback;
150
+ tmplnk.click();
151
+ }, 1000);
152
+ }
88
153
  }
89
154
  disconnectedCallback() {
155
+ this._log("disconnectedCallback")
156
+ this._isConnected = false;
90
157
  if (this._openAppTag) {
91
158
  this._openAppTag.remove();
92
159
  this._openAppTag = null;
@@ -96,61 +163,118 @@ function defineTag() {
96
163
  this._alink = null;
97
164
  }
98
165
  }
166
+ _initClipboardText() {
167
+ // 延迟20ms执行,如果20ms后卸载了,直接不执行了
168
+ this._clipboardTextTimer = setTimeout(() => {
169
+ if(!this._isConnected){
170
+ this._log("not connected, no need to init clipboard text")
171
+ return;
172
+ }
173
+ const extinfo = this.getAttribute('extinfo') || '';
174
+ if(!extinfo){
175
+ this._log("extinfo is empty, no need to init clipboard text")
176
+ return;
177
+ }
178
+ this._log("initClipboardText")
179
+ if(!this._clipboardTextPs){
180
+ this._clipboardTextPs = new Promise(async (resolve, reject) => {
181
+ try {
182
+ await resolveTwKit();
183
+ const urlText = `https://${twKit.isTest ? 'y-test.tuwan.com' : 'y.tuwan.com'}/events/app_transfer_page?extinfo=` + encodeURIComponent(extinfo);
184
+ const shorUrl = await twKit.genShortUrl(urlText);
185
+ this._clipboardText = `【${this._appInfo.app_name}】 ${shorUrl} `;
186
+ this._log("initClipboardText success", this._clipboardText);
187
+ resolve();
188
+ } catch (error) {
189
+ this._log("initClipboardText error", error);
190
+ reject(error);
191
+ }
192
+ });
193
+ }
194
+ }, 25);
195
+ }
196
+ async _writeClickboard() {
197
+ const text = this._clipboardText;
198
+ if(!text){
199
+ this._log("clipboard text is empty, no need to write clipboard")
200
+ return;
201
+ }
202
+ if (!navigator.clipboard) {
203
+ const textarea = document.createElement("textarea");
204
+ textarea.value = text;
205
+ textarea.style.position = "fixed"; // 防止闪烁
206
+ document.body.appendChild(textarea);
207
+ textarea.focus();
208
+ textarea.select();
209
+ try {
210
+ document.execCommand("copy");
211
+ } catch (err) {
212
+ this._log('open-diandian: _writeClickboard error 1', err, text);
213
+ }
214
+ document.body.removeChild(textarea);
215
+ } else {
216
+ try {
217
+ await navigator.clipboard.writeText(text);
218
+ } catch (err) {
219
+ this._log('open-diandian: _writeClickboard error 2', err, text);
220
+ }
221
+ }
222
+ }
223
+ _showOpenInBrowserHint() { // 提示用户在浏览器中打开
224
+ this._log('open-diandian: showOpenInBrowserHint');
225
+ let _hHintDiv = document.getElementById('open-diandian-h-hint-div');
226
+ if (_hHintDiv) {
227
+ _hHintDiv.remove();
228
+ _hHintDiv = null;
229
+ }
230
+ // https://asset.tuwan.com/images/llqdk.png
231
+ _hHintDiv = document.createElement('div');
232
+ _hHintDiv.id = 'open-diandian-h-hint-div';
233
+ _hHintDiv.style.position = 'fixed';
234
+ _hHintDiv.style.top = '0';
235
+ _hHintDiv.style.left = '0';
236
+ _hHintDiv.style.width = '100%';
237
+ _hHintDiv.style.height = '100%';
238
+ _hHintDiv.style.zIndex = '100000';
239
+ _hHintDiv.style.backgroundImage = 'url(https://asset.tuwan.com/images/llqdk.png)';
240
+ _hHintDiv.style.backgroundRepeat = 'no-repeat';
241
+ _hHintDiv.style.backgroundSize = '80vw auto';
242
+ _hHintDiv.style.backgroundPosition = 'top right';
243
+ _hHintDiv.style.backgroundColor = 'rgba(0,0,0,0.5)';
244
+ _hHintDiv.onclick = function () {
245
+ _hHintDiv.remove();
246
+ _hHintDiv = null;
247
+ };
248
+ this._hHintDiv = _hHintDiv;
249
+ document.body.appendChild(this._hHintDiv);
250
+ }
99
251
  _genTemplate() {
100
252
  if (!this._template) {
101
253
  this._template = document.createElement('template');
102
254
  this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;opacity: 0;background:transparent;}</style>';
103
255
  }
104
256
  }
105
- _genFallbackLink() {
106
- const isDianDian = this.getAttribute('appid') === this._defaultAppid;
107
- const isTxc = this.getAttribute('appid') === this._txcAppid;
108
- if (isDianDian) {
109
- if (this._isIOS) {
110
- if (this.appid)
111
- this._alink_fallback = "https://apps.apple.com/cn/app/%E7%82%B9%E7%82%B9-%E8%AF%AD%E9%9F%B3%E5%BC%80%E9%BB%91/id1449564746";
112
- } else {
113
- var packageName = "com.tuwan.yw";
114
- this._alink_fallback = "https://sj.qq.com/myapp/detail.htm?apkName=" + packageName;
115
- }
116
- } else if (isTxc) {
117
- if (this._isIOS) {
118
- this._alink_fallback = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
119
- } else {
120
- this._alink_fallback = "https://m.malink.cn/s/rYNfAj";
121
- }
257
+ _updateTagAttr() {
258
+ this._debug = this.getAttribute('debug') !== null;
259
+ this._appid = this.getAttribute('appid') || this._defaultAppid;
260
+ this._appInfo = appInfoMap[this._appid];
261
+ if (!this._appInfo) {
262
+ console.error('open-diandian: appid not supported', this._appid);
263
+ return;
264
+ }
265
+ this._log('open-diandian: appInfo', this._appInfo);
266
+ if (this._isIOS) {
267
+ this._alink_fallback = this._appInfo.fallback_link_ios;
268
+ this._alink_link = this._appInfo.link_ios || this._alink_fallback;
122
269
  } else {
123
- if (this._isIOS) {
124
- this._alink_fallback = this.getAttribute('fallback_link_ios');
125
- } else {
126
- this._alink_fallback = this.getAttribute('fallback_link_android');
127
- }
270
+ this._alink_fallback = this._appInfo.fallback_link_android;
271
+ this._alink_link = this._appInfo.link_android || this._alink_fallback;
128
272
  }
129
- }
130
- _updateTagAttr() {
131
- this._genFallbackLink();
132
273
  if (this._openAppTag) {
133
- this._openAppTag.setAttribute('appid', this.getAttribute('appid') || this._defaultAppid);
274
+ this._openAppTag.setAttribute('appid', this._appid);
134
275
  this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
135
276
  } else if (this._alink) {
136
- const isDianDian = this.getAttribute('appid') === this._defaultAppid;
137
- const isTxc = this.getAttribute('appid') === this._txcAppid;
138
- if (isDianDian) {
139
- if (this._isIOS) {
140
- this._alink.href = "com.tuwan.diandian://openPage";
141
- } else {
142
- var packageName = "com.tuwan.yw";
143
- this._alink.href = "intent://diandain:8888/splash#Intent;scheme=taole;package=" + packageName + ";S.browser_fallback_url=" + this._alink_fallback + ";end";
144
- }
145
- } else if (isTxc) {
146
- if (this._isAndroid || this._isHarmony) {
147
- this._alink.href = "tuxiaochan://diandain:8888/splash";
148
- } else if (this._isIOS) { // ios 跳转appstore
149
- this._alink.href = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
150
- } else {
151
- this._alink.href = "https://m.malink.cn/s/rYNfAj";
152
- }
153
- }
277
+ this._alink.href = this._alink_link;
154
278
  }
155
279
  }
156
280
  },
@@ -168,5 +292,5 @@ function registerTdiv() {
168
292
  registerTdiv();
169
293
 
170
294
  // export default {
171
- // name
295
+ // name
172
296
  // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.0.30",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npx -y rimraf dist && rollup -c",