eoss 0.1.0-alpha.4 → 0.1.0-alpha.6

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.
Files changed (103) hide show
  1. package/lib/account-login.js +3591 -3410
  2. package/lib/autocomplete.js +3585 -3380
  3. package/lib/button-group.js +7675 -7493
  4. package/lib/button.js +3582 -3377
  5. package/lib/ca-login.js +3580 -3375
  6. package/lib/calendar.js +7683 -7501
  7. package/lib/carousel.js +3 -3
  8. package/lib/cascader-panel.js +3612 -3407
  9. package/lib/cascader.js +3612 -3407
  10. package/lib/checkbox-group.js +3563 -3381
  11. package/lib/checkbox.js +70 -70
  12. package/lib/collapse-item.js +3580 -3375
  13. package/lib/color-picker.js +3581 -3376
  14. package/lib/data-table.js +19151 -18970
  15. package/lib/date-picker.js +3579 -3374
  16. package/lib/dialog.js +3582 -3377
  17. package/lib/dropdown.js +7832 -7650
  18. package/lib/email-login.js +3593 -3411
  19. package/lib/eoss.common.js +521 -326
  20. package/lib/flow-group.js +3576 -3366
  21. package/lib/flow.js +4385 -4203
  22. package/lib/form-item.js +3583 -3377
  23. package/lib/form.js +10064 -9883
  24. package/lib/icon.js +3580 -3375
  25. package/lib/image.js +3580 -3375
  26. package/lib/index.js +1 -1
  27. package/lib/index.js.LICENSE.txt +1 -1
  28. package/lib/input-number.js +2563 -2358
  29. package/lib/input.js +3582 -3377
  30. package/lib/loading.js +3582 -3377
  31. package/lib/login.js +5237 -5053
  32. package/lib/main.js +3581 -3402
  33. package/lib/menu-item-group.js +3582 -3377
  34. package/lib/menu-item.js +3582 -3377
  35. package/lib/menu.js +3582 -3377
  36. package/lib/message-box.js +3582 -3377
  37. package/lib/message.js +3582 -3377
  38. package/lib/notification.js +3582 -3377
  39. package/lib/option.js +3601 -3396
  40. package/lib/pagination.js +9907 -9726
  41. package/lib/phone-login.js +3593 -3411
  42. package/lib/popconfirm.js +4794 -4589
  43. package/lib/popover.js +3585 -3380
  44. package/lib/qrcode-login.js +3593 -3411
  45. package/lib/radio-group.js +4389 -4207
  46. package/lib/radio.js +24 -24
  47. package/lib/rate.js +3582 -3377
  48. package/lib/scrollbar.js +3582 -3377
  49. package/lib/select.js +3596 -3415
  50. package/lib/selector-panel.js +3629 -3446
  51. package/lib/selector.js +3597 -3414
  52. package/lib/slider.js +2566 -2361
  53. package/lib/step.js +3580 -3375
  54. package/lib/steps.js +3582 -3377
  55. package/lib/submenu.js +3582 -3377
  56. package/lib/switch.js +3582 -3377
  57. package/lib/table-column.js +3770 -3564
  58. package/lib/table.js +4844 -4662
  59. package/lib/tabs.js +3580 -3375
  60. package/lib/time-picker.js +3581 -3376
  61. package/lib/time-select.js +3581 -3376
  62. package/lib/tips.js +4378 -4196
  63. package/lib/tooltip.js +3582 -3377
  64. package/lib/transfer.js +3563 -3381
  65. package/lib/tree-group.js +3568 -3363
  66. package/lib/tree.js +4652 -4447
  67. package/lib/upload.js +3595 -3413
  68. package/lib/utils/ajax.js +25 -51
  69. package/lib/utils/util.js +330 -132
  70. package/lib/wujie.js +3571 -3363
  71. package/package.json +1 -1
  72. package/packages/autocomplete/src/autocomplete.vue +1 -1
  73. package/packages/carousel/src/item.vue +1 -1
  74. package/packages/carousel/src/main.vue +1 -1
  75. package/packages/checkbox/src/checkbox-group.vue +1 -1
  76. package/packages/checkbox/src/checkbox.vue +29 -29
  77. package/packages/flow-group/src/main.vue +2 -2
  78. package/packages/form/src/form.vue +3 -5
  79. package/packages/input/src/input.vue +2 -2
  80. package/packages/input-number/src/input-number.vue +2 -2
  81. package/packages/login/src/login.vue +4 -4
  82. package/packages/popover/src/main.vue +1 -1
  83. package/packages/radio/src/radio-group.vue +1 -1
  84. package/packages/radio/src/radio.vue +1 -1
  85. package/packages/select/src/select.vue +1 -1
  86. package/packages/slider/src/slider.vue +2 -4
  87. package/packages/table/src/layout-observer.js +5 -5
  88. package/packages/table/src/table-body.js +11 -11
  89. package/packages/table/src/table-column.js +1 -1
  90. package/packages/theme-chalk/package.json +6 -6
  91. package/packages/theme-chalk/src/button.scss +29 -8
  92. package/packages/theme-chalk/src/common/color/colorPalette.scss +5 -5
  93. package/packages/theme-chalk/src/common/var.scss +1 -1
  94. package/packages/theme-chalk/src/dropdown.scss +7 -2
  95. package/packages/theme-chalk/src/link.scss +3 -2
  96. package/packages/theme-chalk/src/mixins/_button.scss +28 -15
  97. package/packages/theme-chalk/src/mixins/color.scss +21 -18
  98. package/packages/theme-chalk/src/mixins/function.scss +108 -44
  99. package/packages/theme-chalk/src/tag.scss +49 -20
  100. package/packages/upload/src/index.vue +2 -2
  101. package/src/index.js +2 -2
  102. package/src/utils/ajax.js +0 -14
  103. package/src/utils/util.js +274 -94
