@haluo/util 1.0.31 → 2.0.0

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 (38) hide show
  1. package/dist/index.js +33 -36
  2. package/dist/modules/cookie/index.js +54 -54
  3. package/dist/modules/date/index.js +192 -192
  4. package/dist/modules/dom/index.js +62 -62
  5. package/dist/modules/filter/index.js +44 -57
  6. package/dist/modules/format/index.js +21 -21
  7. package/dist/modules/match/index.js +31 -31
  8. package/dist/modules/monitor/index.js +17 -17
  9. package/dist/modules/monitor/lib/jsError.js +53 -61
  10. package/dist/modules/monitor/lib/timing.js +69 -69
  11. package/dist/modules/monitor/lib/xhr.js +48 -50
  12. package/dist/modules/monitor/utils/onload.js +11 -11
  13. package/dist/modules/monitor/utils/tracker.js +63 -84
  14. package/dist/modules/number/index.js +102 -102
  15. package/dist/modules/sentry/index.js +81 -78
  16. package/dist/modules/tools/index.js +393 -393
  17. package/package.json +3 -4
  18. package/publish.sh +0 -0
  19. package/src/index.ts +3 -6
  20. package/src/modules/filter/index.ts +0 -14
  21. package/src/modules/monitor/lib/jsError.ts +10 -10
  22. package/src/modules/monitor/lib/xhr.ts +1 -3
  23. package/src/modules/monitor/utils/tracker.ts +1 -15
  24. package/src/modules/sentry/index.ts +7 -4
  25. package/dist/index.cjs.js +0 -89
  26. package/dist/index.d.ts +0 -12
  27. package/dist/index.esm.js +0 -87
  28. package/dist/lib-list.d.ts +0 -2
  29. package/dist/modules/cookie/index.d.ts +0 -27
  30. package/dist/modules/date/index.d.ts +0 -1
  31. package/dist/modules/dom/index.d.ts +0 -1
  32. package/dist/modules/filter/index.d.ts +0 -26
  33. package/dist/modules/format/index.d.ts +0 -13
  34. package/dist/modules/match/index.d.ts +0 -1
  35. package/dist/modules/number/index.d.ts +0 -39
  36. package/dist/modules/sentry/index.d.ts +0 -15
  37. package/dist/modules/tools/index.d.ts +0 -1
  38. package/yarn-error.log +0 -9316
