@haluo/util 2.1.5 → 2.1.8

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.
Files changed (32) hide show
  1. package/dist/index.js +20 -19
  2. package/dist/modules/app-call/configs.js +14 -6
  3. package/dist/modules/app-call/core.d.ts +1 -1
  4. package/dist/modules/app-call/core.js +59 -49
  5. package/dist/modules/app-call/extensions.d.ts +1 -1
  6. package/dist/modules/app-call/extensions.js +324 -257
  7. package/dist/modules/app-call/index.js +9 -9
  8. package/dist/modules/app-call/offline.js +42 -34
  9. package/dist/modules/cookie/index.js +22 -17
  10. package/dist/modules/date/index.js +54 -48
  11. package/dist/modules/dom/index.js +21 -15
  12. package/dist/modules/filter/index.js +14 -8
  13. package/dist/modules/format/index.js +9 -5
  14. package/dist/modules/match/index.js +8 -5
  15. package/dist/modules/monitor/lib/jsError.js +27 -38
  16. package/dist/modules/monitor/lib/timing.js +15 -17
  17. package/dist/modules/monitor/lib/xhr.js +26 -25
  18. package/dist/modules/monitor/utils/tracker.js +22 -10
  19. package/dist/modules/number/index.js +33 -30
  20. package/dist/modules/open-app/index.d.ts +1 -0
  21. package/dist/modules/open-app/index.js +55 -64
  22. package/dist/modules/sentry/index.js +16 -12
  23. package/dist/modules/tools/index.d.ts +1 -1
  24. package/dist/modules/tools/index.js +164 -154
  25. package/dist/modules/track/index.js +149 -96
  26. package/dist/modules/upload/aliOss.d.ts +36 -4
  27. package/dist/modules/upload/aliOss.js +569 -396
  28. package/dist/modules/upload/index.js +32 -29
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +1 -1
  31. package/dist/modules/app-call/partner-bridge.d.ts +0 -5
  32. package/dist/modules/app-call/partner-bridge.js +0 -68
@@ -7,40 +7,28 @@
7
7
  */
8
8
  import qs from 'qs';
9
9
  import tools from '../tools';
