eoss-ui 0.4.70 → 0.4.72
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/lib/button-group.js +597 -117
- package/lib/button.js +597 -117
- package/lib/card.js +2 -2
- package/lib/cascader.js +2 -2
- package/lib/checkbox-group.js +598 -118
- package/lib/clients.js +2 -2
- package/lib/data-table-form.js +598 -118
- package/lib/data-table.js +598 -118
- package/lib/date-picker.js +597 -117
- package/lib/dialog.js +596 -116
- package/lib/enterprise.js +2 -2
- package/lib/eoss-ui.common.js +619 -125
- package/lib/error-page.js +2 -2
- package/lib/flow-group.js +598 -118
- package/lib/flow-list.js +774 -294
- package/lib/flow.js +600 -120
- package/lib/form.js +623 -143
- package/lib/handle-user.js +598 -118
- package/lib/handler.js +598 -118
- package/lib/icons.js +2 -2
- package/lib/index.js +1 -1
- package/lib/input-number.js +597 -117
- package/lib/input.js +622 -142
- package/lib/label.js +2 -2
- package/lib/login.js +598 -118
- package/lib/main.js +598 -118
- package/lib/menu.js +2 -2
- package/lib/nav.js +597 -117
- package/lib/notify.js +4 -4
- package/lib/page.js +597 -117
- package/lib/pagination.js +2 -2
- package/lib/player.js +613 -133
- package/lib/qr-code.js +604 -124
- package/lib/radio-group.js +598 -118
- package/lib/retrial-auth.js +598 -118
- package/lib/select-ganged.js +597 -117
- package/lib/select.js +605 -125
- package/lib/selector-panel.js +598 -118
- package/lib/selector.js +605 -125
- package/lib/sizer.js +598 -118
- package/lib/steps.js +597 -117
- package/lib/switch.js +597 -117
- package/lib/table-form.js +623 -143
- package/lib/tabs-panel.js +2 -2
- package/lib/tabs.js +598 -118
- package/lib/tips.js +598 -118
- package/lib/toolbar.js +2 -2
- package/lib/tree-group.js +621 -127
- package/lib/tree.js +598 -118
- package/lib/upload.js +599 -119
- package/lib/utils/util.js +582 -102
- package/lib/wujie.js +597 -117
- package/lib/wxlogin.js +598 -118
- package/package.json +1 -1
- package/packages/tree-group/src/main.vue +26 -8
- package/src/index.js +1 -1
- package/src/utils/util.js +530 -80
package/src/utils/util.js
CHANGED
|
@@ -386,6 +386,28 @@ const arrUnique = function (data, key) {
|
|
|
386
386
|
}
|
|
387
387
|
return newArr;
|
|
388
388
|
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* average
|
|
392
|
+
* @desc 计算平均值
|
|
393
|
+
* @author SuTao
|
|
394
|
+
* @date 2023年12月14日
|
|
395
|
+
* @param {...number} numbers - 一组数字
|
|
396
|
+
* @return {number} 数组中数字的平均值
|
|
397
|
+
**/
|
|
398
|
+
const average = function(...numbers) {
|
|
399
|
+
// Ensure that all arguments are valid numbers
|
|
400
|
+
if (!numbers.every(Number.isFinite)) {
|
|
401
|
+
throw new Error('Invalid input. Please provide valid numbers.');
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Calculate the average of the numbers
|
|
405
|
+
const sum = numbers.reduce((acc, num) => acc + num, 0);
|
|
406
|
+
const average = sum / numbers.length;
|
|
407
|
+
|
|
408
|
+
return average;
|
|
409
|
+
};
|
|
410
|
+
|
|
389
411
|
/**
|
|
390
412
|
* browser
|
|
391
413
|
* @desc:浏览器类型
|
|
@@ -402,106 +424,154 @@ const browser = function () {
|
|
|
402
424
|
};
|
|
403
425
|
|
|
404
426
|
/**
|
|
405
|
-
*
|
|
406
|
-
* @desc
|
|
407
|
-
* @
|
|
408
|
-
* @
|
|
409
|
-
* @param {
|
|
410
|
-
* @param {
|
|
427
|
+
* calculateNetworkDays
|
|
428
|
+
* @desc 工作日天数
|
|
429
|
+
* @desc 计算两个日期之间的工作日天数,可以排除周末和指定的假期
|
|
430
|
+
* @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
|
|
431
|
+
* @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
|
|
432
|
+
* @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
|
|
433
|
+
* @return {number} 工作日天数
|
|
411
434
|
**/
|
|
412
|
-
const
|
|
413
|
-
if (
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const d1 = new Date(date1);
|
|
417
|
-
const d2 = new Date(date2);
|
|
435
|
+
const calculateNetworkDays = function(start_date, end_date, holidays = []) {
|
|
436
|
+
if (typeof start_date !== 'string' || typeof end_date !== 'string') {
|
|
437
|
+
throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
|
|
438
|
+
}
|
|
418
439
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
440
|
+
const startDateObj = new Date(start_date);
|
|
441
|
+
const endDateObj = new Date(end_date);
|
|
442
|
+
|
|
443
|
+
if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
|
|
444
|
+
throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (startDateObj > endDateObj) {
|
|
448
|
+
throw new Error('Start date should be earlier than or equal to end date.');
|
|
449
|
+
}
|
|
423
450
|
|
|
424
|
-
|
|
425
|
-
const timeDiff = Math.abs(d2.getTime() - d1.getTime());
|
|
451
|
+
let workdays = 0;
|
|
426
452
|
|
|
427
|
-
|
|
428
|
-
|
|
453
|
+
// Iterate through each day in the date range
|
|
454
|
+
for (let currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
|
|
455
|
+
// Check if the current day is a weekend (Saturday or Sunday)
|
|
456
|
+
const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
|
|
429
457
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
458
|
+
// Check if the current day is a holiday
|
|
459
|
+
const isHoliday = holidays.some((holiday) => {
|
|
460
|
+
const holidayDate = new Date(holiday);
|
|
461
|
+
return currentDate.toDateString() === holidayDate.toDateString();
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// If it's a workday (not a weekend or holiday), increment the workdays count
|
|
465
|
+
if (!isWeekend && !isHoliday) {
|
|
466
|
+
workdays++;
|
|
434
467
|
}
|
|
435
468
|
}
|
|
436
469
|
|
|
470
|
+
return workdays;
|
|
437
471
|
};
|
|
438
472
|
|
|
439
473
|
/**
|
|
440
|
-
*
|
|
441
|
-
* @desc
|
|
442
|
-
* @
|
|
443
|
-
* @
|
|
444
|
-
* @
|
|
445
|
-
* @param {
|
|
474
|
+
* concatenate
|
|
475
|
+
* @desc 指定连接符合并文本
|
|
476
|
+
* @desc 使用指定的连接符合并文本字符串
|
|
477
|
+
* @author SuTao
|
|
478
|
+
* @date 2023年12月14日
|
|
479
|
+
* @param {string} separator - 指定的连接符
|
|
480
|
+
* @param {...string} strings - 多个文本字符串
|
|
481
|
+
* @return {string} 合并后的字符串
|
|
446
482
|
**/
|
|
447
|
-
const
|
|
448
|
-
if (
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
483
|
+
const concatenate = function(separator, ...strings) {
|
|
484
|
+
if (typeof separator !== 'string' || !strings.every(str => typeof str === 'string')) {
|
|
485
|
+
throw new Error('Invalid input. Please provide a valid separator and valid strings.');
|
|
486
|
+
}
|
|
487
|
+
return strings.join(separator);
|
|
488
|
+
};
|
|
453
489
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
490
|
+
/**
|
|
491
|
+
* dateAddDays
|
|
492
|
+
* @desc 加减日期天数
|
|
493
|
+
* @desc 在给定的日期上加上或减去指定的天数
|
|
494
|
+
* @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
|
|
495
|
+
* @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
|
|
496
|
+
* @return {string} 计算后的日期字符串
|
|
497
|
+
**/
|
|
498
|
+
const dateAddDays = function(start_date, days) {
|
|
499
|
+
if (typeof start_date !== 'string' || !Number.isInteger(days)) {
|
|
500
|
+
throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days.");
|
|
501
|
+
}
|
|
458
502
|
|
|
459
|
-
|
|
460
|
-
|
|
503
|
+
const startDateObj = new Date(start_date);
|
|
504
|
+
if (isNaN(startDateObj.getTime())) {
|
|
505
|
+
throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
506
|
+
}
|
|
461
507
|
|
|
462
|
-
|
|
463
|
-
|
|
508
|
+
const resultDateObj = new Date(startDateObj);
|
|
509
|
+
resultDateObj.setDate(resultDateObj.getDate() + days);
|
|
464
510
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
511
|
+
const resultYear = resultDateObj.getFullYear();
|
|
512
|
+
const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
|
|
513
|
+
const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
|
|
514
|
+
|
|
515
|
+
return `${resultYear}-${resultMonth}-${resultDay}`;
|
|
471
516
|
};
|
|
472
517
|
|
|
473
518
|
/**
|
|
474
|
-
*
|
|
475
|
-
* @desc
|
|
476
|
-
* @author
|
|
477
|
-
* @date 2023年
|
|
478
|
-
* @param {String
|
|
479
|
-
* @param {String
|
|
519
|
+
* dateDiff
|
|
520
|
+
* @desc 计算两个日期之间的差距
|
|
521
|
+
* @author SuTao
|
|
522
|
+
* @date 2023年12月14日
|
|
523
|
+
* @param {String} start_date - 起始日期字符串
|
|
524
|
+
* @param {String} end_date - 结束日期字符串
|
|
525
|
+
* @param {String} [unit] - 计算的时间单位 ("y", "M", "d", "h", "m", "s")
|
|
526
|
+
* @return {Number} 两个日期之间的差距
|
|
480
527
|
**/
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
528
|
+
const dateDiff = function(start_date, end_date, unit) {
|
|
529
|
+
// Assuming date strings are in "YYYY-MM-DD" format
|
|
530
|
+
var startDate = new Date(start_date);
|
|
531
|
+
var endDate = new Date(end_date);
|
|
532
|
+
|
|
533
|
+
// Calculate the difference in milliseconds
|
|
534
|
+
var timeDifference = endDate - startDate;
|
|
535
|
+
|
|
536
|
+
// Convert milliseconds to the specified unit
|
|
537
|
+
unit = unit || 'd'; // Set default unit to "d"
|
|
538
|
+
|
|
539
|
+
switch (unit) {
|
|
540
|
+
case 'y':
|
|
541
|
+
return endDate.getFullYear() - startDate.getFullYear();
|
|
542
|
+
case 'M':
|
|
543
|
+
return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
|
|
544
|
+
case 'd':
|
|
545
|
+
return Math.floor(timeDifference / (1000 * 60 * 60 * 24));
|
|
546
|
+
case 'h':
|
|
547
|
+
return Math.floor(timeDifference / (1000 * 60 * 60));
|
|
548
|
+
case 'm':
|
|
549
|
+
return Math.floor(timeDifference / (1000 * 60));
|
|
550
|
+
case 's':
|
|
551
|
+
return Math.floor(timeDifference / 1000);
|
|
552
|
+
default:
|
|
553
|
+
throw new Error("Invalid unit. Supported units are 'y', 'M', 'd', 'h', 'm', 's'.");
|
|
554
|
+
}
|
|
555
|
+
};
|
|
495
556
|
|
|
496
|
-
|
|
497
|
-
|
|
557
|
+
/**
|
|
558
|
+
* dayOfMonth
|
|
559
|
+
* @desc 当月第几天
|
|
560
|
+
* @desc 返回给定日期是所在月的第几天
|
|
561
|
+
* @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
|
|
562
|
+
* @return {number} 当月的第几天
|
|
563
|
+
**/
|
|
564
|
+
const dayOfMonth = function(date) {
|
|
565
|
+
if (typeof date !== 'string') {
|
|
566
|
+
throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
567
|
+
}
|
|
498
568
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
MessageBox.error(error.message, 5);
|
|
503
|
-
}
|
|
569
|
+
const dateObj = new Date(date);
|
|
570
|
+
if (isNaN(dateObj.getTime())) {
|
|
571
|
+
throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
504
572
|
}
|
|
573
|
+
|
|
574
|
+
return dateObj.getDate();
|
|
505
575
|
};
|
|
506
576
|
|
|
507
577
|
/**
|
|
@@ -940,6 +1010,114 @@ const getHue = function ($h, $i, $isLight) {
|
|
|
940
1010
|
return Math.round($hue);
|
|
941
1011
|
};
|
|
942
1012
|
|
|
1013
|
+
/**
|
|
1014
|
+
* getCurrentDate
|
|
1015
|
+
* @desc 获取今天
|
|
1016
|
+
* @desc 返回当前日期
|
|
1017
|
+
* @return {string} 当前日期字符串,格式为 "YYYY-MM-DD"
|
|
1018
|
+
**/
|
|
1019
|
+
const getCurrentDate = function() {
|
|
1020
|
+
const today = new Date();
|
|
1021
|
+
|
|
1022
|
+
const year = today.getFullYear();
|
|
1023
|
+
const month = String(today.getMonth() + 1).padStart(2, '0');
|
|
1024
|
+
const day = String(today.getDate()).padStart(2, '0');
|
|
1025
|
+
|
|
1026
|
+
return `${year}-${month}-${day}`;
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* getCurrentDateTime
|
|
1031
|
+
* @desc 获取当前时间
|
|
1032
|
+
* @desc 返回当前日期和时间
|
|
1033
|
+
* @return {string} 当前日期和时间字符串,格式为 "YYYY-MM-DD HH:mm:ss"
|
|
1034
|
+
**/
|
|
1035
|
+
const getCurrentDateTime = function() {
|
|
1036
|
+
const currentDateTime = new Date();
|
|
1037
|
+
|
|
1038
|
+
const year = currentDateTime.getFullYear();
|
|
1039
|
+
const month = String(currentDateTime.getMonth() + 1).padStart(2, '0');
|
|
1040
|
+
const day = String(currentDateTime.getDate()).padStart(2, '0');
|
|
1041
|
+
const hours = String(currentDateTime.getHours()).padStart(2, '0');
|
|
1042
|
+
const minutes = String(currentDateTime.getMinutes()).padStart(2, '0');
|
|
1043
|
+
const seconds = String(currentDateTime.getSeconds()).padStart(2, '0');
|
|
1044
|
+
|
|
1045
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* getHour
|
|
1050
|
+
* @desc 获取小时
|
|
1051
|
+
* @desc 返回给定日期或时间的小时部分
|
|
1052
|
+
* @param {string} datetime - 日期时间字符串,格式为 "YYYY-MM-DD HH:mm:ss"
|
|
1053
|
+
* @return {number} 给定日期或时间的小时部分
|
|
1054
|
+
**/
|
|
1055
|
+
const getHour = function(datetime) {
|
|
1056
|
+
if (typeof datetime !== 'string') {
|
|
1057
|
+
throw new Error("Invalid input. Please provide a valid datetime string in the format 'YYYY-MM-DD HH:mm:ss'.");
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
const datetimeObj = new Date(datetime);
|
|
1061
|
+
if (isNaN(datetimeObj.getTime())) {
|
|
1062
|
+
throw new Error("Invalid datetime format. Please provide a valid datetime string in the format 'YYYY-MM-DD HH:mm:ss'.");
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
return datetimeObj.getHours();
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* getWeekNumber
|
|
1070
|
+
* @desc 当年第几周
|
|
1071
|
+
* @desc 返回给定日期属于所在年的第几周
|
|
1072
|
+
* @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
|
|
1073
|
+
* @param {number} type - 可选参数,表示周的起始日,0 表示星期天,1 表示星期一,以此类推,默认为 0
|
|
1074
|
+
* @return {number} 给定日期属于所在年的第几周
|
|
1075
|
+
**/
|
|
1076
|
+
const getWeekNumber = function(date, type = 1) {
|
|
1077
|
+
if (typeof date !== 'string') {
|
|
1078
|
+
throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
const dateObj = new Date(date);
|
|
1082
|
+
if (isNaN(dateObj.getTime())) {
|
|
1083
|
+
throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// Copy the date object to avoid modifying the original
|
|
1087
|
+
const clonedDate = new Date(dateObj);
|
|
1088
|
+
|
|
1089
|
+
// Set the time to the beginning of the year
|
|
1090
|
+
clonedDate.setMonth(0, 1);
|
|
1091
|
+
clonedDate.setHours(0, 0, 0, 0);
|
|
1092
|
+
|
|
1093
|
+
// Find the first day of the week
|
|
1094
|
+
const dayOfWeek = clonedDate.getDay();
|
|
1095
|
+
const firstDay = (dayOfWeek - type + 7) % 7;
|
|
1096
|
+
|
|
1097
|
+
// Adjust for days until the first Sunday/Monday
|
|
1098
|
+
clonedDate.setDate(1 + (type === 0 ? (7 - firstDay) : (1 - firstDay)));
|
|
1099
|
+
|
|
1100
|
+
// Calculate the week number
|
|
1101
|
+
const weekNumber = Math.ceil((dateObj - clonedDate) / (7 * 24 * 60 * 60 * 1000));
|
|
1102
|
+
|
|
1103
|
+
return weekNumber;
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* getLength
|
|
1108
|
+
* @desc 计算字符个数
|
|
1109
|
+
* @desc 计算给定文本字符串的字符个数
|
|
1110
|
+
* @param {string} text - 要计算字符个数的文本字符串
|
|
1111
|
+
* @return {number} 文本字符串的字符个数
|
|
1112
|
+
**/
|
|
1113
|
+
const getLength = function(text) {
|
|
1114
|
+
if (typeof text !== 'string') {
|
|
1115
|
+
throw new Error('Invalid input. Please provide a valid text string.');
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
return text.length;
|
|
1119
|
+
};
|
|
1120
|
+
|
|
943
1121
|
/**
|
|
944
1122
|
* getLightness
|
|
945
1123
|
* @desc:转换明度
|
|
@@ -954,6 +1132,46 @@ const getLightness = function ($v, $i, $isLight) {
|
|
|
954
1132
|
return toFixed($value, 2);
|
|
955
1133
|
};
|
|
956
1134
|
|
|
1135
|
+
/**
|
|
1136
|
+
* getMinute
|
|
1137
|
+
* @desc 获取分钟
|
|
1138
|
+
* @desc 返回给定日期或时间的分钟部分
|
|
1139
|
+
* @param {string} datetime - 日期时间字符串,格式为 "YYYY-MM-DD HH:mm:ss"
|
|
1140
|
+
* @return {number} 给定日期或时间的分钟部分
|
|
1141
|
+
**/
|
|
1142
|
+
const getMinute = function(datetime) {
|
|
1143
|
+
if (typeof datetime !== 'string') {
|
|
1144
|
+
throw new Error("Invalid input. Please provide a valid datetime string in the format 'YYYY-MM-DD HH:mm:ss'.");
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const datetimeObj = new Date(datetime);
|
|
1148
|
+
if (isNaN(datetimeObj.getTime())) {
|
|
1149
|
+
throw new Error("Invalid datetime format. Please provide a valid datetime string in the format 'YYYY-MM-DD HH:mm:ss'.");
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
return datetimeObj.getMinutes();
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* getMonth
|
|
1157
|
+
* @desc 获取月份
|
|
1158
|
+
* @desc 返回给定日期的月份
|
|
1159
|
+
* @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
|
|
1160
|
+
* @return {number} 给定日期的月份
|
|
1161
|
+
**/
|
|
1162
|
+
const getMonth = function(date) {
|
|
1163
|
+
if (typeof date !== 'string') {
|
|
1164
|
+
throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
const dateObj = new Date(date);
|
|
1168
|
+
if (isNaN(dateObj.getTime())) {
|
|
1169
|
+
throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
return dateObj.getMonth() + 1; // Months are zero-indexed in JavaScript (0 is January)
|
|
1173
|
+
};
|
|
1174
|
+
|
|
957
1175
|
/**
|
|
958
1176
|
* getObjectType
|
|
959
1177
|
* @desc:获取数据类型
|
|
@@ -1154,6 +1372,26 @@ const getScript = function (url, callback) {
|
|
|
1154
1372
|
});
|
|
1155
1373
|
};
|
|
1156
1374
|
|
|
1375
|
+
/**
|
|
1376
|
+
* getSecond
|
|
1377
|
+
* @desc 获取秒数
|
|
1378
|
+
* @desc 返回给定日期或时间的秒钟部分
|
|
1379
|
+
* @param {string} datetime - 日期时间字符串,格式为 "YYYY-MM-DD HH:mm:ss"
|
|
1380
|
+
* @return {number} 给定日期或时间的秒钟部分
|
|
1381
|
+
**/
|
|
1382
|
+
const getSecond = function(datetime) {
|
|
1383
|
+
if (typeof datetime !== 'string') {
|
|
1384
|
+
throw new Error("Invalid input. Please provide a valid datetime string in the format 'YYYY-MM-DD HH:mm:ss'.");
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
const datetimeObj = new Date(datetime);
|
|
1388
|
+
if (isNaN(datetimeObj.getTime())) {
|
|
1389
|
+
throw new Error("Invalid datetime format. Please provide a valid datetime string in the format 'YYYY-MM-DD HH:mm:ss'.");
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
return datetimeObj.getSeconds();
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1157
1395
|
/**
|
|
1158
1396
|
* getStorage
|
|
1159
1397
|
* @desc:获取本地储存数据
|
|
@@ -1339,6 +1577,33 @@ const getValues = function (obj, flag) {
|
|
|
1339
1577
|
return val;
|
|
1340
1578
|
};
|
|
1341
1579
|
|
|
1580
|
+
/**
|
|
1581
|
+
* getWeekday
|
|
1582
|
+
* @desc 获取星期数
|
|
1583
|
+
* @desc 返回给定日期是所在星期的第几天
|
|
1584
|
+
* @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
|
|
1585
|
+
* @param {number} type - 可选参数,表示星期的起始日,0 表示星期天,1 表示星期一,以此类推,默认为 0
|
|
1586
|
+
* @return {number} 给定日期是所在星期的第几天
|
|
1587
|
+
**/
|
|
1588
|
+
const getWeekday = function(date, type = 0) {
|
|
1589
|
+
if (typeof date !== 'string') {
|
|
1590
|
+
throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
const dateObj = new Date(date);
|
|
1594
|
+
if (isNaN(dateObj.getTime())) {
|
|
1595
|
+
throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
const dayOfWeek = dateObj.getDay();
|
|
1599
|
+
|
|
1600
|
+
// Calculate weekday based on the specified starting day
|
|
1601
|
+
const adjustedDay = (dayOfWeek - type + 7) % 7;
|
|
1602
|
+
|
|
1603
|
+
// Adjust for JavaScript's day numbering (0 is Sunday, 1 is Monday, etc.)
|
|
1604
|
+
return adjustedDay === 0 ? 7 : adjustedDay;
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1342
1607
|
/**
|
|
1343
1608
|
* handlerUrl
|
|
1344
1609
|
* @desc:更新url参数中的时间戳
|
|
@@ -1807,6 +2072,21 @@ const loading = function ($loading, res) {
|
|
|
1807
2072
|
}
|
|
1808
2073
|
};
|
|
1809
2074
|
|
|
2075
|
+
/**
|
|
2076
|
+
* lowerCase
|
|
2077
|
+
* @desc 大写转小写
|
|
2078
|
+
* @desc 将文本字符串中的大写字母转换为小写字母
|
|
2079
|
+
* @param {string} text - 要转换的文本字符串
|
|
2080
|
+
* @return {string} 转换为小写字母后的字符串
|
|
2081
|
+
**/
|
|
2082
|
+
const lowerCase = function(text) {
|
|
2083
|
+
if (typeof text !== 'string') {
|
|
2084
|
+
throw new Error('Invalid input. Please provide a valid text string.');
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
return text.toLowerCase();
|
|
2088
|
+
};
|
|
2089
|
+
|
|
1810
2090
|
/**
|
|
1811
2091
|
* mixColor
|
|
1812
2092
|
* @desc:生成混合色
|
|
@@ -1960,6 +2240,74 @@ const rgbToHsv = function ($color) {
|
|
|
1960
2240
|
return [$h, $s, $v];
|
|
1961
2241
|
};
|
|
1962
2242
|
|
|
2243
|
+
/**
|
|
2244
|
+
* rmbToCapital
|
|
2245
|
+
* @desc 人民币大写
|
|
2246
|
+
* @desc 将人民币金额转换为大写形式
|
|
2247
|
+
* @param {number} number - 人民币金额
|
|
2248
|
+
* @return {string} 人民币大写形式
|
|
2249
|
+
**/
|
|
2250
|
+
const rmbToCapital = function(number) {
|
|
2251
|
+
if (!Number.isFinite(number)) {
|
|
2252
|
+
throw new Error('Invalid input. Please provide a valid number for the RMB amount.');
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
const capitalUnits = ['', '万', '亿', '万亿'];
|
|
2256
|
+
const numberToChinese = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
2257
|
+
|
|
2258
|
+
let result = '';
|
|
2259
|
+
let unitIndex = 0;
|
|
2260
|
+
|
|
2261
|
+
// 处理小数部分
|
|
2262
|
+
const decimalPart = Math.round((number % 1) * 100);
|
|
2263
|
+
if (decimalPart > 0) {
|
|
2264
|
+
result += '元';
|
|
2265
|
+
result += numberToChinese[Math.floor(decimalPart / 10)] + '角';
|
|
2266
|
+
result += numberToChinese[decimalPart % 10] + '分';
|
|
2267
|
+
} else {
|
|
2268
|
+
result += '元整';
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
// 处理整数部分
|
|
2272
|
+
let integerPart = Math.floor(number);
|
|
2273
|
+
while (integerPart > 0) {
|
|
2274
|
+
let chunk = integerPart % 10000;
|
|
2275
|
+
if (chunk > 0) {
|
|
2276
|
+
result = capitalUnits[unitIndex] + result;
|
|
2277
|
+
result = chunkToChinese(chunk) + result;
|
|
2278
|
+
}
|
|
2279
|
+
integerPart = Math.floor(integerPart / 10000);
|
|
2280
|
+
unitIndex++;
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
return result;
|
|
2284
|
+
};
|
|
2285
|
+
|
|
2286
|
+
// 辅助函数,将四位数的整数转换为中文大写
|
|
2287
|
+
function chunkToChinese(chunk) {
|
|
2288
|
+
const numberToChinese = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
2289
|
+
const capitalDigits = ['', '拾', '佰', '仟'];
|
|
2290
|
+
|
|
2291
|
+
let result = '';
|
|
2292
|
+
let digitIndex = 0;
|
|
2293
|
+
|
|
2294
|
+
while (chunk > 0) {
|
|
2295
|
+
const digit = chunk % 10;
|
|
2296
|
+
if (digit > 0) {
|
|
2297
|
+
result = numberToChinese[digit] + capitalDigits[digitIndex] + result;
|
|
2298
|
+
} else {
|
|
2299
|
+
// 当前数字是零,需要判断是否需要添加零
|
|
2300
|
+
if (result.charAt(0) !== '零') {
|
|
2301
|
+
result = '零' + result;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
chunk = Math.floor(chunk / 10);
|
|
2305
|
+
digitIndex++;
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
return result;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
1963
2311
|
/**
|
|
1964
2312
|
* sendMessage
|
|
1965
2313
|
* @desc:向iframe发送信息
|
|
@@ -2043,6 +2391,27 @@ const setStorage = function ({ type, key, value }) {
|
|
|
2043
2391
|
}
|
|
2044
2392
|
}
|
|
2045
2393
|
};
|
|
2394
|
+
|
|
2395
|
+
/**
|
|
2396
|
+
* sum
|
|
2397
|
+
* @desc 求和
|
|
2398
|
+
* @author SuTao
|
|
2399
|
+
* @date 2023年12月14日
|
|
2400
|
+
* @param {...number} numbers - 一列或多列数字
|
|
2401
|
+
* @return {number} 计算结果的总和
|
|
2402
|
+
**/
|
|
2403
|
+
function sum(...numbers) {
|
|
2404
|
+
// Ensure that all arguments are valid numbers
|
|
2405
|
+
if (!numbers.every(Number.isFinite)) {
|
|
2406
|
+
throw new Error('Invalid input. Please provide valid numbers.');
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
// Calculate the sum of the numbers
|
|
2410
|
+
const result = numbers.reduce((acc, num) => acc + num, 0);
|
|
2411
|
+
|
|
2412
|
+
return result;
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2046
2415
|
/**
|
|
2047
2416
|
* startWith
|
|
2048
2417
|
* @desc:判断值是否以指定字符开头
|
|
@@ -2071,6 +2440,38 @@ const startWith = function (value, reg, or = true) {
|
|
|
2071
2440
|
return false;
|
|
2072
2441
|
};
|
|
2073
2442
|
|
|
2443
|
+
/**
|
|
2444
|
+
* takeLeft
|
|
2445
|
+
* @desc 从左侧提取指定数量的字符
|
|
2446
|
+
* @desc 返回文本字符串的左侧指定数量的字符
|
|
2447
|
+
* @param {string} text - 要提取字符的文本字符串
|
|
2448
|
+
* @param {number} num_chars - 要返回的字符数量
|
|
2449
|
+
* @return {string} 从左侧提取的字符
|
|
2450
|
+
**/
|
|
2451
|
+
const takeLeft = function(text, num_chars) {
|
|
2452
|
+
if (typeof text !== 'string' || !Number.isInteger(num_chars) || num_chars < 0) {
|
|
2453
|
+
throw new Error('Invalid input. Please provide a valid text string and a non-negative integer for the number of characters.');
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
return text.slice(0, num_chars);
|
|
2457
|
+
};
|
|
2458
|
+
|
|
2459
|
+
/**
|
|
2460
|
+
* takeRight
|
|
2461
|
+
* @desc 从右返回指定个字符
|
|
2462
|
+
* @desc 返回文本字符串的右侧指定数量的字符
|
|
2463
|
+
* @param {string} text - 要提取字符的文本字符串
|
|
2464
|
+
* @param {number} num_chars - 要返回的字符数量
|
|
2465
|
+
* @return {string} 从右侧提取的字符
|
|
2466
|
+
**/
|
|
2467
|
+
const takeRight = function(text, num_chars) {
|
|
2468
|
+
if (typeof text !== 'string' || !Number.isInteger(num_chars) || num_chars < 0) {
|
|
2469
|
+
throw new Error('Invalid input. Please provide a valid text string and a non-negative integer for the number of characters.');
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
return text.slice(-num_chars);
|
|
2473
|
+
};
|
|
2474
|
+
|
|
2074
2475
|
/**
|
|
2075
2476
|
* throttle
|
|
2076
2477
|
* @desc:添加js内容
|
|
@@ -2117,6 +2518,21 @@ const timeCycle = function (date) {
|
|
|
2117
2518
|
return period;
|
|
2118
2519
|
};
|
|
2119
2520
|
|
|
2521
|
+
/**
|
|
2522
|
+
* trimWhitespace
|
|
2523
|
+
* @desc 删除首尾空格
|
|
2524
|
+
* @desc 删除文本字符串首尾的空格
|
|
2525
|
+
* @param {string} text - 要处理的文本字符串
|
|
2526
|
+
* @return {string} 删除首尾空格后的字符串
|
|
2527
|
+
**/
|
|
2528
|
+
const trimWhitespace = function(text) {
|
|
2529
|
+
if (typeof text !== 'string') {
|
|
2530
|
+
throw new Error('Invalid input. Please provide a valid text string.');
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
return text.trim();
|
|
2534
|
+
};
|
|
2535
|
+
|
|
2120
2536
|
/**
|
|
2121
2537
|
* toFixed
|
|
2122
2538
|
* @desc:浮点数保留小数位
|
|
@@ -2193,6 +2609,21 @@ const updateTheme = function ($color, send) {
|
|
|
2193
2609
|
}
|
|
2194
2610
|
};
|
|
2195
2611
|
|
|
2612
|
+
/**
|
|
2613
|
+
* upperCase
|
|
2614
|
+
* @desc 小写转大写
|
|
2615
|
+
* @desc 将文本字符串中的小写字母转换为大写字母
|
|
2616
|
+
* @param {string} text - 要转换的文本字符串
|
|
2617
|
+
* @return {string} 转换为大写字母后的字符串
|
|
2618
|
+
**/
|
|
2619
|
+
const upperCase = function(text) {
|
|
2620
|
+
if (typeof text !== 'string') {
|
|
2621
|
+
throw new Error('Invalid input. Please provide a valid text string.');
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
return text.toUpperCase();
|
|
2625
|
+
};
|
|
2626
|
+
|
|
2196
2627
|
/**
|
|
2197
2628
|
* urlJoinParams
|
|
2198
2629
|
* @desc:对象转url拼接参数
|
|
@@ -2306,10 +2737,13 @@ const watermark = function (option) {
|
|
|
2306
2737
|
export default {
|
|
2307
2738
|
ajax,
|
|
2308
2739
|
arrUnique,
|
|
2740
|
+
average,
|
|
2309
2741
|
browser,
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2742
|
+
calculateNetworkDays,
|
|
2743
|
+
concatenate,
|
|
2744
|
+
dateAddDays,
|
|
2745
|
+
dateDiff,
|
|
2746
|
+
dayOfMonth,
|
|
2313
2747
|
debounce,
|
|
2314
2748
|
delUrlParam,
|
|
2315
2749
|
domEval,
|
|
@@ -2321,14 +2755,23 @@ export default {
|
|
|
2321
2755
|
exportXls,
|
|
2322
2756
|
extend,
|
|
2323
2757
|
formatDate,
|
|
2758
|
+
getCurrentDate,
|
|
2759
|
+
getCurrentDateTime,
|
|
2760
|
+
getHour,
|
|
2761
|
+
getWeekNumber,
|
|
2762
|
+
getLength,
|
|
2763
|
+
getMinute,
|
|
2764
|
+
getMonth,
|
|
2324
2765
|
getObjectType,
|
|
2325
2766
|
getParams,
|
|
2326
2767
|
getRgb,
|
|
2327
2768
|
getScript,
|
|
2769
|
+
getSecond,
|
|
2328
2770
|
getStorage,
|
|
2329
2771
|
getStyle,
|
|
2330
2772
|
getTypeName,
|
|
2331
2773
|
getValues,
|
|
2774
|
+
getWeekday,
|
|
2332
2775
|
handlerUrl,
|
|
2333
2776
|
hasChars,
|
|
2334
2777
|
hasClass,
|
|
@@ -2342,6 +2785,7 @@ export default {
|
|
|
2342
2785
|
jointUrl,
|
|
2343
2786
|
loadJs,
|
|
2344
2787
|
loading,
|
|
2788
|
+
lowerCase,
|
|
2345
2789
|
mixColor,
|
|
2346
2790
|
overbrim,
|
|
2347
2791
|
queryParams,
|
|
@@ -2349,15 +2793,21 @@ export default {
|
|
|
2349
2793
|
removeStorage,
|
|
2350
2794
|
replenish,
|
|
2351
2795
|
rgbToHsv,
|
|
2796
|
+
rmbToCapital,
|
|
2352
2797
|
sendMessage,
|
|
2353
2798
|
setFavicon,
|
|
2354
2799
|
setStorage,
|
|
2355
2800
|
startWith,
|
|
2801
|
+
sum,
|
|
2802
|
+
takeLeft,
|
|
2803
|
+
takeRight,
|
|
2356
2804
|
throttle,
|
|
2357
2805
|
timeCycle,
|
|
2806
|
+
trimWhitespace,
|
|
2358
2807
|
toFixed,
|
|
2359
2808
|
toFunction,
|
|
2360
2809
|
updateTheme,
|
|
2810
|
+
upperCase,
|
|
2361
2811
|
urlJoinParams,
|
|
2362
2812
|
uuid,
|
|
2363
2813
|
watermark,
|