@taole/dev-helper 0.0.15 → 0.0.17

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