gxxc-util 1.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.
- package/README.md +47 -0
- package/dist/cjs/constant/city.js +5711 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/modules/author.js +167 -0
- package/dist/cjs/modules/cityOptions.js +76 -0
- package/dist/cjs/modules/color.js +88 -0
- package/dist/cjs/modules/demo.js +10 -0
- package/dist/cjs/modules/file.js +73 -0
- package/dist/cjs/modules/number.js +137 -0
- package/dist/cjs/modules/other.js +260 -0
- package/dist/cjs/modules/validation.js +189 -0
- package/dist/esm/constant/city.js +5708 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/modules/author.js +160 -0
- package/dist/esm/modules/cityOptions.js +72 -0
- package/dist/esm/modules/color.js +82 -0
- package/dist/esm/modules/demo.js +8 -0
- package/dist/esm/modules/file.js +69 -0
- package/dist/esm/modules/number.js +131 -0
- package/dist/esm/modules/other.js +231 -0
- package/dist/esm/modules/validation.js +178 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/modules/author.d.ts +95 -0
- package/dist/types/modules/cityOptions.d.ts +26 -0
- package/dist/types/modules/color.d.ts +34 -0
- package/dist/types/modules/demo.d.ts +6 -0
- package/dist/types/modules/file.d.ts +25 -0
- package/dist/types/modules/number.d.ts +30 -0
- package/dist/types/modules/other.d.ts +58 -0
- package/dist/types/modules/validation.d.ts +12 -0
- package/dist/types/tsdoc-metadata.json +11 -0
- package/dist/types/types/index.d.ts +23 -0
- package/dist/umd/index.js +85 -0
- package/package.json +79 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import printJS from 'print-js';
|
|
2
|
+
import * as detectBrowser from 'detect-browser';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
5
|
+
import 'dayjs/locale/zh-cn';
|
|
6
|
+
|
|
7
|
+
dayjs.extend(quarterOfYear);
|
|
8
|
+
dayjs.locale("zh-cn");
|
|
9
|
+
/**
|
|
10
|
+
* 函数"sys_print"接受具有“url”属性的对象,并使用它通过“printJS”函数打印文档。
|
|
11
|
+
* @param props - `props` 参数是一个具有单个属性 `url` 的对象,该属性是一个字符串。
|
|
12
|
+
*/
|
|
13
|
+
const sys_print = (props) => {
|
|
14
|
+
printJS(props?.url);
|
|
15
|
+
};
|
|
16
|
+
const BrowserNameVersion = [
|
|
17
|
+
{ name: "chrome", version: 88 },
|
|
18
|
+
{ name: "safari", version: 14 },
|
|
19
|
+
{ name: "firefox", version: 78 },
|
|
20
|
+
{ name: "opera", version: 74 },
|
|
21
|
+
{ name: "edge-chromium", version: 88 },
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* 函数"sys_detectBrowser"检查浏览器版本,版本在当前系统兼容之外,将弹出提示
|
|
25
|
+
*/
|
|
26
|
+
const sys_detectBrowser = () => {
|
|
27
|
+
const browser = detectBrowser.detect();
|
|
28
|
+
if (browser) {
|
|
29
|
+
let isShowAlert = false;
|
|
30
|
+
const currentBrowser = BrowserNameVersion?.filter((item) => item.name === browser.name)?.[0];
|
|
31
|
+
if (currentBrowser?.version && browser?.version && parseInt(browser?.version) < currentBrowser?.version) {
|
|
32
|
+
isShowAlert = true;
|
|
33
|
+
}
|
|
34
|
+
if (isShowAlert) {
|
|
35
|
+
alert("您当前的浏览器版本较低,请考虑升级浏览器版本或使用其他浏览器以获取最佳体验。");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 函数“win_dynamic_fontSize”根据当前屏幕宽度计算并设置文档的字体大小。
|
|
41
|
+
*/
|
|
42
|
+
const win_dynamic_fontSize = () => {
|
|
43
|
+
const screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
44
|
+
const baseScreenWidth = 1920;
|
|
45
|
+
const baseFontSize = 16;
|
|
46
|
+
const fontSize = (screenWidth / baseScreenWidth) * baseFontSize;
|
|
47
|
+
document.documentElement.style.fontSize = fontSize + "px";
|
|
48
|
+
};
|
|
49
|
+
// 废弃
|
|
50
|
+
const tem_compare_version = (version1, version2) => {
|
|
51
|
+
const v1Array = version1.split(".").map(Number);
|
|
52
|
+
const v2Array = version2.split(".").map(Number);
|
|
53
|
+
for (let i = 0; i < Math.max(v1Array.length, v2Array.length); i++) {
|
|
54
|
+
const v1Part = v1Array[i] || 0;
|
|
55
|
+
const v2Part = v2Array[i] || 0;
|
|
56
|
+
if (v1Part > v2Part) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
else if (v1Part < v2Part) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 新的表头数据转译
|
|
67
|
+
* @param {KeyVal} keyVal 接口返回的存在的表头
|
|
68
|
+
* @param {TableHeaderItem} cache 存储
|
|
69
|
+
* @param {TableHeaderItem} initial 默认
|
|
70
|
+
*/
|
|
71
|
+
const tem_get_tableHeader = (keyVal, cache, initial) => {
|
|
72
|
+
const returnList = [];
|
|
73
|
+
const transformList = [];
|
|
74
|
+
if (keyVal) {
|
|
75
|
+
Object.keys(keyVal)?.forEach((key) => {
|
|
76
|
+
const item = {};
|
|
77
|
+
item.key = key;
|
|
78
|
+
item.name = keyVal[key];
|
|
79
|
+
transformList.push(item);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
transformList.forEach((i) => {
|
|
83
|
+
initial?.forEach((j) => {
|
|
84
|
+
if (cache?.length > 0 && initial?.length === cache?.length) {
|
|
85
|
+
cache?.forEach((k) => {
|
|
86
|
+
if (i?.key === j?.key && i?.key === k?.key) {
|
|
87
|
+
i = { ...i, ...j, ...k };
|
|
88
|
+
i.width = j?.width;
|
|
89
|
+
i.sort = k?.sort ? k?.sort : j.sort;
|
|
90
|
+
i.selected = k?.selected === undefined ? true : k?.selected;
|
|
91
|
+
returnList.push(i);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
if (i?.key === j?.key) {
|
|
97
|
+
i = { ...i, ...j };
|
|
98
|
+
i.selected = true;
|
|
99
|
+
returnList.push(i);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
if (initial[initial.length - 1]?.key === "operate") {
|
|
105
|
+
returnList.push(initial[initial.length - 1]);
|
|
106
|
+
}
|
|
107
|
+
returnList.sort((a, b) => {
|
|
108
|
+
return (a?.sort ?? 1) - (b?.sort ?? 2);
|
|
109
|
+
});
|
|
110
|
+
return returnList;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* 获取枚举配置
|
|
114
|
+
* @param {*} value 当前value值
|
|
115
|
+
* @param {*} array 当前枚举配置
|
|
116
|
+
*/
|
|
117
|
+
const getOptionConfig = (value, array) => {
|
|
118
|
+
if (!!value || value === 0) {
|
|
119
|
+
const findItem = array?.find((item) => item.value === value);
|
|
120
|
+
return findItem ? findItem : {};
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* 获取url 文件名 除后缀名以外的地址名 后缀名
|
|
128
|
+
* @param {*} url 地址
|
|
129
|
+
*/
|
|
130
|
+
const getUrlConfig = (url) => {
|
|
131
|
+
if (!!url) {
|
|
132
|
+
const urlObj = new URL(url);
|
|
133
|
+
const path = urlObj.pathname;
|
|
134
|
+
const fileName = decodeURIComponent(path.substring(path.lastIndexOf("/") + 1));
|
|
135
|
+
const suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
|
|
136
|
+
const prefixPath = url.substring(0, url.lastIndexOf("."));
|
|
137
|
+
return {
|
|
138
|
+
fileName: fileName ?? "",
|
|
139
|
+
prefix: prefixPath ?? "",
|
|
140
|
+
suffix: suffix ?? "",
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* timejs 依赖于 dayjs 构建,形成管理时间的工具函数
|
|
149
|
+
* TypeScript 中的 `timejs` 函数接受一个参数 `props`,并返回使用 `props` 调用 `dayjs` 的结果。
|
|
150
|
+
* @param {any} props - `timejs` 函数中的 `props` 参数预计为 `any` 类型,这意味着它可以接受任何数据类型作为其值。
|
|
151
|
+
*
|
|
152
|
+
* @returns `timejs` 函数正在返回使用 `props` 参数调用 `dayjs` 函数的结果。
|
|
153
|
+
*/
|
|
154
|
+
const timejs = (props, props1, props2) => {
|
|
155
|
+
return dayjs(props, props1, props2);
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* 从视频地址中提取第一帧作为预览图(base64 格式)
|
|
159
|
+
* @param videoUrl 视频地址(支持跨域或 Blob URL)
|
|
160
|
+
* @param frameTime 预览帧时间点(number)
|
|
161
|
+
* @returns 返回一个Promise,成功时返回 base64 图片,失败返回空字符串
|
|
162
|
+
*/
|
|
163
|
+
const video_preview = (videoUrl, frameTime = 0.1) => {
|
|
164
|
+
return new Promise((resolve) => {
|
|
165
|
+
// 参数校验:无效地址或非法时间直接返回空
|
|
166
|
+
if (!videoUrl || typeof videoUrl !== "string" || frameTime < 0) {
|
|
167
|
+
return resolve("");
|
|
168
|
+
}
|
|
169
|
+
// 创建 video 元素用于加载视频
|
|
170
|
+
const video = document.createElement("video");
|
|
171
|
+
video.crossOrigin = "anonymous"; // 解决跨域问题
|
|
172
|
+
video.src = videoUrl; // 设置视频地址
|
|
173
|
+
video.muted = true; // 静音播放,避免浏览器限制
|
|
174
|
+
// 超时控制:10 秒内未完成则中断并返回空
|
|
175
|
+
const timeout = setTimeout(() => {
|
|
176
|
+
cleanup();
|
|
177
|
+
resolve("");
|
|
178
|
+
}, 10000);
|
|
179
|
+
// 清理函数:释放资源
|
|
180
|
+
const cleanup = () => {
|
|
181
|
+
clearTimeout(timeout); // 清除超时定时器
|
|
182
|
+
video.pause(); // 暂停播放
|
|
183
|
+
video.removeAttribute("src"); // 清除 src 属性
|
|
184
|
+
video.load(); // 重新加载资源(释放内存)
|
|
185
|
+
};
|
|
186
|
+
// 视频元数据加载完成后触发
|
|
187
|
+
video.onloadedmetadata = () => {
|
|
188
|
+
// 如果宽高为 0,说明视频未正确加载
|
|
189
|
+
if (video.videoWidth === 0 || video.videoHeight === 0) {
|
|
190
|
+
return resolve("");
|
|
191
|
+
}
|
|
192
|
+
// 设置到指定帧位置
|
|
193
|
+
video.currentTime = frameTime;
|
|
194
|
+
};
|
|
195
|
+
// seeked 事件表示视频已经跳转到目标时间点(即已准备好绘制)
|
|
196
|
+
video.onseeked = () => {
|
|
197
|
+
try {
|
|
198
|
+
// 创建 canvas 用于绘制视频帧
|
|
199
|
+
const canvas = document.createElement("canvas");
|
|
200
|
+
canvas.width = video.videoWidth;
|
|
201
|
+
canvas.height = video.videoHeight;
|
|
202
|
+
// 获取 canvas 的绘图上下文
|
|
203
|
+
const ctx = canvas.getContext("2d");
|
|
204
|
+
if (!ctx)
|
|
205
|
+
return resolve("");
|
|
206
|
+
// 将当前帧绘制到 canvas 上
|
|
207
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
208
|
+
// 将 canvas 内容转换为 base64 图片
|
|
209
|
+
const imgUrl = canvas.toDataURL("image/jpeg");
|
|
210
|
+
// 清理资源并返回结果
|
|
211
|
+
cleanup();
|
|
212
|
+
resolve(imgUrl);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
console.error("Canvas draw error:", error);
|
|
216
|
+
// 绘制过程中出错,清理并返回空
|
|
217
|
+
cleanup();
|
|
218
|
+
resolve("");
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
// 视频加载错误处理
|
|
222
|
+
video.onerror = () => {
|
|
223
|
+
cleanup();
|
|
224
|
+
resolve("");
|
|
225
|
+
};
|
|
226
|
+
// 开始加载视频
|
|
227
|
+
video.load();
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export { getOptionConfig, getUrlConfig, sys_detectBrowser, sys_print, tem_compare_version, tem_get_tableHeader, timejs, video_preview, win_dynamic_fontSize };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// 数字文本
|
|
2
|
+
const val_number = (_, value) => {
|
|
3
|
+
if (value) {
|
|
4
|
+
if (/\s/.test(value)) {
|
|
5
|
+
return Promise.reject(new Error("请去除文本前后及内容中的空格!"));
|
|
6
|
+
}
|
|
7
|
+
else if (isNaN(Number(value))) {
|
|
8
|
+
return Promise.reject(new Error("请输入有效的数字文本!"));
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return Promise.resolve();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
// 两位小数点百分比
|
|
19
|
+
const val_two_percent = (_, value) => {
|
|
20
|
+
if (value) {
|
|
21
|
+
if (/\s/.test(value)) {
|
|
22
|
+
return Promise.reject(new Error("请去除文本前后及内容中的空格!"));
|
|
23
|
+
}
|
|
24
|
+
else if (isNaN(Number(value))) {
|
|
25
|
+
return Promise.reject(new Error("请输入有效的数字文本!"));
|
|
26
|
+
}
|
|
27
|
+
else if (Number(value) <= 0 || Number(value) >= 100) {
|
|
28
|
+
return Promise.reject(new Error("范围必须在0到100之间!"));
|
|
29
|
+
}
|
|
30
|
+
else if (!/^\d+(\.\d{1,2})?$/.test(value)) {
|
|
31
|
+
return Promise.reject(new Error("最多支持两位小数!"));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return Promise.resolve();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
// 三位小数点百分比
|
|
42
|
+
const val_three_percent = (_, value) => {
|
|
43
|
+
if (value) {
|
|
44
|
+
if (/\s/.test(value)) {
|
|
45
|
+
return Promise.reject(new Error("请去除文本前后及内容中的空格!"));
|
|
46
|
+
}
|
|
47
|
+
else if (isNaN(Number(value))) {
|
|
48
|
+
return Promise.reject(new Error("请输入有效的数字文本!"));
|
|
49
|
+
}
|
|
50
|
+
else if (Number(value) <= 0 || Number(value) >= 100) {
|
|
51
|
+
return Promise.reject(new Error("范围必须在0到100之间!"));
|
|
52
|
+
}
|
|
53
|
+
else if (!/^\d+(\.\d{1,3})?$/.test(value)) {
|
|
54
|
+
return Promise.reject(new Error("最多支持三位小数!"));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
// 金额文本 支持到小数点后两位
|
|
65
|
+
const val_amount = (_, value) => {
|
|
66
|
+
if (value) {
|
|
67
|
+
if (/\s/.test(value)) {
|
|
68
|
+
return Promise.reject(new Error("请去除文本前后及内容中的空格!"));
|
|
69
|
+
}
|
|
70
|
+
else if (isNaN(Number(value))) {
|
|
71
|
+
return Promise.reject(new Error("请输入有效的数字文本!"));
|
|
72
|
+
}
|
|
73
|
+
else if (!/^\d+(\.\d{1,2})?$/.test(value)) {
|
|
74
|
+
return Promise.reject(new Error("最多支持两位小数!"));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return Promise.resolve();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return Promise.resolve();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// 身份证
|
|
85
|
+
const val_idcard = (_rule, value) => {
|
|
86
|
+
if (value) {
|
|
87
|
+
const idCardRegex = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|10|11|12)(0[1-9]|[1-2]\d|30|31)\d{3}[0-9X]$/;
|
|
88
|
+
if (/\s/.test(value)) {
|
|
89
|
+
return Promise.reject(new Error("请去除文本前后及内容中的空格!"));
|
|
90
|
+
}
|
|
91
|
+
else if (!idCardRegex.test(value)) {
|
|
92
|
+
return Promise.reject(new Error("身份证号格式不正确!"));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return Promise.resolve();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return Promise.resolve();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
// 手机号
|
|
103
|
+
const val_phone = (_, value) => {
|
|
104
|
+
if (value) {
|
|
105
|
+
const phoneRegex = /^1[0-9]{10}$/;
|
|
106
|
+
if (/\s/.test(value)) {
|
|
107
|
+
return Promise.reject(new Error("请去除文本前后及内容中的空格!"));
|
|
108
|
+
}
|
|
109
|
+
else if (!phoneRegex.test(value)) {
|
|
110
|
+
return Promise.reject(new Error("手机号格式不正确!"));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
return Promise.resolve();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return Promise.resolve();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
// 联系电话校验(只校验座机格式 例如 010-12345678 010 12345678 (010)12345678)
|
|
121
|
+
const val_landline = (_, value) => {
|
|
122
|
+
if (value) {
|
|
123
|
+
const landlinePhoneRegex = /^[\d\s()-]+$/;
|
|
124
|
+
if (!landlinePhoneRegex.test(value)) {
|
|
125
|
+
return Promise.reject(new Error("联系电话格式不正确!"));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return Promise.resolve();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return Promise.resolve();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
// 邮箱校验
|
|
136
|
+
const val_email = (_, value) => {
|
|
137
|
+
if (!value || value === "/") {
|
|
138
|
+
return Promise.resolve();
|
|
139
|
+
}
|
|
140
|
+
if (/\s/.test(value)) {
|
|
141
|
+
return Promise.reject(new Error("请去除文本前后及内容中的空格!"));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const emailRegex = /^[\p{L}\d_\-.]+@[\p{L}\d-]+(\.[\p{L}\d-]+)*\.[\p{L}]{2,}$/u;
|
|
145
|
+
if (!emailRegex.test(value)) {
|
|
146
|
+
return Promise.reject(new Error("邮箱格式不正确!"));
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return Promise.resolve();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
//空格校验
|
|
154
|
+
const val_space = (_, value) => {
|
|
155
|
+
if (!value) {
|
|
156
|
+
return Promise.resolve();
|
|
157
|
+
}
|
|
158
|
+
else if (/\s/.test(value)) {
|
|
159
|
+
return Promise.reject(new Error("文本内容包含空格!"));
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return Promise.resolve();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
//前后空格
|
|
166
|
+
const val_beforeAfter_space = (_, value) => {
|
|
167
|
+
if (!value) {
|
|
168
|
+
return Promise.resolve();
|
|
169
|
+
}
|
|
170
|
+
else if (/^\s|\s$/g.test(value)) {
|
|
171
|
+
return Promise.reject(new Error("文本内容前后包含空格!"));
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
return Promise.resolve();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export { val_amount, val_beforeAfter_space, val_email, val_idcard, val_landline, val_number, val_phone, val_space, val_three_percent, val_two_percent };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { author_passwordCheck, author_router_add, author_router_filter, author_rsa, author_strict, author_traceId } from './modules/author.js';
|
|
2
|
+
export { city_code_text, city_options, city_two_code_text } from './modules/cityOptions.js';
|
|
3
|
+
export { get_multiple_color, hex_to_rgb, reduce_opacity, rgb_to_hex, theme_change } from './modules/color.js';
|
|
4
|
+
export { demo } from './modules/demo.js';
|
|
5
|
+
export { file_calculate_md5, file_load, file_open } from './modules/file.js';
|
|
6
|
+
export { num_expand, num_expand_100, num_reduce_100, num_text, num_unit } from './modules/number.js';
|
|
7
|
+
export { getOptionConfig, getUrlConfig, sys_detectBrowser, sys_print, tem_compare_version, tem_get_tableHeader, timejs, video_preview, win_dynamic_fontSize } from './modules/other.js';
|
|
8
|
+
export { val_amount, val_beforeAfter_space, val_email, val_idcard, val_landline, val_number, val_phone, val_space, val_three_percent, val_two_percent } from './modules/validation.js';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ResourceItem } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 生成TraceId
|
|
5
|
+
* @param {string} origin 请求源(请求发起方)
|
|
6
|
+
* @param {string} url 请求url
|
|
7
|
+
* @returns - traceId,例如 "os-os-1d677771-4e85-460d-b669-682077a5067f"
|
|
8
|
+
*/
|
|
9
|
+
declare const author_traceId: (origin: string, url: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* 严格匹配当前按钮权限
|
|
12
|
+
* @param {ResourceItem[]} list 当前的页面权限
|
|
13
|
+
* @param {number} id 当前的按钮权限
|
|
14
|
+
* @returns {boolean} 是否存在该权限 true/false
|
|
15
|
+
*/
|
|
16
|
+
declare const author_strict: (list: ResourceItem[], id: number) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 计算密码强度,返回等级
|
|
19
|
+
* @param {string} str 当前密码
|
|
20
|
+
* @returns {number} 强度等级
|
|
21
|
+
*/
|
|
22
|
+
declare const author_passwordCheck: (str: string) => number;
|
|
23
|
+
/** 菜单类型 */
|
|
24
|
+
interface MenuInformation {
|
|
25
|
+
menuid?: number;
|
|
26
|
+
menuId?: number;
|
|
27
|
+
parentid?: number;
|
|
28
|
+
parentId?: number;
|
|
29
|
+
parentname?: string;
|
|
30
|
+
parentName?: string;
|
|
31
|
+
resourcelist?: ResourceList[];
|
|
32
|
+
resourceList?: ResourceList[];
|
|
33
|
+
sort?: number;
|
|
34
|
+
label?: string;
|
|
35
|
+
key?: string;
|
|
36
|
+
icon?: any;
|
|
37
|
+
element?: any;
|
|
38
|
+
children?: any;
|
|
39
|
+
}
|
|
40
|
+
/** 按钮类型 */
|
|
41
|
+
interface ResourceList {
|
|
42
|
+
resourceId: number;
|
|
43
|
+
resourceName?: string;
|
|
44
|
+
key?: string;
|
|
45
|
+
element?: any;
|
|
46
|
+
more?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 处理接口的路由数据,将本地的路由信息补充进去
|
|
50
|
+
* 数据层面:既处理数据问题,也解决浏览器关于menuId,resourceList等字段驼峰大小写的警告
|
|
51
|
+
* 业务层面:处理的的数据存储到localstore中,便于系统使用
|
|
52
|
+
* @param {Array} origin 接口的路由信息
|
|
53
|
+
* @param {Array} local 本地的路由信息
|
|
54
|
+
* @returns {Array} 适配到项目的路由树
|
|
55
|
+
*/
|
|
56
|
+
declare const author_router_filter: (origin: MenuInformation[], local: MenuInformation[]) => ({
|
|
57
|
+
key: string | undefined;
|
|
58
|
+
menuid: number | undefined;
|
|
59
|
+
label: string | undefined;
|
|
60
|
+
resourcelist: ResourceList[] | undefined;
|
|
61
|
+
children: any;
|
|
62
|
+
} | null)[];
|
|
63
|
+
/**
|
|
64
|
+
* 处理缓存的路由数据,将本地的路由信息补充进去
|
|
65
|
+
* 数据层面:既处理数据问题,也将DOM元素打进当前函数
|
|
66
|
+
* 业务层面:可以在当前函数中使用DOM元素,用于渲染
|
|
67
|
+
* @param {Array} origin 接口的路由信息
|
|
68
|
+
* @param {Array} local 本地的路由信息
|
|
69
|
+
* @returns {Array} 用于渲染的路由树
|
|
70
|
+
*/
|
|
71
|
+
declare const author_router_add: (origin: MenuInformation[], local: MenuInformation[]) => ({
|
|
72
|
+
resourcelist: ResourceList[] | undefined;
|
|
73
|
+
menuid?: number;
|
|
74
|
+
menuId?: number;
|
|
75
|
+
parentid?: number;
|
|
76
|
+
parentId?: number;
|
|
77
|
+
parentname?: string;
|
|
78
|
+
parentName?: string;
|
|
79
|
+
resourceList?: ResourceList[];
|
|
80
|
+
sort?: number;
|
|
81
|
+
label?: string;
|
|
82
|
+
key?: string;
|
|
83
|
+
icon?: any;
|
|
84
|
+
element?: any;
|
|
85
|
+
children?: any;
|
|
86
|
+
} | null)[];
|
|
87
|
+
/**
|
|
88
|
+
* RSA数据加密处理,用于密码加密传输
|
|
89
|
+
* @param {String} pubKey 公钥
|
|
90
|
+
* @param {String} password 密码
|
|
91
|
+
* @returns {String} 加密后的数据,吐出为十六进制
|
|
92
|
+
*/
|
|
93
|
+
declare const author_rsa: (pubKey: string, password: string) => string;
|
|
94
|
+
|
|
95
|
+
export { author_passwordCheck, author_router_add, author_router_filter, author_rsa, author_strict, author_traceId };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 城市选择器
|
|
3
|
+
* <Cascader/> 组件内使用 options={cityOptions} 引入省市区
|
|
4
|
+
*/
|
|
5
|
+
declare const city_options: (level?: string) => ({
|
|
6
|
+
label: string;
|
|
7
|
+
value: string;
|
|
8
|
+
children?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
label: string;
|
|
11
|
+
value: string;
|
|
12
|
+
children: {
|
|
13
|
+
label: string;
|
|
14
|
+
value: string;
|
|
15
|
+
}[];
|
|
16
|
+
})[];
|
|
17
|
+
/**
|
|
18
|
+
* 编码转城市
|
|
19
|
+
*/
|
|
20
|
+
declare const city_two_code_text: (provinceId: string, cityId?: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* 编码转城市,默认三级
|
|
23
|
+
*/
|
|
24
|
+
declare const city_code_text: (provinceId: string, cityId?: string, districtId?: string) => string;
|
|
25
|
+
|
|
26
|
+
export { city_code_text, city_options, city_two_code_text };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RgbColor } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 函数“hex_to_rgb”将十六进制颜色代码转换为 RGB 颜色数组。
|
|
5
|
+
* @param {string} hex - 十六进制颜色代码,例如“#FFA500”
|
|
6
|
+
* @returns 包含从输入提供的十六进制颜色代码转换而来的 RGB 值的数组。
|
|
7
|
+
*/
|
|
8
|
+
declare const hex_to_rgb: (hex: string) => RgbColor;
|
|
9
|
+
/**
|
|
10
|
+
* 函数“reduce_opacity”将十六进制颜色透明度改变,得到同等规则下的颜色。
|
|
11
|
+
* @param rgb - RGB颜色代码,例如 [ 22, 34, 55 ]
|
|
12
|
+
* @returns - RGB颜色代码,例如 [ 69, 78, 95 ]
|
|
13
|
+
*/
|
|
14
|
+
declare const reduce_opacity: (rgb: RgbColor, opacity: number) => RgbColor;
|
|
15
|
+
/**
|
|
16
|
+
* 该函数将 RGB 颜色数组转换为十六进制颜色代码。
|
|
17
|
+
* @param rgb - 参数 `rgb` 应该是一个数字数组,表示 RGB 颜色模型中颜色的红色、绿色和蓝色值。
|
|
18
|
+
* @returns 十六进制颜色代码。
|
|
19
|
+
*/
|
|
20
|
+
declare const rgb_to_hex: (rgb: RgbColor) => string;
|
|
21
|
+
/**
|
|
22
|
+
* 该函数将颜色转成一种颜色的多种透明度的
|
|
23
|
+
* @param value rgb或者十六进制
|
|
24
|
+
* @param {number} opacity 透明度
|
|
25
|
+
* @returns 十六进制颜色代码
|
|
26
|
+
*/
|
|
27
|
+
declare const get_multiple_color: (value: string | null, opacity: number) => string;
|
|
28
|
+
/**
|
|
29
|
+
* 该函数用于生成主题颜色。
|
|
30
|
+
* @param value - 主题颜色值
|
|
31
|
+
*/
|
|
32
|
+
declare const theme_change: (value: string) => void;
|
|
33
|
+
|
|
34
|
+
export { get_multiple_color, hex_to_rgb, reduce_opacity, rgb_to_hex, theme_change };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface IProps {
|
|
2
|
+
url: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 函数“file_calculate_md5”读取一个文件,计算其 MD5 哈希值,并将哈希值作为 Promise 返回。
|
|
7
|
+
* @param {any} file - `file_calculate_md5` 函数将文件作为输入,并使用 CryptoJS 库计算文件内容的 MD5 哈希值。`file` 参数表示要计算 MD5
|
|
8
|
+
* 哈希值的文件。
|
|
9
|
+
* @returns 一旦文件被读取并处理完毕,`file_calculate_md5` 函数就会返回一个 Promise,该 Promise 会使用文件内容的 MD5 哈希值进行解析。
|
|
10
|
+
*/
|
|
11
|
+
declare const file_calculate_md5: (file: any) => Promise<unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* 函数 "file_open" 打开一个文件,如果该文件再浏览器无法预览,会实现下载功能
|
|
14
|
+
* @param {string} url 必填参数,传入的文件的url
|
|
15
|
+
* @param {string=} name 可选参数,传入的文件的文件名。如果不提供,默认使用URL中的文件名
|
|
16
|
+
*/
|
|
17
|
+
declare const file_open: (props: IProps) => void;
|
|
18
|
+
/**
|
|
19
|
+
* 函数 "file_load" 下载一个文件
|
|
20
|
+
* @param {string} url 必填参数,传入的文件的url
|
|
21
|
+
* @param {string=} name 可选参数,传入的文件的文件名。如果不提供,默认使用URL中的文件名
|
|
22
|
+
*/
|
|
23
|
+
declare const file_load: (props: IProps) => Promise<void> | undefined;
|
|
24
|
+
|
|
25
|
+
export { file_calculate_md5, file_load, file_open };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 单位扩大固定倍数
|
|
3
|
+
* @param {*} amount 当前金额
|
|
4
|
+
* @param {*} unit 转换单位,默认100
|
|
5
|
+
* @param {*} accuracy 保留几位小数,默认2位
|
|
6
|
+
*/
|
|
7
|
+
declare const num_expand: (amount: any, unit?: number, accuracy?: number) => any;
|
|
8
|
+
/**
|
|
9
|
+
* 单位扩大两位,一般用于(分->元)(百分数->数)
|
|
10
|
+
* @param {*} amount 当前金额
|
|
11
|
+
* @param {*} accuracy 保留几位小数,默认2位
|
|
12
|
+
*/
|
|
13
|
+
declare const num_expand_100: (amount: any, accuracy?: number) => any;
|
|
14
|
+
declare const num_unit: (amount: any) => any;
|
|
15
|
+
/**
|
|
16
|
+
* 单位缩小两位,一般用于(元->分)(数->百分数)
|
|
17
|
+
* @param {*} amount 当前金额
|
|
18
|
+
*/
|
|
19
|
+
declare const num_reduce_100: (amount: any) => any;
|
|
20
|
+
/**
|
|
21
|
+
* @description 数字转中文数码
|
|
22
|
+
*
|
|
23
|
+
* @param {Number|String} num 数字[正整数]
|
|
24
|
+
* @param {String} type 文本类型,lower|upper,默认upper
|
|
25
|
+
*
|
|
26
|
+
* @example number2text(100000000) => "壹亿元整"
|
|
27
|
+
*/
|
|
28
|
+
declare const num_text: (number: any, type?: string) => string | false;
|
|
29
|
+
|
|
30
|
+
export { num_expand, num_expand_100, num_reduce_100, num_text, num_unit };
|