10
- class OpenAppClass {
11
- env;
12
- postJddTrack;
13
- trackId;
14
- openAppState;
15
- ua;
16
- _wx;
17
- _android;
18
- _isHarmonyos;
19
- _ios;
20
- _isPrice;
21
- currentEnv;
22
- appUrl;
23
- appStoreUrl;
24
- underway;
10
+ var OpenAppClass = /** @class */ (function () {
25
11
  /**
26
12
  * @param {Object} env - 环境配置,必须
27
13
  * @param {Function} postJddTrack - 埋点方法,必须
28
14
  * @param {String} trackId - 埋点id,可选
29
15
  * @param {Object} openAppState - 打开app状态,可选
30
16
  */
31
- constructor(env, postJddTrack, trackId = 'S_00000000000108', openAppState) {
17
+ function OpenAppClass(env, postJddTrack, trackId, openAppState) {
18
+ if (trackId === void 0) { trackId = 'S_00000000000108'; }
32
19
  this.env = env; // 环境配置,必须
33
20
  this.postJddTrack = postJddTrack; // 埋点方法,必须
34
21
  this.trackId = trackId; // 埋点id,可选
35
22
  this.openAppState = openAppState; // 打开app状态,可选
23
+ this.isBrowser = typeof window !== 'undefined';
36
24
  this.ua = navigator.userAgent.toLowerCase();
37
25
  this._wx = this.ua.indexOf('micromessenger') > -1;
38
26
  this._android = !!(this.ua.match(/android/i) || this.ua.match(/miuibrowser/i));
39
27
  this._isHarmonyos = !!this.ua.match(/harmonyos/i);
40
28
  this._ios = navigator.userAgent.match(/(iPhone|iPod|iPad);?/i);
41
- this._isPrice = sessionStorage.getItem('isHaloenterprise') || false; // 厂家版,切换打开地址
29
+ this._isPrice = this.isBrowser && sessionStorage.getItem('isHaloenterprise') || false; // 厂家版,切换打开地址
42
30
  this.currentEnv = env;
43
- this.getCurrentEnv();
31
+ this.isBrowser && this.getCurrentEnv();
44
32
  this.appUrl = this._isPrice ? env.APPLINKPRICE : this.currentEnv.APPLINK;
45
33
  this.appStoreUrl = this._isPrice ? env.APPLINKPRICEIOS : this.currentEnv.APPLINKIOS;
46
34
  this.underway = false;
@@ -48,8 +36,8 @@ class OpenAppClass {
48
36
  /**
49
37
  * 根据域名动态获取配置,保证多项目代码一样
50
38
  */
51
- getCurrentEnv() {
52
- const host = location.host;
39
+ OpenAppClass.prototype.getCurrentEnv = function () {
40
+ var host = location.host;
53
41
  if (host.includes('58moto')) {
54
42
  this.currentEnv = {
55
43
  motoAndroidScheme: this.env.motoAndroidScheme,
@@ -90,11 +78,11 @@ class OpenAppClass {
90
78
  APPLINKIOS: this.env.dronefineAPPLINKIOS,
91
79
  };
92
80
  }
93
- }
81
+ };
94
82
  /**
95
83
  * 打开APP主流程
96
84
  */
97
- invoke() {
85
+ OpenAppClass.prototype.invoke = function () {
98
86
  if (this.underway) {
99
87
  return;
100
88
  }
@@ -105,13 +93,13 @@ class OpenAppClass {
105
93
  }
106
94
  this.underway = true;
107
95
  // 生成url并且放到剪贴板
108
- let url = this.getSechmaUrl();
96
+ var url = this.getSechmaUrl();
109
97
  if (url) {
110
98
  tools.clipboard(url);
111
99
  }
112
- const apk = JSON.parse(sessionStorage.getItem('downloadApk') || '{}');
113
- const tag = this._ios ? (apk.channelName ? `App Store-${apk.channelName}` : 'App Store') : (apk.channelName ? `渠道${apk.channelName}包` : '安卓包');
114
- this.postJddTrack(this.trackId, { tag });
100
+ var apk = JSON.parse(sessionStorage.getItem('downloadApk') || '{}');
101
+ var tag = this._ios ? (apk.channelName ? "App Store-".concat(apk.channelName) : 'App Store') : (apk.channelName ? "\u6E20\u9053".concat(apk.channelName, "\u5305") : '安卓包');
102
+ this.postJddTrack(this.trackId, { tag: tag });
115
103
  // 厂家版 app
116
104
  if (this._android && location.href.includes('downloadPrise')) {
117
105
  window.location.href = (apk && apk.path) || this.appUrl;
@@ -121,7 +109,7 @@ class OpenAppClass {
121
109
  // 客户端打开app-下载页特殊处理
122
110
  if (location.href.includes('download') && window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
123
111
  this.underway = false;
124
- return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: `https://${location.host}/home` });
112
+ return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: "https://".concat(location.host, "/home") });
125
113
  }
126
114
  // 客户端打开app
127
115
  if (window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
@@ -134,21 +122,22 @@ class OpenAppClass {
134
122
  url = this.appStoreUrl;
135
123
  }
136
124
  this.open(url);
137
- }
125
+ };
138
126
  // 获取自定义的url
139
- getUrl() {
140
- const searchParams = qs.parse(location.search.slice(1)); // 路由的query
141
- const url = searchParams.customOpenUrl || window.location.href;
127
+ OpenAppClass.prototype.getUrl = function () {
128
+ var searchParams = qs.parse(location.search.slice(1)); // 路由的query
129
+ var url = searchParams.customOpenUrl || window.location.href;
142
130
  return url;
143
- }
131
+ };
144
132
  /**
145
133
  * 获取打开 app sechma url
146
134
  * @returns {string | undefined} 打开app的schema或跳转链接
147
135
  * params:params={"type":"","id":0,"name":"","travelId":0}
148
136
  * type:原生页面key(必须);id:页面id(可选);subject 短话题、版块名称 或 页面标题(可选);travelId 游记id(可选)
149
137
  */
150
- getSechmaUrl() {
151
- const keys = {
138
+ OpenAppClass.prototype.getSechmaUrl = function () {
139
+ var _a, _b;
140
+ var keys = {
152
141
  '/posts/': 'thread_detail',
153
142
  '/detailedForum/': 'forum_detail',
154
143
  '/video/': 'video_detail',
@@ -167,94 +156,96 @@ class OpenAppClass {
167
156
  '/coupon-detail': 'coupon_detail',
168
157
  '/news/': 'essay_detail' // 文章详情
169
158
  };
170
- const target = Object.keys(keys).filter(function (value) {
159
+ var target = Object.keys(keys).filter(function (value) {
171
160
  return window.location.href.indexOf(value) > -1;
172
161
  });
173
- const type = target && target[0] && keys[target[0]];
174
- const searchParams = qs.parse(location.search.slice(1)); // 路由的query
175
- const id = parseInt(location.pathname.split('/').reverse()[0]) ||
162
+ var type = target && target[0] && keys[target[0]];
163
+ var searchParams = qs.parse(location.search.slice(1)); // 路由的query
164
+ var id = parseInt(location.pathname.split('/').reverse()[0]) ||
176
165
  parseInt(searchParams.id) ||
177
166
  parseInt(searchParams.carId) ||
178
167
  parseInt(searchParams.goodId); // 页面id
179
- const subject = searchParams.subject || undefined; // 页面标题或name
180
- const temp = {
168
+ var subject = searchParams.subject || undefined; // 页面标题或name
169
+ var temp = {
181
170
  relationType: type,
182
171
  id: id,
183
172
  name: subject
184
173
  };
185
- const data = this.openAppState?.state?.openApps || {};
186
- let open_url = '';
174
+ var data = ((_b = (_a = this.openAppState) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.openApps) || {};
175
+ var open_url = '';
187
176
  if (data.type && data.href === window.location.href) {
188
177
  temp.relationType = keys[data.type] || '';
189
178
  temp.id = data.id || '';
190
179
  temp.name = data.title || '';
191
180
  open_url = data.url || '';
192
181
  }
193
- const openUrl = open_url || searchParams.customOpenUrl || window.location.href;
182
+ var openUrl = open_url || searchParams.customOpenUrl || window.location.href;
194
183
  // activityId 大于零,type 为 activity
195
184
  if (searchParams.activityId) {
196
185
  temp.relationType = 'activity';
197
186
  temp.link = decodeURIComponent(decodeURIComponent(openUrl));
198
187
  }
199
188
  temp.jumpUrl = decodeURIComponent(decodeURIComponent(openUrl));
200
- const params = JSON.stringify(temp);
189
+ var params = JSON.stringify(temp);
201
190
  if (this._ios) {
202
- return `${this.currentEnv.motoIOSScheme}?params=${params}`;
191
+ return "".concat(this.currentEnv.motoIOSScheme, "?params=").concat(params);
203
192
  }
204
193
  if (this._android || this._isHarmonyos) {
205
- const url = this._wx ? `${this.appUrl}&android_scheme=${this.currentEnv.motoAndroidScheme}?params=${params}` : `${this.currentEnv.motoAndroidScheme}?params=${params}`;
194
+ var url = this._wx ? "".concat(this.appUrl, "&android_scheme=").concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params) : "".concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params);
206
195
  return url;
207
196
  }
208
197
  return undefined;
209
- }
198
+ };
210
199
  /**
211
200
  * 方法一(推荐):打开APP
212
201
  * http://www.cnblogs.com/shadajin/p/5724117.html
213
202
  */
214
- open(openUrl) {
203
+ OpenAppClass.prototype.open = function (openUrl) {
204
+ var _this = this;
215
205
  if (!openUrl) {
216
206
  this.underway = false;
217
207
  return;
218
208
  }
219
209
  if (this._ios) {
220
210
  this.underway = false;
221
- setTimeout(() => (location.href = this.appStoreUrl || ''), 3000);
211
+ setTimeout(function () { return (location.href = _this.appStoreUrl || ''); }, 3000);
222
212
  return (location.href = openUrl);
223
213
  }
224
214
  if (this._android) {
225
- const ifr = document.createElement('iframe');
226
- ifr.src = openUrl;
227
- ifr.style.display = 'none';
228
- document.body.appendChild(ifr);
215
+ var ifr_1 = document.createElement('iframe');
216
+ ifr_1.src = openUrl;
217
+ ifr_1.style.display = 'none';
218
+ document.body.appendChild(ifr_1);
229
219
  setTimeout(function () {
230
- document.body.removeChild(ifr);
220
+ document.body.removeChild(ifr_1);
231
221
  }, 3000);
232
222
  }
233
- return new Promise((resolve, reject) => {
223
+ return new Promise(function (resolve, reject) {
234
224
  // 检查APP是否打开
235
- const check = (elsTime) => {
225
+ var check = function (elsTime) {
236
226
  if (elsTime > 3000 || document.hidden) {
237
227
  // @ts-ignore
238
228
  resolve('成功打开APP');
239
229
  }
240
230
  else {
241
231
  // @ts-ignore
242
- window.location.href = `https://${location.host}/download`;
232
+ window.location.href = "https://".concat(location.host, "/download");
243
233
  reject('打开APP失败');
244
234
  }
245
- this.underway = false;
235
+ _this.underway = false;
246
236
  };
247
- let _count = 0;
248
- const _clickTime = +new Date();
249
- const intHandle = setInterval(() => {
237
+ var _count = 0;
238
+ var _clickTime = +new Date();
239
+ var intHandle = setInterval(function () {
250
240
  _count++;
251
- const elsTime = +new Date() - _clickTime;
241
+ var elsTime = +new Date() - _clickTime;
252
242
  if (_count >= 100 || elsTime > 3000) {
253
243
  clearInterval(intHandle);
254
244
  check(elsTime);
255
245
  }
256
246
  }, 20);
257
247
  });
258
- }
259
- }
248
+ };
249
+ return OpenAppClass;
250
+ }());
260
251
  export default OpenAppClass;
@@ -9,23 +9,23 @@
9
9
  'use strict';
10
10
  import Raven from 'raven-js';
11
11
  // import RavenVue from 'raven-js/plugins/vue';
12
- class Report {
13
- static instance;
14
- constructor(Vue, options = {}) {
12
+ var Report = /** @class */ (function () {
13
+ function Report(Vue, options) {
14
+ if (options === void 0) { options = {}; }
15
15
  if (process.env.NODE_ENV !== 'development') {
16
16
  // todo
17
17
  }
18
18
  this.vue = Vue;
19
19
  this.options = options;
20
20
  }
21
- static getInstance(Vue, Option) {
21
+ Report.getInstance = function (Vue, Option) {
22
22
  if (!(this.instance instanceof this)) {
23
23
  this.instance = new this(Vue, Option);
24
24
  this.instance.install();
25
25
  }
26
26
  return this.instance;
27
- }
28
- install() {
27
+ };
28
+ Report.prototype.install = function () {
29
29
  if (process.env.NODE_ENV !== 'development') {
30
30
  // Raven.config(this.options.dsn, {
31
31
  // environment: process.env.NODE_ENV,
@@ -36,14 +36,17 @@ class Report {
36
36
  // 设置全局tag标签
37
37
  Raven.setTagsContext({ environment: this.options.env || '' });
38
38
  }
39
- }
39
+ };
40
40
  /**
41
41
  * 主动上报
42
42
  * @param {String} data
43
43
  * @param {String} type 'info','warning','error'
44
44
  * @param {Object} options
45
45
  */
46
- log(data = null, type = 'error', options = {}) {
46
+ Report.prototype.log = function (data, type, options) {
47
+ if (data === void 0) { data = null; }
48
+ if (type === void 0) { type = 'error'; }
49
+ if (options === void 0) { options = {}; }
47
50
  // 添加面包屑
48
51
  Raven.captureBreadcrumb({
49
52
  message: data,
@@ -54,7 +57,7 @@ class Report {
54
57
  Raven.captureException(data, {
55
58
  level: type,
56
59
  logger: 'manual exception',
57
- tags: { options },
60
+ tags: { options: options },
58
61
  });
59
62
  }
60
63
  else {
@@ -62,12 +65,13 @@ class Report {
62
65
  level: type,
63
66
  logger: 'manual data',
64
67
  extra: {
65
- data,
68
+ data: data,
66
69
  options: this.options,
67
70
  date: new Date(),
68
71
  },
69
72
  });
70
73
  }
71
- }
72
- }
74
+ };
75
+ return Report;
76
+ }());
73
77
  export default Report;
@@ -76,7 +76,7 @@ declare class ToolsClass {
76
76
  * @param {String} str
77
77
  * @return {String}
78
78
  */
79
- clipboard(str: string): Promise<void> | Error;
79
+ clipboard(str: string): Error | Promise<void>;
80
80
  /**
81
81
  * 首字母大写
82
82
  * @param {String} str