package/src/utils/util.js CHANGED
@@ -13,14 +13,38 @@ import { formatDate } from './date';
13
13
 
14
14
  const publicKey = 'abcdefghijklmnopqrstuvwxyz12345678';
15
15
 
16
- export function noop() { };
16
+ /**
17
+ * 空函数
18
+ * @desc 不执行任何操作的空函数
19
+ * @return {undefined}
20
+ **/
21
+ export const noop = () => {};
17
22
 
18
- export function hasOwn(obj, key) {
23
+ /**
24
+ * 检查对象是否拥有指定属性
25
+ * @desc 检查对象自身是否包含指定的属性(不包括原型链上的属性)
26
+ * @param {Object} obj - 要检查的对象
27
+ * @param {string} key - 要检查的属性名
28
+ * @return {boolean} 是否拥有该属性
29
+ **/
30
+ export const hasOwn = (obj, key) => {
31
+ if (!isObject(obj) && typeof obj !== 'object') {
32
+ return false;
33
+ }
19
34
  return hasOwnProperty.call(obj, key);
20
35
  };
21
36
 
22
- export function toObject(arr) {
37
+ /**
38
+ * 将数组转换为对象
39
+ * @desc 将对象数组合并为一个对象
40
+ * @param {Array} [arr=[]] - 对象数组
41
+ * @return {Object} 合并后的对象
42
+ **/
43
+ export const toObject = (arr = []) => {
23
44
  var res = {};
45
+ if (!Array.isArray(arr)) {
46
+ return res;
47
+ }
24
48
  for (let i = 0; i < arr.length; i++) {
25
49
  if (arr[i]) {
26
50
  extend(res, arr[i]);
@@ -29,6 +53,13 @@ export function toObject(arr) {
29
53
  return res;
30
54
  };
31
55
 
56
+ /**
57
+ * 根据路径获取对象属性值
58
+ * @desc 根据点分隔的路径字符串获取对象中的属性值
59
+ * @param {Object} object - 源对象
60
+ * @param {string} prop - 属性路径(如 'a.b.c')
61
+ * @return {*} 获取到的属性值,如果路径不存在则返回null
62
+ **/
32
63
  export const getValueByPath = function (object, prop) {
33
64
  if (Object.prototype.toString.call(object).toLowerCase() !== '[object object]') {
34
65
  return object;
@@ -50,7 +81,22 @@ export const getValueByPath = function (object, prop) {
50
81
  return result;
51
82
  };
52
83
 
53
- export function getPropByPath(obj, path, strict) {
84
+ /**
85
+ * 获取属性路径信息
86
+ * @desc 获取对象属性路径的详细信息,包括父对象、属性名和属性值
87
+ * @param {Object} obj - 源对象
88
+ * @param {string} path - 属性路径(如 'a.b.c' 或 'a[0].b')
89
+ * @param {boolean} [strict=false] - 是否严格模式,严格模式下路径不存在会抛出错误
90
+ * @return {Object} 包含父对象(o)、属性名(k)和属性值(v)的对象
91
+ **/
92
+ export const getPropByPath = (obj, path, strict = false) => {
93
+ if (!isObject(obj) && typeof obj !== 'object') {
94
+ return { o: null, k: '', v: null };
95
+ }
96
+ if (!isString(path)) {
97
+ return { o: obj, k: '', v: null };
98
+ }
99
+
54
100
  let tempObj = obj;
55
101
  path = path.replace(/\[(\w+)\]/g, '.$1');
56
102
  path = path.replace(/^\./, '');
@@ -76,10 +122,22 @@ export function getPropByPath(obj, path, strict) {
76
122
  };
77
123
  };
78
124
 
125
+ /**
126
+ * 生成随机ID
127
+ * @desc 生成一个1-9999之间的随机整数作为ID
128
+ * @return {number} 随机ID
129
+ **/
79
130
  export const generateId = function () {
80
131
  return Math.floor(Math.random() * 10000);
81
132
  };
82
133
 
134
+ /**
135
+ * 检查两个数组是否值相等
136
+ * @desc 深度比较两个数组是否包含相同的元素(严格相等比较)
137
+ * @param {Array} a - 第一个数组
138
+ * @param {Array} b - 第二个数组
139
+ * @return {boolean} 数组是否值相等
140
+ **/
83
141
  export const valueEquals = (a, b) => {
84
142
  // see: https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript
85
143
  if (a === b) return true;
@@ -92,10 +150,29 @@ export const valueEquals = (a, b) => {
92
150
  return true;
93
151
  };
94
152
 
153
+ /**
154
+ * 转义正则表达式特殊字符
155
+ * @desc 将字符串中的正则表达式特殊字符转义,使其可以安全地用于正则表达式
156
+ * @param {*} [value=''] - 要转义的字符串
157
+ * @return {string} 转义后的字符串
158
+ **/
95
159
  export const escapeRegexpString = (value = '') => String(value).replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
96
160
 
97
161
  // TODO: use native Array.find, Array.findIndex when IE support is dropped
98
- export const arrayFindIndex = function (arr, pred) {
162
+ /**
163
+ * 查找数组中符合条件的元素索引
164
+ * @desc 查找数组中第一个满足测试函数的元素的索引
165
+ * @param {Array} arr - 要查找的数组
166
+ * @param {Function} pred - 测试函数,返回true表示找到匹配元素
167
+ * @return {number} 找到的元素索引,未找到返回-1
168
+ **/
169
+ export const arrayFindIndex = (arr, pred) => {
170
+ if (!Array.isArray(arr)) {
171
+ return -1;
172
+ }
173
+ if (typeof pred !== 'function') {
174
+ return -1;
175
+ }
99
176
  for (let i = 0; i !== arr.length; ++i) {
100
177
  if (pred(arr[i])) {
101
178
  return i;
@@ -104,12 +181,31 @@ export const arrayFindIndex = function (arr, pred) {
104
181
  return -1;
105
182
  };
106
183
 
107
- export const arrayFind = function (arr, pred) {
184
+ /**
185
+ * 查找数组中符合条件的元素
186
+ * @desc 查找数组中第一个满足测试函数的元素
187
+ * @param {Array} arr - 要查找的数组
188
+ * @param {Function} pred - 测试函数,返回true表示找到匹配元素
189
+ * @return {*} 找到的元素,未找到返回undefined
190
+ **/
191
+ export const arrayFind = (arr, pred) => {
192
+ if (!Array.isArray(arr)) {
193
+ return undefined;
194
+ }
195
+ if (typeof pred !== 'function') {
196
+ return undefined;
197
+ }
108
198
  const idx = arrayFindIndex(arr, pred);
109
199
  return idx !== -1 ? arr[idx] : undefined;
110
200
  };
111
201
 
112
202
  // coerce truthy value to array
203
+ /**
204
+ * 将真值转换为数组
205
+ * @desc 如果输入是数组则直接返回,否则将真值包装为数组,假值返回空数组
206
+ * @param {*} val - 要转换的值
207
+ * @return {Array} 转换后的数组
208
+ **/
113
209
  export const coerceTruthyValueToArray = function (val) {
114
210
  if (Array.isArray(val)) {
115
211
  return val;
@@ -229,7 +325,7 @@ export function objToArray(obj) {
229
325
  // requestAnimationFrame 适配函数
230
326
  const raFrame =
231
327
  window.requestAnimationFrame ||
232
- window.webkitRequestAnimationFrame ||
328
+ window['webkitRequestAnimationFrame'] ||
233
329
  function (callback) {
234
330
  return window.setTimeout(callback, 1000 / 60);
235
331
  };
@@ -265,7 +361,7 @@ export const requestAnimationFrame = raFrame;
265
361
  */
266
362
  export const cancelAnimationFrame =
267
363
  window.cancelAnimationFrame ||
268
- window.webkitRequestAnimationFrame ||
364
+ window['webkitCancelAnimationFrame'] ||
269
365
  function (id) {
270
366
  window.clearTimeout(id);
271
367
  };
@@ -433,7 +529,8 @@ export function pager(data, page = 1, size = 10) {
433
529
  /**
434
530
  * getWinTop
435
531
  * @desc 获取同域的top窗口
436
- * @param {object} wind - window对象
532
+ * @param {object} [wind] - window对象
533
+ * @return {Window} 同域的top窗口
437
534
  **/
438
535
  export const getWinTop = function (wind) {
439
536
  wind = wind ? wind : window.__WUJIE_RAW_WINDOW__ ? window.__WUJIE_RAW_WINDOW__ : window;
@@ -581,28 +678,35 @@ export const getFileType = function (fileName) {
581
678
 
582
679
  /**
583
680
  * arrUnique
584
- * @desc:数组元素对象去重
681
+ * @desc 数组元素对象去重
585
682
  * @author huangbo
586
683
  * @date 2022年5月7日
587
- * @param {Object} [data] - 原始数组
684
+ * @param {Array} [data] - 原始数组
588
685
  * @param {String} [key] - 对象子元素的属性名
686
+ * @return {Array} 去重后的数组
589
687
  **/
590
688
  export const arrUnique = function (data, key) {
689
+ // 验证输入参数
690
+ if (!Array.isArray(data) || data.length === 0) return [];
691
+
591
692
  let newArr = [];
592
693
  if (key === undefined) {
593
- data.sort();
594
- newArr = [data[0]];
595
- for (let i = 1; i < data.length; i++) {
596
- if (data[i] !== newArr[newArr.length - 1]) {
597
- newArr.push(data[i]);
694
+ // 对基本类型数组去重
695
+ const sortedData = [...data].sort(); // 避免修改原数组
696
+ newArr = [sortedData[0]];
697
+ for (let i = 1; i < sortedData.length; i++) {
698
+ if (sortedData[i] !== newArr[newArr.length - 1]) {
699
+ newArr.push(sortedData[i]);
598
700
  }
599
701
  }
600
702
  } else {
703
+ // 对对象数组按指定键去重
601
704
  let obj = {};
602
705
  for (let i = 0; i < data.length; i++) {
603
- if (!obj[data[i][key]]) {
604
- newArr.push(data[i]);
605
- obj[data[i][key]] = true;
706
+ const item = data[i];
707
+ if (item && obj[item[key]] === undefined) {
708
+ newArr.push(item);
709
+ obj[item[key]] = true;
606
710
  }
607
711
  }
608
712
  }
@@ -618,16 +722,17 @@ export const arrUnique = function (data, key) {
618
722
  * @return {number} 数组中数字的平均值
619
723
  **/
620
724
  export const average = function (...numbers) {
621
- // Ensure that all arguments are valid numbers
725
+ // 处理空参数情况
726
+ if (numbers.length === 0) return 0;
727
+
728
+ // 确保所有参数都是有效数字
622
729
  if (!numbers.every(Number.isFinite)) {
623
730
  throw new Error('Invalid input. Please provide valid numbers.');
624
731
  }
625
732
 
626
- // Calculate the average of the numbers
733
+ // 计算平均值
627
734
  const sum = numbers.reduce((acc, num) => acc + num, 0);
628
- const average = sum / numbers.length;
629
-
630
- return average;
735
+ return sum / numbers.length;
631
736
  };
632
737
 
633
738
  /**
@@ -640,7 +745,9 @@ export const average = function (...numbers) {
640
745
  * @return {string} 格式化后的文件大小
641
746
  */
642
747
  export const formatFileSize = function (size, digits = 2) {
643
- if (size === 0) return '';
748
+ // 验证输入参数
749
+ if (size === 0 || typeof size !== 'number' || isNaN(size)) return '';
750
+ if (typeof digits !== 'number' || isNaN(digits)) digits = 2;
644
751
 
645
752
  const k = 1024;
646
753
  const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
@@ -654,9 +761,10 @@ export const formatFileSize = function (size, digits = 2) {
654
761
 
655
762
  /**
656
763
  * browser
657
- * @desc:浏览器类型
764
+ * @desc 浏览器类型
658
765
  * @author huangbo
659
766
  * @date 2022年5月7日
767
+ * @return {string|undefined} 浏览器类型标识
660
768
  **/
661
769
  export const browser = function () {
662
770
  const reg = { ie: /msie/, moz: /gecko/, opera: /opera/, safari: /safari/ };
@@ -669,9 +777,14 @@ export const browser = function () {
669
777
 
670
778
  /**
671
779
  * busEmit
672
- * @desc:发送事件
780
+ * @desc 发送事件
673
781
  * @author huangbo
674
782
  * @date 2022年5月7日
783
+ * @param {Object} that - Vue实例或包含bus的对象
784
+ * @param {Object} options - 事件选项
785
+ * @param {string} options.method - 事件名称
786
+ * @param {Array|*} options.args - 事件参数
787
+ * @param {Object} [options.opener] - 窗口对象(用于跨窗口通信)
675
788
  **/
676
789
  export const busEmit = function (that, { method, args, opener }) {
677
790
  if (opener) {
@@ -706,6 +819,7 @@ export const busEmit = function (that, { method, args, opener }) {
706
819
  * chunkToChinese
707
820
  * @desc 将四位数的整数转换为中文大写
708
821
  * @param {number} chunk - 数字
822
+ * @return {string} 中文大写数字
709
823
  **/
710
824
  export const chunkToChinese = function chunkToChinese(chunk) {
711
825
 
@@ -745,7 +859,6 @@ export const chunkToChinese = function chunkToChinese(chunk) {
745
859
 
746
860
  /**
747
861
  * concatenate
748
- * @desc 指定连接符合并文本
749
862
  * @desc 使用指定的连接符合并文本字符串
750
863
  * @author SuTao
751
864
  * @date 2023年12月14日
@@ -767,11 +880,13 @@ export const concatenate = function (separator, ...strings) {
767
880
 
768
881
  /**
769
882
  * delUrlParam
770
- * @desc:删除url指定参数
883
+ * @desc 删除url指定参数
771
884
  * @author huangbo
772
885
  * @date 2022年5月7日
773
- * @param {String} [url] - url地址
774
- * @param {String,Array} [key] - 参数名
886
+ * @param {Object} options - 参数选项
887
+ * @param {String} [options.url] - url地址
888
+ * @param {String|Array} [options.key] - 参数名
889
+ * @return {string} 删除参数后的url
775
890
  **/
776
891
  export const delUrlParam = function ({ url, key }) {
777
892
  let pUrl = '';
@@ -817,7 +932,7 @@ export const delUrlParam = function ({ url, key }) {
817
932
 
818
933
  /**
819
934
  * domEval
820
- * @desc:添加js内容
935
+ * @desc 添加js内容
821
936
  * @author huangbo
822
937
  * @date 2022年5月7日
823
938
  * @param {String} [code] - js内容
@@ -830,10 +945,10 @@ export const domEval = function (code) {
830
945
 
831
946
  /**
832
947
  * downloadFile
833
- * @desc:下载附件
948
+ * @desc 下载附件
834
949
  * @author huangbo
835
950
  * @date 2022年5月7日
836
- * @param {String} [code] - js内容
951
+ * @param {String} fileUrl - 文件下载地址
837
952
  **/
838
953
  export const downloadFile = function (fileUrl) {
839
954
  const link = document.createElement('a');
@@ -847,10 +962,11 @@ export const downloadFile = function (fileUrl) {
847
962
 
848
963
  /**
849
964
  * encode
850
- * @desc:加密
965
+ * @desc 加密
851
966
  * @author huangbo
852
967
  * @date 2022年5月7日
853
- * @param {string} [data] - 被加密的字符串
968
+ * @param {string} value - 被加密的字符串
969
+ * @return {string} 加密后的字符串
854
970
  **/
855
971
  export const encode = function (value) {
856
972
  let kleng = publicKey.length;
@@ -874,11 +990,11 @@ export const encode = function (value) {
874
990
 
875
991
  /**
876
992
  * decode
877
- * @desc:解密
993
+ * @desc 解密
878
994
  * @author huangbo
879
995
  * @date 2022年5月7日
880
- * @param {string} [value] - 被解密的加密字符串
881
- * @param {string} [key] - 私钥
996
+ * @param {string} value - 被解密的加密字符串
997
+ * @return {string} 解密后的字符串
882
998
  **/
883
999
  export const decode = function (value) {
884
1000
  let kleng = publicKey.length;
@@ -905,11 +1021,14 @@ export const decode = function (value) {
905
1021
  };
906
1022
 
907
1023
  /**
908
- * 排除属性
909
- * @desc:exclAttribute
1024
+ * exclAttribute
1025
+ * @desc 排除对象中的指定属性
910
1026
  * @author huangbo
911
1027
  * @date 2022年5月7日
912
- * @param {String/Array} [attrs] - 要排除的属性
1028
+ * @param {Object} options - 参数选项
1029
+ * @param {String|Array} [options.attrs='value'] - 要排除的属性
1030
+ * @param {Object} options.data - 源对象
1031
+ * @return {Object} 排除属性后的新对象
913
1032
  **/
914
1033
  // 用于缓存exclAttribute的结果
915
1034
  const _exclAttributeCache = new Map();
@@ -954,8 +1073,9 @@ export const exclAttribute = ({ attrs = 'value', data }) => {
954
1073
  * @desc 导出表格数据
955
1074
  * @author huangbo
956
1075
  * @date 2022年5月7日
957
- * @param {Object} [data] - 导出数据
958
- * @param {String} [name] - 文件名
1076
+ * @param {Object} options - 参数选项
1077
+ * @param {Object} options.data - 导出数据
1078
+ * @param {String} [options.name] - 文件名
959
1079
  **/
960
1080
  export const exportXls = function ({ data, name }) {
961
1081
  // 创建Blob对象
@@ -987,6 +1107,7 @@ export const exportXls = function ({ data, name }) {
987
1107
  * @param {Boolean} [deep] - 是否深拷贝
988
1108
  * @param {Object} [target] - 目标对象
989
1109
  * @param {...Object} [source] - 源对象
1110
+ * @return {Object} 拷贝后的对象
990
1111
  **/
991
1112
  export const extend = function () {
992
1113
  // target目标对象 source源对象
@@ -1043,7 +1164,8 @@ export const extend = function () {
1043
1164
  * @desc 获取数据类型
1044
1165
  * @author huangbo
1045
1166
  * @date 2022年5月7日
1046
- * @param {Any} [obj] - 任意值
1167
+ * @param {*} [obj] - 任意值
1168
+ * @return {string} 数据类型
1047
1169
  **/
1048
1170
  export const getObjectType = function (obj) {
1049
1171
  return Object.prototype.toString.call(obj).replace(/\[object (.*)\]/, '$1').toLowerCase();
@@ -1054,25 +1176,44 @@ export const getObjectType = function (obj) {
1054
1176
  * @desc 获取URL参数
1055
1177
  * @author huangbo
1056
1178
  * @date 2022年5月7日
1057
- * @param {String} [url] - url地址
1179
+ * @param {Object} options - 参数配置对象
1180
+ * @param {String} [options.url] - url地址,可选
1181
+ * @param {String} [options.name] - 参数名,可选
1182
+ * @return {Object|string} 参数对象或指定参数值
1058
1183
  **/
1059
- export const getParams = function (key, url) {
1184
+ export const getParams = function ({url, name} = {}) {
1060
1185
  let href = '';
1061
1186
  try {
1062
1187
  href = window.top.location.href;
1063
1188
  } catch (e) {
1064
1189
  href = window.location.href;
1065
1190
  }
1191
+
1066
1192
  const paramStr = (url || href).split('?')[1] || '';
1067
- if (!paramStr) return '';
1068
1193
  const params = {};
1069
- paramStr.split('&').forEach((item) => {
1070
- const [k, value] = item.split('=');
1071
- if (k) {
1072
- params[decodeURIComponent(k)] = decodeURIComponent(value || '');
1073
- }
1074
- });
1075
- return key ? params[key] || '' : params;
1194
+
1195
+ if (paramStr) {
1196
+ paramStr.split('&').forEach((item) => {
1197
+ const [k, value] = item.split('=');
1198
+ if (k) {
1199
+ const decodedKey = decodeURIComponent(k);
1200
+ const decodedValue = decodeURIComponent(value || '');
1201
+
1202
+ // 处理重复参数,保存为数组
1203
+ if (params[decodedKey] !== undefined) {
1204
+ if (!Array.isArray(params[decodedKey])) {
1205
+ params[decodedKey] = [params[decodedKey]];
1206
+ }
1207
+ params[decodedKey].push(decodedValue);
1208
+ } else {
1209
+ params[decodedKey] = decodedValue;
1210
+ }
1211
+ }
1212
+ });
1213
+ }
1214
+
1215
+ return name ? params[name] || '' : params;
1216
+
1076
1217
  };
1077
1218
 
1078
1219
  /**
@@ -1080,7 +1221,8 @@ export const getParams = function (key, url) {
1080
1221
  * @desc 获取并执行JS文件
1081
1222
  * @author huangbo
1082
1223
  * @date 2022年5月7日
1083
- * @param {String} [url] - 脚本地址
1224
+ * @param {String} url - 脚本地址
1225
+ * @return {Promise} Promise对象
1084
1226
  **/
1085
1227
  export const getScript = function (url) {
1086
1228
  return new Promise((resolve, reject) => {
@@ -1105,6 +1247,7 @@ export const getScript = function (url) {
1105
1247
  * @date 2022年5月7日
1106
1248
  * @param {Element} [el] - dom元素
1107
1249
  * @param {String} [style] - 样式名称
1250
+ * @return {string} 样式值
1108
1251
  **/
1109
1252
  export const getStyle = function (el, style) {
1110
1253
  if (!el || !style) return '';
@@ -1129,6 +1272,7 @@ export const getStyle = function (el, style) {
1129
1272
  * @author huangbo
1130
1273
  * @date 2022年5月7日
1131
1274
  * @param {String} [type] - 类型
1275
+ * @return {string} 转换后的类型文本
1132
1276
  **/
1133
1277
  export const getTypeName = function (type) {
1134
1278
  if (!type) return '';
@@ -1154,8 +1298,9 @@ export const getTypeName = function (type) {
1154
1298
  * @desc 处理数据获取值
1155
1299
  * @author huangbo
1156
1300
  * @date 2022年5月7日
1157
- * @param {Any} [obj] - 数据源
1301
+ * @param {Object} [obj] - 数据源
1158
1302
  * @param {String} [key] - 键名,支持a.b.c形式
1303
+ * @return {*} 获取的值
1159
1304
  **/
1160
1305
  export const getValues = function (obj, key) {
1161
1306
  if (!obj || !key) return obj;
@@ -1173,6 +1318,7 @@ export const getValues = function (obj, key) {
1173
1318
  * @desc 获取缩放比
1174
1319
  * @author huangbo
1175
1320
  * @date 2022年5月7日
1321
+ * @return {number} 缩放比例
1176
1322
  **/
1177
1323
  export const getZoom = function () {
1178
1324
  // 获取当前页面的缩放比例
@@ -1203,6 +1349,7 @@ export const getZoom = function () {
1203
1349
  * @desc 获取同域top窗口
1204
1350
  * @author huangbo
1205
1351
  * @date 2022年5月7日
1352
+ * @return {Window} 同域的top窗口
1206
1353
  **/
1207
1354
  export const getMyWinTop = function () {
1208
1355
  const win = window.__WUJIE_RAW_WINDOW__
@@ -1228,6 +1375,7 @@ export const getMyWinTop = function () {
1228
1375
  * @author huangbo
1229
1376
  * @date 2022年5月7日
1230
1377
  * @param {String} [str] - 字符串
1378
+ * @return {number} 字符个数(中文算2个,其他算1个)
1231
1379
  **/
1232
1380
  export const getLength = function (str) {
1233
1381
  if (!str) return 0;
@@ -1252,6 +1400,7 @@ export const getLength = function (str) {
1252
1400
  * @author huangbo
1253
1401
  * @date 2022年5月7日
1254
1402
  * @param {String} [url] - url地址
1403
+ * @return {string} 更新时间戳后的url
1255
1404
  **/
1256
1405
  export const timestampUrl = function (url) {
1257
1406
  if (!url) return '';
@@ -1273,7 +1422,8 @@ export const timestampUrl = function (url) {
1273
1422
  * @author huangbo
1274
1423
  * @date 2022年5月7日
1275
1424
  * @param {String} [str] - 被检测字符串
1276
- * @param {String} [chars] - 目标字符
1425
+ * @param {String|Array} [chars] - 目标字符
1426
+ * @return {boolean} 是否包含目标字符
1277
1427
  **/
1278
1428
  export const hasChars = function (str, chars) {
1279
1429
  if (!str || !chars) return false;
@@ -1295,8 +1445,9 @@ export const hasChars = function (str, chars) {
1295
1445
  * @desc 验证值是否相同
1296
1446
  * @author huangbo
1297
1447
  * @date 2022年5月7日
1298
- * @param {Any} [a] - 第一个值
1299
- * @param {Any} [b] - 第二个值
1448
+ * @param {*} [a] - 第一个值
1449
+ * @param {*} [b] - 第二个值
1450
+ * @return {boolean} 值是否相同
1300
1451
  **/
1301
1452
  export const identical = function (a, b) {
1302
1453
  // 如果是严格相等,直接返回
@@ -1340,7 +1491,8 @@ export const identical = function (a, b) {
1340
1491
  * @date 2022年5月7日
1341
1492
  * @param {Array} [arr] - 源数组
1342
1493
  * @param {String} [key] - 键名
1343
- * @param {String} [value] - 键值
1494
+ * @param {*} [value] - 键值
1495
+ * @return {number} 数组下标,没找到返回-1
1344
1496
  **/
1345
1497
  export const indexOfObj = function (arr, key, value) {
1346
1498
  if (!Array.isArray(arr) || !key) return -1;
@@ -1357,7 +1509,8 @@ export const indexOfObj = function (arr, key, value) {
1357
1509
  * @desc 判断是否为空
1358
1510
  * @author huangbo
1359
1511
  * @date 2022年5月7日
1360
- * @param {Any} [value] - 任意值
1512
+ * @param {*} [value] - 任意值
1513
+ * @return {boolean} 是否为空
1361
1514
  **/
1362
1515
  export const isEmpty = function (value) {
1363
1516
  if (value === undefined || value === null) {
@@ -1380,7 +1533,8 @@ export const isEmpty = function (value) {
1380
1533
  * @desc 判断是否存在
1381
1534
  * @author huangbo
1382
1535
  * @date 2022年5月7日
1383
- * @param {Any} [value] - 任意值
1536
+ * @param {*} [value] - 任意值
1537
+ * @return {boolean} 是否存在
1384
1538
  **/
1385
1539
  export const isExist = function (value) {
1386
1540
  return value !== undefined && value !== null;
@@ -1391,7 +1545,8 @@ export const isExist = function (value) {
1391
1545
  * @desc 判断是否是函数
1392
1546
  * @author huangbo
1393
1547
  * @date 2022年5月7日
1394
- * @param {Any} [value] - 任意值
1548
+ * @param {*} [value] - 任意值
1549
+ * @return {boolean} 是否是函数
1395
1550
  **/
1396
1551
  export const isFunction = function (value) {
1397
1552
  return typeof value === 'function';
@@ -1402,8 +1557,9 @@ export const isFunction = function (value) {
1402
1557
  * @desc 判断对象是否相等
1403
1558
  * @author huangbo
1404
1559
  * @date 2022年5月7日
1405
- * @param {Object} [a] - 第一个对象
1406
- * @param {Object} [b] - 第二个对象
1560
+ * @param {*} [a] - 第一个值
1561
+ * @param {*} [b] - 第二个值
1562
+ * @return {boolean} 对象是否相等
1407
1563
  **/
1408
1564
  export const isObjectEqual = function (a, b) {
1409
1565
  // 如果两者严格相等,直接返回true
@@ -1461,22 +1617,15 @@ export const isObjectEqual = function (a, b) {
1461
1617
  return true;
1462
1618
  };
1463
1619
 
1464
- /**
1465
- * joinUrl
1466
- * @desc:判断url地址是否以字符开头,没有则添加
1467
- * @author huangbo
1468
- * @date 2022年5月7日
1469
- * @param {string} [reg] - 域名或者路径
1470
- * @param {string/array} [url] - 地址
1471
- * @param {boolean} [single] - 是否做js沙箱隔离
1472
- **/
1473
1620
  /**
1474
1621
  * joinUrl
1475
1622
  * @desc 拼接路径
1476
1623
  * @author huangbo
1477
1624
  * @date 2022年5月7日
1478
- * @param {string} [url] - 地址
1479
- * @param {string/array} [reg] - 域名或者路径前缀
1625
+ * @param {Object} options - 参数选项
1626
+ * @param {string} options.url - 地址
1627
+ * @param {string|array} options.reg - 域名或者路径前缀
1628
+ * @return {string} 拼接后的url
1480
1629
  **/
1481
1630
  export const joinUrl = function ({ url, reg }) {
1482
1631
  // 类型检查
@@ -1526,7 +1675,7 @@ export const joinUrl = function ({ url, reg }) {
1526
1675
  * @desc 加载JS文件
1527
1676
  * @author huangbo
1528
1677
  * @date 2022年5月7日
1529
- * @param {String} [url] - JS文件地址
1678
+ * @param {String} url - JS文件地址
1530
1679
  * @param {Function} [callback] - 回调函数
1531
1680
  **/
1532
1681
  export const loadJs = function (url, callback) {
@@ -1545,7 +1694,8 @@ export const loadJs = function (url, callback) {
1545
1694
  * @desc 加载动画
1546
1695
  * @author huangbo
1547
1696
  * @date 2022年5月7日
1548
- * @param {String} [text] - 提示文本
1697
+ * @param {String} [text='请求中...'] - 提示文本
1698
+ * @return {Object} Loading实例
1549
1699
  **/
1550
1700
  export const loading = function (text = '请求中...') {
1551
1701
  return Loading.service({
@@ -1561,6 +1711,7 @@ export const loading = function (text = '请求中...') {
1561
1711
  * @author huangbo
1562
1712
  * @date 2022年5月7日
1563
1713
  * @param {String} [str] - 字符串
1714
+ * @return {string} 转换后的字符串
1564
1715
  **/
1565
1716
  export const lowerCase = function (str) {
1566
1717
  if (typeof str !== 'string') return str;
@@ -1573,6 +1724,7 @@ export const lowerCase = function (str) {
1573
1724
  * @author huangbo
1574
1725
  * @date 2022年5月7日
1575
1726
  * @param {Element} [el] - dom元素
1727
+ * @return {boolean} 是否溢出
1576
1728
  **/
1577
1729
  export const overbrim = function (el) {
1578
1730
  if (!el) return false;
@@ -1603,6 +1755,7 @@ export const overbrim = function (el) {
1603
1755
  * @author huangbo
1604
1756
  * @date 2022年5月7日
1605
1757
  * @param {Object} [obj] - 源对象
1758
+ * @return {string} URL参数字符串
1606
1759
  **/
1607
1760
  export const queryParams = function (obj) {
1608
1761
  if (!obj || typeof obj !== 'object') return '';
@@ -1629,6 +1782,7 @@ export const queryParams = function (obj) {
1629
1782
  * @author huangbo
1630
1783
  * @date 2022年5月7日
1631
1784
  * @param {Function} [callback] - 回调函数
1785
+ * @return {Function} 移除监听器的函数
1632
1786
  **/
1633
1787
  export const receiveMessage = function (callback) {
1634
1788
  const handleMessage = function (event) {
@@ -1650,7 +1804,8 @@ export const receiveMessage = function (callback) {
1650
1804
  * @author huangbo
1651
1805
  * @date 2022年5月7日
1652
1806
  * @param {Number} [num] - 数字
1653
- * @param {Number} [digits] - 小数位数
1807
+ * @param {Number} [digits=2] - 小数位数
1808
+ * @return {string} 补全后的数字字符串
1654
1809
  **/
1655
1810
  export const replenish = function (num, digits = 2) {
1656
1811
  if (typeof num !== 'number' || isNaN(num)) {
@@ -1666,6 +1821,7 @@ export const replenish = function (num, digits = 2) {
1666
1821
  * @author huangbo
1667
1822
  * @date 2022年5月7日
1668
1823
  * @param {Number} [num] - 金额
1824
+ * @return {string} 人民币大写
1669
1825
  **/
1670
1826
  export const rmbToCapital = function (num) {
1671
1827
  // 检查输入是否为数字
@@ -1767,8 +1923,9 @@ export const setScale = function (scale) {
1767
1923
  * @desc 向iframe发送信息
1768
1924
  * @author huangbo
1769
1925
  * @date 2022年5月7日
1770
- * @param {String} [id] - iframe元素id
1771
- * @param {Object} [data] - 发送的数据
1926
+ * @param {Object} options - 参数选项
1927
+ * @param {String} options.id - iframe元素id
1928
+ * @param {Object} options.data - 发送的数据
1772
1929
  **/
1773
1930
  export const sendMessage = function ({ id, data }) {
1774
1931
  const iframe = document.getElementById(id);
@@ -1789,7 +1946,7 @@ export const sendMessage = function ({ id, data }) {
1789
1946
  * @desc 设置浏览器图标
1790
1947
  * @author huangbo
1791
1948
  * @date 2022年5月7日
1792
- * @param {String} [url] - 图标URL
1949
+ * @param {String} url - 图标URL
1793
1950
  **/
1794
1951
  export const setFavicon = function (url) {
1795
1952
  if (!url) {
@@ -1821,7 +1978,8 @@ export const setFavicon = function (url) {
1821
1978
  * @desc 求和
1822
1979
  * @author huangbo
1823
1980
  * @date 2022年5月7日
1824
- * @param {...number} [numbers] - 数字
1981
+ * @param {...number} numbers - 数字
1982
+ * @return {number} 数字的总和
1825
1983
  **/
1826
1984
  export const sum = function (...numbers) {
1827
1985
  // 确保所有参数都是有效的数字
@@ -1839,6 +1997,7 @@ export const sum = function (...numbers) {
1839
1997
  * @date 2022年5月7日
1840
1998
  * @param {String} [str] - 源字符串
1841
1999
  * @param {String} [searchString] - 搜索字符串
2000
+ * @return {boolean} 是否以指定字符开头
1842
2001
  **/
1843
2002
  export const startWith = function (str, searchString) {
1844
2003
  if (typeof str !== 'string' || typeof searchString !== 'string') {
@@ -1854,6 +2013,7 @@ export const startWith = function (str, searchString) {
1854
2013
  * @date 2022年5月7日
1855
2014
  * @param {String} [str] - 源字符串
1856
2015
  * @param {Number} [length] - 提取长度
2016
+ * @return {string} 提取后的字符串
1857
2017
  **/
1858
2018
  export const takeLeft = function (str, length) {
1859
2019
  if (typeof str !== 'string' || typeof length !== 'number' || length < 0) {
@@ -1869,6 +2029,7 @@ export const takeLeft = function (str, length) {
1869
2029
  * @date 2022年5月7日
1870
2030
  * @param {String} [str] - 源字符串
1871
2031
  * @param {Number} [length] - 提取长度
2032
+ * @return {string} 提取后的字符串
1872
2033
  **/
1873
2034
  export const takeRight = function (str, length) {
1874
2035
  if (typeof str !== 'string' || typeof length !== 'number' || length < 0) {
@@ -1883,6 +2044,7 @@ export const takeRight = function (str, length) {
1883
2044
  * @author huangbo
1884
2045
  * @date 2022年5月7日
1885
2046
  * @param {String} [str] - 源字符串
2047
+ * @return {string} 删除空格后的字符串
1886
2048
  **/
1887
2049
  export const trimWhitespace = function (str) {
1888
2050
  if (typeof str !== 'string') {
@@ -1897,7 +2059,8 @@ export const trimWhitespace = function (str) {
1897
2059
  * @author huangbo
1898
2060
  * @date 2022年5月7日
1899
2061
  * @param {Number} [num] - 浮点数
1900
- * @param {Number} [digits] - 小数位数
2062
+ * @param {Number} [digits=2] - 小数位数
2063
+ * @return {number} 保留小数位后的数字
1901
2064
  **/
1902
2065
  export const toFixed = function (num, digits = 2) {
1903
2066
  if (typeof num !== 'number' || isNaN(num)) {
@@ -1913,6 +2076,7 @@ export const toFixed = function (num, digits = 2) {
1913
2076
  * @author huangbo
1914
2077
  * @date 2022年5月7日
1915
2078
  * @param {String} [str] - 函数字符串
2079
+ * @return {Function|null} 转换后的函数或null
1916
2080
  **/
1917
2081
  export const toFunction = function (str) {
1918
2082
  if (typeof str !== 'string') {
@@ -1961,6 +2125,7 @@ export const updateTheme = function (color) {
1961
2125
  * @author huangbo
1962
2126
  * @date 2022年5月7日
1963
2127
  * @param {String} [str] - 字符串
2128
+ * @return {string} 转换后的字符串
1964
2129
  **/
1965
2130
  export const upperType = function (str) {
1966
2131
  if (typeof str !== 'string') {
@@ -1974,25 +2139,40 @@ export const upperType = function (str) {
1974
2139
  * @desc 对象转url拼接参数
1975
2140
  * @author huangbo
1976
2141
  * @date 2022年5月7日
1977
- * @param {String} [url] - 源url
1978
- * @param {Object} [params] - 参数对象
2142
+ * @param {String} [options.url] - 源url
2143
+ * @param {Object} [options.params] - 参数对象
2144
+ * @param {Boolean} [options.timestamp] - 是否添加时间戳
1979
2145
  **/
1980
- export const urlJoinParams = function (url, params) {
2146
+ export const urlJoinParams = function ({url = '', params = {}, timestamp = false} = {}) {
1981
2147
  if (typeof url !== 'string') {
1982
- return url;
2148
+ return '';
1983
2149
  }
1984
- if (!params || typeof params !== 'object') {
1985
- return url;
2150
+ if (!url) {
2151
+ return '';
2152
+ }
2153
+ // 处理URL中的锚点
2154
+ let urlWithoutHash = url;
2155
+ let hash = '';
2156
+ const hashIndex = url.indexOf('#');
2157
+ if (hashIndex > -1) {
2158
+ urlWithoutHash = url.slice(0, hashIndex);
2159
+ hash = url.slice(hashIndex);
2160
+ }
2161
+ // 复制参数对象以避免修改原对象
2162
+ const paramsCopy = {...params};
2163
+ // 添加时间戳
2164
+ if (timestamp) {
2165
+ paramsCopy._t = Date.now();
1986
2166
  }
1987
2167
  // 将参数对象转换为URL参数字符串
1988
- const queryString = queryParams(params);
2168
+ const queryString = queryParams(paramsCopy);
1989
2169
  if (!queryString) {
1990
2170
  return url;
1991
2171
  }
1992
2172
  // 检查URL是否已经包含查询参数
1993
- const hasQuery = url.includes('?');
2173
+ const hasQuery = urlWithoutHash.includes('?');
1994
2174
  // 拼接URL和查询参数
1995
- return `${url}${hasQuery ? '&' : '?'}${queryString}`;
2175
+ return `${urlWithoutHash}${hasQuery ? '&' : '?'}${queryString}${hash}`;
1996
2176
  };
1997
2177
 
1998
2178
  /**