|
@@ -3,10 +3,17 @@ import FastScanner from './libs/fastscan';
|
3
|
3
|
|
4
|
4
|
/**
|
5
|
5
|
* 随机数
|
6
|
|
- * @param len 随机数长度,默认为1
|
7
|
|
- * @returns {string}
|
|
6
|
+ * @param range 范围
|
|
7
|
+ * @returns {number}
|
8
|
8
|
*/
|
9
|
|
-function MathRand(len = 1) {
|
|
9
|
+export const MathRandom = (range = 10) => {
|
|
10
|
+ return Math.floor(Math.random() * range);
|
|
11
|
+};
|
|
12
|
+/**
|
|
13
|
+ *
|
|
14
|
+ * @param {number} len 随机数求和长度
|
|
15
|
+ */
|
|
16
|
+export const MathRand = (len = 1) => {
|
10
|
17
|
let num = "";
|
11
|
18
|
for (let i = 0; i < len; i++) {
|
12
|
19
|
num += Math.floor(Math.random() * 10);
|
|
@@ -19,7 +26,7 @@ function MathRand(len = 1) {
|
19
|
26
|
* CryptoJS.enc.Utf8.parse 转为128bit的字符串
|
20
|
27
|
* @returns {string}
|
21
|
28
|
*/
|
22
|
|
-function Base64(data) {
|
|
29
|
+export const Base64 = (data) => {
|
23
|
30
|
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data));
|
24
|
31
|
};
|
25
|
32
|
|
|
@@ -27,7 +34,7 @@ function Base64(data) {
|
27
|
34
|
* md5加密
|
28
|
35
|
* @returns {string}
|
29
|
36
|
*/
|
30
|
|
-function MD5(data) {
|
|
37
|
+export const MD5 = (data) => {
|
31
|
38
|
return CryptoJS.MD5(data).toString();
|
32
|
39
|
};
|
33
|
40
|
|
|
@@ -35,7 +42,7 @@ function MD5(data) {
|
35
|
42
|
* 3des加密
|
36
|
43
|
* @returns {string}
|
37
|
44
|
*/
|
38
|
|
-function DESencrypt(data, key) {
|
|
45
|
+export const DESencrypt = (data, key) =>{
|
39
|
46
|
return CryptoJS.TripleDES.encrypt(
|
40
|
47
|
data,
|
41
|
48
|
CryptoJS.enc.Utf8.parse(key),
|
|
@@ -50,7 +57,7 @@ function DESencrypt(data, key) {
|
50
|
57
|
* 3des解密
|
51
|
58
|
* @returns {string}
|
52
|
59
|
*/
|
53
|
|
-function DESdecrypt(data, key) {
|
|
60
|
+export const DESdecrypt = (data, key) => {
|
54
|
61
|
return CryptoJS.TripleDES.decrypt(
|
55
|
62
|
{
|
56
|
63
|
ciphertext: CryptoJS.enc.Base64.parse(data)
|
|
@@ -63,7 +70,7 @@ function DESdecrypt(data, key) {
|
63
|
70
|
).toString(CryptoJS.enc.Utf8);
|
64
|
71
|
};
|
65
|
72
|
// 防抖
|
66
|
|
-const debounce = (fn, wait) => {
|
|
73
|
+export const debounce = (fn, wait) => {
|
67
|
74
|
var timeout = null;
|
68
|
75
|
return function() {
|
69
|
76
|
if(timeout !== null) clearTimeout(timeout);
|
|
@@ -71,21 +78,21 @@ const debounce = (fn, wait) => {
|
71
|
78
|
}
|
72
|
79
|
}
|
73
|
80
|
// 节流
|
74
|
|
-const throttle = (func, delay) => {
|
|
81
|
+export const throttle = (fn, delay) => {
|
75
|
82
|
var prev = Date.now();
|
76
|
83
|
return function() {
|
77
|
84
|
var context = this;
|
78
|
85
|
var args = arguments;
|
79
|
86
|
var now = Date.now();
|
80
|
87
|
if (now - prev >= delay) {
|
81
|
|
- func.apply(context, args);
|
|
88
|
+ fn.apply(context, args);
|
82
|
89
|
prev = Date.now();
|
83
|
90
|
}
|
84
|
91
|
}
|
85
|
92
|
}
|
86
|
93
|
|
87
|
94
|
//四舍五入保留2位小数(若第二位小数为0,则保留一位小数)
|
88
|
|
-function keepTwoDecimal(num) {
|
|
95
|
+export const keepTwoDecimal = (num) => {
|
89
|
96
|
var result = parseFloat(num);
|
90
|
97
|
if (isNaN(result)) {
|
91
|
98
|
console.log('传递参数错误,请检查!');
|
|
@@ -96,7 +103,7 @@ function keepTwoDecimal(num) {
|
96
|
103
|
}
|
97
|
104
|
|
98
|
105
|
//四舍五入保留2位小数(不够位数,则用0替补)
|
99
|
|
-function keepTwoDecimalFull(num) {
|
|
106
|
+export const keepTwoDecimalFull = (num) => {
|
100
|
107
|
var result = parseFloat(num);
|
101
|
108
|
if (isNaN(result)) {
|
102
|
109
|
console.log('传递参数错误,请检查!');
|
|
@@ -116,7 +123,7 @@ function keepTwoDecimalFull(num) {
|
116
|
123
|
}
|
117
|
124
|
|
118
|
125
|
// 显示销量的文本
|
119
|
|
-function showSaleNumText(num) {
|
|
126
|
+export const showSaleNumText = (num) => {
|
120
|
127
|
let baseNum_wan = 10000
|
121
|
128
|
let baseNum_sw = 100000
|
122
|
129
|
let baseNum_bw = 1000000
|
|
@@ -166,7 +173,7 @@ const sensitiveWords = (offWords = [], _content = '') => {
|
166
|
173
|
}
|
167
|
174
|
|
168
|
175
|
// 查找敏感词
|
169
|
|
-const ScanSensitiveWords = (content = '') => {
|
|
176
|
+export const ScanSensitiveWords = (content = '') => {
|
170
|
177
|
let _content = content
|
171
|
178
|
let scanner = new FastScanner(sensitiveDectionary)
|
172
|
179
|
let offWords = scanner.search(_content)
|
|
@@ -175,7 +182,7 @@ const ScanSensitiveWords = (content = '') => {
|
175
|
182
|
}
|
176
|
183
|
// 计算时差
|
177
|
184
|
|
178
|
|
-const getDiffTime = (endDate) =>{
|
|
185
|
+export const getDiffTime = (endDate) =>{
|
179
|
186
|
let diff = (Date.parse(new Date(endDate)) - Date.parse(new Date())) / 1000;
|
180
|
187
|
|
181
|
188
|
if (diff <= 0) {
|
|
@@ -209,8 +216,8 @@ const getDiffTime = (endDate) =>{
|
209
|
216
|
}
|
210
|
217
|
timeLeft.sec = diff;
|
211
|
218
|
return timeLeft;
|
212
|
|
- }
|
213
|
|
-const RandomColor = function randomColor(){
|
|
219
|
+}
|
|
220
|
+export const RandomColor = () => {
|
214
|
221
|
var r = Math.floor(Math.random()*256);
|
215
|
222
|
var g = Math.floor(Math.random()*256);
|
216
|
223
|
var b = Math.floor(Math.random()*256);
|
|
@@ -228,7 +235,8 @@ export default {
|
228
|
235
|
DESencrypt, // 3des加密
|
229
|
236
|
MD5, // md5加密
|
230
|
237
|
Base64, // 转为Base64的字符串v
|
231
|
|
- MathRand, // 获取随机数
|
|
238
|
+ MathRand, // 获取一定长度的随机数和
|
|
239
|
+ MathRandom, // 获取随机数
|
232
|
240
|
getDiffTime, // 计算时差
|
233
|
241
|
RandomColor, // 随机颜色
|
234
|
242
|
}
|