@taole/dev-helper 0.0.13 → 0.0.15
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/Tdiv/index.js +2 -0
- package/dist/open-diandian.umd.js +150 -0
- package/dist/tdiv.umd.js +2 -0
- package/package.json +1 -1
package/Tdiv/index.js
CHANGED
|
@@ -209,6 +209,8 @@ class Tdiv extends HTMLElement {
|
|
|
209
209
|
const onClickAttr = this._getAttr('onClick');
|
|
210
210
|
if (onClickAttr && typeof window[onClickAttr] === 'function') {
|
|
211
211
|
window[onClickAttr](e);
|
|
212
|
+
} else if(onClickAttr && typeof onClickAttr === 'function') {
|
|
213
|
+
onClickAttr(e);
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.OpenDiandian = factory());
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
|
+
|
|
7
|
+
const version = '0.0.1';
|
|
8
|
+
// 测试使用open-diandain-app标签
|
|
9
|
+
function defineTag() {
|
|
10
|
+
customElements.define(
|
|
11
|
+
"open-diandain-app",
|
|
12
|
+
class extends HTMLElement {
|
|
13
|
+
static get observedAttributes() {
|
|
14
|
+
return ['appid', 'extinfo'];
|
|
15
|
+
}
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
|
|
19
|
+
this._openAppTag = null;
|
|
20
|
+
this._template = null;
|
|
21
|
+
this._alink = null;
|
|
22
|
+
this._isMobile =
|
|
23
|
+
this._isApp = (window.AndroidJs && window.AndroidJs.publicInteraction) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.AndroidJs);
|
|
24
|
+
this._isWechat = /MicroMessenger/i.test(navigator.userAgent);
|
|
25
|
+
this._isAndroid = /Android/i.test(navigator.userAgent);
|
|
26
|
+
this._isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
27
|
+
this._isMobile = this._isAndroid || this._isIOS;
|
|
28
|
+
}
|
|
29
|
+
attributeChangedCallback() {
|
|
30
|
+
this._updateTagAttr();
|
|
31
|
+
}
|
|
32
|
+
connectedCallback() {
|
|
33
|
+
if (this._isWechat) {
|
|
34
|
+
this._genTemplate();
|
|
35
|
+
if (!this._openAppTag) {
|
|
36
|
+
// 放进去一个wx-open-launch-app, 宽高占满父容器
|
|
37
|
+
this._openAppTag = document.createElement('wx-open-launch-app');
|
|
38
|
+
this._updateTagAttr();
|
|
39
|
+
|
|
40
|
+
var contentEle = document.createElement('div');
|
|
41
|
+
contentEle.style.width = '1000px';
|
|
42
|
+
contentEle.style.height = '1000px';
|
|
43
|
+
contentEle.style.display = 'block';
|
|
44
|
+
|
|
45
|
+
var scriptFragment = document.createDocumentFragment();
|
|
46
|
+
scriptFragment.appendChild(contentEle);
|
|
47
|
+
|
|
48
|
+
var scriptTag = document.createElement('script');
|
|
49
|
+
scriptTag.setAttribute('type', 'text/wxtag-template');
|
|
50
|
+
scriptTag.appendChild(scriptFragment);
|
|
51
|
+
|
|
52
|
+
this._openAppTag.appendChild(scriptTag);
|
|
53
|
+
this._template.content.appendChild(this._openAppTag);
|
|
54
|
+
this.attachShadow({ mode: 'open' });
|
|
55
|
+
this.shadowRoot.appendChild(this._template.content);
|
|
56
|
+
} else {
|
|
57
|
+
this._updateTagAttr();
|
|
58
|
+
}
|
|
59
|
+
} else if (!this._isApp && this._isMobile) {
|
|
60
|
+
this._genTemplate();
|
|
61
|
+
if (!this._alink) {
|
|
62
|
+
this._alink = document.createElement('a');
|
|
63
|
+
this._alink.style.display = 'block';
|
|
64
|
+
this._alink.style.width = '100%';
|
|
65
|
+
this._alink.style.height = '100%';
|
|
66
|
+
this._template.content.appendChild(this._alink);
|
|
67
|
+
this.attachShadow({ mode: 'open' });
|
|
68
|
+
this.shadowRoot.appendChild(this._template.content);
|
|
69
|
+
this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
|
|
70
|
+
}
|
|
71
|
+
this._updateTagAttr();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
_handleAlinkClick() {
|
|
75
|
+
console.log("this._alink is clicked");
|
|
76
|
+
// 端外使用scheme打开app,3秒内如果页面依然可见,说明没有跳转到app里边,则跳转到fallback链接
|
|
77
|
+
if (this._alink_click_timer) {
|
|
78
|
+
clearTimeout(this._alink_click_timer);
|
|
79
|
+
}
|
|
80
|
+
let isPageHide = false;
|
|
81
|
+
this._pagehideCallback = this._pagehideCallback || function () {
|
|
82
|
+
if (document.hidden) isPageHide = true;
|
|
83
|
+
};
|
|
84
|
+
window.removeEventListener("visibilitychange", this._pagehideCallback);
|
|
85
|
+
window.addEventListener("visibilitychange", this._pagehideCallback);
|
|
86
|
+
this._alink_click_timer = setTimeout(() => {
|
|
87
|
+
console.log("3s到了", isPageHide);
|
|
88
|
+
window.removeEventListener("visibilitychange", this._pagehideCallback);
|
|
89
|
+
if (isPageHide) return;
|
|
90
|
+
this._alink_click_timer = null;
|
|
91
|
+
// window.location.href = this._alink_fallback; // 直接重定向的话ios上没法去到appstore
|
|
92
|
+
var tmplnk = document.createElement("a");
|
|
93
|
+
tmplnk.href = this._alink_fallback;
|
|
94
|
+
tmplnk.click();
|
|
95
|
+
}, 3000);
|
|
96
|
+
}
|
|
97
|
+
disconnectedCallback() {
|
|
98
|
+
if (this._openAppTag) {
|
|
99
|
+
this._openAppTag.remove();
|
|
100
|
+
this._openAppTag = null;
|
|
101
|
+
}
|
|
102
|
+
if (this._alink) {
|
|
103
|
+
this._alink.remove();
|
|
104
|
+
this._alink = null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_genTemplate() {
|
|
108
|
+
if (!this._template) {
|
|
109
|
+
this._template = document.createElement('template');
|
|
110
|
+
this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;}</style>';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
_updateTagAttr() {
|
|
114
|
+
if (this._openAppTag) {
|
|
115
|
+
this._openAppTag.setAttribute('appid', this.getAttribute('appid') || this._defaultAppid);
|
|
116
|
+
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
117
|
+
} else if (this._alink) {
|
|
118
|
+
// TODO: 如果设置了点点以外的appid,这里其实是有问题的,待后续更新优化
|
|
119
|
+
if (this._isIOS) {
|
|
120
|
+
this._alink.href = "com.tuwan.diandian://openPage?type=room&id=123";
|
|
121
|
+
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";
|
|
122
|
+
} else {
|
|
123
|
+
var packageName = "com.tuwan.yw";
|
|
124
|
+
this._alink_fallback = "https://sj.qq.com/myapp/detail.htm?apkName=" + packageName;
|
|
125
|
+
this._alink.href = "intent://diandain:8888/splash#Intent;scheme=taole;package=" + packageName + ";S.browser_fallback_url=" + this._alink_fallback + ";end";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let isRegister = false;
|
|
134
|
+
function registerTdiv() {
|
|
135
|
+
if (!isRegister) {
|
|
136
|
+
defineTag();
|
|
137
|
+
isRegister = true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
registerTdiv();
|
|
142
|
+
|
|
143
|
+
// TODO: 之后放出setting入口之类的
|
|
144
|
+
var index = {
|
|
145
|
+
version
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
return index;
|
|
149
|
+
|
|
150
|
+
}));
|
package/dist/tdiv.umd.js
CHANGED