zy-react-library 1.1.1 → 1.1.3
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 +5 -1
- package/components/Cascader/Area/index.js +1 -20
- package/components/Cascader/Basic/index.js +1 -64
- package/components/Cascader/Dictionary/index.js +1 -42
- package/components/Cascader/Industry/index.js +1 -20
- package/components/Editor/index.js +1 -102
- package/components/FormBuilder/FormBuilder.js +1 -87
- package/components/FormBuilder/FormItemsRenderer.js +1 -591
- package/components/FormBuilder/index.js +1 -3
- package/components/HeaderBack/index.js +1 -37
- package/components/HiddenInfo/gwj/index.js +1 -518
- package/components/Icon/AddIcon/index.js +1 -9
- package/components/Icon/BackIcon/index.js +1 -9
- package/components/Icon/DeleteIcon/index.js +1 -9
- package/components/Icon/DownloadIcon/index.js +1 -9
- package/components/Icon/EditIcon/index.js +1 -9
- package/components/Icon/ExportIcon/index.js +1 -9
- package/components/Icon/ImportIcon/index.js +1 -9
- package/components/Icon/LocationIcon/index.js +1 -9
- package/components/Icon/PrintIcon/index.js +1 -9
- package/components/Icon/ResetIcon/index.js +1 -9
- package/components/Icon/SearchIcon/index.js +1 -9
- package/components/Icon/VideoIcon/index.js +1 -9
- package/components/Icon/ViewIcon/index.js +1 -9
- package/components/ImportFile/index.js +1 -91
- package/components/LeftTree/Area/index.js +1 -15
- package/components/LeftTree/Basic/index.js +1 -171
- package/components/LeftTree/Department/Gwj/index.js +1 -32
- package/components/LeftTree/Dictionary/index.js +1 -42
- package/components/Map/MapSelector.js +1 -254
- package/components/Map/index.js +1 -77
- package/components/Page/index.js +1 -50
- package/components/Pdf/index.js +1 -134
- package/components/PreviewImg/index.js +1 -32
- package/components/PreviewPdf/index.js +1 -86
- package/components/Search/index.js +1 -141
- package/components/Select/Basic/index.js +1 -76
- package/components/Select/Dictionary/index.js +1 -42
- package/components/Select/Personnel/Gwj/index.js +1 -49
- package/components/SelectCreate/index.js +1 -55
- package/components/SelectTree/Area/index.js +1 -26
- package/components/SelectTree/Basic/index.js +1 -102
- package/components/SelectTree/Department/Gwj/index.js +1 -46
- package/components/SelectTree/Dictionary/index.js +1 -42
- package/components/SelectTree/HiddenLevel/Gwj/index.js +1 -72
- package/components/SelectTree/HiddenPart/Gwj/index.js +1 -39
- package/components/SelectTree/Industry/index.js +1 -27
- package/components/Signature/index.js +1 -94
- package/components/Table/index.js +1 -73
- package/components/Table/index.less +7 -1
- package/components/TooltipPreviewImg/index.js +1 -27
- package/components/Upload/index.js +1 -275
- package/components/Video/AliPlayer.js +1 -160
- package/components/Video/index.js +1 -90
- package/css/common.less +4 -0
- package/enum/dictionary/index.js +1 -7
- package/enum/formItemRender/index.js +1 -37
- package/enum/hidden/gwj/index.js +1 -31
- package/enum/uploadFile/gwj/index.js +1 -176
- package/hooks/useDeleteFile/index.js +1 -101
- package/hooks/useDictionary/index.js +1 -66
- package/hooks/useDownloadBlob/index.js +1 -79
- package/hooks/useDownloadFile/index.js +1 -81
- package/hooks/useGetFile/index.js +1 -74
- package/hooks/useGetUrlQuery/index.js +1 -16
- package/hooks/useGetUserInfo/index.js +1 -49
- package/hooks/useIdle/index.js +1 -67
- package/hooks/useImportFile/index.js +1 -59
- package/hooks/useIsExistenceDuplicateSelection/index.js +1 -20
- package/hooks/useTable/index.js +1 -113
- package/hooks/useUploadFile/index.js +1 -149
- package/hooks/useUrlQueryCriteria/index.js +1 -77
- package/package.json +18 -1
- package/regular/index.js +1 -61
- package/utils/index.js +1 -587
package/utils/index.js
CHANGED
|
@@ -1,587 +1 @@
|
|
|
1
|
-
import { ID_NUMBER }
|
|
2
|
-
import dayjs from "dayjs";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 计算序号
|
|
6
|
-
*/
|
|
7
|
-
export function serialNumber(pagination, index) {
|
|
8
|
-
return (pagination.current - 1) * pagination.pageSize + (index + 1);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 字符串数组转数组
|
|
13
|
-
*/
|
|
14
|
-
export function toArrayString(value) {
|
|
15
|
-
// eslint-disable-next-line no-eval
|
|
16
|
-
return value ? eval(value).map(String) : [];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 判断文件后缀名是否符合
|
|
21
|
-
*/
|
|
22
|
-
export function interceptTheSuffix(name, suffix) {
|
|
23
|
-
return (
|
|
24
|
-
name.substring(name.lastIndexOf("."), name.length).toLowerCase()
|
|
25
|
-
=== suffix.toLowerCase()
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 图片转base64
|
|
31
|
-
*/
|
|
32
|
-
export function image2Base64(imgUrl) {
|
|
33
|
-
return new Promise((resolve) => {
|
|
34
|
-
const img = new Image();
|
|
35
|
-
img.src = imgUrl;
|
|
36
|
-
img.crossOrigin = "Anonymous";
|
|
37
|
-
img.onload = function () {
|
|
38
|
-
const canvas = document.createElement("canvas");
|
|
39
|
-
canvas.width = img.width;
|
|
40
|
-
canvas.height = img.height;
|
|
41
|
-
const ctx = canvas.getContext("2d");
|
|
42
|
-
ctx.drawImage(img, 0, 0, img.width, img.height);
|
|
43
|
-
const ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
|
|
44
|
-
resolve(canvas.toDataURL(`image/${ext}`));
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
图片转base64 (File对象版本)
|
|
51
|
-
*/
|
|
52
|
-
export function image2Base642(file) {
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
const reader = new FileReader();
|
|
55
|
-
reader.readAsDataURL(file);
|
|
56
|
-
reader.onload = (e) => {
|
|
57
|
-
resolve(e.target.result); // 返回 base64
|
|
58
|
-
};
|
|
59
|
-
reader.onerror = (error) => {
|
|
60
|
-
reject(error); // 处理错误
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
base64转File对象
|
|
67
|
-
*/
|
|
68
|
-
export function base642File(base64, filename = 'file') {
|
|
69
|
-
const arr = base64.split(",");
|
|
70
|
-
const mime = arr[0].match(/:(.*?);/)[1];
|
|
71
|
-
const ext = mime.split('/')[1];
|
|
72
|
-
const bstr = atob(arr[1]);
|
|
73
|
-
let n = bstr.length;
|
|
74
|
-
const u8arr = new Uint8Array(n);
|
|
75
|
-
|
|
76
|
-
while (n--) {
|
|
77
|
-
u8arr[n] = bstr.charCodeAt(n);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return new File([u8arr], `${filename}.${ext}`, { type: mime });
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 判断图片是否可访问成功
|
|
85
|
-
*/
|
|
86
|
-
export function checkImgExists(imgUrl) {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
const ImgObj = new Image();
|
|
89
|
-
ImgObj.src = imgUrl;
|
|
90
|
-
ImgObj.onload = function (res) {
|
|
91
|
-
resolve(res);
|
|
92
|
-
};
|
|
93
|
-
ImgObj.onerror = function (err) {
|
|
94
|
-
reject(err);
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 获取数据类型
|
|
101
|
-
*/
|
|
102
|
-
export function getDataType(data) {
|
|
103
|
-
return Object.prototype.toString.call(data).slice(8, -1);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* 数组去重
|
|
108
|
-
*/
|
|
109
|
-
export function ArrayDeduplication(arr) {
|
|
110
|
-
return [...new Set(arr)];
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 数组对象去重
|
|
115
|
-
*/
|
|
116
|
-
export function arrayObjectDeduplication(arr, key) {
|
|
117
|
-
const obj = {};
|
|
118
|
-
arr = arr.reduce((previousValue, currentValue) => {
|
|
119
|
-
if (!obj[currentValue[key]]) {
|
|
120
|
-
obj[currentValue[key]] = true;
|
|
121
|
-
previousValue.push(currentValue);
|
|
122
|
-
}
|
|
123
|
-
return previousValue;
|
|
124
|
-
}, []);
|
|
125
|
-
return arr;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 查找字符串中指定的值第几次出现的位置
|
|
130
|
-
*/
|
|
131
|
-
export function findCharIndex(options) {
|
|
132
|
-
const { str, char, num } = options;
|
|
133
|
-
let index = str.indexOf(char);
|
|
134
|
-
if (index === -1)
|
|
135
|
-
return -1;
|
|
136
|
-
for (let i = 0; i < num - 1; i++) {
|
|
137
|
-
index = str.indexOf(char, index + 1);
|
|
138
|
-
if (index === -1)
|
|
139
|
-
return -1;
|
|
140
|
-
}
|
|
141
|
-
return index;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* 生成指定两个值之间的随机数
|
|
146
|
-
*/
|
|
147
|
-
export function randoms(min, max) {
|
|
148
|
-
return Math.random() * (max - min + 1) + min;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 千位分隔符
|
|
153
|
-
*/
|
|
154
|
-
export function numFormat(num) {
|
|
155
|
-
if (num) {
|
|
156
|
-
const numArr = num.toString().split(".");
|
|
157
|
-
const arr = numArr[0].split("").reverse();
|
|
158
|
-
let res = [];
|
|
159
|
-
for (let i = 0; i < arr.length; i++) {
|
|
160
|
-
if (i % 3 === 0 && i !== 0) {
|
|
161
|
-
res.push(",");
|
|
162
|
-
}
|
|
163
|
-
res.push(arr[i]);
|
|
164
|
-
}
|
|
165
|
-
res.reverse();
|
|
166
|
-
if (numArr[1]) {
|
|
167
|
-
res = res.join("").concat(`.${numArr[1]}`);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
res = res.join("");
|
|
171
|
-
}
|
|
172
|
-
return res;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* 验证是否为空
|
|
178
|
-
*/
|
|
179
|
-
export function isEmpty(value) {
|
|
180
|
-
return (
|
|
181
|
-
value === undefined
|
|
182
|
-
|| value === null
|
|
183
|
-
|| (typeof value === "object" && Object.keys(value).length === 0)
|
|
184
|
-
|| (typeof value === "string" && value.trim().length === 0)
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* 获取url参数
|
|
190
|
-
*/
|
|
191
|
-
export function getUrlParam(key) {
|
|
192
|
-
const reg = new RegExp(`(^|&)${key}=([^&]*)(&|$)`);
|
|
193
|
-
const r = window.location.search.substr(1).match(reg);
|
|
194
|
-
if (r != null)
|
|
195
|
-
return decodeURI(r[2]);
|
|
196
|
-
return "";
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 数据分页
|
|
201
|
-
*/
|
|
202
|
-
export function paging(options) {
|
|
203
|
-
const { list, currentPage, pageSize } = options;
|
|
204
|
-
return list.filter((item, index) => {
|
|
205
|
-
return (
|
|
206
|
-
index < +currentPage * +pageSize
|
|
207
|
-
&& index >= (+currentPage - 1) * +pageSize
|
|
208
|
-
);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* 获取文件后缀
|
|
214
|
-
*/
|
|
215
|
-
export function getFileSuffix(name) {
|
|
216
|
-
return name.substring(name.lastIndexOf(".") + 1);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* 获取文件名称
|
|
221
|
-
*/
|
|
222
|
-
export function getFileName(name) {
|
|
223
|
-
if (!name)
|
|
224
|
-
return "";
|
|
225
|
-
return name.substring(name.lastIndexOf("/") + 1);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* 读取txt文档
|
|
230
|
-
*/
|
|
231
|
-
export function readTxtDocument(filePah) {
|
|
232
|
-
return new Promise((resolve) => {
|
|
233
|
-
const FILE_URL = getFileUrl();
|
|
234
|
-
const file_url = FILE_URL + filePah;
|
|
235
|
-
const xhr = new XMLHttpRequest();
|
|
236
|
-
xhr.open("get", file_url, true);
|
|
237
|
-
xhr.responseType = "blob";
|
|
238
|
-
xhr.onload = function (event) {
|
|
239
|
-
const reader = new FileReader();
|
|
240
|
-
reader.readAsText(event.target.response, "GB2312");
|
|
241
|
-
reader.onload = function () {
|
|
242
|
-
resolve(reader.result);
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
xhr.send();
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* 将秒转换成时分秒
|
|
251
|
-
*/
|
|
252
|
-
export function secondConversion(second) {
|
|
253
|
-
if (!second)
|
|
254
|
-
return 0;
|
|
255
|
-
const h = Number.parseInt(second / 60 / 60, 10);
|
|
256
|
-
const m = Number.parseInt((second / 60) % 60, 10);
|
|
257
|
-
const s = Number.parseInt(second % 60, 10);
|
|
258
|
-
if (h) {
|
|
259
|
-
return `${h}小时${m}分钟${s}秒`;
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
if (m) {
|
|
263
|
-
return `${m}分钟${s}秒`;
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
return `${s}秒`;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* 附件添加前缀
|
|
273
|
-
*/
|
|
274
|
-
export function addingPrefixToFile(list, options = {}) {
|
|
275
|
-
if (!list)
|
|
276
|
-
return [];
|
|
277
|
-
const {
|
|
278
|
-
pathKey = "filePath",
|
|
279
|
-
nameKey = "fileName",
|
|
280
|
-
idKey = "id",
|
|
281
|
-
} = options;
|
|
282
|
-
const FILE_URL = getFileUrl();
|
|
283
|
-
for (let i = 0; i < list.length; i++) {
|
|
284
|
-
list[i].url = FILE_URL + list[i][pathKey];
|
|
285
|
-
list[i].name = list[i][nameKey] || getFileName(list[i][pathKey]);
|
|
286
|
-
list[i].id = list[i][idKey];
|
|
287
|
-
}
|
|
288
|
-
return list;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* 翻译状态
|
|
293
|
-
*/
|
|
294
|
-
export function getLabelName(options) {
|
|
295
|
-
const { status, list, idKey = "bianma", nameKey = "name" } = options;
|
|
296
|
-
for (let i = 0; i < list.length; i++) {
|
|
297
|
-
if (status?.toString() === list[i][idKey]?.toString()) {
|
|
298
|
-
return list[i][nameKey];
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* 计算文件大小
|
|
305
|
-
*/
|
|
306
|
-
export function calculateFileSize(size) {
|
|
307
|
-
return size > 1024
|
|
308
|
-
? `${(`${size / 1024}`).substring(0, (`${size / 1024}`).lastIndexOf(".") + 3)
|
|
309
|
-
}MB`
|
|
310
|
-
: `${size}KB`;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* 根据身份证号获取出生日期和性别
|
|
315
|
-
*/
|
|
316
|
-
export function idCardGetDateAndGender(idCard) {
|
|
317
|
-
let sex = "";
|
|
318
|
-
let date = "";
|
|
319
|
-
if (ID_NUMBER.test(idCard)) {
|
|
320
|
-
const org_birthday = idCard.substring(6, 14);
|
|
321
|
-
const org_gender = idCard.substring(16, 17);
|
|
322
|
-
const birthday
|
|
323
|
-
= `${org_birthday.substring(0, 4)
|
|
324
|
-
}-${
|
|
325
|
-
org_birthday.substring(4, 6)
|
|
326
|
-
}-${
|
|
327
|
-
org_birthday.substring(6, 8)}`;
|
|
328
|
-
const birthdays = new Date(birthday.replace(/-/g, "/"));
|
|
329
|
-
const Month = birthdays.getMonth() + 1;
|
|
330
|
-
let MonthDate;
|
|
331
|
-
const DayDate = birthdays.getDate();
|
|
332
|
-
let Day;
|
|
333
|
-
if (Month < 10)
|
|
334
|
-
MonthDate = `0${Month}`;
|
|
335
|
-
else MonthDate = Month;
|
|
336
|
-
if (DayDate < 10)
|
|
337
|
-
Day = `0${DayDate}`;
|
|
338
|
-
else Day = DayDate;
|
|
339
|
-
sex = org_gender % 2 === 1 ? "1" : "0";
|
|
340
|
-
date = `${birthdays.getFullYear()}-${MonthDate}-${Day}`;
|
|
341
|
-
}
|
|
342
|
-
return { sex, date };
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* 获取select中指定项组成的数组
|
|
347
|
-
*/
|
|
348
|
-
export function getSelectAppointItemList(options) {
|
|
349
|
-
const { list, value, idKey = "bianma" } = options;
|
|
350
|
-
return list.filter(item => value.includes(item[idKey]));
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* json转换为树形结构
|
|
355
|
-
*/
|
|
356
|
-
export function listTransTree(options) {
|
|
357
|
-
const { json, idKey, parentIdKey, childrenKey } = options;
|
|
358
|
-
const r = [];
|
|
359
|
-
const hash = {};
|
|
360
|
-
let i = 0;
|
|
361
|
-
let j = 0;
|
|
362
|
-
const len = json.length;
|
|
363
|
-
for (; i < len; i++) {
|
|
364
|
-
hash[json[i][idKey]] = json[i];
|
|
365
|
-
}
|
|
366
|
-
for (; j < len; j++) {
|
|
367
|
-
const aVal = json[j];
|
|
368
|
-
const hashVP = hash[aVal[parentIdKey]];
|
|
369
|
-
if (hashVP) {
|
|
370
|
-
!hashVP[childrenKey] && (hashVP[childrenKey] = []);
|
|
371
|
-
hashVP[childrenKey].push(aVal);
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
r.push(aVal);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return r;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* 将值转换为"是"/"否"显示文本
|
|
382
|
-
*/
|
|
383
|
-
export function isEmptyToWhether(value, options = {}) {
|
|
384
|
-
const { yesText = "是", noText = "否", yesValue = "1" } = options;
|
|
385
|
-
return !isEmpty(value)
|
|
386
|
-
? value.toString() === yesValue.toString()
|
|
387
|
-
? yesText
|
|
388
|
-
: noText
|
|
389
|
-
: "";
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* 生成指定长度的guid
|
|
394
|
-
*/
|
|
395
|
-
export function createGuid(len = 32) {
|
|
396
|
-
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
397
|
-
let result = "";
|
|
398
|
-
for (let i = 0; i < len; i++) {
|
|
399
|
-
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
400
|
-
}
|
|
401
|
-
return result;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* 获取序号列
|
|
406
|
-
*/
|
|
407
|
-
export function getIndexColumn(pagination) {
|
|
408
|
-
return {
|
|
409
|
-
title: "序号",
|
|
410
|
-
key: "index",
|
|
411
|
-
width: 70,
|
|
412
|
-
render: (_, __, index) => pagination === false ? index + 1 : serialNumber(pagination, index),
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* 获取树形节点路径
|
|
418
|
-
*/
|
|
419
|
-
export function getTreeNodePaths(options) {
|
|
420
|
-
const { data, targetId, idKey, childrenKey, path = [], isIncludeOneself } = options;
|
|
421
|
-
for (let i = 0; i < data.length; i++) {
|
|
422
|
-
const node = data[i];
|
|
423
|
-
const newPath = [...path, node];
|
|
424
|
-
|
|
425
|
-
// 找到目标节点,根据isIncludeOneself决定是否包含自身
|
|
426
|
-
if (node[idKey] === targetId) {
|
|
427
|
-
if (isIncludeOneself)
|
|
428
|
-
return newPath; // 包含自身
|
|
429
|
-
else
|
|
430
|
-
return path; // 不包含自身,只返回父节点路径
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// 递归查找子节点
|
|
434
|
-
if (node[childrenKey] && node[childrenKey].length > 0) {
|
|
435
|
-
const result = getTreeNodePaths({
|
|
436
|
-
data: node[childrenKey],
|
|
437
|
-
targetId,
|
|
438
|
-
idKey,
|
|
439
|
-
childrenKey,
|
|
440
|
-
path: newPath,
|
|
441
|
-
isIncludeOneself,
|
|
442
|
-
});
|
|
443
|
-
if (result) {
|
|
444
|
-
return result;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
return null;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* 根据 level 属性处理树数据,添加 isLeaf 属性控制节点是否可展开
|
|
454
|
-
*/
|
|
455
|
-
export const processTreeDataByLevel = (options) => {
|
|
456
|
-
const { data, level, childrenKey, currentLevel = 1 } = options;
|
|
457
|
-
return data.map((item) => {
|
|
458
|
-
const processedItem = { ...item };
|
|
459
|
-
|
|
460
|
-
// 如果指定了 level 且当前层级达到指定层级,则标记为叶子节点
|
|
461
|
-
if (level && currentLevel >= level) {
|
|
462
|
-
processedItem.isLeaf = true;
|
|
463
|
-
// 移除子节点
|
|
464
|
-
delete processedItem[childrenKey];
|
|
465
|
-
}
|
|
466
|
-
else if (item[childrenKey] && item[childrenKey].length > 0) {
|
|
467
|
-
// 未达到指定层级,继续处理子节点
|
|
468
|
-
processedItem[childrenKey] = processTreeDataByLevel({
|
|
469
|
-
data: item[childrenKey],
|
|
470
|
-
currentLevel: currentLevel + 1,
|
|
471
|
-
level,
|
|
472
|
-
childrenKey,
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
// 没有子节点,标记为叶子节点
|
|
477
|
-
processedItem.isLeaf = true;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
return processedItem;
|
|
481
|
-
});
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* 根据 onlyLastLevel 属性处理树数据,添加 selectable 属性控制节点是否可选择
|
|
486
|
-
*/
|
|
487
|
-
export const processTreeDataForOnlyLastLevel = (options) => {
|
|
488
|
-
const { data, childrenKey, onlyLastLevel = false } = options;
|
|
489
|
-
if (!onlyLastLevel)
|
|
490
|
-
return data;
|
|
491
|
-
|
|
492
|
-
return data.map((item) => {
|
|
493
|
-
// 检查是否有子节点
|
|
494
|
-
const hasChildren = item[childrenKey] && item[childrenKey].length > 0;
|
|
495
|
-
|
|
496
|
-
// 如果有子节点,则不可选择
|
|
497
|
-
const processedItem = {
|
|
498
|
-
...item,
|
|
499
|
-
selectable: !hasChildren,
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
// 递归处理子节点
|
|
503
|
-
if (hasChildren) {
|
|
504
|
-
processedItem[childrenKey] = processTreeDataForOnlyLastLevel({ data: item[childrenKey], childrenKey, onlyLastLevel });
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
return processedItem;
|
|
508
|
-
});
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* 验证结束时间是否大于开始时间
|
|
513
|
-
*/
|
|
514
|
-
export const validatorEndTime = (timeStart, message = "结束时间不能早于开始时间") => {
|
|
515
|
-
return {
|
|
516
|
-
validator: (_, value) => {
|
|
517
|
-
if (value && timeStart && value < timeStart) {
|
|
518
|
-
return Promise.reject(message);
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
return Promise.resolve();
|
|
522
|
-
}
|
|
523
|
-
},
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* 验证时间是否大于等于当前时间
|
|
529
|
-
*/
|
|
530
|
-
export const validatorTimeGTCurrentDay = (message = "需要大于当前时间") => {
|
|
531
|
-
return {
|
|
532
|
-
validator: (_, value) => {
|
|
533
|
-
if (value && value <= dayjs().format("YYYY-MM-DD HH:mm:ss")) {
|
|
534
|
-
return Promise.reject(message);
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
return Promise.resolve();
|
|
538
|
-
}
|
|
539
|
-
},
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* 动态加载js资源
|
|
545
|
-
*/
|
|
546
|
-
export function dynamicLoadJs(url) {
|
|
547
|
-
return new Promise((resolve, reject) => {
|
|
548
|
-
const script = document.createElement("script");
|
|
549
|
-
script.type = "text/javascript";
|
|
550
|
-
script.src = url;
|
|
551
|
-
script.onload = resolve;
|
|
552
|
-
script.onerror = reject;
|
|
553
|
-
document.body.appendChild(script);
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* 动态加载css资源
|
|
559
|
-
*/
|
|
560
|
-
export function dynamicLoadCss(url) {
|
|
561
|
-
return new Promise((resolve, reject) => {
|
|
562
|
-
const link = document.createElement("link");
|
|
563
|
-
link.rel = "stylesheet";
|
|
564
|
-
link.type = "text/css";
|
|
565
|
-
link.href = url;
|
|
566
|
-
link.onload = resolve;
|
|
567
|
-
link.onerror = reject;
|
|
568
|
-
document.head.appendChild(link);
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* 是否空html,用于给富文本编辑器使用
|
|
574
|
-
*/
|
|
575
|
-
export function normalizeEmptyHtml(html) {
|
|
576
|
-
if (!html)
|
|
577
|
-
return "";
|
|
578
|
-
const cleaned = html.replace(/\s+/g, "").toLowerCase();
|
|
579
|
-
return cleaned === "<p><br></p>" || cleaned === "<p></p>" || cleaned === "" ? "" : html;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
* 获取文件url
|
|
584
|
-
*/
|
|
585
|
-
export function getFileUrl() {
|
|
586
|
-
return process.env.app["fileUrl"];
|
|
587
|
-
}
|
|
1
|
+
import{ID_NUMBER}from"../regular/index.js";import dayjs from"dayjs";function serialNumber(e,t){return(e.current-1)*e.pageSize+(t+1)}function toArrayString(value){return value?eval(value).map(String):[]}function interceptTheSuffix(e,t){return e.substring(e.lastIndexOf("."),e.length).toLowerCase()===t.toLowerCase()}function image2Base64(e){return new Promise(t=>{const n=new Image;n.src=e,n.crossOrigin="Anonymous",n.onload=function(){const e=document.createElement("canvas");e.width=n.width,e.height=n.height,e.getContext("2d").drawImage(n,0,0,n.width,n.height);const r=n.src.substring(n.src.lastIndexOf(".")+1).toLowerCase();t(e.toDataURL(`image/${r}`))}})}function image2Base642(e){return new Promise((t,n)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=e=>{t(e.target.result)},r.onerror=e=>{n(e)}})}function base642File(e,t="file"){const n=e.split(","),r=n[0].match(/:(.*?);/)[1],i=r.split("/")[1],o=atob(n[1]);let a=o.length;const s=new Uint8Array(a);for(;a--;)s[a]=o.charCodeAt(a);return new File([s],`${t}.${i}`,{type:r})}function checkImgExists(e){return new Promise((t,n)=>{const r=new Image;r.src=e,r.onload=function(e){t(e)},r.onerror=function(e){n(e)}})}function getDataType(e){return Object.prototype.toString.call(e).slice(8,-1)}function ArrayDeduplication(e){return[...new Set(e)]}function arrayObjectDeduplication(e,t){const n={};return e.reduce((e,r)=>(n[r[t]]||(n[r[t]]=!0,e.push(r)),e),[])}function findCharIndex(e){const{str:t,char:n,num:r}=e;let i=t.indexOf(n);if(-1===i)return-1;for(let e=0;e<r-1;e++)if(i=t.indexOf(n,i+1),-1===i)return-1;return i}function randoms(e,t){return Math.random()*(t-e+1)+e}function numFormat(e){if(e){const t=e.toString().split("."),n=t[0].split("").reverse();let r=[];for(let e=0;e<n.length;e++)e%3==0&&0!==e&&r.push(","),r.push(n[e]);return r.reverse(),r=t[1]?r.join("").concat(`.${t[1]}`):r.join(""),r}}function isEmpty(e){return null==e||"object"==typeof e&&0===Object.keys(e).length||"string"==typeof e&&0===e.trim().length}function getUrlParam(e){const t=new RegExp(`(^|&)${e}=([^&]*)(&|$)`),n=window.location.search.substr(1).match(t);return null!=n?decodeURI(n[2]):""}function paging(e){const{list:t,currentPage:n,pageSize:r}=e;return t.filter((e,t)=>t<+n*+r&&t>=(+n-1)*+r)}function getFileSuffix(e){return e.substring(e.lastIndexOf(".")+1)}function getFileName(e){return e?e.substring(e.lastIndexOf("/")+1):""}function readTxtDocument(e){return new Promise(t=>{const n=getFileUrl()+e,r=new XMLHttpRequest;r.open("get",n,!0),r.responseType="blob",r.onload=function(e){const n=new FileReader;n.readAsText(e.target.response,"GB2312"),n.onload=function(){t(n.result)}},r.send()})}function secondConversion(e){if(!e)return 0;const t=Number.parseInt(e/60/60,10),n=Number.parseInt(e/60%60,10),r=Number.parseInt(e%60,10);return t?`${t}小时${n}分钟${r}秒`:n?`${n}分钟${r}秒`:`${r}秒`}function addingPrefixToFile(e,t={}){if(!e)return[];const{pathKey:n="filePath",nameKey:r="fileName",idKey:i="id"}=t,o=getFileUrl();for(let t=0;t<e.length;t++)e[t].url=o+e[t][n],e[t].name=e[t][r]||getFileName(e[t][n]),e[t].id=e[t][i];return e}function getLabelName(e){const{status:t,list:n,idKey:r="bianma",nameKey:i="name"}=e;for(let e=0;e<n.length;e++)if(t?.toString()===n[e][r]?.toString())return n[e][i]}function calculateFileSize(e){return e>1024?`${(""+e/1024).substring(0,(""+e/1024).lastIndexOf(".")+3)}MB`:`${e}KB`}function idCardGetDateAndGender(e){let t="",n="";if(ID_NUMBER.test(e)){const r=e.substring(6,14),i=e.substring(16,17),o=`${r.substring(0,4)}-${r.substring(4,6)}-${r.substring(6,8)}`,a=new Date(o.replace(/-/g,"/")),s=a.getMonth()+1;let l;const c=a.getDate();let u;l=s<10?`0${s}`:s,u=c<10?`0${c}`:c,t=i%2==1?"1":"0",n=`${a.getFullYear()}-${l}-${u}`}return{sex:t,date:n}}function getSelectAppointItemList(e){const{list:t,value:n,idKey:r="bianma"}=e;return t.filter(e=>n.includes(e[r]))}function listTransTree(e){const{json:t,idKey:n,parentIdKey:r,childrenKey:i}=e,o=[],a={};let s=0,l=0;const c=t.length;for(;s<c;s++)a[t[s][n]]=t[s];for(;l<c;l++){const e=t[l],n=a[e[r]];n?(!n[i]&&(n[i]=[]),n[i].push(e)):o.push(e)}return o}function isEmptyToWhether(e,t={}){const{yesText:n="是",noText:r="否",yesValue:i="1"}=t;return isEmpty(e)?"":e.toString()===i.toString()?n:r}function createGuid(e=32){let t="";for(let n=0;n<e;n++)t+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()));return t}function getIndexColumn(e){return{title:"序号",key:"index",width:70,render:(t,n,r)=>!1===e?r+1:serialNumber(e,r)}}function getTreeNodePaths(e){const{data:t,targetId:n,idKey:r,childrenKey:i,path:o=[],isIncludeOneself:a}=e;for(let e=0;e<t.length;e++){const s=t[e],l=[...o,s];if(s[r]===n)return a?l:o;if(s[i]&&s[i].length>0){const e=getTreeNodePaths({data:s[i],targetId:n,idKey:r,childrenKey:i,path:l,isIncludeOneself:a});if(e)return e}}return null}const processTreeDataByLevel=e=>{const{data:t,level:n,childrenKey:r,currentLevel:i=1}=e;return t.map(e=>{const t={...e};return n&&i>=n?(t.isLeaf=!0,delete t[r]):e[r]&&e[r].length>0?t[r]=processTreeDataByLevel({data:e[r],currentLevel:i+1,level:n,childrenKey:r}):t.isLeaf=!0,t})},processTreeDataForOnlyLastLevel=e=>{const{data:t,childrenKey:n,onlyLastLevel:r=!1}=e;return r?t.map(e=>{const t=e[n]&&e[n].length>0,i={...e,selectable:!t};return t&&(i[n]=processTreeDataForOnlyLastLevel({data:e[n],childrenKey:n,onlyLastLevel:r})),i}):t},validatorEndTime=(e,t="结束时间不能早于开始时间")=>({validator:(n,r)=>r&&e&&r<e?Promise.reject(t):Promise.resolve()}),validatorTimeGTCurrentDay=(e="需要大于当前时间")=>({validator:(t,n)=>n&&n<=dayjs().format("YYYY-MM-DD HH:mm:ss")?Promise.reject(e):Promise.resolve()});function dynamicLoadJs(e){return new Promise((t,n)=>{const r=document.createElement("script");r.type="text/javascript",r.src=e,r.onload=t,r.onerror=n,document.body.appendChild(r)})}function dynamicLoadCss(e){return new Promise((t,n)=>{const r=document.createElement("link");r.rel="stylesheet",r.type="text/css",r.href=e,r.onload=t,r.onerror=n,document.head.appendChild(r)})}function normalizeEmptyHtml(e){if(!e)return"";const t=e.replace(/\s+/g,"").toLowerCase();return"<p><br></p>"===t||"<p></p>"===t||""===t?"":e}function getFileUrl(){return process.env.app.fileUrl}export{ArrayDeduplication,addingPrefixToFile,arrayObjectDeduplication,base642File,calculateFileSize,checkImgExists,createGuid,dynamicLoadCss,dynamicLoadJs,findCharIndex,getDataType,getFileName,getFileSuffix,getFileUrl,getIndexColumn,getLabelName,getSelectAppointItemList,getTreeNodePaths,getUrlParam,idCardGetDateAndGender,image2Base64,image2Base642,interceptTheSuffix,isEmpty,isEmptyToWhether,listTransTree,normalizeEmptyHtml,numFormat,paging,processTreeDataByLevel,processTreeDataForOnlyLastLevel,randoms,readTxtDocument,secondConversion,serialNumber,toArrayString,validatorEndTime,validatorTimeGTCurrentDay};
|