@haluo/util 2.0.23 → 2.0.24
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 -1
- package/dist/index.js +33 -61
- package/dist/modules/cookie/index.js +18 -24
- package/dist/modules/date/index.js +49 -56
- package/dist/modules/dom/index.js +16 -23
- package/dist/modules/filter/index.js +15 -25
- package/dist/modules/format/index.js +6 -12
- package/dist/modules/match/index.js +6 -10
- package/dist/modules/monitor/index.js +7 -14
- package/dist/modules/monitor/lib/jsError.js +39 -35
- package/dist/modules/monitor/lib/timing.js +24 -28
- package/dist/modules/monitor/lib/xhr.js +26 -33
- package/dist/modules/monitor/utils/onload.js +1 -4
- package/dist/modules/monitor/utils/tracker.js +13 -27
- package/dist/modules/number/index.js +31 -35
- package/dist/modules/open-app/index.js +66 -61
- package/dist/modules/sentry/index.js +19 -27
- package/dist/modules/tools/index.d.ts +1 -1
- package/dist/modules/tools/index.js +158 -169
- package/dist/modules/upload/aliOss.d.ts +75 -124
- package/dist/modules/upload/aliOss.js +175 -357
- package/dist/modules/upload/index.d.ts +2 -14
- package/dist/modules/upload/index.js +2 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.js +1 -2
- package/package.json +14 -3
- package/dist/modules/upload/aliOss copy.d.ts +0 -321
- package/dist/modules/upload/aliOss copy.js +0 -734
- package/dist/modules/upload/backup-aliOss.d.ts +0 -321
- package/dist/modules/upload/backup-aliOss.js +0 -734
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
1
|
/**
|
|
7
2
|
* H5打开APP工具类
|
|
8
3
|
*
|
|
@@ -10,17 +5,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
5
|
* 1、应用宝打开app指定页面,参考今日头条
|
|
11
6
|
* 2、浏览器中进入页面立即打开app,参考掘金
|
|
12
7
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
import qs from 'qs';
|
|
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;
|
|
16
25
|
/**
|
|
17
26
|
* @param {Object} env - 环境配置,必须
|
|
18
27
|
* @param {Function} postJddTrack - 埋点方法,必须
|
|
19
28
|
* @param {String} trackId - 埋点id,可选
|
|
20
29
|
* @param {Object} openAppState - 打开app状态,可选
|
|
21
30
|
*/
|
|
22
|
-
|
|
23
|
-
if (trackId === void 0) { trackId = 'S_00000000000108'; }
|
|
31
|
+
constructor(env, postJddTrack, trackId = 'S_00000000000108', openAppState) {
|
|
24
32
|
this.env = env; // 环境配置,必须
|
|
25
33
|
this.postJddTrack = postJddTrack; // 埋点方法,必须
|
|
26
34
|
this.trackId = trackId; // 埋点id,可选
|
|
@@ -40,8 +48,8 @@ var OpenAppClass = /** @class */ (function () {
|
|
|
40
48
|
/**
|
|
41
49
|
* 根据域名动态获取配置,保证多项目代码一样
|
|
42
50
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
getCurrentEnv() {
|
|
52
|
+
const host = location.host;
|
|
45
53
|
if (host.includes('58moto')) {
|
|
46
54
|
this.currentEnv = {
|
|
47
55
|
motoAndroidScheme: this.env.motoAndroidScheme,
|
|
@@ -66,11 +74,11 @@ var OpenAppClass = /** @class */ (function () {
|
|
|
66
74
|
APPLINKIOS: this.env.BIAOFINEAPPLINKIOS,
|
|
67
75
|
};
|
|
68
76
|
}
|
|
69
|
-
}
|
|
77
|
+
}
|
|
70
78
|
/**
|
|
71
79
|
* 打开APP主流程
|
|
72
80
|
*/
|
|
73
|
-
|
|
81
|
+
invoke() {
|
|
74
82
|
if (this.underway) {
|
|
75
83
|
return;
|
|
76
84
|
}
|
|
@@ -81,13 +89,13 @@ var OpenAppClass = /** @class */ (function () {
|
|
|
81
89
|
}
|
|
82
90
|
this.underway = true;
|
|
83
91
|
// 生成url并且放到剪贴板
|
|
84
|
-
|
|
92
|
+
let url = this.getSechmaUrl();
|
|
85
93
|
if (url) {
|
|
86
|
-
|
|
94
|
+
tools.clipboard(url);
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.postJddTrack(this.trackId, { tag
|
|
96
|
+
const apk = JSON.parse(sessionStorage.getItem('downloadApk') || '{}');
|
|
97
|
+
const tag = this._ios ? (apk.channelName ? `App Store-${apk.channelName}` : 'App Store') : (apk.channelName ? `渠道${apk.channelName}包` : '安卓包');
|
|
98
|
+
this.postJddTrack(this.trackId, { tag });
|
|
91
99
|
// 厂家版 app
|
|
92
100
|
if (this._android && location.href.includes('downloadPrise')) {
|
|
93
101
|
window.location.href = (apk && apk.path) || this.appUrl;
|
|
@@ -97,7 +105,7 @@ var OpenAppClass = /** @class */ (function () {
|
|
|
97
105
|
// 客户端打开app-下载页特殊处理
|
|
98
106
|
if (location.href.includes('download') && window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
|
|
99
107
|
this.underway = false;
|
|
100
|
-
return window.AppCall.openOtherAppUrlRouter({ appUrlRouter:
|
|
108
|
+
return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: `https://${location.host}/home` });
|
|
101
109
|
}
|
|
102
110
|
// 客户端打开app
|
|
103
111
|
if (window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
|
|
@@ -110,22 +118,21 @@ var OpenAppClass = /** @class */ (function () {
|
|
|
110
118
|
url = this.appStoreUrl;
|
|
111
119
|
}
|
|
112
120
|
this.open(url);
|
|
113
|
-
}
|
|
121
|
+
}
|
|
114
122
|
// 获取自定义的url
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
123
|
+
getUrl() {
|
|
124
|
+
const searchParams = qs.parse(location.search.slice(1)); // 路由的query
|
|
125
|
+
const url = searchParams.customOpenUrl || window.location.href;
|
|
118
126
|
return url;
|
|
119
|
-
}
|
|
127
|
+
}
|
|
120
128
|
/**
|
|
121
129
|
* 获取打开 app sechma url
|
|
122
130
|
* @returns {string | undefined} 打开app的schema或跳转链接
|
|
123
131
|
* params:params={"type":"","id":0,"name":"","travelId":0}
|
|
124
132
|
* type:原生页面key(必须);id:页面id(可选);subject 短话题、版块名称 或 页面标题(可选);travelId 游记id(可选)
|
|
125
133
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
var keys = {
|
|
134
|
+
getSechmaUrl() {
|
|
135
|
+
const keys = {
|
|
129
136
|
'/posts/': 'thread_detail',
|
|
130
137
|
'/detailedForum/': 'forum_detail',
|
|
131
138
|
'/video/': 'video_detail',
|
|
@@ -144,96 +151,94 @@ var OpenAppClass = /** @class */ (function () {
|
|
|
144
151
|
'/coupon-detail': 'coupon_detail',
|
|
145
152
|
'/news/': 'essay_detail' // 文章详情
|
|
146
153
|
};
|
|
147
|
-
|
|
154
|
+
const target = Object.keys(keys).filter(function (value) {
|
|
148
155
|
return window.location.href.indexOf(value) > -1;
|
|
149
156
|
});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
const type = target && target[0] && keys[target[0]];
|
|
158
|
+
const searchParams = qs.parse(location.search.slice(1)); // 路由的query
|
|
159
|
+
const id = parseInt(location.pathname.split('/').reverse()[0]) ||
|
|
153
160
|
parseInt(searchParams.id) ||
|
|
154
161
|
parseInt(searchParams.carId) ||
|
|
155
162
|
parseInt(searchParams.goodId); // 页面id
|
|
156
|
-
|
|
157
|
-
|
|
163
|
+
const subject = searchParams.subject || undefined; // 页面标题或name
|
|
164
|
+
const temp = {
|
|
158
165
|
relationType: type,
|
|
159
166
|
id: id,
|
|
160
167
|
name: subject
|
|
161
168
|
};
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
const data = this.openAppState?.state?.openApps || {};
|
|
170
|
+
let open_url = '';
|
|
164
171
|
if (data.type && data.href === window.location.href) {
|
|
165
172
|
temp.relationType = keys[data.type] || '';
|
|
166
173
|
temp.id = data.id || '';
|
|
167
174
|
temp.name = data.title || '';
|
|
168
175
|
open_url = data.url || '';
|
|
169
176
|
}
|
|
170
|
-
|
|
177
|
+
const openUrl = open_url || searchParams.customOpenUrl || window.location.href;
|
|
171
178
|
// activityId 大于零,type 为 activity
|
|
172
179
|
if (searchParams.activityId) {
|
|
173
180
|
temp.relationType = 'activity';
|
|
174
181
|
temp.link = decodeURIComponent(decodeURIComponent(openUrl));
|
|
175
182
|
}
|
|
176
183
|
temp.jumpUrl = decodeURIComponent(decodeURIComponent(openUrl));
|
|
177
|
-
|
|
184
|
+
const params = JSON.stringify(temp);
|
|
178
185
|
if (this._ios) {
|
|
179
|
-
return
|
|
186
|
+
return `${this.currentEnv.motoIOSScheme}?params=${params}`;
|
|
180
187
|
}
|
|
181
188
|
if (this._android || this._isHarmonyos) {
|
|
182
|
-
|
|
189
|
+
const url = this._wx ? `${this.appUrl}&android_scheme=${this.currentEnv.motoAndroidScheme}?params=${params}` : `${this.currentEnv.motoAndroidScheme}?params=${params}`;
|
|
183
190
|
return url;
|
|
184
191
|
}
|
|
185
192
|
return undefined;
|
|
186
|
-
}
|
|
193
|
+
}
|
|
187
194
|
/**
|
|
188
195
|
* 方法一(推荐):打开APP
|
|
189
196
|
* http://www.cnblogs.com/shadajin/p/5724117.html
|
|
190
197
|
*/
|
|
191
|
-
|
|
192
|
-
var _this = this;
|
|
198
|
+
open(openUrl) {
|
|
193
199
|
if (!openUrl) {
|
|
194
200
|
this.underway = false;
|
|
195
201
|
return;
|
|
196
202
|
}
|
|
197
203
|
if (this._ios) {
|
|
198
204
|
this.underway = false;
|
|
199
|
-
setTimeout(
|
|
205
|
+
setTimeout(() => (location.href = this.appStoreUrl || ''), 3000);
|
|
200
206
|
return (location.href = openUrl);
|
|
201
207
|
}
|
|
202
208
|
if (this._android) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
document.body.appendChild(
|
|
209
|
+
const ifr = document.createElement('iframe');
|
|
210
|
+
ifr.src = openUrl;
|
|
211
|
+
ifr.style.display = 'none';
|
|
212
|
+
document.body.appendChild(ifr);
|
|
207
213
|
setTimeout(function () {
|
|
208
|
-
document.body.removeChild(
|
|
214
|
+
document.body.removeChild(ifr);
|
|
209
215
|
}, 3000);
|
|
210
216
|
}
|
|
211
|
-
return new Promise(
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
212
218
|
// 检查APP是否打开
|
|
213
|
-
|
|
219
|
+
const check = (elsTime) => {
|
|
214
220
|
if (elsTime > 3000 || document.hidden) {
|
|
215
221
|
// @ts-ignore
|
|
216
222
|
resolve('成功打开APP');
|
|
217
223
|
}
|
|
218
224
|
else {
|
|
219
225
|
// @ts-ignore
|
|
220
|
-
window.location.href =
|
|
226
|
+
window.location.href = `https://${location.host}/download`;
|
|
221
227
|
reject('打开APP失败');
|
|
222
228
|
}
|
|
223
|
-
|
|
229
|
+
this.underway = false;
|
|
224
230
|
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
231
|
+
let _count = 0;
|
|
232
|
+
const _clickTime = +new Date();
|
|
233
|
+
const intHandle = setInterval(() => {
|
|
228
234
|
_count++;
|
|
229
|
-
|
|
235
|
+
const elsTime = +new Date() - _clickTime;
|
|
230
236
|
if (_count >= 100 || elsTime > 3000) {
|
|
231
237
|
clearInterval(intHandle);
|
|
232
238
|
check(elsTime);
|
|
233
239
|
}
|
|
234
240
|
}, 20);
|
|
235
241
|
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
exports.default = OpenAppClass;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export default OpenAppClass;
|
|
@@ -7,75 +7,67 @@
|
|
|
7
7
|
* 3.自动捕获没有被catch的运行异常
|
|
8
8
|
*/
|
|
9
9
|
'use strict';
|
|
10
|
-
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
var raven_js_1 = __importDefault(require("raven-js"));
|
|
10
|
+
import Raven from 'raven-js';
|
|
15
11
|
// import RavenVue from 'raven-js/plugins/vue';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
class Report {
|
|
13
|
+
static instance;
|
|
14
|
+
constructor(Vue, options = {}) {
|
|
19
15
|
if (process.env.NODE_ENV !== 'development') {
|
|
20
16
|
// todo
|
|
21
17
|
}
|
|
22
18
|
this.vue = Vue;
|
|
23
19
|
this.options = options;
|
|
24
20
|
}
|
|
25
|
-
|
|
21
|
+
static getInstance(Vue, Option) {
|
|
26
22
|
if (!(this.instance instanceof this)) {
|
|
27
23
|
this.instance = new this(Vue, Option);
|
|
28
24
|
this.instance.install();
|
|
29
25
|
}
|
|
30
26
|
return this.instance;
|
|
31
|
-
}
|
|
32
|
-
|
|
27
|
+
}
|
|
28
|
+
install() {
|
|
33
29
|
if (process.env.NODE_ENV !== 'development') {
|
|
34
30
|
// Raven.config(this.options.dsn, {
|
|
35
31
|
// environment: process.env.NODE_ENV,
|
|
36
32
|
// }).addPlugin(RavenVue, this.Vue).install();
|
|
37
33
|
// raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
|
|
38
34
|
// 记录用户信息
|
|
39
|
-
|
|
35
|
+
Raven.setUserContext({ user: this.options.user || '' });
|
|
40
36
|
// 设置全局tag标签
|
|
41
|
-
|
|
37
|
+
Raven.setTagsContext({ environment: this.options.env || '' });
|
|
42
38
|
}
|
|
43
|
-
}
|
|
39
|
+
}
|
|
44
40
|
/**
|
|
45
41
|
* 主动上报
|
|
46
42
|
* @param {String} data
|
|
47
43
|
* @param {String} type 'info','warning','error'
|
|
48
44
|
* @param {Object} options
|
|
49
45
|
*/
|
|
50
|
-
|
|
51
|
-
if (data === void 0) { data = null; }
|
|
52
|
-
if (type === void 0) { type = 'error'; }
|
|
53
|
-
if (options === void 0) { options = {}; }
|
|
46
|
+
log(data = null, type = 'error', options = {}) {
|
|
54
47
|
// 添加面包屑
|
|
55
|
-
|
|
48
|
+
Raven.captureBreadcrumb({
|
|
56
49
|
message: data,
|
|
57
50
|
category: 'manual message',
|
|
58
51
|
});
|
|
59
52
|
// 异常上报
|
|
60
53
|
if (data instanceof Error) {
|
|
61
|
-
|
|
54
|
+
Raven.captureException(data, {
|
|
62
55
|
level: type,
|
|
63
56
|
logger: 'manual exception',
|
|
64
|
-
tags: { options
|
|
57
|
+
tags: { options },
|
|
65
58
|
});
|
|
66
59
|
}
|
|
67
60
|
else {
|
|
68
|
-
|
|
61
|
+
Raven.captureException('error', {
|
|
69
62
|
level: type,
|
|
70
63
|
logger: 'manual data',
|
|
71
64
|
extra: {
|
|
72
|
-
data
|
|
65
|
+
data,
|
|
73
66
|
options: this.options,
|
|
74
67
|
date: new Date(),
|
|
75
68
|
},
|
|
76
69
|
});
|
|
77
70
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
exports.default = Report;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export default Report;
|