@haluo/util 1.0.3 → 1.0.4

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.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @Author: wanghui
3
+ * createBy: @2020.05.21
4
+ */
5
+ 'use strict';
6
+ var modules = {
7
+ cookie: require('./modules/cookie'),
8
+ date: require('./modules/date'),
9
+ dom: require('./modules/dom'),
10
+ filter: require('./modules/filter'),
11
+ format: require('./modules/format'),
12
+ match: require('./modules/match'),
13
+ number: require('./modules/number'),
14
+ tools: require('./modules/tools'),
15
+ };
16
+ var Utils = /** @class */ (function () {
17
+ function Utils() {
18
+ Object.assign(this, modules);
19
+ }
20
+ /**
21
+ * 挂载各组件
22
+ * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
23
+ * @param {Object} app 需要挂载的目标对象
24
+ */
25
+ Utils.prototype.install = function (app) {
26
+ Object.keys(modules).forEach(function (key) {
27
+ if (key === 'filter') {
28
+ return modules[key].install(app);
29
+ }
30
+ app.config.globalProperties['$' + key] = modules[key];
31
+ });
32
+ };
33
+ return Utils;
34
+ }());
35
+ module.exports = new Utils();
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @file Cookie
3
+ * @Author: wanghui
4
+ * @createBy: @2021.01.21
5
+ */
6
+ 'use strict';
7
+ var CookieClass = /** @class */ (function () {
8
+ function CookieClass() {
9
+ }
10
+ /**
11
+ * 获取cookie
12
+ * @param {String} name
13
+ * @return {String}
14
+ */
15
+ CookieClass.prototype.getCookie = function (name) {
16
+ var _name = name + '=';
17
+ var ca = document.cookie.split(';');
18
+ for (var i = 0; i < ca.length; i++) {
19
+ var c = ca[i];
20
+ while (c.charAt(0) === ' ')
21
+ c = c.substring(1);
22
+ if (c.includes(_name))
23
+ return c.substring(_name.length, c.length);
24
+ }
25
+ return '';
26
+ };
27
+ /**
28
+ * 设置cookie
29
+ * @param {Object} ICookie
30
+ */
31
+ CookieClass.prototype.setCookie = function (_a) {
32
+ var _b = _a.name, name = _b === void 0 ? '' : _b, _c = _a.value, value = _c === void 0 ? '' : _c, _d = _a.exdays, exdays = _d === void 0 ? -1 : _d, _e = _a.path, path = _e === void 0 ? '/' : _e, _f = _a.domain, domain = _f === void 0 ? '.jddmoto.com' : _f;
33
+ var d = new Date();
34
+ d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
35
+ var expires = "expires=" + d.toUTCString();
36
+ document.cookie = name + "=" + value + ";" + expires + ";path=" + path + ";domain=" + domain + ";";
37
+ };
38
+ /**
39
+ * 清除Cookie
40
+ * @param {String} name
41
+ */
42
+ CookieClass.prototype.clearCookie = function (name) {
43
+ this.setCookie({
44
+ name: name,
45
+ value: '',
46
+ exdays: -1,
47
+ });
48
+ };
49
+ return CookieClass;
50
+ }());
51
+ module.exports = new CookieClass();
@@ -0,0 +1,192 @@
1
+ /**
2
+ * @file date 格式化
3
+ * @Author: wanghui
4
+ * @createBy: @2020.05.21
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ /**
9
+ * 格式化时间 详情内容里的时间格式
10
+ * @param {Object} data 格式,可参考format 中的o属性
11
+ * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
12
+ * @return 返回fmt 格式 时间
13
+ */
14
+ function replacementDate(data, fmt) {
15
+ for (var k in data) {
16
+ if (new RegExp('(' + k + ')').test(fmt)) {
17
+ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : (("00" + data[k]).substr(('' + data[k]).length)));
18
+ }
19
+ }
20
+ return fmt;
21
+ }
22
+ /**
23
+ * 格式化年份
24
+ * @param {String} date Date 格式
25
+ * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
26
+ * @return 仅返回年份
27
+ */
28
+ function replacementYear(date, fmt) {
29
+ if (/(Y+)/.test(fmt)) {
30
+ fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
31
+ }
32
+ return fmt;
33
+ }
34
+ var DateClass = /** @class */ (function () {
35
+ function DateClass() {
36
+ }
37
+ /**
38
+ * 格式化时间
39
+ * @param {String|Number} date 需要格式化的时间 2017-11-11、2017/11/11、linux time
40
+ * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
41
+ * date.format(new Date()) // 默认格式 'YYYY-MM-DD HH:mm:ss'
42
+ * date.format(1586840260500) // 默认格式,传参为linux时间
43
+ * date.format(new Date(), 'YYYY:MM:DD') // 自定义格式 'YYYY:MM:DD'
44
+ * @return {String} fmt 'YYYY-MM-DD HH:mm:ss'
45
+ */
46
+ DateClass.prototype.format = function (date, fmt) {
47
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
48
+ if (!date)
49
+ return '';
50
+ var timeData = typeof date === 'string' ? new Date(date.replace(/-/g, '/')) : date;
51
+ timeData = typeof date === 'number' ? new Date(date) : timeData;
52
+ var o = {
53
+ 'M+': timeData.getMonth() + 1,
54
+ 'D+': timeData.getDate(),
55
+ 'h+': timeData.getHours() % 12 === 0 ? 12 : timeData.getHours() % 12,
56
+ 'H+': timeData.getHours(),
57
+ 'm+': timeData.getMinutes(),
58
+ 's+': timeData.getSeconds(),
59
+ 'q+': Math.floor((timeData.getMonth() + 3) / 3),
60
+ 'S': timeData.getMilliseconds()
61
+ };
62
+ var week = {
63
+ '0': '\u65e5',
64
+ '1': '\u4e00',
65
+ '2': '\u4e8c',
66
+ '3': '\u4e09',
67
+ '4': '\u56db',
68
+ '5': '\u4e94',
69
+ '6': '\u516d'
70
+ };
71
+ fmt = replacementYear(timeData, fmt);
72
+ if (/(E+)/.test(fmt)) {
73
+ fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week[timeData.getDay() + " "]);
74
+ }
75
+ return replacementDate(o, fmt);
76
+ };
77
+ /**
78
+ * 天数加减
79
+ * @param {string | Date} date 传入的时间 2020-10-15 or Date
80
+ * @param {String} days 天数
81
+ * addDaysToDate('2020-10-15', 10) // '2020-10-25'
82
+ * addDaysToDate('2020-10-15', -10) // '2020-10-05'
83
+ * @return {String} fmt 'YYYY-MM-DD'
84
+ */
85
+ DateClass.prototype.addDaysToDate = function (date, days) {
86
+ var d = typeof date === 'object' ? date : new Date(date);
87
+ d.setDate(d.getDate() + days);
88
+ return d.toISOString().split('T')[0];
89
+ };
90
+ /**
91
+ * 获取倒计时剩余时间
92
+ * @param {Date | Number} endTime 截止时间
93
+ * @param {Date | Number} startTime 开始时间,默认取客户端当前时间
94
+ * date.format(new Date()) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
95
+ * date.format(1586840260500) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
96
+ * @return {object | boolean} {dd: '天', hh: '时', mm: '分', ss: '秒'}
97
+ */
98
+ DateClass.prototype.remainTime = function (endTime, startTime) {
99
+ if (startTime === void 0) { startTime = new Date(); }
100
+ var ts = Number(endTime) - Number(startTime); // 计算剩余的毫秒数
101
+ var dd = Math.floor(ts / 1000 / 60 / 60 / 24); // 计算剩余的天数
102
+ var hh = Math.floor(ts / 1000 / 60 / 60 % 24); // 计算剩余的小时数
103
+ var mm = Math.floor(ts / 1000 / 60 % 60); // 计算剩余的分钟数
104
+ var ss = Math.floor(ts / 1000 % 60); // 计算剩余的秒数
105
+ if (ts <= 0)
106
+ return false;
107
+ return {
108
+ dd: (dd < 10 ? "0" + dd : dd),
109
+ hh: (hh < 10 ? "0" + hh : hh),
110
+ mm: (mm < 10 ? "0" + mm : mm),
111
+ ss: (ss < 10 ? "0" + ss : ss)
112
+ };
113
+ };
114
+ /**
115
+ * 格式化现在的已过时间
116
+ * @param {Number} startTime
117
+ * @return {String} *年前 *个月前 *天前 *小时前 *分钟前 刚刚
118
+ */
119
+ DateClass.prototype.formatPassTime = function (startTime) {
120
+ var currentTime = new Date();
121
+ var time = currentTime - startTime;
122
+ var year = Math.floor(time / (1000 * 60 * 60 * 24) / 30 / 12);
123
+ if (year)
124
+ return year + "\u5E74\u524D";
125
+ var month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
126
+ if (month)
127
+ return month + "\u4E2A\u6708\u524D";
128
+ var day = Math.floor(time / (1000 * 60 * 60 * 24));
129
+ if (day)
130
+ return day + "\u5929\u524D";
131
+ var hour = Math.floor(time / (1000 * 60 * 60));
132
+ if (hour)
133
+ return hour + "\u5C0F\u65F6\u524D";
134
+ var min = Math.floor(time / (1000 * 60));
135
+ if (min)
136
+ return min + "\u5206\u949F\u524D";
137
+ else
138
+ return '刚刚';
139
+ };
140
+ /**
141
+ * 格式化时间 列表里的时间内容格式 待废弃,统一时间格式
142
+ * @param {Number} time 1494141000*1000
143
+ * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
144
+ */
145
+ DateClass.prototype.formatPassTimeForList = function (time) {
146
+ return DateClass.prototype.formatPassTimeForDetail(time, 'YYYY年MM月DD日', true);
147
+ };
148
+ /**
149
+ * 格式化时间 详情内容里的时间格式
150
+ * @param {Number} time 1494141000*1000
151
+ * @param {String} fmt 想要格式化的格式
152
+ * @param {Boolean} noYear 是否显示年
153
+ * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
154
+ */
155
+ DateClass.prototype.formatPassTimeForDetail = function (time, fmt, noYear) {
156
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD'; }
157
+ var date = (typeof time === 'number') ? new Date(time) : new Date((time || '').replace(/-/g, '/'));
158
+ var diff = (((new Date()).getTime() - date.getTime()) / 1000);
159
+ var dayDiff = Math.floor(diff / 86400);
160
+ var isValidDate = Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
161
+ if (!isValidDate)
162
+ return '';
163
+ var formatDate = function () {
164
+ var today = new Date(date);
165
+ var o = {
166
+ 'Y+': today.getFullYear(),
167
+ 'M+': ('0' + (today.getMonth() + 1)).slice(-2),
168
+ 'D+': ('0' + today.getDate()).slice(-2)
169
+ };
170
+ fmt = replacementYear(date, fmt);
171
+ var year = today.getFullYear();
172
+ if (!(new Date().getFullYear() > year) && noYear) {
173
+ var backData = replacementDate(o, fmt);
174
+ return backData.split('年')[1];
175
+ }
176
+ return replacementDate(o, fmt);
177
+ };
178
+ if (dayDiff === -1) {
179
+ return '刚刚';
180
+ }
181
+ else if (isNaN(dayDiff) || dayDiff < 0 || dayDiff >= 15) {
182
+ return formatDate();
183
+ }
184
+ return (dayDiff === 0 && ((diff < 60 && '刚刚') ||
185
+ (diff < 120 && '1分钟前') ||
186
+ (diff < 3600 && Math.floor(diff / 60) + '分钟前') ||
187
+ (diff < 7200 && '1小时前') ||
188
+ (diff < 86400 && Math.floor(diff / 3600) + '小时前'))) || (dayDiff < 16 && dayDiff + '天前');
189
+ };
190
+ return DateClass;
191
+ }());
192
+ module.exports = new DateClass();
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @file Cookie
3
+ * @Author: wanghui
4
+ * @createBy: @2021.08.17
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ var DomClass = /** @class */ (function () {
9
+ function DomClass() {
10
+ }
11
+ /**
12
+ * 创建一个子元素并添加至父节点
13
+ * @param {Object} { name = 'div', innerHTML = '', style = {}, parent, }
14
+ * @return {String}
15
+ */
16
+ DomClass.prototype.createElement = function (_a) {
17
+ var _b = _a.name, name = _b === void 0 ? 'div' : _b, _c = _a.innerHTML, innerHTML = _c === void 0 ? '' : _c, _d = _a.style, style = _d === void 0 ? {} : _d, parent = _a.parent;
18
+ if (!(window && window.document)) {
19
+ return new Error('仅支持浏览器');
20
+ }
21
+ var element = document.createElement(name);
22
+ element.innerHTML = innerHTML;
23
+ Object.keys(style).map(function (_) { return element.style[_] = style[_]; });
24
+ if (parent) {
25
+ var body = document.querySelector(parent);
26
+ body && body.append(element);
27
+ }
28
+ return element;
29
+ };
30
+ /**
31
+ * 获取文本中的url并用a标签包裹
32
+ * @param {Object} ICookie
33
+ */
34
+ DomClass.prototype.wrapperA = function (text) {
35
+ if (!(window && window.document)) {
36
+ return new Error('仅支持浏览器');
37
+ }
38
+ return text.replace(/((https|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g, '<a href="$1">$1</a>');
39
+ };
40
+ /**
41
+ * 对象转化为formdata
42
+ * getFormData({a: 1, b: 2})
43
+ * @param {Object} object
44
+ */
45
+ DomClass.prototype.getFormData = function (object) {
46
+ var formData = new FormData();
47
+ Object.keys(object).forEach(function (key) {
48
+ var value = object[key];
49
+ if (Array.isArray(value)) {
50
+ value.forEach(function (subValue, i) {
51
+ return formData.append(key + ("[" + i + "]"), subValue);
52
+ });
53
+ }
54
+ else {
55
+ formData.append(key, object[key]);
56
+ }
57
+ });
58
+ return formData;
59
+ };
60
+ return DomClass;
61
+ }());
62
+ module.exports = new DomClass();
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @file 过滤器
3
+ * @Author: wanghui
4
+ * @createBy: @2020.05.28
5
+ */
6
+ /**
7
+ * 示例:注入所有过滤器
8
+ * import { filter as filters } from '@haluo/util'
9
+ * Object.keys(filters).forEach(key => {
10
+ * Vue.filter(key, filters[key])
11
+ * })
12
+ */
13
+ 'use strict';
14
+ var dateClass = require('../date');
15
+ var numberClass = require('../number');
16
+ var toolsClass = require('../tools');
17
+ var FilterClass = /** @class */ (function () {
18
+ function FilterClass() {
19
+ }
20
+ /**
21
+ * 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
22
+ * @param {String|Number} date
23
+ * @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
24
+ * @return {String} 'YYYY-MM-DD HH:mm:ss'
25
+ */
26
+ FilterClass.prototype.format = function (date, fmt) {
27
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
28
+ return dateClass.format(date, fmt);
29
+ };
30
+ /**
31
+ * 格式化金额,示例:123456 | formatMoney
32
+ * @param {Number} num
33
+ * @return {String} 123,456
34
+ */
35
+ FilterClass.prototype.formatMoney = function (money) {
36
+ return numberClass.formatMoney(money);
37
+ };
38
+ /**
39
+ * 截取数组或字符串,示例:'1234' | slice(3)
40
+ * @param {Array|String} target 数组或字符串
41
+ * @param {Number} length 截取长度,从0开始
42
+ * @return {any}
43
+ */
44
+ FilterClass.prototype.slice = function (target, length) {
45
+ if (target === void 0) { target = ''; }
46
+ if (length === void 0) { length = 0; }
47
+ return toolsClass.slice(target, length);
48
+ };
49
+ FilterClass.prototype.install = function (app) {
50
+ var _this = this;
51
+ var globalProperties = app.config.globalProperties;
52
+ globalProperties.$filters = globalProperties.$filters || {};
53
+ globalProperties.$filters.format = _this.format;
54
+ globalProperties.$filters.formatMoney = _this.formatMoney;
55
+ globalProperties.$filters.slice = _this.slice;
56
+ };
57
+ return FilterClass;
58
+ }());
59
+ module.exports = new FilterClass();
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var Format = /** @class */ (function () {
3
+ function Format() {
4
+ }
5
+ /**
6
+ * @desc 对于对象非数字与布尔值的value,当其为falsy时,转换成separator
7
+ * @param {object} obj 传入的对象
8
+ * @param {string} separator 替换后的值
9
+ * transformObjectNullVal({ a: null, b: 0}, '23') // {a: "23", b: 0}
10
+ * @return {object}
11
+ */
12
+ Format.prototype.transformObjectNullVal = function (obj, separator) {
13
+ if (separator === void 0) { separator = '-'; }
14
+ return Object.keys(obj).reduce(function (cur, key) {
15
+ cur[key] = obj[key] || ((obj[key] === 0 || obj[key] === false) ? obj[key] : separator);
16
+ return cur;
17
+ }, {});
18
+ };
19
+ return Format;
20
+ }());
21
+ module.exports = new Format();
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file: tools 常用的工具函数
3
+ * @Author: wanghui
4
+ */
5
+ 'use strict';
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ var MatchClass = /** @class */ (function () {
8
+ function MatchClass() {
9
+ }
10
+ /**
11
+ * 根据类型返回正则
12
+ * @param {String} str 检测的内容
13
+ * @param {String} type 检测类型
14
+ * checkType('10.120.33.11', 'ip') // true
15
+ * @return {Boolean} true or false
16
+ */
17
+ MatchClass.prototype.checkType = function (str, type) {
18
+ var regexp = {
19
+ 'ip': /((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}/.test(str),
20
+ 'port': /^(\d|[1-5]\d{4}|6[1-4]\d{3}|65[1-4]\d{2}|655[1-2]\d|6553[1-5])$/.test(str),
21
+ 'phone': /^1[3|4|5|6|7|8][0-9]{9}$/.test(str),
22
+ 'number': /^[0-9]+$/.test(str),
23
+ 'email': /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(str),
24
+ 'IDCard': /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(str),
25
+ 'url': /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(str)
26
+ };
27
+ return regexp[type];
28
+ };
29
+ return MatchClass;
30
+ }());
31
+ module.exports = new MatchClass();
@@ -0,0 +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();
@@ -0,0 +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;