@wzyjs/types 0.0.28
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/cjs/common/index.d.ts +6 -0
- package/dist/cjs/common/tools/index.d.ts +4 -0
- package/dist/cjs/common/tools/number.d.ts +3 -0
- package/dist/cjs/common/tools/number.js +34 -0
- package/dist/cjs/common/tools/object.d.ts +10 -0
- package/dist/cjs/common/tools/object.js +43 -0
- package/dist/cjs/common/tools/other.d.ts +26 -0
- package/dist/cjs/common/tools/other.js +112 -0
- package/dist/cjs/common/tools/string.d.ts +16 -0
- package/dist/cjs/common/tools/string.js +137 -0
- package/dist/cjs/common/types/index.d.ts +20 -0
- package/dist/cjs/fe/dayjs.d.ts +4 -0
- package/dist/cjs/fe/element.d.ts +9 -0
- package/dist/cjs/fe/index.d.ts +20 -0
- package/dist/cjs/fe/middlewares/error.d.ts +3 -0
- package/dist/cjs/fe/middlewares/index.d.ts +1 -0
- package/dist/cjs/fe/other.d.ts +1 -0
- package/dist/cjs/fe/style.d.ts +10 -0
- package/dist/cjs/index_all.d.ts +3 -0
- package/dist/cjs/index_fe.d.ts +2 -0
- package/dist/cjs/index_rd.d.ts +2 -0
- package/dist/cjs/index_rd.js +141 -0
- package/dist/cjs/rd/database/Collection.d.ts +22 -0
- package/dist/cjs/rd/database/Collection.js +202 -0
- package/dist/cjs/rd/database/Database.d.ts +10 -0
- package/dist/cjs/rd/database/Database.js +25 -0
- package/dist/cjs/rd/database/index.d.ts +2 -0
- package/dist/cjs/rd/database/types.d.ts +151 -0
- package/dist/cjs/rd/database/types.js +25 -0
- package/dist/cjs/rd/database/utils.d.ts +3 -0
- package/dist/cjs/rd/database/utils.js +30 -0
- package/dist/cjs/rd/index.d.ts +3 -0
- package/dist/cjs/rd/jsonFile/index.d.ts +6 -0
- package/dist/cjs/rd/jsonFile/index.js +29 -0
- package/dist/cjs/rd/mail/index.d.ts +1 -0
- package/dist/cjs/rd/mail/index.js +31 -0
- package/dist/cjs/rd/middlewares/index.d.ts +1 -0
- package/dist/cjs/rd/middlewares/logger.d.ts +1 -0
- package/dist/esm/common/index.d.ts +6 -0
- package/dist/esm/common/tools/index.d.ts +4 -0
- package/dist/esm/common/tools/number.d.ts +3 -0
- package/dist/esm/common/tools/number.js +30 -0
- package/dist/esm/common/tools/object.d.ts +10 -0
- package/dist/esm/common/tools/object.js +39 -0
- package/dist/esm/common/tools/other.d.ts +26 -0
- package/dist/esm/common/tools/other.js +106 -0
- package/dist/esm/common/tools/string.d.ts +16 -0
- package/dist/esm/common/tools/string.js +120 -0
- package/dist/esm/common/types/index.d.ts +20 -0
- package/dist/esm/fe/dayjs.d.ts +4 -0
- package/dist/esm/fe/dayjs.js +18 -0
- package/dist/esm/fe/element.d.ts +9 -0
- package/dist/esm/fe/element.js +36 -0
- package/dist/esm/fe/index.d.ts +20 -0
- package/dist/esm/fe/index.js +16 -0
- package/dist/esm/fe/middlewares/error.d.ts +3 -0
- package/dist/esm/fe/middlewares/error.js +22 -0
- package/dist/esm/fe/middlewares/index.d.ts +1 -0
- package/dist/esm/fe/other.d.ts +1 -0
- package/dist/esm/fe/other.js +10 -0
- package/dist/esm/fe/style.d.ts +10 -0
- package/dist/esm/fe/style.js +45 -0
- package/dist/esm/index_all.d.ts +3 -0
- package/dist/esm/index_fe.d.ts +2 -0
- package/dist/esm/index_fe.js +19 -0
- package/dist/esm/index_rd.d.ts +2 -0
- package/dist/esm/rd/database/Collection.d.ts +22 -0
- package/dist/esm/rd/database/Database.d.ts +10 -0
- package/dist/esm/rd/database/index.d.ts +2 -0
- package/dist/esm/rd/database/types.d.ts +151 -0
- package/dist/esm/rd/database/utils.d.ts +3 -0
- package/dist/esm/rd/index.d.ts +3 -0
- package/dist/esm/rd/jsonFile/index.d.ts +6 -0
- package/dist/esm/rd/mail/index.d.ts +1 -0
- package/index.ts +40 -0
- package/package.json +16 -0
|
@@ -0,0 +1,106 @@
|
|
|
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 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const getChineseByStr: (str: string) => string;
|
|
2
|
+
export declare const getStrLength: (value: string) => number;
|
|
3
|
+
export declare const replaceAll: (str: string, searchValue: string, replaceValue: string) => string;
|
|
4
|
+
export declare const replaceByRules: (str: string, rules: [string, string][]) => string;
|
|
5
|
+
export declare const getType: (value: any) => string;
|
|
6
|
+
export declare const amount: (str: string) => string;
|
|
7
|
+
export declare const jsonParse: (value: string | object) => object;
|
|
8
|
+
export declare const isJson: (str: string) => boolean;
|
|
9
|
+
export declare const toString: (value: any) => string;
|
|
10
|
+
export declare const getRandomColor: () => string;
|
|
11
|
+
export declare const getRandomString: (length?: number) => string;
|
|
12
|
+
export declare const getChinese: (str: string) => string;
|
|
13
|
+
export declare const getSliceStr: (str: string, before: string, after: string) => string;
|
|
14
|
+
export declare const getProxyUrl: (url: string) => string;
|
|
15
|
+
export declare const getLength: (value: string) => number;
|
|
16
|
+
export declare const getCookie: (name: string) => string | null;
|
|
@@ -0,0 +1,120 @@
|
|
|
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 };
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
export { Dayjs, default } from 'dayjs';
|
|
3
|
+
import isBetween from 'dayjs/plugin/isBetween';
|
|
4
|
+
import weekday from 'dayjs/plugin/weekday';
|
|
5
|
+
import localeData from 'dayjs/plugin/localeData';
|
|
6
|
+
import isoWeek from 'dayjs/plugin/isoWeek';
|
|
7
|
+
import updateLocale from 'dayjs/plugin/updateLocale';
|
|
8
|
+
import 'dayjs/locale/zh-cn';
|
|
9
|
+
|
|
10
|
+
dayjs.extend(isBetween);
|
|
11
|
+
dayjs.extend(weekday);
|
|
12
|
+
dayjs.extend(localeData);
|
|
13
|
+
dayjs.extend(isoWeek);
|
|
14
|
+
dayjs.extend(updateLocale);
|
|
15
|
+
dayjs.locale('zh-cn');
|
|
16
|
+
dayjs.updateLocale('zh-cn', {
|
|
17
|
+
weekStart: 1,
|
|
18
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// 滚动到让指定元素显示出来的位置
|
|
2
|
+
const scrollIntoView = (el, option) => {
|
|
3
|
+
if (!el) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
el.scrollIntoView({ behavior: 'smooth', block: 'start', ...option });
|
|
7
|
+
};
|
|
8
|
+
// 获取指定元素 已经元素原始的样式
|
|
9
|
+
const getElement = (el) => {
|
|
10
|
+
const element = typeof el === 'string' ? document.querySelector(el) : el;
|
|
11
|
+
if (!element) {
|
|
12
|
+
return {
|
|
13
|
+
element: null,
|
|
14
|
+
originalStyle: {},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
// 获取元素原始的样式
|
|
18
|
+
return {
|
|
19
|
+
element,
|
|
20
|
+
originalStyle: window.getComputedStyle(element),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
// 判断元素是否在可见范围内
|
|
24
|
+
const isElementInViewport = (el) => {
|
|
25
|
+
const { element } = getElement(el);
|
|
26
|
+
if (!element) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const rect = element.getBoundingClientRect();
|
|
30
|
+
return (rect.top >= 0 &&
|
|
31
|
+
rect.left >= 0 &&
|
|
32
|
+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
|
|
33
|
+
rect.right <= (window.innerWidth || document.documentElement.clientWidth));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { getElement, isElementInViewport, scrollIntoView };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import md5 from 'md5';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import copy from 'copy-to-clipboard';
|
|
4
|
+
import anime from 'animejs';
|
|
5
|
+
export { copy, classnames, md5, anime };
|
|
6
|
+
export declare const localforage: {
|
|
7
|
+
config: {
|
|
8
|
+
(options: LocalForageOptions): boolean;
|
|
9
|
+
(options: string): any;
|
|
10
|
+
(): LocalForageOptions;
|
|
11
|
+
};
|
|
12
|
+
setItem: <T>(key: string, value: T, callback?: ((err: any, value: T) => void) | undefined) => Promise<T>;
|
|
13
|
+
getItem: <T_1>(key: string, callback?: ((err: any, value: T_1 | null) => void) | undefined) => Promise<T_1 | null>;
|
|
14
|
+
removeItem: (key: string, callback?: ((err: any) => void) | undefined) => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
export { default as dayjs, Dayjs } from './dayjs';
|
|
17
|
+
export * from './style';
|
|
18
|
+
export * from './element';
|
|
19
|
+
export * from './other';
|
|
20
|
+
export * from './middlewares';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as md5 } from 'md5';
|
|
2
|
+
export { default as classnames } from 'classnames';
|
|
3
|
+
export { default as copy } from 'copy-to-clipboard';
|
|
4
|
+
import { config, setItem, getItem, removeItem } from 'localforage';
|
|
5
|
+
export { default as anime } from 'animejs';
|
|
6
|
+
import './dayjs.js';
|
|
7
|
+
export { setupHttpClient } from '@midwayjs/rpc';
|
|
8
|
+
|
|
9
|
+
const localforage = {
|
|
10
|
+
config,
|
|
11
|
+
setItem,
|
|
12
|
+
getItem,
|
|
13
|
+
removeItem,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { localforage };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { setupHttpClient } from '@midwayjs/rpc';
|
|
2
|
+
|
|
3
|
+
const ErrorMiddleware = async (ctx, next) => {
|
|
4
|
+
try {
|
|
5
|
+
await next();
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
switch (err?.status) {
|
|
9
|
+
case 401:
|
|
10
|
+
location.href = '/login';
|
|
11
|
+
break;
|
|
12
|
+
case 500:
|
|
13
|
+
alert('Internal Server Error');
|
|
14
|
+
break;
|
|
15
|
+
default:
|
|
16
|
+
alert(`Unknown Error, status: ${err?.status}`);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { ErrorMiddleware };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './error';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const readClipboard: () => Promise<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import anime from 'animejs';
|
|
2
|
+
import { getElement } from './element.js';
|
|
3
|
+
|
|
4
|
+
// 颜色值转换
|
|
5
|
+
const hexToRgba = (hexColor, a = 1) => {
|
|
6
|
+
let red = parseInt(hexColor.substr(1, 2), 16);
|
|
7
|
+
let green = parseInt(hexColor.substr(3, 2), 16);
|
|
8
|
+
let blue = parseInt(hexColor.substr(5, 2), 16);
|
|
9
|
+
return {
|
|
10
|
+
nums: { red, green, blue },
|
|
11
|
+
text: `rgba(${red}, ${green}, ${blue}, ${a})`,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
// 背景颜色闪动
|
|
15
|
+
const flashBackground = (el, color, a = 1) => {
|
|
16
|
+
const { element, originalStyle } = getElement(el);
|
|
17
|
+
if (!element) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
anime({
|
|
21
|
+
targets: element,
|
|
22
|
+
backgroundColor: [hexToRgba(color, a).text, originalStyle.backgroundColor],
|
|
23
|
+
duration: 1500,
|
|
24
|
+
easing: 'easeInOutSine',
|
|
25
|
+
direction: 'alternate',
|
|
26
|
+
loop: false,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
// 边框闪动
|
|
30
|
+
const flashBorder = (el, color, a = 1) => {
|
|
31
|
+
const { element } = getElement(el);
|
|
32
|
+
if (!element) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
anime({
|
|
36
|
+
targets: element,
|
|
37
|
+
border: [`1px solid ${hexToRgba(color, a).text}`, 'none'],
|
|
38
|
+
duration: 1500,
|
|
39
|
+
easing: 'easeInOutSine',
|
|
40
|
+
direction: 'alternate',
|
|
41
|
+
loop: false,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { flashBackground, flashBorder, hexToRgba };
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export { amount, getChinese, getChineseByStr, getCookie, getLength, getProxyUrl, getRandomColor, getRandomString, getSliceStr, getStrLength, getType, isJson, jsonParse, replaceAll, replaceByRules, toString } from './common/tools/string.js';
|
|
5
|
+
export { filterParams, findItem, watch } from './common/tools/object.js';
|
|
6
|
+
export { delay, executePromise, handleParams, handleRes2List, locationFn } from './common/tools/other.js';
|
|
7
|
+
export { getFileSize, getRandomNum, limitDecimals } from './common/tools/number.js';
|
|
8
|
+
export { localforage } from './fe/index.js';
|
|
9
|
+
import './fe/dayjs.js';
|
|
10
|
+
export { Dayjs, default as dayjs } from 'dayjs';
|
|
11
|
+
export { flashBackground, flashBorder, hexToRgba } from './fe/style.js';
|
|
12
|
+
export { getElement, isElementInViewport, scrollIntoView } from './fe/element.js';
|
|
13
|
+
export { readClipboard } from './fe/other.js';
|
|
14
|
+
export { setupHttpClient } from '@midwayjs/rpc';
|
|
15
|
+
export { ErrorMiddleware } from './fe/middlewares/error.js';
|
|
16
|
+
export { default as copy } from 'copy-to-clipboard';
|
|
17
|
+
export { default as classnames } from 'classnames';
|
|
18
|
+
export { default as md5 } from 'md5';
|
|
19
|
+
export { default as anime } from 'animejs';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Database, IKeyValue } from '@cloudbase/node-sdk';
|
|
2
|
+
import { Add, Conditions, Count, Delete, Find, FindList, IdConditions, MethodParams, Update, WhereConditions } from './types';
|
|
3
|
+
export declare class Collection<D extends IKeyValue> {
|
|
4
|
+
private readonly db;
|
|
5
|
+
private readonly collection;
|
|
6
|
+
constructor(db: Database.Db, name: string);
|
|
7
|
+
private joinConditions;
|
|
8
|
+
private request;
|
|
9
|
+
private handleRes;
|
|
10
|
+
private handleData;
|
|
11
|
+
handleConditions(params: MethodParams<D>): MethodParams<D>;
|
|
12
|
+
private exec;
|
|
13
|
+
add(data: Add.Params<D>['data']): Promise<Add.Res>;
|
|
14
|
+
add(data: Add.Params<D>['data'], isReturn: true, conditions?: Pick<IdConditions, 'field'>): Promise<Find.Res<D>>;
|
|
15
|
+
delete(conditions: Conditions): Promise<Delete.Res>;
|
|
16
|
+
update(conditions: Conditions, data: Update.Params<D>['data'], isSet?: true): Promise<Update.Res<D>>;
|
|
17
|
+
update(conditions: IdConditions, data: Update.Params<D>['data'], isSet?: true): Promise<Update.Res<D>>;
|
|
18
|
+
update(conditions: IdConditions, data: Update.Params<D>['data'], isReturn: true, isSet?: true): Promise<Find.Res<D>>;
|
|
19
|
+
find(conditions?: Conditions): Promise<Find.Res<D>>;
|
|
20
|
+
findList(conditions?: WhereConditions): Promise<FindList.Res<D>>;
|
|
21
|
+
count(conditions: Conditions): Promise<Count.Res>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import tcb, { IKeyValue } from '@cloudbase/node-sdk';
|
|
2
|
+
import { Config } from './types';
|
|
3
|
+
import { Collection } from './Collection';
|
|
4
|
+
export declare class Database {
|
|
5
|
+
private readonly db;
|
|
6
|
+
private readonly instance;
|
|
7
|
+
constructor(config: Config);
|
|
8
|
+
collection<D extends IKeyValue>(name: string): Collection<D>;
|
|
9
|
+
createCollection(name: string): tcb.IBaseRes;
|
|
10
|
+
}
|