@haluo/util 2.0.0 → 2.0.2-0.1
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/README.md +12 -1
- package/dist/index.d.ts +39 -0
- package/dist/index.js +74 -33
- package/dist/modules/cookie/index.d.ts +27 -0
- package/dist/modules/cookie/index.js +55 -54
- package/dist/modules/date/index.d.ts +52 -0
- package/dist/modules/date/index.js +192 -192
- package/dist/modules/dom/index.d.ts +28 -0
- package/dist/modules/dom/index.js +62 -62
- package/dist/modules/filter/index.d.ts +24 -0
- package/dist/modules/filter/index.js +48 -44
- package/dist/modules/format/index.d.ts +15 -0
- package/dist/modules/format/index.js +22 -21
- package/dist/modules/match/index.d.ts +12 -0
- package/dist/modules/match/index.js +31 -31
- package/dist/modules/monitor/index.d.ts +3 -0
- package/dist/modules/monitor/index.js +17 -17
- package/dist/modules/monitor/lib/jsError.d.ts +1 -0
- package/dist/modules/monitor/lib/jsError.js +53 -53
- package/dist/modules/monitor/lib/timing.d.ts +1 -0
- package/dist/modules/monitor/lib/timing.js +69 -69
- package/dist/modules/monitor/lib/xhr.d.ts +1 -0
- package/dist/modules/monitor/lib/xhr.js +48 -48
- package/dist/modules/monitor/utils/onload.d.ts +1 -0
- package/dist/modules/monitor/utils/onload.js +11 -11
- package/dist/modules/monitor/utils/tracker.d.ts +7 -0
- package/dist/modules/monitor/utils/tracker.js +63 -63
- package/dist/modules/number/index.d.ts +47 -0
- package/dist/modules/number/index.js +118 -102
- package/dist/modules/open-app/index.d.ts +84 -0
- package/dist/modules/open-app/index.js +239 -0
- package/dist/modules/sentry/index.d.ts +15 -0
- package/dist/modules/sentry/index.js +81 -81
- package/dist/modules/tools/index.d.ts +166 -0
- package/dist/modules/tools/index.js +393 -393
- package/dist/modules/upload/ALIOSS_EXAMPLE.d.ts +12 -0
- package/dist/modules/upload/ALIOSS_EXAMPLE.js +320 -0
- package/dist/modules/upload/aliOss.d.ts +324 -0
- package/dist/modules/upload/aliOss.js +838 -0
- package/dist/modules/upload/index.d.ts +51 -0
- package/dist/modules/upload/index.js +55 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +2 -0
- package/dist/types/modules/cookie/index.d.ts +27 -0
- package/dist/types/modules/date/index.d.ts +52 -0
- package/dist/types/modules/dom/index.d.ts +28 -0
- package/dist/types/modules/filter/index.d.ts +24 -0
- package/dist/types/modules/format/index.d.ts +15 -0
- package/dist/types/modules/match/index.d.ts +12 -0
- package/dist/types/modules/monitor/index.d.ts +3 -0
- package/dist/types/modules/monitor/lib/jsError.d.ts +1 -0
- package/dist/types/modules/monitor/lib/timing.d.ts +1 -0
- package/dist/types/modules/monitor/lib/xhr.d.ts +1 -0
- package/dist/types/modules/monitor/utils/onload.d.ts +1 -0
- package/dist/types/modules/monitor/utils/tracker.d.ts +7 -0
- package/dist/types/modules/number/index.d.ts +41 -0
- package/dist/types/modules/sentry/index.d.ts +15 -0
- package/dist/types/modules/tools/index.d.ts +166 -0
- package/dist/types/types/index.d.ts +3 -0
- package/package.json +18 -13
- package/.babelrc +0 -21
- package/.eslintrc.js +0 -216
- package/__tests__/unit/date/date.spec.js +0 -14
- package/__tests__/unit/jest.conf.js +0 -25
- package/__tests__/unit/specs/date.test.js +0 -11
- package/global.d.ts +0 -0
- package/publish.sh +0 -11
- package/specification/CSS.md +0 -25
- package/specification/JS.md +0 -9
- package/specification/VUE.md +0 -1
- package/src/consts/httpCode.js +0 -10
- package/src/index.ts +0 -51
- package/src/modules/cookie/index.ts +0 -69
- package/src/modules/date/index.ts +0 -196
- package/src/modules/dom/index.ts +0 -78
- package/src/modules/filter/index.ts +0 -43
- package/src/modules/format/index.ts +0 -19
- package/src/modules/match/index.ts +0 -31
- package/src/modules/monitor/index.ts +0 -13
- package/src/modules/monitor/lib/jsError.ts +0 -57
- package/src/modules/monitor/lib/timing.ts +0 -75
- package/src/modules/monitor/lib/xhr.ts +0 -40
- package/src/modules/monitor/utils/onload.ts +0 -8
- package/src/modules/monitor/utils/tracker.ts +0 -47
- package/src/modules/number/index.ts +0 -108
- package/src/modules/sentry/index.ts +0 -82
- package/src/modules/tools/index.ts +0 -427
- package/tsconfig.json +0 -34
|
@@ -0,0 +1,239 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* H5打开APP工具类
|
|
8
|
+
*
|
|
9
|
+
* feature
|
|
10
|
+
* 1、应用宝打开app指定页面,参考今日头条
|
|
11
|
+
* 2、浏览器中进入页面立即打开app,参考掘金
|
|
12
|
+
*/
|
|
13
|
+
var qs_1 = __importDefault(require("qs"));
|
|
14
|
+
var tools_1 = __importDefault(require("../tools"));
|
|
15
|
+
var OpenAppClass = /** @class */ (function () {
|
|
16
|
+
/**
|
|
17
|
+
* @param {Object} env - 环境配置,必须
|
|
18
|
+
* @param {Function} postJddTrack - 埋点方法,必须
|
|
19
|
+
* @param {String} trackId - 埋点id,可选
|
|
20
|
+
* @param {Object} openAppState - 打开app状态,可选
|
|
21
|
+
*/
|
|
22
|
+
function OpenAppClass(env, postJddTrack, trackId, openAppState) {
|
|
23
|
+
if (trackId === void 0) { trackId = 'S_00000000000108'; }
|
|
24
|
+
this.env = env; // 环境配置,必须
|
|
25
|
+
this.postJddTrack = postJddTrack; // 埋点方法,必须
|
|
26
|
+
this.trackId = trackId; // 埋点id,可选
|
|
27
|
+
this.openAppState = openAppState; // 打开app状态,可选
|
|
28
|
+
this.ua = navigator.userAgent.toLowerCase();
|
|
29
|
+
this._wx = this.ua.indexOf('micromessenger') > -1;
|
|
30
|
+
this._android = !!(this.ua.match(/android/i) || this.ua.match(/miuibrowser/i));
|
|
31
|
+
this._isHarmonyos = !!this.ua.match(/harmonyos/i);
|
|
32
|
+
this._ios = navigator.userAgent.match(/(iPhone|iPod|iPad);?/i);
|
|
33
|
+
this._isPrice = sessionStorage.getItem('isHaloenterprise') || false; // 厂家版,切换打开地址
|
|
34
|
+
this.currentEnv = env;
|
|
35
|
+
this.getCurrentEnv();
|
|
36
|
+
this.appUrl = this._isPrice ? env.APPLINKPRICE : this.currentEnv.APPLINK;
|
|
37
|
+
this.appStoreUrl = this._isPrice ? env.APPLINKPRICEIOS : this.currentEnv.APPLINKIOS;
|
|
38
|
+
this.underway = false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 根据域名动态获取配置,保证多项目代码一样
|
|
42
|
+
*/
|
|
43
|
+
OpenAppClass.prototype.getCurrentEnv = function () {
|
|
44
|
+
var host = location.host;
|
|
45
|
+
if (host.includes('58moto')) {
|
|
46
|
+
this.currentEnv = {
|
|
47
|
+
motoAndroidScheme: this.env.motoAndroidScheme,
|
|
48
|
+
motoIOSScheme: this.env.motoIOSScheme,
|
|
49
|
+
APPLINK: this.env.APPLINK,
|
|
50
|
+
APPLINKIOS: this.env.APPLINKIOS,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if (host.includes('emotofine')) {
|
|
54
|
+
this.currentEnv = {
|
|
55
|
+
motoAndroidScheme: this.env.emotofineAndroidScheme,
|
|
56
|
+
motoIOSScheme: this.env.emotofineIOSScheme,
|
|
57
|
+
APPLINK: this.env.EMOTOFINEAPPLINK,
|
|
58
|
+
APPLINKIOS: this.env.EMOTOFINEAPPLINKIOS,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
else if (host.includes('biaofine')) {
|
|
62
|
+
this.currentEnv = {
|
|
63
|
+
motoAndroidScheme: this.env.biaofineAndroidScheme,
|
|
64
|
+
motoIOSScheme: this.env.biaofineIOSScheme,
|
|
65
|
+
APPLINK: this.env.BIAOFINEAPPLINK,
|
|
66
|
+
APPLINKIOS: this.env.BIAOFINEAPPLINKIOS,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 打开APP主流程
|
|
72
|
+
*/
|
|
73
|
+
OpenAppClass.prototype.invoke = function () {
|
|
74
|
+
if (this.underway) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// 微信里面 安卓、鸿蒙 不支持打开app(待确认)
|
|
78
|
+
if (this._wx && (this._android || this._isHarmonyos)) {
|
|
79
|
+
this.underway = false;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.underway = true;
|
|
83
|
+
// 生成url并且放到剪贴板
|
|
84
|
+
var url = this.getSechmaUrl();
|
|
85
|
+
if (url) {
|
|
86
|
+
tools_1.default.clipboard(url);
|
|
87
|
+
}
|
|
88
|
+
var apk = JSON.parse(sessionStorage.getItem('downloadApk') || '{}');
|
|
89
|
+
var tag = this._ios ? (apk.channelName ? "App Store-".concat(apk.channelName) : 'App Store') : (apk.channelName ? "\u6E20\u9053".concat(apk.channelName, "\u5305") : '安卓包');
|
|
90
|
+
this.postJddTrack(this.trackId, { tag: tag });
|
|
91
|
+
// 厂家版 app
|
|
92
|
+
if (this._android && location.href.includes('downloadPrise')) {
|
|
93
|
+
window.location.href = (apk && apk.path) || this.appUrl;
|
|
94
|
+
this.underway = false;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// 客户端打开app-下载页特殊处理
|
|
98
|
+
if (location.href.includes('download') && window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
|
|
99
|
+
this.underway = false;
|
|
100
|
+
return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: "https://".concat(location.host, "/home") });
|
|
101
|
+
}
|
|
102
|
+
// 客户端打开app
|
|
103
|
+
if (window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
|
|
104
|
+
this.underway = false;
|
|
105
|
+
url = this.getUrl();
|
|
106
|
+
return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: url || '' });
|
|
107
|
+
}
|
|
108
|
+
// IOS系统下,H5中的特殊处理,历史逻辑,应该是用了universal link,待确认
|
|
109
|
+
if (this._ios) {
|
|
110
|
+
url = this.appStoreUrl;
|
|
111
|
+
}
|
|
112
|
+
this.open(url);
|
|
113
|
+
};
|
|
114
|
+
// 获取自定义的url
|
|
115
|
+
OpenAppClass.prototype.getUrl = function () {
|
|
116
|
+
var searchParams = qs_1.default.parse(location.search.slice(1)); // 路由的query
|
|
117
|
+
var url = searchParams.customOpenUrl || window.location.href;
|
|
118
|
+
return url;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* 获取打开 app sechma url
|
|
122
|
+
* @returns {string | undefined} 打开app的schema或跳转链接
|
|
123
|
+
* params:params={"type":"","id":0,"name":"","travelId":0}
|
|
124
|
+
* type:原生页面key(必须);id:页面id(可选);subject 短话题、版块名称 或 页面标题(可选);travelId 游记id(可选)
|
|
125
|
+
*/
|
|
126
|
+
OpenAppClass.prototype.getSechmaUrl = function () {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
var keys = {
|
|
129
|
+
'/posts/': 'thread_detail',
|
|
130
|
+
'/detailedForum/': 'forum_detail',
|
|
131
|
+
'/video/': 'video_detail',
|
|
132
|
+
'/answer-details/': 'topic_detail',
|
|
133
|
+
'/details-article/': 'essay_detail',
|
|
134
|
+
'/details-views/': 'opinion_detail',
|
|
135
|
+
'/topic-homepage': 'short_topic',
|
|
136
|
+
'/label-detail': 'tag_detail',
|
|
137
|
+
'/circle-article/': 'moment_detail',
|
|
138
|
+
'/vehicle-details/': 'car_detail',
|
|
139
|
+
'/car-detail': 'newcar_sale_detail',
|
|
140
|
+
'/myhomepage': 'person_detail',
|
|
141
|
+
'/dealer': 'shop_detail',
|
|
142
|
+
'/circle-preview': 'hoop_detail',
|
|
143
|
+
'/used-car-detail': 'used_detail',
|
|
144
|
+
'/coupon-detail': 'coupon_detail',
|
|
145
|
+
'/news/': 'essay_detail' // 文章详情
|
|
146
|
+
};
|
|
147
|
+
var target = Object.keys(keys).filter(function (value) {
|
|
148
|
+
return window.location.href.indexOf(value) > -1;
|
|
149
|
+
});
|
|
150
|
+
var type = target && target[0] && keys[target[0]];
|
|
151
|
+
var searchParams = qs_1.default.parse(location.search.slice(1)); // 路由的query
|
|
152
|
+
var id = parseInt(location.pathname.split('/').reverse()[0]) ||
|
|
153
|
+
parseInt(searchParams.id) ||
|
|
154
|
+
parseInt(searchParams.carId) ||
|
|
155
|
+
parseInt(searchParams.goodId); // 页面id
|
|
156
|
+
var subject = searchParams.subject || undefined; // 页面标题或name
|
|
157
|
+
var temp = {
|
|
158
|
+
relationType: type,
|
|
159
|
+
id: id,
|
|
160
|
+
name: subject
|
|
161
|
+
};
|
|
162
|
+
var data = ((_b = (_a = this.openAppState) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.openApps) || {};
|
|
163
|
+
var open_url = '';
|
|
164
|
+
if (data.type && data.href === window.location.href) {
|
|
165
|
+
temp.relationType = keys[data.type] || '';
|
|
166
|
+
temp.id = data.id || '';
|
|
167
|
+
temp.name = data.title || '';
|
|
168
|
+
open_url = data.url || '';
|
|
169
|
+
}
|
|
170
|
+
var openUrl = open_url || searchParams.customOpenUrl || window.location.href;
|
|
171
|
+
// activityId 大于零,type 为 activity
|
|
172
|
+
if (searchParams.activityId) {
|
|
173
|
+
temp.relationType = 'activity';
|
|
174
|
+
temp.link = decodeURIComponent(decodeURIComponent(openUrl));
|
|
175
|
+
}
|
|
176
|
+
temp.jumpUrl = decodeURIComponent(decodeURIComponent(openUrl));
|
|
177
|
+
var params = JSON.stringify(temp);
|
|
178
|
+
if (this._ios) {
|
|
179
|
+
return "".concat(this.currentEnv.motoIOSScheme, "?params=").concat(params);
|
|
180
|
+
}
|
|
181
|
+
if (this._android || this._isHarmonyos) {
|
|
182
|
+
var url = this._wx ? "".concat(this.appUrl, "&android_scheme=").concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params) : "".concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params);
|
|
183
|
+
return url;
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* 方法一(推荐):打开APP
|
|
189
|
+
* http://www.cnblogs.com/shadajin/p/5724117.html
|
|
190
|
+
*/
|
|
191
|
+
OpenAppClass.prototype.open = function (openUrl) {
|
|
192
|
+
var _this = this;
|
|
193
|
+
if (!openUrl) {
|
|
194
|
+
this.underway = false;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (this._ios) {
|
|
198
|
+
this.underway = false;
|
|
199
|
+
setTimeout(function () { return (location.href = _this.appStoreUrl || ''); }, 3000);
|
|
200
|
+
return (location.href = openUrl);
|
|
201
|
+
}
|
|
202
|
+
if (this._android) {
|
|
203
|
+
var ifr_1 = document.createElement('iframe');
|
|
204
|
+
ifr_1.src = openUrl;
|
|
205
|
+
ifr_1.style.display = 'none';
|
|
206
|
+
document.body.appendChild(ifr_1);
|
|
207
|
+
setTimeout(function () {
|
|
208
|
+
document.body.removeChild(ifr_1);
|
|
209
|
+
}, 3000);
|
|
210
|
+
}
|
|
211
|
+
return new Promise(function (resolve, reject) {
|
|
212
|
+
// 检查APP是否打开
|
|
213
|
+
var check = function (elsTime) {
|
|
214
|
+
if (elsTime > 3000 || document.hidden) {
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
resolve('成功打开APP');
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
// @ts-ignore
|
|
220
|
+
window.location.href = "https://".concat(location.host, "/download");
|
|
221
|
+
reject('打开APP失败');
|
|
222
|
+
}
|
|
223
|
+
_this.underway = false;
|
|
224
|
+
};
|
|
225
|
+
var _count = 0;
|
|
226
|
+
var _clickTime = +new Date();
|
|
227
|
+
var intHandle = setInterval(function () {
|
|
228
|
+
_count++;
|
|
229
|
+
var elsTime = +new Date() - _clickTime;
|
|
230
|
+
if (_count >= 100 || elsTime > 3000) {
|
|
231
|
+
clearInterval(intHandle);
|
|
232
|
+
check(elsTime);
|
|
233
|
+
}
|
|
234
|
+
}, 20);
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
return OpenAppClass;
|
|
238
|
+
}());
|
|
239
|
+
exports.default = OpenAppClass;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare class Report {
|
|
2
|
+
static instance: any;
|
|
3
|
+
constructor(Vue: Object, options?: {});
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
static getInstance(Vue: Object, Option: Object): any;
|
|
6
|
+
install(): void;
|
|
7
|
+
/**
|
|
8
|
+
* 主动上报
|
|
9
|
+
* @param {String} data
|
|
10
|
+
* @param {String} type 'info','warning','error'
|
|
11
|
+
* @param {Object} options
|
|
12
|
+
*/
|
|
13
|
+
log(data?: any, type?: any, options?: any): void;
|
|
14
|
+
}
|
|
15
|
+
export default Report;
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 异常上报日志监控类
|
|
3
|
-
* @Author: wanghui
|
|
4
|
-
* 常用配置 option:https://docs.sentry.io/clients/javascript/config/
|
|
5
|
-
* 1.自动捕获vue组件内异常
|
|
6
|
-
* 2.自动捕获promise内的异常
|
|
7
|
-
* 3.自动捕获没有被catch的运行异常
|
|
8
|
-
*/
|
|
9
|
-
'use strict';
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
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"));
|
|
15
|
-
// import RavenVue from 'raven-js/plugins/vue';
|
|
16
|
-
var Report = /** @class */ (function () {
|
|
17
|
-
function Report(Vue, options) {
|
|
18
|
-
if (options === void 0) { options = {}; }
|
|
19
|
-
if (process.env.NODE_ENV !== 'development') {
|
|
20
|
-
// todo
|
|
21
|
-
}
|
|
22
|
-
this.vue = Vue;
|
|
23
|
-
this.options = options;
|
|
24
|
-
}
|
|
25
|
-
Report.getInstance = function (Vue, Option) {
|
|
26
|
-
if (!(this.instance instanceof this)) {
|
|
27
|
-
this.instance = new this(Vue, Option);
|
|
28
|
-
this.instance.install();
|
|
29
|
-
}
|
|
30
|
-
return this.instance;
|
|
31
|
-
};
|
|
32
|
-
Report.prototype.install = function () {
|
|
33
|
-
if (process.env.NODE_ENV !== 'development') {
|
|
34
|
-
// Raven.config(this.options.dsn, {
|
|
35
|
-
// environment: process.env.NODE_ENV,
|
|
36
|
-
// }).addPlugin(RavenVue, this.Vue).install();
|
|
37
|
-
// raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
|
|
38
|
-
// 记录用户信息
|
|
39
|
-
raven_js_1.default.setUserContext({ user: this.options.user || '' });
|
|
40
|
-
// 设置全局tag标签
|
|
41
|
-
raven_js_1.default.setTagsContext({ environment: this.options.env || '' });
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* 主动上报
|
|
46
|
-
* @param {String} data
|
|
47
|
-
* @param {String} type 'info','warning','error'
|
|
48
|
-
* @param {Object} options
|
|
49
|
-
*/
|
|
50
|
-
Report.prototype.log = function (data, type, options) {
|
|
51
|
-
if (data === void 0) { data = null; }
|
|
52
|
-
if (type === void 0) { type = 'error'; }
|
|
53
|
-
if (options === void 0) { options = {}; }
|
|
54
|
-
// 添加面包屑
|
|
55
|
-
raven_js_1.default.captureBreadcrumb({
|
|
56
|
-
message: data,
|
|
57
|
-
category: 'manual message',
|
|
58
|
-
});
|
|
59
|
-
// 异常上报
|
|
60
|
-
if (data instanceof Error) {
|
|
61
|
-
raven_js_1.default.captureException(data, {
|
|
62
|
-
level: type,
|
|
63
|
-
logger: 'manual exception',
|
|
64
|
-
tags: { options: options },
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
raven_js_1.default.captureException('error', {
|
|
69
|
-
level: type,
|
|
70
|
-
logger: 'manual data',
|
|
71
|
-
extra: {
|
|
72
|
-
data: data,
|
|
73
|
-
options: this.options,
|
|
74
|
-
date: new Date(),
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
return Report;
|
|
80
|
-
}());
|
|
81
|
-
exports.default = Report;
|
|
1
|
+
/**
|
|
2
|
+
* 异常上报日志监控类
|
|
3
|
+
* @Author: wanghui
|
|
4
|
+
* 常用配置 option:https://docs.sentry.io/clients/javascript/config/
|
|
5
|
+
* 1.自动捕获vue组件内异常
|
|
6
|
+
* 2.自动捕获promise内的异常
|
|
7
|
+
* 3.自动捕获没有被catch的运行异常
|
|
8
|
+
*/
|
|
9
|
+
'use strict';
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
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"));
|
|
15
|
+
// import RavenVue from 'raven-js/plugins/vue';
|
|
16
|
+
var Report = /** @class */ (function () {
|
|
17
|
+
function Report(Vue, options) {
|
|
18
|
+
if (options === void 0) { options = {}; }
|
|
19
|
+
if (process.env.NODE_ENV !== 'development') {
|
|
20
|
+
// todo
|
|
21
|
+
}
|
|
22
|
+
this.vue = Vue;
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
Report.getInstance = function (Vue, Option) {
|
|
26
|
+
if (!(this.instance instanceof this)) {
|
|
27
|
+
this.instance = new this(Vue, Option);
|
|
28
|
+
this.instance.install();
|
|
29
|
+
}
|
|
30
|
+
return this.instance;
|
|
31
|
+
};
|
|
32
|
+
Report.prototype.install = function () {
|
|
33
|
+
if (process.env.NODE_ENV !== 'development') {
|
|
34
|
+
// Raven.config(this.options.dsn, {
|
|
35
|
+
// environment: process.env.NODE_ENV,
|
|
36
|
+
// }).addPlugin(RavenVue, this.Vue).install();
|
|
37
|
+
// raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
|
|
38
|
+
// 记录用户信息
|
|
39
|
+
raven_js_1.default.setUserContext({ user: this.options.user || '' });
|
|
40
|
+
// 设置全局tag标签
|
|
41
|
+
raven_js_1.default.setTagsContext({ environment: this.options.env || '' });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 主动上报
|
|
46
|
+
* @param {String} data
|
|
47
|
+
* @param {String} type 'info','warning','error'
|
|
48
|
+
* @param {Object} options
|
|
49
|
+
*/
|
|
50
|
+
Report.prototype.log = function (data, type, options) {
|
|
51
|
+
if (data === void 0) { data = null; }
|
|
52
|
+
if (type === void 0) { type = 'error'; }
|
|
53
|
+
if (options === void 0) { options = {}; }
|
|
54
|
+
// 添加面包屑
|
|
55
|
+
raven_js_1.default.captureBreadcrumb({
|
|
56
|
+
message: data,
|
|
57
|
+
category: 'manual message',
|
|
58
|
+
});
|
|
59
|
+
// 异常上报
|
|
60
|
+
if (data instanceof Error) {
|
|
61
|
+
raven_js_1.default.captureException(data, {
|
|
62
|
+
level: type,
|
|
63
|
+
logger: 'manual exception',
|
|
64
|
+
tags: { options: options },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
raven_js_1.default.captureException('error', {
|
|
69
|
+
level: type,
|
|
70
|
+
logger: 'manual data',
|
|
71
|
+
extra: {
|
|
72
|
+
data: data,
|
|
73
|
+
options: this.options,
|
|
74
|
+
date: new Date(),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return Report;
|
|
80
|
+
}());
|
|
81
|
+
exports.default = Report;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { IObjectKey } from '../../types/index';
|
|
2
|
+
declare class ToolsClass {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* 深拷贝 Object|Array
|
|
7
|
+
* 深拷贝,支持 普通对象、数组,但是未解决Function、Date、RegExp,且1M以上数据性能不好
|
|
8
|
+
* @param {String} data
|
|
9
|
+
* @return {Object}
|
|
10
|
+
*/
|
|
11
|
+
deepCopy(data: object): object;
|
|
12
|
+
/**
|
|
13
|
+
* 深拷贝 Object|Array
|
|
14
|
+
* 支持 普通对象、数组和函数的深复制,但是未解决循环引用、Date、RegExp
|
|
15
|
+
* @param {Object|Array} data
|
|
16
|
+
* @return {Object}
|
|
17
|
+
*/
|
|
18
|
+
deepCopy2<T>(obj: T): T;
|
|
19
|
+
/**
|
|
20
|
+
* 深拷贝 Object|Array
|
|
21
|
+
* 注意:需要 yarn add lodash
|
|
22
|
+
* @param {Object|Array} data
|
|
23
|
+
* @return {Object}
|
|
24
|
+
*/
|
|
25
|
+
deepCopy3(obj: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* 防抖
|
|
28
|
+
* demo:debounce(func, 300)(args)
|
|
29
|
+
* @param {Function} func 执行函数
|
|
30
|
+
* @param {Number} wait 节流时间,毫秒
|
|
31
|
+
* @return {Function} delay
|
|
32
|
+
*/
|
|
33
|
+
debounce(func: Function, wait: number): () => void;
|
|
34
|
+
/**
|
|
35
|
+
* 节流
|
|
36
|
+
* demo:throttle(func, 300)(args)
|
|
37
|
+
* @param {Object|Array} func 执行函数
|
|
38
|
+
* @param {Number} wait 节流时间,毫秒
|
|
39
|
+
* @return {Function} delay
|
|
40
|
+
*/
|
|
41
|
+
throttle(func: Function, wait: number): () => void;
|
|
42
|
+
/**
|
|
43
|
+
* 获取路径中文件名称
|
|
44
|
+
* @param {String} url
|
|
45
|
+
* @return {String}
|
|
46
|
+
*/
|
|
47
|
+
getUrlName(url: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* 动态加载脚本
|
|
50
|
+
* tip:按需加载时用(多次调用,js不会重复加载)
|
|
51
|
+
* @param {String} url
|
|
52
|
+
* @return {Promise}
|
|
53
|
+
*/
|
|
54
|
+
loadJs(url: string): Error | Promise<unknown>;
|
|
55
|
+
/**
|
|
56
|
+
* 动态加载样式
|
|
57
|
+
* @param {String} url
|
|
58
|
+
* @return {Promise}
|
|
59
|
+
*/
|
|
60
|
+
loadCss(url: string): Error | Promise<unknown>;
|
|
61
|
+
/**
|
|
62
|
+
* 蒙层显示后,html禁止滚动操作
|
|
63
|
+
* @param {String} className
|
|
64
|
+
* @return {Void}
|
|
65
|
+
*/
|
|
66
|
+
stopScroll: (className: string) => Error | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* 蒙层隐藏后,html开启滚动操作
|
|
69
|
+
* @param {String} className
|
|
70
|
+
* @return {Void}
|
|
71
|
+
*/
|
|
72
|
+
startScroll: (className: string) => Error | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* 字符串复制到剪贴板
|
|
75
|
+
* 注意:需要 yarn add clipboard-copy
|
|
76
|
+
* @param {String} str
|
|
77
|
+
* @return {String}
|
|
78
|
+
*/
|
|
79
|
+
clipboard(str: string): any;
|
|
80
|
+
/**
|
|
81
|
+
* 首字母大写
|
|
82
|
+
* @param {String} str
|
|
83
|
+
* @return {String}
|
|
84
|
+
*/
|
|
85
|
+
firstUpperCase(str: string): string;
|
|
86
|
+
/**
|
|
87
|
+
* 截取数组或字符串,示例:slice('1234', 3)
|
|
88
|
+
* @param {Array|String} target 数组或字符串
|
|
89
|
+
* @param {Number} length 截取长度,从0开始
|
|
90
|
+
* @return {any}
|
|
91
|
+
*/
|
|
92
|
+
slice(target?: Array<any> | string, length?: number): string | any[];
|
|
93
|
+
/**
|
|
94
|
+
* 获取guid
|
|
95
|
+
* @return {String}
|
|
96
|
+
*/
|
|
97
|
+
guid(): string;
|
|
98
|
+
/**
|
|
99
|
+
* 获取文本字节数(含中文)
|
|
100
|
+
* @param {String} str
|
|
101
|
+
* @return {String}
|
|
102
|
+
*/
|
|
103
|
+
getBytesOfText(str?: string): number;
|
|
104
|
+
/**
|
|
105
|
+
* object 对象转 array 数组
|
|
106
|
+
* demo:
|
|
107
|
+
* objectToArray({a:1,b:2}) 输出:["a=1", "b=2"]
|
|
108
|
+
* @param {Object} obj
|
|
109
|
+
* @returns {Array} arr
|
|
110
|
+
*/
|
|
111
|
+
objectToArray: (obj: IObjectKey<string>) => Array<string>;
|
|
112
|
+
/**
|
|
113
|
+
* convertEnum
|
|
114
|
+
* 枚举键值互换
|
|
115
|
+
* @param {Object} obj
|
|
116
|
+
* convertKeyValueEnum({a: 1, b: 2}) // {1: "a", 2: "b"}
|
|
117
|
+
* @returns {Object} result
|
|
118
|
+
*/
|
|
119
|
+
convertKeyValueEnum: (obj: IObjectKey<string>) => IObjectKey<string>;
|
|
120
|
+
/**
|
|
121
|
+
* 数组去重
|
|
122
|
+
* @param {Array} arr
|
|
123
|
+
* @returns {Array}
|
|
124
|
+
*/
|
|
125
|
+
uniqueArr(arr: Array<any>): Array<any>;
|
|
126
|
+
/**
|
|
127
|
+
* 数组元素交换位置
|
|
128
|
+
* index1和index2分别是两个数组的索引值,即是两个要交换元素位置的索引值,如1,5就是数组中下标为1和5的两个元素交换位置
|
|
129
|
+
* @param {Array<string | number>} array 数组
|
|
130
|
+
* @param {number} index1 添加项目的位置
|
|
131
|
+
* @param {number} index2 删除项目的位置
|
|
132
|
+
* swapArray([1, 2, 3, 4], 2, 3) // [1, 2, 4, 3]
|
|
133
|
+
* @returns {Array<string | number>} array
|
|
134
|
+
*/
|
|
135
|
+
swapArray(array: Array<string | number>, index1: number, index2: number): Array<string | number>;
|
|
136
|
+
/**
|
|
137
|
+
* 过滤表情符号
|
|
138
|
+
* @param {String} str
|
|
139
|
+
* @return {String}
|
|
140
|
+
*/
|
|
141
|
+
filterEmoji(str: string): string;
|
|
142
|
+
/**
|
|
143
|
+
* 是否包含表情
|
|
144
|
+
* @param {String} str
|
|
145
|
+
* @return {boolean}
|
|
146
|
+
*/
|
|
147
|
+
containsEmoji(str: string): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* 是否包含表汉字
|
|
150
|
+
* @param {String} str
|
|
151
|
+
* @return {boolean}
|
|
152
|
+
*/
|
|
153
|
+
containsHanZi(str: string): boolean;
|
|
154
|
+
isEmpty(val: any): boolean;
|
|
155
|
+
isDefined: (val: any) => boolean;
|
|
156
|
+
/**
|
|
157
|
+
* 字段脱敏处理
|
|
158
|
+
* @param {String} field 未脱敏字段
|
|
159
|
+
* @param {Int} before 开头未脱敏字符数
|
|
160
|
+
* @param {Int} after 结尾未脱敏字符数
|
|
161
|
+
* @return {String} 已脱敏字段
|
|
162
|
+
*/
|
|
163
|
+
sensitiveField(field: string | number, before?: number, after?: number): string;
|
|
164
|
+
}
|
|
165
|
+
declare const _default: ToolsClass;
|
|
166
|
+
export default _default;
|