@haluo/util 2.0.33 → 2.0.35
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/index.d.ts +3 -0
- package/dist/index.js +23 -19
- package/dist/modules/app-call/configs.d.ts +9 -0
- package/dist/modules/app-call/configs.js +44 -0
- package/dist/modules/app-call/core.d.ts +53 -0
- package/dist/modules/app-call/core.js +175 -0
- package/dist/modules/app-call/extensions.d.ts +187 -0
- package/dist/modules/app-call/extensions.js +1297 -0
- package/dist/modules/app-call/index.d.ts +16 -0
- package/dist/modules/app-call/index.js +84 -0
- package/dist/modules/app-call/offline.d.ts +12 -0
- package/dist/modules/app-call/offline.js +191 -0
- package/dist/modules/app-call/types.d.ts +67 -0
- package/dist/modules/app-call/types.js +4 -0
- package/dist/modules/cookie/index.js +22 -17
- package/dist/modules/date/index.js +54 -48
- package/dist/modules/dom/index.js +21 -15
- package/dist/modules/filter/index.js +14 -8
- package/dist/modules/format/index.js +9 -5
- package/dist/modules/match/index.js +8 -5
- package/dist/modules/monitor/lib/jsError.js +27 -38
- package/dist/modules/monitor/lib/timing.js +15 -17
- package/dist/modules/monitor/lib/xhr.js +26 -25
- package/dist/modules/monitor/utils/tracker.js +22 -10
- package/dist/modules/number/index.js +33 -30
- package/dist/modules/open-app/index.d.ts +3 -7
- package/dist/modules/open-app/index.js +55 -63
- package/dist/modules/sentry/index.js +16 -12
- package/dist/modules/tools/index.js +164 -154
- package/dist/modules/track/index.d.ts +122 -0
- package/dist/modules/track/index.js +421 -0
- package/dist/modules/track/types.d.ts +108 -0
- package/dist/modules/track/types.js +4 -0
- package/dist/modules/upload/aliOss.d.ts +52 -5
- package/dist/modules/upload/aliOss.js +589 -378
- package/dist/modules/upload/index.js +32 -29
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -2
|
@@ -7,28 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import qs from 'qs';
|
|
9
9
|
import tools from '../tools';
|
|
10
|
-
|
|
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
|
-
|
|
17
|
+
function OpenAppClass(env, postJddTrack, trackId, openAppState) {
|
|
18
|
+
if (trackId === void 0) { trackId = 'S_00000000000108'; }
|
|
19
|
+
var _a;
|
|
32
20
|
this.env = env; // 环境配置,必须
|
|
33
21
|
this.postJddTrack = postJddTrack; // 埋点方法,必须
|
|
34
22
|
this.trackId = trackId; // 埋点id,可选
|
|
@@ -38,7 +26,7 @@ class OpenAppClass {
|
|
|
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 = ((_a = window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem('isHaloenterprise')) || false; // 厂家版,切换打开地址
|
|
42
30
|
this.currentEnv = env;
|
|
43
31
|
this.getCurrentEnv();
|
|
44
32
|
this.appUrl = this._isPrice ? env.APPLINKPRICE : this.currentEnv.APPLINK;
|
|
@@ -48,8 +36,8 @@ class OpenAppClass {
|
|
|
48
36
|
/**
|
|
49
37
|
* 根据域名动态获取配置,保证多项目代码一样
|
|
50
38
|
*/
|
|
51
|
-
getCurrentEnv() {
|
|
52
|
-
|
|
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,12 @@ 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 () {
|
|
86
|
+
var _a;
|
|
98
87
|
if (this.underway) {
|
|
99
88
|
return;
|
|
100
89
|
}
|
|
@@ -105,13 +94,13 @@ class OpenAppClass {
|
|
|
105
94
|
}
|
|
106
95
|
this.underway = true;
|
|
107
96
|
// 生成url并且放到剪贴板
|
|
108
|
-
|
|
97
|
+
var url = this.getSechmaUrl();
|
|
109
98
|
if (url) {
|
|
110
99
|
tools.clipboard(url);
|
|
111
100
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.postJddTrack(this.trackId, { tag });
|
|
101
|
+
var apk = JSON.parse(((_a = window.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem('downloadApk')) || '{}');
|
|
102
|
+
var tag = this._ios ? (apk.channelName ? "App Store-".concat(apk.channelName) : 'App Store') : (apk.channelName ? "\u6E20\u9053".concat(apk.channelName, "\u5305") : '安卓包');
|
|
103
|
+
this.postJddTrack(this.trackId, { tag: tag });
|
|
115
104
|
// 厂家版 app
|
|
116
105
|
if (this._android && location.href.includes('downloadPrise')) {
|
|
117
106
|
window.location.href = (apk && apk.path) || this.appUrl;
|
|
@@ -121,7 +110,7 @@ class OpenAppClass {
|
|
|
121
110
|
// 客户端打开app-下载页特殊处理
|
|
122
111
|
if (location.href.includes('download') && window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
|
|
123
112
|
this.underway = false;
|
|
124
|
-
return window.AppCall.openOtherAppUrlRouter({ appUrlRouter:
|
|
113
|
+
return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: "https://".concat(location.host, "/home") });
|
|
125
114
|
}
|
|
126
115
|
// 客户端打开app
|
|
127
116
|
if (window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
|
|
@@ -134,21 +123,22 @@ class OpenAppClass {
|
|
|
134
123
|
url = this.appStoreUrl;
|
|
135
124
|
}
|
|
136
125
|
this.open(url);
|
|
137
|
-
}
|
|
126
|
+
};
|
|
138
127
|
// 获取自定义的url
|
|
139
|
-
getUrl() {
|
|
140
|
-
|
|
141
|
-
|
|
128
|
+
OpenAppClass.prototype.getUrl = function () {
|
|
129
|
+
var searchParams = qs.parse(location.search.slice(1)); // 路由的query
|
|
130
|
+
var url = searchParams.customOpenUrl || window.location.href;
|
|
142
131
|
return url;
|
|
143
|
-
}
|
|
132
|
+
};
|
|
144
133
|
/**
|
|
145
134
|
* 获取打开 app sechma url
|
|
146
135
|
* @returns {string | undefined} 打开app的schema或跳转链接
|
|
147
136
|
* params:params={"type":"","id":0,"name":"","travelId":0}
|
|
148
137
|
* type:原生页面key(必须);id:页面id(可选);subject 短话题、版块名称 或 页面标题(可选);travelId 游记id(可选)
|
|
149
138
|
*/
|
|
150
|
-
getSechmaUrl() {
|
|
151
|
-
|
|
139
|
+
OpenAppClass.prototype.getSechmaUrl = function () {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
var keys = {
|
|
152
142
|
'/posts/': 'thread_detail',
|
|
153
143
|
'/detailedForum/': 'forum_detail',
|
|
154
144
|
'/video/': 'video_detail',
|
|
@@ -167,94 +157,96 @@ class OpenAppClass {
|
|
|
167
157
|
'/coupon-detail': 'coupon_detail',
|
|
168
158
|
'/news/': 'essay_detail' // 文章详情
|
|
169
159
|
};
|
|
170
|
-
|
|
160
|
+
var target = Object.keys(keys).filter(function (value) {
|
|
171
161
|
return window.location.href.indexOf(value) > -1;
|
|
172
162
|
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
163
|
+
var type = target && target[0] && keys[target[0]];
|
|
164
|
+
var searchParams = qs.parse(location.search.slice(1)); // 路由的query
|
|
165
|
+
var id = parseInt(location.pathname.split('/').reverse()[0]) ||
|
|
176
166
|
parseInt(searchParams.id) ||
|
|
177
167
|
parseInt(searchParams.carId) ||
|
|
178
168
|
parseInt(searchParams.goodId); // 页面id
|
|
179
|
-
|
|
180
|
-
|
|
169
|
+
var subject = searchParams.subject || undefined; // 页面标题或name
|
|
170
|
+
var temp = {
|
|
181
171
|
relationType: type,
|
|
182
172
|
id: id,
|
|
183
173
|
name: subject
|
|
184
174
|
};
|
|
185
|
-
|
|
186
|
-
|
|
175
|
+
var data = ((_b = (_a = this.openAppState) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.openApps) || {};
|
|
176
|
+
var open_url = '';
|
|
187
177
|
if (data.type && data.href === window.location.href) {
|
|
188
178
|
temp.relationType = keys[data.type] || '';
|
|
189
179
|
temp.id = data.id || '';
|
|
190
180
|
temp.name = data.title || '';
|
|
191
181
|
open_url = data.url || '';
|
|
192
182
|
}
|
|
193
|
-
|
|
183
|
+
var openUrl = open_url || searchParams.customOpenUrl || window.location.href;
|
|
194
184
|
// activityId 大于零,type 为 activity
|
|
195
185
|
if (searchParams.activityId) {
|
|
196
186
|
temp.relationType = 'activity';
|
|
197
187
|
temp.link = decodeURIComponent(decodeURIComponent(openUrl));
|
|
198
188
|
}
|
|
199
189
|
temp.jumpUrl = decodeURIComponent(decodeURIComponent(openUrl));
|
|
200
|
-
|
|
190
|
+
var params = JSON.stringify(temp);
|
|
201
191
|
if (this._ios) {
|
|
202
|
-
return
|
|
192
|
+
return "".concat(this.currentEnv.motoIOSScheme, "?params=").concat(params);
|
|
203
193
|
}
|
|
204
194
|
if (this._android || this._isHarmonyos) {
|
|
205
|
-
|
|
195
|
+
var url = this._wx ? "".concat(this.appUrl, "&android_scheme=").concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params) : "".concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params);
|
|
206
196
|
return url;
|
|
207
197
|
}
|
|
208
198
|
return undefined;
|
|
209
|
-
}
|
|
199
|
+
};
|
|
210
200
|
/**
|
|
211
201
|
* 方法一(推荐):打开APP
|
|
212
202
|
* http://www.cnblogs.com/shadajin/p/5724117.html
|
|
213
203
|
*/
|
|
214
|
-
open(openUrl) {
|
|
204
|
+
OpenAppClass.prototype.open = function (openUrl) {
|
|
205
|
+
var _this = this;
|
|
215
206
|
if (!openUrl) {
|
|
216
207
|
this.underway = false;
|
|
217
208
|
return;
|
|
218
209
|
}
|
|
219
210
|
if (this._ios) {
|
|
220
211
|
this.underway = false;
|
|
221
|
-
setTimeout(()
|
|
212
|
+
setTimeout(function () { return (location.href = _this.appStoreUrl || ''); }, 3000);
|
|
222
213
|
return (location.href = openUrl);
|
|
223
214
|
}
|
|
224
215
|
if (this._android) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
document.body.appendChild(
|
|
216
|
+
var ifr_1 = document.createElement('iframe');
|
|
217
|
+
ifr_1.src = openUrl;
|
|
218
|
+
ifr_1.style.display = 'none';
|
|
219
|
+
document.body.appendChild(ifr_1);
|
|
229
220
|
setTimeout(function () {
|
|
230
|
-
document.body.removeChild(
|
|
221
|
+
document.body.removeChild(ifr_1);
|
|
231
222
|
}, 3000);
|
|
232
223
|
}
|
|
233
|
-
return new Promise((resolve, reject)
|
|
224
|
+
return new Promise(function (resolve, reject) {
|
|
234
225
|
// 检查APP是否打开
|
|
235
|
-
|
|
226
|
+
var check = function (elsTime) {
|
|
236
227
|
if (elsTime > 3000 || document.hidden) {
|
|
237
228
|
// @ts-ignore
|
|
238
229
|
resolve('成功打开APP');
|
|
239
230
|
}
|
|
240
231
|
else {
|
|
241
232
|
// @ts-ignore
|
|
242
|
-
window.location.href =
|
|
233
|
+
window.location.href = "https://".concat(location.host, "/download");
|
|
243
234
|
reject('打开APP失败');
|
|
244
235
|
}
|
|
245
|
-
|
|
236
|
+
_this.underway = false;
|
|
246
237
|
};
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
238
|
+
var _count = 0;
|
|
239
|
+
var _clickTime = +new Date();
|
|
240
|
+
var intHandle = setInterval(function () {
|
|
250
241
|
_count++;
|
|
251
|
-
|
|
242
|
+
var elsTime = +new Date() - _clickTime;
|
|
252
243
|
if (_count >= 100 || elsTime > 3000) {
|
|
253
244
|
clearInterval(intHandle);
|
|
254
245
|
check(elsTime);
|
|
255
246
|
}
|
|
256
247
|
}, 20);
|
|
257
248
|
});
|
|
258
|
-
}
|
|
259
|
-
|
|
249
|
+
};
|
|
250
|
+
return OpenAppClass;
|
|
251
|
+
}());
|
|
260
252
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
|
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;
|