@@ -1,50 +1,48 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- var tracker_1 = __importDefault(require("../utils/tracker"));
18
- function injectXHR(data) {
19
- if (data === void 0) { data = {}; }
20
- var XMLHttpRequest = window.XMLHttpRequest;
21
- var oldOpen = XMLHttpRequest.prototype.open;
22
- XMLHttpRequest.prototype.open = function (method, url, async) {
23
- this.logData = { method: method, url: url, async: async };
24
- return oldOpen.apply(this, arguments);
25
- };
26
- var oldSend = XMLHttpRequest.prototype.send;
27
- XMLHttpRequest.prototype.send = function (body) {
28
- var _this = this;
29
- if (this.logData) {
30
- var startTime_1 = Date.now();
31
- var handler = function (type) { return function (event) {
32
- if (_this.logData.url.indexOf('app/collect/original/info/report/v2') > -1)
33
- return;
34
- // status = 0 是在跨域与404的情况下
35
- // 当前都是在readyState为4(请求已完成)的情况下,进行处理
36
- if (type !== 'error' || _this.status === 0)
37
- return;
38
- var duration = Date.now() - startTime_1;
39
- var status = _this.status;
40
- var statusText = _this.statusText;
41
- tracker_1.default.send(__assign({ kind: 'stability', type: 'xhr', eventType: event.type, pathname: _this.logData.url, status: status + '-' + statusText, duration: duration, response: _this.response ? JSON.stringify(_this.response) : '', params: body || '', title: 'xhr', reason: status + '-' + statusText + (" " + _this.logData.url + " " + (_this.response ? JSON.stringify(_this.response) : '')) }, data));
42
- }; };
43
- this.addEventListener('load', handler('load'), false);
44
- this.addEventListener('error', handler('error'), false);
45
- this.addEventListener('abort', handler('abort'), false);
46
- }
47
- return oldSend.apply(this, arguments);
48
- };
49
- }
50
- exports.default = injectXHR;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var tracker_1 = __importDefault(require("../utils/tracker"));
18
+ function injectXHR(data) {
19
+ if (data === void 0) { data = {}; }
20
+ var XMLHttpRequest = window.XMLHttpRequest;
21
+ var oldOpen = XMLHttpRequest.prototype.open;
22
+ XMLHttpRequest.prototype.open = function (method, url, async) {
23
+ this.logData = { method: method, url: url, async: async };
24
+ return oldOpen.apply(this, arguments);
25
+ };
26
+ var oldSend = XMLHttpRequest.prototype.send;
27
+ XMLHttpRequest.prototype.send = function (body) {
28
+ var _this = this;
29
+ if (this.logData) {
30
+ var startTime_1 = Date.now();
31
+ var handler = function (type) { return function (event) {
32
+ if (_this.logData.url.indexOf('app/collect/original/info/report/v2') > -1)
33
+ return;
34
+ if (type !== 'error')
35
+ return;
36
+ var duration = Date.now() - startTime_1;
37
+ var status = _this.status;
38
+ var statusText = _this.statusText;
39
+ tracker_1.default.send(__assign({ kind: 'stability', type: 'xhr', eventType: event.type, pathname: _this.logData.url, status: status + '-' + statusText, duration: duration, response: _this.response ? JSON.stringify(_this.response) : '', params: body || '', title: 'xhr', reason: status + '-' + statusText + " ".concat(_this.logData.url, " ").concat(_this.response ? JSON.stringify(_this.response) : '') }, data));
40
+ }; };
41
+ this.addEventListener('load', handler('load'), false);
42
+ this.addEventListener('error', handler('error'), false);
43
+ this.addEventListener('abort', handler('abort'), false);
44
+ }
45
+ return oldSend.apply(this, arguments);
46
+ };
47
+ }
48
+ exports.default = injectXHR;
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function onload(cb) {
4
- if (document.readyState) {
5
- cb();
6
- }
7
- else {
8
- window.addEventListener('load', cb);
9
- }
10
- }
11
- exports.default = onload;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function onload(cb) {
4
+ if (document.readyState) {
5
+ cb();
6
+ }
7
+ else {
8
+ window.addEventListener('load', cb);
9
+ }
10
+ }
11
+ exports.default = onload;
@@ -1,84 +1,63 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- var uuidv4 = require('uuid').v4;
15
- // const Parser = require('ua-parser-js');
16
- var reg = /((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/g;
17
- var SendTracker = /** @class */ (function () {
18
- function SendTracker() {
19
- this.url = '';
20
- }
21
- SendTracker.prototype.verifyRequest = function (reason) {
22
- if (!reason)
23
- return false;
24
- if (reg.test(reason))
25
- return false;
26
- if (reason.startsWith('halomoto'))
27
- return false;
28
- if (reason.startsWith('file:'))
29
- return false;
30
- if (reason.includes('log-center.58moto.com'))
31
- return false;
32
- if (reason.includes('s23.cnzz.com'))
33
- return false;
34
- if (reason.includes('g.alicdn.com'))
35
- return false;
36
- if (reason.includes('vendors'))
37
- return false;
38
- return true;
39
- };
40
- SendTracker.prototype.send = function (data) {
41
- if (data === void 0) { data = {}; }
42
- var host = window.location.host;
43
- if (host.indexOf('localhost') > -1)
44
- return;
45
- if (reg.test(host))
46
- return;
47
- if (!this.verifyRequest(data.reason))
48
- return;
49
- data.reason = window.location.href + ' ' + data.reason;
50
- var log = __assign(__assign({}, getExtraData()), data);
51
- var formBody = [];
52
- for (var property in log) {
53
- var encodedKey = encodeURIComponent(property);
54
- var encodedValue = encodeURIComponent(log[property]);
55
- formBody.push(encodedKey + "=" + encodedValue);
56
- }
57
- formBody = formBody.join("&");
58
- fetch('https://apm-collect.58moto.com/app/collect/original/info/report/v2', {
59
- method: 'POST',
60
- headers: {
61
- "Content-Type": "application/x-www-form-urlencoded"
62
- },
63
- body: formBody,
64
- }).then(function (res) {
65
- // console.log(res)
66
- }).catch(function (e) {
67
- console.log(e);
68
- });
69
- };
70
- return SendTracker;
71
- }());
72
- function getExtraData() {
73
- return {
74
- deviceId: uuidv4(),
75
- platform: 3,
76
- errorType: 3,
77
- channel: 'h5',
78
- bundle: 'com.jdd.motorfans',
79
- title: '',
80
- frontStatus: 3,
81
- occurTimeStamp: Date.now(),
82
- };
83
- }
84
- exports.default = new SendTracker();
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var uuidv4 = require('uuid').v4;
15
+ // const Parser = require('ua-parser-js');
16
+ var SendTracker = /** @class */ (function () {
17
+ function SendTracker() {
18
+ this.url = '';
19
+ }
20
+ SendTracker.prototype.send = function (data) {
21
+ if (data === void 0) { data = {}; }
22
+ var host = window.location.host;
23
+ if (host.indexOf('localhost') > -1)
24
+ return;
25
+ var reg = /((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/g;
26
+ if (reg.test(host))
27
+ return;
28
+ var log = __assign(__assign({}, getExtraData()), data);
29
+ var formBody = [];
30
+ for (var property in log) {
31
+ var encodedKey = encodeURIComponent(property);
32
+ var encodedValue = encodeURIComponent(log[property]);
33
+ formBody.push(encodedKey + "=" + encodedValue);
34
+ }
35
+ formBody = formBody.join("&");
36
+ fetch('https://apm-collect.58moto.com/app/collect/original/info/report/v2', {
37
+ method: 'POST',
38
+ headers: {
39
+ "Content-Type": "application/x-www-form-urlencoded"
40
+ },
41
+ body: formBody,
42
+ }).then(function (res) {
43
+ // console.log(res)
44
+ }).catch(function (e) {
45
+ console.log(e);
46
+ });
47
+ };
48
+ return SendTracker;
49
+ }());
50
+ function getExtraData() {
51
+ return {
52
+ deviceId: uuidv4(),
53
+ platform: 3,
54
+ errorType: 3,
55
+ channel: 'h5',
56
+ bundle: 'com.jdd.motorfans',
57
+ title: '',
58
+ frontStatus: 3,
59
+ occurTimeStamp: Date.now(),
60
+ // userAgent: new Parser().getResult()
61
+ };
62
+ }
63
+ exports.default = new SendTracker();
@@ -1,102 +1,102 @@
1
- /**
2
- * @file number 格式化
3
- * @Author: wanghui
4
- * @createBy: @2020.05.26
5
- */
6
- 'use strict';
7
- var NumberClass = /** @class */ (function () {
8
- function NumberClass() {
9
- }
10
- /**
11
- * 个位数前面补0
12
- * @param {Number} num 需要格式化的数字
13
- * @return {String} '01'
14
- */
15
- NumberClass.prototype.formatNumber = function (num) {
16
- var res = num.toString();
17
- return res[1] ? res : '0' + res;
18
- };
19
- /**
20
- * 将手机号中间部分替换为星号
21
- * @param {String} phone 手机号码
22
- * @return {String} 131****1111
23
- */
24
- NumberClass.prototype.formatPhone = function (phone) {
25
- return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
26
- };
27
- /**
28
- * 格式化数字 万
29
- * @param {Number} num
30
- * @return {String} 12.3万
31
- */
32
- NumberClass.prototype.convertToWan = function (num) {
33
- var result = '';
34
- if (num < 10000) {
35
- result = num;
36
- }
37
- if (num >= 10000) {
38
- result = (num / 10000).toFixed(1) + '万';
39
- }
40
- return result;
41
- };
42
- /**
43
- * 格式化数字 k
44
- * @param {Number} num
45
- * @return {String} 1.2k
46
- */
47
- NumberClass.prototype.convertToThousand = function (num) {
48
- var result = '';
49
- if (num < 1000) {
50
- result = num;
51
- }
52
- if (num >= 1000) {
53
- result = (num / 1000).toFixed(1) + 'k';
54
- }
55
- return result;
56
- };
57
- /**
58
- * 随机数,指定范围
59
- * @param {Number} min 开始
60
- * @param {Number} max 结束
61
- * @return {Number|Object}
62
- */
63
- NumberClass.prototype.random = function (min, max) {
64
- if (arguments.length === 2) {
65
- return Math.floor(min + Math.random() * ((max + 1) - min));
66
- }
67
- else {
68
- return null;
69
- }
70
- };
71
- /**
72
- * 格式化金额
73
- * @param {Number} num
74
- * @return {String} 123,456
75
- */
76
- NumberClass.prototype.formatMoney = function (money, signal) {
77
- var result = '';
78
- if (money === '') {
79
- return result;
80
- }
81
- money = String(money).replace('.00', '');
82
- money = money.substring(money.length - 2) === '.0' ? money.replace('.0', '') : money;
83
- // 小于3位数,直接返回
84
- if (Number(money) < 1000) {
85
- return result = money;
86
- }
87
- if (money.split('.')[0].length < 3) {
88
- return result = money;
89
- }
90
- signal = signal === '' ? '' : ',';
91
- var price = money.split('.')[0] + '';
92
- var pricePoint = money.split('.')[1];
93
- result = price.length > 6 ?
94
- "" + price.substring(0, price.length - 6) + signal + price.substring(price.length - 6, price.length - 3) + "," + price.substring(price.length - 3, price.length)
95
- :
96
- "" + price.substring(0, price.length - 3) + signal + price.substring(price.length - 3, price.length);
97
- result = pricePoint ? "" + result + signal + pricePoint : result;
98
- return result;
99
- };
100
- return NumberClass;
101
- }());
102
- module.exports = new NumberClass();
1
+ /**
2
+ * @file number 格式化
3
+ * @Author: wanghui
4
+ * @createBy: @2020.05.26
5
+ */
6
+ 'use strict';
7
+ var NumberClass = /** @class */ (function () {
8
+ function NumberClass() {
9
+ }
10
+ /**
11
+ * 个位数前面补0
12
+ * @param {Number} num 需要格式化的数字
13
+ * @return {String} '01'
14
+ */
15
+ NumberClass.prototype.formatNumber = function (num) {
16
+ var res = num.toString();
17
+ return res[1] ? res : '0' + res;
18
+ };
19
+ /**
20
+ * 将手机号中间部分替换为星号
21
+ * @param {String} phone 手机号码
22
+ * @return {String} 131****1111
23
+ */
24
+ NumberClass.prototype.formatPhone = function (phone) {
25
+ return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
26
+ };
27
+ /**
28
+ * 格式化数字 万
29
+ * @param {Number} num
30
+ * @return {String} 12.3万
31
+ */
32
+ NumberClass.prototype.convertToWan = function (num) {
33
+ var result = '';
34
+ if (num < 10000) {
35
+ result = num;
36
+ }
37
+ if (num >= 10000) {
38
+ result = (num / 10000).toFixed(1) + '万';
39
+ }
40
+ return result;
41
+ };
42
+ /**
43
+ * 格式化数字 k
44
+ * @param {Number} num
45
+ * @return {String} 1.2k
46
+ */
47
+ NumberClass.prototype.convertToThousand = function (num) {
48
+ var result = '';
49
+ if (num < 1000) {
50
+ result = num;
51
+ }
52
+ if (num >= 1000) {
53
+ result = (num / 1000).toFixed(1) + 'k';
54
+ }
55
+ return result;
56
+ };
57
+ /**
58
+ * 随机数,指定范围
59
+ * @param {Number} min 开始
60
+ * @param {Number} max 结束
61
+ * @return {Number|Object}
62
+ */
63
+ NumberClass.prototype.random = function (min, max) {
64
+ if (arguments.length === 2) {
65
+ return Math.floor(min + Math.random() * ((max + 1) - min));
66
+ }
67
+ else {
68
+ return null;
69
+ }
70
+ };
71
+ /**
72
+ * 格式化金额
73
+ * @param {Number} num
74
+ * @return {String} 123,456
75
+ */
76
+ NumberClass.prototype.formatMoney = function (money, signal) {
77
+ var result = '';
78
+ if (money === '') {
79
+ return result;
80
+ }
81
+ money = String(money).replace('.00', '');
82
+ money = money.substring(money.length - 2) === '.0' ? money.replace('.0', '') : money;
83
+ // 小于3位数,直接返回
84
+ if (Number(money) < 1000) {
85
+ return result = money;
86
+ }
87
+ if (money.split('.')[0].length < 3) {
88
+ return result = money;
89
+ }
90
+ signal = signal === '' ? '' : ',';
91
+ var price = money.split('.')[0] + '';
92
+ var pricePoint = money.split('.')[1];
93
+ result = price.length > 6 ?
94
+ "".concat(price.substring(0, price.length - 6)).concat(signal).concat(price.substring(price.length - 6, price.length - 3), ",").concat(price.substring(price.length - 3, price.length))
95
+ :
96
+ "".concat(price.substring(0, price.length - 3)).concat(signal).concat(price.substring(price.length - 3, price.length));
97
+ result = pricePoint ? "".concat(result).concat(signal).concat(pricePoint) : result;
98
+ return result;
99
+ };
100
+ return NumberClass;
101
+ }());
102
+ module.exports = new NumberClass();
@@ -1,78 +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 browser_1 = __importDefault(require("@sentry/browser"));
15
- var Report = /** @class */ (function () {
16
- function Report(Vue, options) {
17
- if (options === void 0) { options = {}; }
18
- if (process.env.NODE_ENV !== 'development') {
19
- // todo
20
- }
21
- this.vue = Vue;
22
- this.options = options;
23
- }
24
- Report.getInstance = function (Vue, Option) {
25
- if (!(this.instance instanceof this)) {
26
- this.instance = new this(Vue, Option);
27
- this.instance.install();
28
- }
29
- return this.instance;
30
- };
31
- Report.prototype.install = function () {
32
- if (process.env.NODE_ENV !== 'development') {
33
- // Raven.config(this.options.dsn, {
34
- // environment: process.env.NODE_ENV,
35
- // }).addPlugin(RavenVue, this.Vue).install();
36
- // raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
37
- // 记录用户信息
38
- browser_1.default.setUser({ user: this.options.user || '' });
39
- // 设置全局tag标签
40
- browser_1.default.setTag('environment', this.options.env || '');
41
- }
42
- };
43
- /**
44
- * 主动上报
45
- * @param {String} data
46
- * @param {String} type 'info','warning','error'
47
- * @param {Object} options
48
- */
49
- Report.prototype.log = function (data, type, options) {
50
- if (data === void 0) { data = null; }
51
- if (type === void 0) { type = 'error'; }
52
- if (options === void 0) { options = {}; }
53
- // 添加面包屑
54
- browser_1.default.addBreadcrumb({
55
- message: data,
56
- category: 'manual message',
57
- });
58
- // 异常上报
59
- if (data instanceof Error) {
60
- browser_1.default.captureException(data, {
61
- level: type,
62
- tags: { options: options },
63
- });
64
- }
65
- else {
66
- browser_1.default.captureException('error', {
67
- level: type,
68
- extra: {
69
- data: data,
70
- options: this.options,
71
- date: new Date(),
72
- },
73
- });
74
- }
75
- };
76
- return Report;
77
- }());
78
- 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;