@taole/dev-helper 0.0.31 → 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.
- package/dist/open-diandian.umd.js +151 -63
- package/open-diandian/index.js +151 -63
- package/package.json +1 -1
|
@@ -5,20 +5,62 @@
|
|
|
5
5
|
|
|
6
6
|
// const name = 'open-diandian';
|
|
7
7
|
// 测试使用open-diandain-app标签
|
|
8
|
-
|
|
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
|
-
|
|
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,7 +112,7 @@
|
|
|
57
112
|
this._template.content.appendChild(this._openAppTag);
|
|
58
113
|
this.attachShadow({ mode: 'open' });
|
|
59
114
|
this.shadowRoot.appendChild(this._template.content);
|
|
60
|
-
|
|
115
|
+
this._log('open-diandian: wx-open-launch-app appended');
|
|
61
116
|
// 监听打开app失败的情况,跳转fallback链接
|
|
62
117
|
this._openAppTag.addEventListener('error', (e) => {
|
|
63
118
|
if (this._isHarmony) {
|
|
@@ -67,7 +122,7 @@
|
|
|
67
122
|
var tmplnk = document.createElement("a");
|
|
68
123
|
tmplnk.href = this._alink_fallback;
|
|
69
124
|
tmplnk.click();
|
|
70
|
-
|
|
125
|
+
this._log('open-diandian: wx-open-launch-app error', this._alink_fallback);
|
|
71
126
|
});
|
|
72
127
|
} else {
|
|
73
128
|
this._updateTagAttr();
|
|
@@ -83,23 +138,27 @@
|
|
|
83
138
|
this.attachShadow({ mode: 'open' });
|
|
84
139
|
this.shadowRoot.appendChild(this._template.content);
|
|
85
140
|
this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
|
|
86
|
-
|
|
87
|
-
// only test
|
|
88
|
-
// if(this._isHarmony){
|
|
89
|
-
// this._showOpenInBrowserHint();
|
|
90
|
-
// }
|
|
141
|
+
this._log('open-diandian: open link appended');
|
|
91
142
|
}
|
|
92
143
|
this._updateTagAttr();
|
|
144
|
+
this._initClipboardText();
|
|
145
|
+
} else {
|
|
146
|
+
this._log('open-diandian: not supported pc platform');
|
|
93
147
|
}
|
|
94
148
|
}
|
|
95
149
|
_handleAlinkClick() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
+
}
|
|
101
158
|
}
|
|
102
159
|
disconnectedCallback() {
|
|
160
|
+
this._log("disconnectedCallback");
|
|
161
|
+
this._isConnected = false;
|
|
103
162
|
if (this._openAppTag) {
|
|
104
163
|
this._openAppTag.remove();
|
|
105
164
|
this._openAppTag = null;
|
|
@@ -109,10 +168,67 @@
|
|
|
109
168
|
this._alink = null;
|
|
110
169
|
}
|
|
111
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
|
+
}
|
|
112
228
|
_showOpenInBrowserHint() { // 提示用户在浏览器中打开
|
|
113
|
-
|
|
229
|
+
this._log('open-diandian: showOpenInBrowserHint');
|
|
114
230
|
let _hHintDiv = document.getElementById('open-diandian-h-hint-div');
|
|
115
|
-
if(_hHintDiv){
|
|
231
|
+
if (_hHintDiv) {
|
|
116
232
|
_hHintDiv.remove();
|
|
117
233
|
_hHintDiv = null;
|
|
118
234
|
}
|
|
@@ -130,7 +246,7 @@
|
|
|
130
246
|
_hHintDiv.style.backgroundSize = '80vw auto';
|
|
131
247
|
_hHintDiv.style.backgroundPosition = 'top right';
|
|
132
248
|
_hHintDiv.style.backgroundColor = 'rgba(0,0,0,0.5)';
|
|
133
|
-
_hHintDiv.onclick = function() {
|
|
249
|
+
_hHintDiv.onclick = function () {
|
|
134
250
|
_hHintDiv.remove();
|
|
135
251
|
_hHintDiv = null;
|
|
136
252
|
};
|
|
@@ -143,55 +259,27 @@
|
|
|
143
259
|
this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;opacity: 0;background:transparent;}</style>';
|
|
144
260
|
}
|
|
145
261
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (this._isIOS) {
|
|
159
|
-
this._alink_fallback = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
|
|
160
|
-
} else {
|
|
161
|
-
this._alink_fallback = "https://m.malink.cn/s/rYNfAj";
|
|
162
|
-
}
|
|
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;
|
|
163
274
|
} else {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
} else {
|
|
167
|
-
this._alink_fallback = this.getAttribute('fallback_link_android');
|
|
168
|
-
}
|
|
275
|
+
this._alink_fallback = this._appInfo.fallback_link_android;
|
|
276
|
+
this._alink_link = this._appInfo.link_android || this._alink_fallback;
|
|
169
277
|
}
|
|
170
|
-
}
|
|
171
|
-
_updateTagAttr() {
|
|
172
|
-
this._genFallbackLink();
|
|
173
278
|
if (this._openAppTag) {
|
|
174
|
-
this._openAppTag.setAttribute('appid', this.
|
|
279
|
+
this._openAppTag.setAttribute('appid', this._appid);
|
|
175
280
|
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
176
281
|
} else if (this._alink) {
|
|
177
|
-
|
|
178
|
-
const isTxc = this.getAttribute('appid') === this._txcAppid;
|
|
179
|
-
if (isDianDian) {
|
|
180
|
-
if (this._isIOS) {
|
|
181
|
-
this._alink.href = "com.tuwan.diandian://openPage";
|
|
182
|
-
} else {
|
|
183
|
-
var packageName = "com.tuwan.yw";
|
|
184
|
-
this._alink.href = "intent://diandain:8888/splash#Intent;scheme=taole;package=" + packageName + ";S.browser_fallback_url=" + this._alink_fallback + ";end";
|
|
185
|
-
}
|
|
186
|
-
} else if (isTxc) {
|
|
187
|
-
if (this._isAndroid || this._isHarmony) {
|
|
188
|
-
this._alink.href = "tuxiaochan://diandain:8888/splash";
|
|
189
|
-
} else if (this._isIOS) { // ios 跳转appstore
|
|
190
|
-
this._alink.href = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
|
|
191
|
-
} else {
|
|
192
|
-
this._alink.href = "https://m.malink.cn/s/rYNfAj";
|
|
193
|
-
}
|
|
194
|
-
}
|
|
282
|
+
this._alink.href = this._alink_link;
|
|
195
283
|
}
|
|
196
284
|
}
|
|
197
285
|
},
|
package/open-diandian/index.js
CHANGED
|
@@ -1,19 +1,61 @@
|
|
|
1
1
|
// const name = 'open-diandian';
|
|
2
2
|
// 测试使用open-diandain-app标签
|
|
3
|
-
|
|
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
|
-
|
|
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,7 +107,7 @@ 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
|
-
|
|
110
|
+
this._log('open-diandian: wx-open-launch-app appended');
|
|
56
111
|
// 监听打开app失败的情况,跳转fallback链接
|
|
57
112
|
this._openAppTag.addEventListener('error', (e) => {
|
|
58
113
|
if (this._isHarmony) {
|
|
@@ -62,7 +117,7 @@ function defineTag() {
|
|
|
62
117
|
var tmplnk = document.createElement("a");
|
|
63
118
|
tmplnk.href = this._alink_fallback;
|
|
64
119
|
tmplnk.click();
|
|
65
|
-
|
|
120
|
+
this._log('open-diandian: wx-open-launch-app error', this._alink_fallback);
|
|
66
121
|
});
|
|
67
122
|
} else {
|
|
68
123
|
this._updateTagAttr();
|
|
@@ -78,23 +133,27 @@ function defineTag() {
|
|
|
78
133
|
this.attachShadow({ mode: 'open' });
|
|
79
134
|
this.shadowRoot.appendChild(this._template.content);
|
|
80
135
|
this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
|
|
81
|
-
|
|
82
|
-
// only test
|
|
83
|
-
// if(this._isHarmony){
|
|
84
|
-
// this._showOpenInBrowserHint();
|
|
85
|
-
// }
|
|
136
|
+
this._log('open-diandian: open link appended');
|
|
86
137
|
}
|
|
87
138
|
this._updateTagAttr();
|
|
139
|
+
this._initClipboardText();
|
|
140
|
+
} else {
|
|
141
|
+
this._log('open-diandian: not supported pc platform');
|
|
88
142
|
}
|
|
89
143
|
}
|
|
90
144
|
_handleAlinkClick() {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
+
}
|
|
96
153
|
}
|
|
97
154
|
disconnectedCallback() {
|
|
155
|
+
this._log("disconnectedCallback")
|
|
156
|
+
this._isConnected = false;
|
|
98
157
|
if (this._openAppTag) {
|
|
99
158
|
this._openAppTag.remove();
|
|
100
159
|
this._openAppTag = null;
|
|
@@ -104,10 +163,67 @@ function defineTag() {
|
|
|
104
163
|
this._alink = null;
|
|
105
164
|
}
|
|
106
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
|
+
}
|
|
107
223
|
_showOpenInBrowserHint() { // 提示用户在浏览器中打开
|
|
108
|
-
|
|
224
|
+
this._log('open-diandian: showOpenInBrowserHint');
|
|
109
225
|
let _hHintDiv = document.getElementById('open-diandian-h-hint-div');
|
|
110
|
-
if(_hHintDiv){
|
|
226
|
+
if (_hHintDiv) {
|
|
111
227
|
_hHintDiv.remove();
|
|
112
228
|
_hHintDiv = null;
|
|
113
229
|
}
|
|
@@ -125,7 +241,7 @@ function defineTag() {
|
|
|
125
241
|
_hHintDiv.style.backgroundSize = '80vw auto';
|
|
126
242
|
_hHintDiv.style.backgroundPosition = 'top right';
|
|
127
243
|
_hHintDiv.style.backgroundColor = 'rgba(0,0,0,0.5)';
|
|
128
|
-
_hHintDiv.onclick = function() {
|
|
244
|
+
_hHintDiv.onclick = function () {
|
|
129
245
|
_hHintDiv.remove();
|
|
130
246
|
_hHintDiv = null;
|
|
131
247
|
};
|
|
@@ -138,55 +254,27 @@ function defineTag() {
|
|
|
138
254
|
this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;opacity: 0;background:transparent;}</style>';
|
|
139
255
|
}
|
|
140
256
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (this._isIOS) {
|
|
154
|
-
this._alink_fallback = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
|
|
155
|
-
} else {
|
|
156
|
-
this._alink_fallback = "https://m.malink.cn/s/rYNfAj";
|
|
157
|
-
}
|
|
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;
|
|
158
269
|
} else {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
} else {
|
|
162
|
-
this._alink_fallback = this.getAttribute('fallback_link_android');
|
|
163
|
-
}
|
|
270
|
+
this._alink_fallback = this._appInfo.fallback_link_android;
|
|
271
|
+
this._alink_link = this._appInfo.link_android || this._alink_fallback;
|
|
164
272
|
}
|
|
165
|
-
}
|
|
166
|
-
_updateTagAttr() {
|
|
167
|
-
this._genFallbackLink();
|
|
168
273
|
if (this._openAppTag) {
|
|
169
|
-
this._openAppTag.setAttribute('appid', this.
|
|
274
|
+
this._openAppTag.setAttribute('appid', this._appid);
|
|
170
275
|
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
171
276
|
} else if (this._alink) {
|
|
172
|
-
|
|
173
|
-
const isTxc = this.getAttribute('appid') === this._txcAppid;
|
|
174
|
-
if (isDianDian) {
|
|
175
|
-
if (this._isIOS) {
|
|
176
|
-
this._alink.href = "com.tuwan.diandian://openPage";
|
|
177
|
-
} else {
|
|
178
|
-
var packageName = "com.tuwan.yw";
|
|
179
|
-
this._alink.href = "intent://diandain:8888/splash#Intent;scheme=taole;package=" + packageName + ";S.browser_fallback_url=" + this._alink_fallback + ";end";
|
|
180
|
-
}
|
|
181
|
-
} else if (isTxc) {
|
|
182
|
-
if (this._isAndroid || this._isHarmony) {
|
|
183
|
-
this._alink.href = "tuxiaochan://diandain:8888/splash";
|
|
184
|
-
} else if (this._isIOS) { // ios 跳转appstore
|
|
185
|
-
this._alink.href = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
|
|
186
|
-
} else {
|
|
187
|
-
this._alink.href = "https://m.malink.cn/s/rYNfAj";
|
|
188
|
-
}
|
|
189
|
-
}
|
|
277
|
+
this._alink.href = this._alink_link;
|
|
190
278
|
}
|
|
191
279
|
}
|
|
192
280
|
},
|