@wzyjs/utils 0.0.30 → 0.1.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.
- package/dist/{browser/cjs/utils/src → cjs}/browser/element.d.ts +9 -9
- package/dist/cjs/browser/element.js +59 -0
- package/dist/{node/cjs/utils/src → cjs}/browser/index.d.ts +18 -18
- package/dist/cjs/browser/index.js +64 -0
- package/dist/{browser/cjs/utils/src → cjs}/browser/other.d.ts +1 -1
- package/dist/cjs/browser/other.js +35 -0
- package/dist/{browser/esm/utils/src → cjs}/browser/style.d.ts +10 -10
- package/dist/cjs/browser/style.js +81 -0
- package/dist/{browser/cjs/utils/src → cjs}/browser.d.ts +2 -2
- package/dist/cjs/browser.js +25 -0
- package/dist/{browser/esm/utils/src → cjs}/common/classs.d.ts +5 -5
- package/dist/cjs/common/classs.js +36 -0
- package/dist/{browser/cjs/utils/src → cjs}/common/dayjs.d.ts +4 -4
- package/dist/cjs/common/dayjs.js +57 -0
- package/dist/{node/cjs/utils/src → cjs}/common/index.d.ts +11 -11
- package/dist/cjs/common/index.js +99 -0
- package/dist/{browser/cjs/utils/src → cjs}/common/number.d.ts +3 -3
- package/dist/cjs/common/number.js +55 -0
- package/dist/{browser/esm/utils/src → cjs}/common/object.d.ts +10 -10
- package/dist/cjs/common/object.js +65 -0
- package/dist/{node/esm/utils/src → cjs}/common/other.d.ts +26 -26
- package/dist/cjs/common/other.js +129 -0
- package/dist/{browser/cjs/utils/src → cjs}/common/string.d.ts +16 -16
- package/dist/cjs/common/string.js +157 -0
- package/dist/{node/cjs/utils/src → cjs}/node/database/Collection.d.ts +22 -22
- package/dist/cjs/node/database/Collection.js +219 -0
- package/dist/{node/cjs/utils/src → cjs}/node/database/Database.d.ts +10 -10
- package/dist/cjs/node/database/Database.js +47 -0
- package/dist/{browser/esm/utils/src → cjs}/node/database/index.d.ts +2 -2
- package/dist/cjs/node/database/index.js +38 -0
- package/dist/{node/esm/utils/src → cjs}/node/database/types.d.ts +151 -151
- package/dist/cjs/node/database/types.js +51 -0
- package/dist/{browser/cjs/utils/src → cjs}/node/database/utils.d.ts +3 -3
- package/dist/cjs/node/database/utils.js +53 -0
- package/dist/{browser/cjs/utils/src → cjs}/node/index.d.ts +3 -3
- package/dist/cjs/node/index.js +27 -0
- package/dist/{node/cjs/utils/src → cjs}/node/jsonFile/index.d.ts +6 -6
- package/dist/cjs/node/jsonFile/index.js +51 -0
- package/dist/{browser/cjs/utils/src → cjs}/node/mail/index.d.ts +1 -1
- package/dist/cjs/node/mail/index.js +67 -0
- package/dist/{node/cjs/utils/src → cjs}/node.d.ts +2 -2
- package/dist/cjs/node.js +25 -0
- package/dist/{node/cjs/utils/src → esm}/browser/element.d.ts +9 -9
- package/dist/esm/browser/element.js +43 -0
- package/dist/{node/esm/utils/src → esm}/browser/index.d.ts +18 -18
- package/dist/esm/browser/index.js +15 -0
- package/dist/{node/cjs/utils/src → esm}/browser/other.d.ts +1 -1
- package/dist/esm/browser/other.js +28 -0
- package/dist/{browser/cjs/utils/src → esm}/browser/style.d.ts +10 -10
- package/dist/esm/browser/style.js +55 -0
- package/dist/{node/cjs/utils/src → esm}/browser.d.ts +2 -2
- package/dist/esm/browser.js +2 -0
- package/dist/{browser/cjs/utils/src → esm}/common/classs.d.ts +5 -5
- package/dist/esm/common/classs.js +33 -0
- package/dist/{browser/esm/utils/src → esm}/common/dayjs.d.ts +4 -4
- package/dist/{browser/esm → esm}/common/dayjs.js +10 -10
- package/dist/{node/esm/utils/src → esm}/common/index.d.ts +11 -11
- package/dist/{browser/cjs/utils/src/common/index.d.ts → esm/common/index.js} +12 -11
- package/dist/{browser/esm/utils/src → esm}/common/number.d.ts +3 -3
- package/dist/esm/common/number.js +31 -0
- package/dist/{node/cjs/utils/src → esm}/common/object.d.ts +10 -10
- package/dist/esm/common/object.js +84 -0
- package/dist/{browser/esm/utils/src → esm}/common/other.d.ts +26 -26
- package/dist/esm/common/other.js +173 -0
- package/dist/{browser/esm/utils/src → esm}/common/string.d.ts +16 -16
- package/dist/esm/common/string.js +140 -0
- package/dist/{browser/cjs/utils/src → esm}/node/database/Collection.d.ts +22 -22
- package/dist/esm/node/database/Collection.js +356 -0
- package/dist/{browser/cjs/utils/src → esm}/node/database/Database.d.ts +10 -10
- package/dist/esm/node/database/Database.js +36 -0
- package/dist/{node/cjs/utils/src → esm}/node/database/index.d.ts +2 -2
- package/dist/{browser/cjs/utils/src/node/database/index.d.ts → esm/node/database/index.js} +2 -2
- package/dist/{node/cjs/utils/src → esm}/node/database/types.d.ts +151 -151
- package/dist/esm/node/database/types.js +55 -0
- package/dist/{browser/esm/utils/src → esm}/node/database/utils.d.ts +3 -3
- package/dist/esm/node/database/utils.js +29 -0
- package/dist/{browser/esm/utils/src → esm}/node/index.d.ts +3 -3
- package/dist/esm/node/index.js +3 -0
- package/dist/{browser/cjs/utils/src → esm}/node/jsonFile/index.d.ts +6 -6
- package/dist/esm/node/jsonFile/index.js +43 -0
- package/dist/{browser/esm/utils/src → esm}/node/mail/index.d.ts +1 -1
- package/dist/esm/node/mail/index.js +48 -0
- package/dist/{browser/cjs/utils/src → esm}/node.d.ts +2 -2
- package/dist/esm/node.js +2 -0
- package/package.json +10 -23
- package/dist/browser/cjs/browser/element.js +0 -40
- package/dist/browser/cjs/browser/index.js +0 -20
- package/dist/browser/cjs/browser/other.js +0 -12
- package/dist/browser/cjs/browser/style.js +0 -49
- package/dist/browser/cjs/browser.js +0 -171
- package/dist/browser/cjs/common/classs.js +0 -14
- package/dist/browser/cjs/common/dayjs.js +0 -27
- package/dist/browser/cjs/common/number.js +0 -34
- package/dist/browser/cjs/common/object.js +0 -43
- package/dist/browser/cjs/common/other.js +0 -112
- package/dist/browser/cjs/common/string.js +0 -137
- package/dist/browser/cjs/types/index.d.ts +0 -27
- package/dist/browser/cjs/utils/src/browser/index.d.ts +0 -18
- package/dist/browser/cjs/utils/src/common/object.d.ts +0 -10
- package/dist/browser/cjs/utils/src/common/other.d.ts +0 -26
- package/dist/browser/cjs/utils/src/node/database/types.d.ts +0 -151
- package/dist/browser/esm/browser/element.js +0 -36
- package/dist/browser/esm/browser/index.js +0 -14
- package/dist/browser/esm/browser/other.js +0 -10
- package/dist/browser/esm/browser/style.js +0 -45
- package/dist/browser/esm/browser.js +0 -19
- package/dist/browser/esm/common/classs.js +0 -12
- package/dist/browser/esm/common/number.js +0 -30
- package/dist/browser/esm/common/object.js +0 -39
- package/dist/browser/esm/common/other.js +0 -106
- package/dist/browser/esm/common/string.js +0 -120
- package/dist/browser/esm/types/index.d.ts +0 -27
- package/dist/browser/esm/utils/src/browser/element.d.ts +0 -9
- package/dist/browser/esm/utils/src/browser/index.d.ts +0 -18
- package/dist/browser/esm/utils/src/browser/other.d.ts +0 -1
- package/dist/browser/esm/utils/src/browser.d.ts +0 -2
- package/dist/browser/esm/utils/src/common/index.d.ts +0 -11
- package/dist/browser/esm/utils/src/node/database/Collection.d.ts +0 -22
- package/dist/browser/esm/utils/src/node/database/Database.d.ts +0 -10
- package/dist/browser/esm/utils/src/node/database/types.d.ts +0 -151
- package/dist/browser/esm/utils/src/node/jsonFile/index.d.ts +0 -6
- package/dist/browser/esm/utils/src/node.d.ts +0 -2
- package/dist/node/cjs/common/classs.js +0 -14
- package/dist/node/cjs/common/dayjs.js +0 -27
- package/dist/node/cjs/common/number.js +0 -34
- package/dist/node/cjs/common/object.js +0 -43
- package/dist/node/cjs/common/other.js +0 -112
- package/dist/node/cjs/common/string.js +0 -137
- package/dist/node/cjs/node/database/Collection.js +0 -202
- package/dist/node/cjs/node/database/Database.js +0 -25
- package/dist/node/cjs/node/database/types.js +0 -25
- package/dist/node/cjs/node/database/utils.js +0 -30
- package/dist/node/cjs/node/jsonFile/index.js +0 -29
- package/dist/node/cjs/node/mail/index.js +0 -31
- package/dist/node/cjs/node.js +0 -157
- package/dist/node/cjs/types/index.d.ts +0 -27
- package/dist/node/cjs/utils/src/browser/style.d.ts +0 -10
- package/dist/node/cjs/utils/src/common/classs.d.ts +0 -5
- package/dist/node/cjs/utils/src/common/dayjs.d.ts +0 -4
- package/dist/node/cjs/utils/src/common/number.d.ts +0 -3
- package/dist/node/cjs/utils/src/common/other.d.ts +0 -26
- package/dist/node/cjs/utils/src/common/string.d.ts +0 -16
- package/dist/node/cjs/utils/src/node/database/utils.d.ts +0 -3
- package/dist/node/cjs/utils/src/node/index.d.ts +0 -3
- package/dist/node/cjs/utils/src/node/mail/index.d.ts +0 -1
- package/dist/node/esm/common/classs.js +0 -12
- package/dist/node/esm/common/dayjs.js +0 -18
- package/dist/node/esm/common/number.js +0 -30
- package/dist/node/esm/common/object.js +0 -39
- package/dist/node/esm/common/other.js +0 -106
- package/dist/node/esm/common/string.js +0 -120
- package/dist/node/esm/node/database/Collection.js +0 -200
- package/dist/node/esm/node/database/Database.js +0 -23
- package/dist/node/esm/node/database/types.js +0 -25
- package/dist/node/esm/node/database/utils.js +0 -27
- package/dist/node/esm/node/jsonFile/index.js +0 -27
- package/dist/node/esm/node/mail/index.js +0 -29
- package/dist/node/esm/node.js +0 -14
- package/dist/node/esm/types/index.d.ts +0 -27
- package/dist/node/esm/utils/src/browser/element.d.ts +0 -9
- package/dist/node/esm/utils/src/browser/other.d.ts +0 -1
- package/dist/node/esm/utils/src/browser/style.d.ts +0 -10
- package/dist/node/esm/utils/src/browser.d.ts +0 -2
- package/dist/node/esm/utils/src/common/classs.d.ts +0 -5
- package/dist/node/esm/utils/src/common/dayjs.d.ts +0 -4
- package/dist/node/esm/utils/src/common/number.d.ts +0 -3
- package/dist/node/esm/utils/src/common/object.d.ts +0 -10
- package/dist/node/esm/utils/src/common/string.d.ts +0 -16
- package/dist/node/esm/utils/src/node/database/Collection.d.ts +0 -22
- package/dist/node/esm/utils/src/node/database/Database.d.ts +0 -10
- package/dist/node/esm/utils/src/node/database/index.d.ts +0 -2
- package/dist/node/esm/utils/src/node/database/utils.d.ts +0 -3
- package/dist/node/esm/utils/src/node/index.d.ts +0 -3
- package/dist/node/esm/utils/src/node/jsonFile/index.d.ts +0 -6
- package/dist/node/esm/utils/src/node/mail/index.d.ts +0 -1
- package/dist/node/esm/utils/src/node.d.ts +0 -2
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// 判断是否有包含指定属性的对象,第三个参数可以指定具体的值
|
|
2
|
-
const findItem = (list, attr, value) => {
|
|
3
|
-
return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
|
|
4
|
-
};
|
|
5
|
-
// 过滤对象中为undefined的属性
|
|
6
|
-
const filterParams = (params) => {
|
|
7
|
-
return Object.entries(params || {}).reduce((obj, [key, value]) => {
|
|
8
|
-
if (value !== undefined) {
|
|
9
|
-
obj[key] = value;
|
|
10
|
-
}
|
|
11
|
-
return obj;
|
|
12
|
-
}, {});
|
|
13
|
-
};
|
|
14
|
-
// 监听属性
|
|
15
|
-
const watch = {
|
|
16
|
-
observe(obj, key, watchFun) {
|
|
17
|
-
// 给该属性设默认值
|
|
18
|
-
const val = obj[key];
|
|
19
|
-
Object.defineProperty(obj, key, {
|
|
20
|
-
configurable: true,
|
|
21
|
-
enumerable: true,
|
|
22
|
-
set(value) {
|
|
23
|
-
obj[key] = value;
|
|
24
|
-
// 赋值(set)时,调用对应函数
|
|
25
|
-
watchFun(value, val);
|
|
26
|
-
},
|
|
27
|
-
get() {
|
|
28
|
-
return val;
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
setWatcher(data = {}, watch = {}) {
|
|
33
|
-
Object.keys(watch).forEach(v => {
|
|
34
|
-
this.observe(data, v, watch[v]); // 监听data内的v属性,传入watch内对应函数以调用
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export { filterParams, findItem, watch };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { pick } from 'lodash';
|
|
2
|
-
|
|
3
|
-
// 处理 ProComponents 中 ProTable 参数中的 page 和 where 和 sort
|
|
4
|
-
const handleParams = (params, sort) => {
|
|
5
|
-
if (!params) {
|
|
6
|
-
return {
|
|
7
|
-
page: {},
|
|
8
|
-
where: {},
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
const { current, pageSize, ...other } = params;
|
|
12
|
-
return {
|
|
13
|
-
page: {
|
|
14
|
-
current: current || 1,
|
|
15
|
-
size: pageSize || 10,
|
|
16
|
-
},
|
|
17
|
-
where: Object.entries(other).reduce((acc, [key, value]) => {
|
|
18
|
-
if (key && value) {
|
|
19
|
-
acc[key] = typeof value === 'string' ? new RegExp(value) : value;
|
|
20
|
-
}
|
|
21
|
-
return acc;
|
|
22
|
-
}, {}),
|
|
23
|
-
order: sort && {
|
|
24
|
-
field: Object.keys(sort)[0],
|
|
25
|
-
type: Object.values(sort)[0] === 'ascend' ? 'asc' : 'desc',
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
// 将 list 的数据处理为 { label: string, value: string }[]
|
|
30
|
-
const handleRes2List = async (reqPromise) => {
|
|
31
|
-
const { data } = await reqPromise();
|
|
32
|
-
return (data?.list || []).map((item) => ({
|
|
33
|
-
label: item.name,
|
|
34
|
-
value: item._id || item.key,
|
|
35
|
-
}));
|
|
36
|
-
};
|
|
37
|
-
// 计算执行 promise 花费的时间
|
|
38
|
-
const executePromise = async (promise) => {
|
|
39
|
-
const start = Date.now();
|
|
40
|
-
const result = await promise;
|
|
41
|
-
const time = Date.now() - start;
|
|
42
|
-
return {
|
|
43
|
-
result,
|
|
44
|
-
time,
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
// 地址栏方面的操作
|
|
48
|
-
const locationFn = {
|
|
49
|
-
// url地址的query转为query对象
|
|
50
|
-
url2Params: (url = location.href) => {
|
|
51
|
-
url = decodeURIComponent(url);
|
|
52
|
-
let jsonList = {};
|
|
53
|
-
if (url.indexOf('?') > -1) {
|
|
54
|
-
let str = url.slice(url.indexOf('?') + 1);
|
|
55
|
-
let strs = str.split('&');
|
|
56
|
-
for (let i = 0; i < strs.length; i++) {
|
|
57
|
-
jsonList[strs[i].split('=')[0]] = strs[i].split('=')[1]; // 如果出现乱码的话,可以用decodeURI()进行解码
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return jsonList || {};
|
|
61
|
-
},
|
|
62
|
-
// 参数对象转换为url
|
|
63
|
-
params2Url: (params) => {
|
|
64
|
-
let url = '';
|
|
65
|
-
for (let k in params) {
|
|
66
|
-
if (k) {
|
|
67
|
-
url += `${k}=${params[k]}&`;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return url.substr(0, url.length - 1);
|
|
71
|
-
},
|
|
72
|
-
// 设置地址栏参数
|
|
73
|
-
setUrlParams: (key, value, keepName) => {
|
|
74
|
-
if (key === undefined || value === undefined)
|
|
75
|
-
return;
|
|
76
|
-
// 给地址栏参数对象添加指定参数
|
|
77
|
-
let allParams = locationFn.url2Params();
|
|
78
|
-
if (keepName) {
|
|
79
|
-
allParams = pick(allParams, keepName) || {};
|
|
80
|
-
}
|
|
81
|
-
allParams[key] = encodeURIComponent(value);
|
|
82
|
-
// 域名和路径
|
|
83
|
-
const url = location.href;
|
|
84
|
-
const sliceEnd = url.indexOf('?') === -1 ? url.length : url.indexOf('?');
|
|
85
|
-
const domainPath = url.slice(0, sliceEnd);
|
|
86
|
-
// 参数
|
|
87
|
-
const params = locationFn.params2Url(allParams);
|
|
88
|
-
// 修改地址栏url
|
|
89
|
-
location.replace(`${domainPath}?${params}`);
|
|
90
|
-
},
|
|
91
|
-
// 取地址栏的path部分
|
|
92
|
-
urlGetPath: (url = location.href) => {
|
|
93
|
-
// 计算要截取的最后一位
|
|
94
|
-
let lastIndex = url.indexOf('?');
|
|
95
|
-
if (lastIndex === -1) {
|
|
96
|
-
lastIndex = url.length;
|
|
97
|
-
}
|
|
98
|
-
return url.slice(0, lastIndex);
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
// 延迟指定毫秒数
|
|
102
|
-
const delay = (time = 1000) => {
|
|
103
|
-
return new Promise(resolve => setTimeout(resolve, time));
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export { delay, executePromise, handleParams, handleRes2List, locationFn };
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// 获取字符串中的中文字符串
|
|
2
|
-
const getChineseByStr = (str) => {
|
|
3
|
-
if (!str) {
|
|
4
|
-
return '';
|
|
5
|
-
}
|
|
6
|
-
const match = str.match(/[\u4e00-\u9fa5]/g);
|
|
7
|
-
if (!match) {
|
|
8
|
-
return '';
|
|
9
|
-
}
|
|
10
|
-
return match.join('');
|
|
11
|
-
};
|
|
12
|
-
// 获取字符串中的长度,中文算 2 个字符
|
|
13
|
-
const getStrLength = (value) => {
|
|
14
|
-
if (!value) {
|
|
15
|
-
return 0;
|
|
16
|
-
}
|
|
17
|
-
const chineseLength = getChineseByStr(value).length;
|
|
18
|
-
return (value.length - chineseLength) + chineseLength * 2;
|
|
19
|
-
};
|
|
20
|
-
// 替换全部指定字符串
|
|
21
|
-
const replaceAll = (str, searchValue, replaceValue) => {
|
|
22
|
-
if (!str || !searchValue || !replaceValue) {
|
|
23
|
-
return str || '';
|
|
24
|
-
}
|
|
25
|
-
str = str.replace(searchValue, replaceValue);
|
|
26
|
-
if (!str.includes(searchValue)) {
|
|
27
|
-
return str;
|
|
28
|
-
}
|
|
29
|
-
return replaceAll(str, searchValue, replaceValue);
|
|
30
|
-
};
|
|
31
|
-
// 根据规则替换字符串
|
|
32
|
-
const replaceByRules = (str, rules) => {
|
|
33
|
-
rules.forEach(([searchValue, replaceValue]) => {
|
|
34
|
-
str = str.replaceAll(searchValue, replaceValue);
|
|
35
|
-
});
|
|
36
|
-
return str;
|
|
37
|
-
};
|
|
38
|
-
// 获取变量的类型
|
|
39
|
-
const getType = (value) => {
|
|
40
|
-
return Object.prototype.toString.call(value).slice(8, -1);
|
|
41
|
-
};
|
|
42
|
-
// 金钱格式化,每三位加,
|
|
43
|
-
const amount = (str) => {
|
|
44
|
-
const reg = /(?=(?!\b)(\d{3})+$)/g;
|
|
45
|
-
return str.replace(reg, ',');
|
|
46
|
-
};
|
|
47
|
-
// 更安全的 JSON.parse
|
|
48
|
-
const jsonParse = (value) => {
|
|
49
|
-
if (typeof value === 'object') {
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
return JSON.parse(value);
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
// 是否为json字符串
|
|
60
|
-
const isJson = (str) => {
|
|
61
|
-
try {
|
|
62
|
-
if (getType(JSON.parse(str)) === 'Object') {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
};
|
|
70
|
-
// 将变量转为字符串
|
|
71
|
-
const toString = (value) => {
|
|
72
|
-
return Object.prototype.toString.call(value).slice(8, -1) === 'object' ? JSON.stringify(value) : String(value);
|
|
73
|
-
};
|
|
74
|
-
// 生成随机颜色
|
|
75
|
-
const getRandomColor = () => {
|
|
76
|
-
const color = Math.floor(Math.random() * 16777215).toString(16);
|
|
77
|
-
if (color.length === 6) {
|
|
78
|
-
return color;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return getRandomColor();
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
// 生成随机字符串
|
|
85
|
-
const getRandomString = (length = 4) => {
|
|
86
|
-
return Math.random().toString(36).substr(2, length);
|
|
87
|
-
};
|
|
88
|
-
// 获取字符串内的中文
|
|
89
|
-
const getChinese = (str) => {
|
|
90
|
-
if (str == null || str === '') {
|
|
91
|
-
return '';
|
|
92
|
-
}
|
|
93
|
-
const res = str.match(/[\u4e00-\u9fa5]/g);
|
|
94
|
-
if (!res) {
|
|
95
|
-
return '';
|
|
96
|
-
}
|
|
97
|
-
return res.join('');
|
|
98
|
-
};
|
|
99
|
-
// 截取指定两个文本之间的字符串 (不好用)
|
|
100
|
-
const getSliceStr = (str, before, after) => {
|
|
101
|
-
return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
|
|
102
|
-
};
|
|
103
|
-
// 获取代理后的url
|
|
104
|
-
const getProxyUrl = (url) => {
|
|
105
|
-
const beforeUrl = 'https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=';
|
|
106
|
-
return beforeUrl + url;
|
|
107
|
-
};
|
|
108
|
-
// 获取字符串的长度
|
|
109
|
-
const getLength = (value) => {
|
|
110
|
-
const chineseLength = getChinese(value).length;
|
|
111
|
-
return (value.length - chineseLength) + chineseLength * 2;
|
|
112
|
-
};
|
|
113
|
-
// 获取指定cookie
|
|
114
|
-
const getCookie = (name) => {
|
|
115
|
-
const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
|
|
116
|
-
const arr = document.cookie.match(reg);
|
|
117
|
-
return arr ? unescape(arr[2]) : null;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export { amount, getChinese, getChineseByStr, getCookie, getLength, getProxyUrl, getRandomColor, getRandomString, getSliceStr, getStrLength, getType, isJson, jsonParse, replaceAll, replaceByRules, toString };
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { merge, cloneDeep, isObject } from 'lodash';
|
|
2
|
-
import { appendTime, defaultConditions } from './utils.js';
|
|
3
|
-
import { Method, Command } from './types.js';
|
|
4
|
-
|
|
5
|
-
class Collection {
|
|
6
|
-
db;
|
|
7
|
-
collection;
|
|
8
|
-
constructor(db, name) {
|
|
9
|
-
this.db = db;
|
|
10
|
-
this.collection = db.collection(name);
|
|
11
|
-
}
|
|
12
|
-
joinConditions(conditions) {
|
|
13
|
-
let record = this.collection;
|
|
14
|
-
if (!conditions) {
|
|
15
|
-
return record;
|
|
16
|
-
}
|
|
17
|
-
// 如果是根据 _id 查询
|
|
18
|
-
if ('_id' in conditions) {
|
|
19
|
-
record = record.doc(conditions._id);
|
|
20
|
-
// 如果是根据 条件 查询
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
const { page, order, where, options } = conditions;
|
|
24
|
-
if (options) {
|
|
25
|
-
record = record.options(options);
|
|
26
|
-
}
|
|
27
|
-
if (where) {
|
|
28
|
-
record = record.where(where);
|
|
29
|
-
}
|
|
30
|
-
if (order) {
|
|
31
|
-
record = record.orderBy(order.field, order.type || 'desc');
|
|
32
|
-
}
|
|
33
|
-
if (page?.current && page?.size) {
|
|
34
|
-
record = record.skip((page.current - 1) * page.size);
|
|
35
|
-
}
|
|
36
|
-
if (page?.size) {
|
|
37
|
-
record = record.limit(page.size);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (Array.isArray(conditions.field)) {
|
|
41
|
-
record = record.field(conditions.field.reduce((o, i) => ({ ...o, [i]: true }), {}));
|
|
42
|
-
}
|
|
43
|
-
else if (conditions.field) {
|
|
44
|
-
record = record.field(conditions.field);
|
|
45
|
-
}
|
|
46
|
-
return record;
|
|
47
|
-
}
|
|
48
|
-
request(params) {
|
|
49
|
-
switch (params.method) {
|
|
50
|
-
case Method.Add:
|
|
51
|
-
return this.joinConditions().add(params.data);
|
|
52
|
-
case Method.Find:
|
|
53
|
-
case Method.FindList:
|
|
54
|
-
return this.joinConditions(params.conditions).get();
|
|
55
|
-
case Method.Delete:
|
|
56
|
-
return this.joinConditions(params.conditions).remove();
|
|
57
|
-
case Method.Update:
|
|
58
|
-
if (params.isSet && '_id' in params.conditions) {
|
|
59
|
-
return this.joinConditions(params.conditions).set(params.data);
|
|
60
|
-
}
|
|
61
|
-
return this.joinConditions(params.conditions).update(params.data);
|
|
62
|
-
case Method.Count:
|
|
63
|
-
return this.joinConditions(params.conditions).count();
|
|
64
|
-
default:
|
|
65
|
-
throw new Error('method is not exist');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// 处理出参
|
|
69
|
-
async handleRes(params, res) {
|
|
70
|
-
if (res) {
|
|
71
|
-
delete res.requestId;
|
|
72
|
-
}
|
|
73
|
-
let data = res;
|
|
74
|
-
switch (params.method) {
|
|
75
|
-
case Method.Add:
|
|
76
|
-
const addRes = res;
|
|
77
|
-
if (addRes.id && params.isReturn) {
|
|
78
|
-
data = await this.find({ _id: addRes.id, field: params.conditions?.field });
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
case Method.Update:
|
|
82
|
-
const updateRes = res;
|
|
83
|
-
if (updateRes.updated && params.isReturn && '_id' in params.conditions) {
|
|
84
|
-
data = await this.find({ _id: params.conditions._id, field: params.conditions?.field });
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
case Method.Find:
|
|
88
|
-
const getRes = res;
|
|
89
|
-
data = getRes?.data[0] || null;
|
|
90
|
-
break;
|
|
91
|
-
case Method.FindList:
|
|
92
|
-
const getListRes = res;
|
|
93
|
-
const countRes = await this.request({
|
|
94
|
-
method: Method.Count,
|
|
95
|
-
conditions: params.conditions,
|
|
96
|
-
});
|
|
97
|
-
data = {
|
|
98
|
-
list: getListRes.data,
|
|
99
|
-
total: countRes.total,
|
|
100
|
-
};
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
return data;
|
|
104
|
-
}
|
|
105
|
-
// 处理数据
|
|
106
|
-
async handleData(params) {
|
|
107
|
-
switch (params.method) {
|
|
108
|
-
case Method.Add:
|
|
109
|
-
params.data = appendTime(params.data, 'create');
|
|
110
|
-
params.data = appendTime(params.data, 'update');
|
|
111
|
-
break;
|
|
112
|
-
case Method.Update:
|
|
113
|
-
if ('_id' in params.data) {
|
|
114
|
-
delete params.data._id;
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
return params;
|
|
119
|
-
}
|
|
120
|
-
// 处理条件
|
|
121
|
-
handleConditions(params) {
|
|
122
|
-
if (params.method !== Method.Add) {
|
|
123
|
-
params.conditions = merge(cloneDeep(defaultConditions), params.conditions);
|
|
124
|
-
}
|
|
125
|
-
// 处理 where 条件
|
|
126
|
-
if (params.conditions && 'where' in params.conditions) {
|
|
127
|
-
const { command: _ } = this.db;
|
|
128
|
-
for (const key in params.conditions.where) {
|
|
129
|
-
const whereValue = params.conditions.where[key];
|
|
130
|
-
if (isObject(whereValue)) {
|
|
131
|
-
const { type, value } = whereValue;
|
|
132
|
-
switch (type) {
|
|
133
|
-
case Command.In:
|
|
134
|
-
params.conditions.where[key] = _.in(value);
|
|
135
|
-
break;
|
|
136
|
-
case Command.Nin:
|
|
137
|
-
params.conditions.where[key] = _.nin(value);
|
|
138
|
-
break;
|
|
139
|
-
case Command.Gt:
|
|
140
|
-
params.conditions.where[key] = _.gt(value);
|
|
141
|
-
break;
|
|
142
|
-
case Command.Gte:
|
|
143
|
-
params.conditions.where[key] = _.gte(value);
|
|
144
|
-
break;
|
|
145
|
-
case Command.Lt:
|
|
146
|
-
params.conditions.where[key] = _.lt(value);
|
|
147
|
-
break;
|
|
148
|
-
case Command.Lte:
|
|
149
|
-
params.conditions.where[key] = _.lte(value);
|
|
150
|
-
break;
|
|
151
|
-
case Command.Eq:
|
|
152
|
-
params.conditions.where[key] = _.eq(value);
|
|
153
|
-
break;
|
|
154
|
-
case Command.Neq:
|
|
155
|
-
params.conditions.where[key] = _.neq(value);
|
|
156
|
-
break;
|
|
157
|
-
case Command.Gtlt:
|
|
158
|
-
params.conditions.where[key] = _.and(_.gt(value[0]), _.lt(value[1]));
|
|
159
|
-
break;
|
|
160
|
-
default:
|
|
161
|
-
const check = type;
|
|
162
|
-
console.error(666, '处理 where 条件 出现未定义的情况', check);
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return params;
|
|
169
|
-
}
|
|
170
|
-
async exec(params) {
|
|
171
|
-
params = await this.handleData(params);
|
|
172
|
-
params = await this.handleConditions(params);
|
|
173
|
-
const res = await this.request(params);
|
|
174
|
-
return this.handleRes(params, res);
|
|
175
|
-
}
|
|
176
|
-
add(data, isReturn, conditions) {
|
|
177
|
-
return this.exec({ method: Method.Add, conditions, data, isReturn });
|
|
178
|
-
}
|
|
179
|
-
// 删
|
|
180
|
-
delete(conditions) {
|
|
181
|
-
return this.exec({ method: Method.Delete, conditions });
|
|
182
|
-
}
|
|
183
|
-
update(conditions, data, isReturn, isSet) {
|
|
184
|
-
return this.exec({ method: Method.Update, conditions, data, isReturn, isSet });
|
|
185
|
-
}
|
|
186
|
-
// 查
|
|
187
|
-
find(conditions) {
|
|
188
|
-
return this.exec({ method: Method.Find, conditions });
|
|
189
|
-
}
|
|
190
|
-
// 查列表
|
|
191
|
-
findList(conditions) {
|
|
192
|
-
return this.exec({ method: Method.FindList, conditions });
|
|
193
|
-
}
|
|
194
|
-
// 查
|
|
195
|
-
count(conditions) {
|
|
196
|
-
return this.exec({ method: Method.Count, conditions });
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export { Collection };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { init } from '@cloudbase/node-sdk';
|
|
2
|
-
import { Collection } from './Collection.js';
|
|
3
|
-
|
|
4
|
-
class Database {
|
|
5
|
-
db;
|
|
6
|
-
instance = {};
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.db = init(config).database();
|
|
9
|
-
}
|
|
10
|
-
// 封装了较多功能的 collection
|
|
11
|
-
collection(name) {
|
|
12
|
-
if (!this.instance[name]) {
|
|
13
|
-
this.instance[name] = new Collection(this.db, name);
|
|
14
|
-
}
|
|
15
|
-
return this.instance[name];
|
|
16
|
-
}
|
|
17
|
-
// 创建 collection
|
|
18
|
-
createCollection(name) {
|
|
19
|
-
return this.db.createCollection(name);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { Database };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// 查询数据库的条件 - 比较的特殊条件
|
|
2
|
-
var Command;
|
|
3
|
-
(function (Command) {
|
|
4
|
-
Command["Eq"] = "eq";
|
|
5
|
-
Command["Neq"] = "neq";
|
|
6
|
-
Command["Lt"] = "lt";
|
|
7
|
-
Command["Lte"] = "lte";
|
|
8
|
-
Command["Gt"] = "gt";
|
|
9
|
-
Command["Gte"] = "gte";
|
|
10
|
-
Command["In"] = "in";
|
|
11
|
-
Command["Nin"] = "nin";
|
|
12
|
-
Command["Gtlt"] = "gtlt";
|
|
13
|
-
})(Command || (Command = {}));
|
|
14
|
-
// 查询的方法
|
|
15
|
-
var Method;
|
|
16
|
-
(function (Method) {
|
|
17
|
-
Method["Add"] = "add";
|
|
18
|
-
Method["Find"] = "find";
|
|
19
|
-
Method["FindList"] = "findList";
|
|
20
|
-
Method["Delete"] = "delete";
|
|
21
|
-
Method["Update"] = "update";
|
|
22
|
-
Method["Count"] = "count";
|
|
23
|
-
})(Method || (Method = {}));
|
|
24
|
-
|
|
25
|
-
export { Command, Method };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// 给记录添加时间
|
|
2
|
-
const appendTime = (data, type) => {
|
|
3
|
-
if (!data) {
|
|
4
|
-
return {};
|
|
5
|
-
}
|
|
6
|
-
return {
|
|
7
|
-
...data,
|
|
8
|
-
[type + 'At']: Date.now(),
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
// 默认条件
|
|
12
|
-
const defaultConditions = {
|
|
13
|
-
order: {
|
|
14
|
-
field: 'createAt',
|
|
15
|
-
type: 'desc',
|
|
16
|
-
},
|
|
17
|
-
options: {
|
|
18
|
-
timeout: 10000,
|
|
19
|
-
multiple: true,
|
|
20
|
-
},
|
|
21
|
-
page: {
|
|
22
|
-
current: 1,
|
|
23
|
-
size: 10,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { appendTime, defaultConditions };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
// 实现一个文件系统读写数据库
|
|
4
|
-
class JsonFile {
|
|
5
|
-
filePath;
|
|
6
|
-
constructor(filePath) {
|
|
7
|
-
this.filePath = path.resolve(__dirname, filePath);
|
|
8
|
-
}
|
|
9
|
-
get(key) {
|
|
10
|
-
return new Promise((resolve) => {
|
|
11
|
-
fs.readFile(this.filePath, (err, data) => {
|
|
12
|
-
const json = data ? JSON.parse(data) : {};
|
|
13
|
-
resolve(json[key]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
set(key, value) {
|
|
18
|
-
fs.readFile(this.filePath, { encoding: 'utf-8' }, (err, data) => {
|
|
19
|
-
const json = data ? JSON.parse(data || '{}') : {};
|
|
20
|
-
json[key] = value;
|
|
21
|
-
fs.writeFile(this.filePath, JSON.stringify(json), () => {
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { JsonFile };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import nodemailer from 'nodemailer';
|
|
2
|
-
|
|
3
|
-
const fromEmail = '15835196981@163.com';
|
|
4
|
-
const fromPass = 'KPTVCFBMRXJVTCGW';
|
|
5
|
-
const transporter = nodemailer.createTransport({
|
|
6
|
-
host: 'smtp.163.com',
|
|
7
|
-
port: 465,
|
|
8
|
-
secure: true,
|
|
9
|
-
auth: {
|
|
10
|
-
user: fromEmail,
|
|
11
|
-
pass: fromPass
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
const sendMail = async (toEmail, title, content) => {
|
|
15
|
-
try {
|
|
16
|
-
await transporter.sendMail({
|
|
17
|
-
from: fromEmail,
|
|
18
|
-
to: toEmail,
|
|
19
|
-
subject: title,
|
|
20
|
-
text: content // 邮件正文
|
|
21
|
-
});
|
|
22
|
-
return title + ' 邮件通知成功';
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
return title + '邮件通知失败' + JSON.stringify(error);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { sendMail };
|
package/dist/node/esm/node.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { default as _, cloneDeep, debounce, find, groupBy, isBoolean, isEmpty, isEqual, isError, isFunction, isNumber, isObject, isString, merge, noop, omit, pick, uniq, uniqBy, uniqWith } from 'lodash';
|
|
2
|
-
import * as consola from 'consola';
|
|
3
|
-
export { consola };
|
|
4
|
-
import './common/dayjs.js';
|
|
5
|
-
export * from 'zod';
|
|
6
|
-
export { amount, getChinese, getChineseByStr, getCookie, getLength, getProxyUrl, getRandomColor, getRandomString, getSliceStr, getStrLength, getType, isJson, jsonParse, replaceAll, replaceByRules, toString } from './common/string.js';
|
|
7
|
-
export { filterParams, findItem, watch } from './common/object.js';
|
|
8
|
-
export { delay, executePromise, handleParams, handleRes2List, locationFn } from './common/other.js';
|
|
9
|
-
export { getFileSize, getRandomNum, limitDecimals } from './common/number.js';
|
|
10
|
-
export { CustomError } from './common/classs.js';
|
|
11
|
-
export { Database } from './node/database/Database.js';
|
|
12
|
-
export { JsonFile } from './node/jsonFile/index.js';
|
|
13
|
-
export { sendMail } from './node/mail/index.js';
|
|
14
|
-
export { Dayjs, default as dayjs } from 'dayjs';
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export interface RequestRes<D = any> {
|
|
2
|
-
success: boolean;
|
|
3
|
-
message: string;
|
|
4
|
-
data: D;
|
|
5
|
-
}
|
|
6
|
-
export type KeyValue<D extends object | string = string, V = any> = Partial<Record<D extends string ? string : keyof D, V>>;
|
|
7
|
-
export interface Pagination {
|
|
8
|
-
current?: number;
|
|
9
|
-
pageSize?: number;
|
|
10
|
-
}
|
|
11
|
-
export type SortParams<D extends object | string = string> = Record<D extends string ? string : keyof D, 'ascend' | 'descend'>;
|
|
12
|
-
export type OrderParams<D extends object | string = string> = {
|
|
13
|
-
field: D extends string ? string : keyof D;
|
|
14
|
-
type: 'asc' | 'desc';
|
|
15
|
-
};
|
|
16
|
-
export interface Option<V extends string | number = string> {
|
|
17
|
-
label: string;
|
|
18
|
-
value: V;
|
|
19
|
-
children?: Option<V>[];
|
|
20
|
-
}
|
|
21
|
-
export type OrderBy = {
|
|
22
|
-
[key: string]: 'asc' | 'desc';
|
|
23
|
-
} | {
|
|
24
|
-
[key: string]: 'asc' | 'desc';
|
|
25
|
-
}[];
|
|
26
|
-
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
27
|
-
export type Set<T, OmitK extends keyof T = never, OptionalK extends Exclude<keyof T, OmitK> = never> = Optional<Omit<T, OmitK>, OptionalK>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const scrollIntoView: (el: Element, option?: ScrollIntoViewOptions) => void;
|
|
2
|
-
export declare const getElement: (el: string | Element) => {
|
|
3
|
-
element: null;
|
|
4
|
-
originalStyle: {};
|
|
5
|
-
} | {
|
|
6
|
-
element: Element;
|
|
7
|
-
originalStyle: CSSStyleDeclaration;
|
|
8
|
-
};
|
|
9
|
-
export declare const isElementInViewport: (el: string | Element) => boolean | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const readClipboard: () => Promise<string>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const hexToRgba: (hexColor: string, a?: number) => {
|
|
2
|
-
nums: {
|
|
3
|
-
red: number;
|
|
4
|
-
green: number;
|
|
5
|
-
blue: number;
|
|
6
|
-
};
|
|
7
|
-
text: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const flashBackground: (el: string | Element, color: string, a?: number) => void;
|
|
10
|
-
export declare const flashBorder: (el: string | Element, color: string, a?: number) => void;
|