@gx-design-vue/pro-utils 0.1.3 → 0.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -2
  3. package/dist/array/index.d.ts +5 -0
  4. package/dist/array/index.js +6 -0
  5. package/dist/array/slice.d.ts +11 -0
  6. package/dist/array/slice.js +29 -0
  7. package/dist/array/sort.d.ts +41 -0
  8. package/dist/array/sort.js +65 -0
  9. package/dist/array/tree.d.ts +83 -0
  10. package/dist/array/tree.js +157 -0
  11. package/dist/array/unique.d.ts +12 -0
  12. package/dist/array/unique.js +14 -0
  13. package/dist/base64/index.d.ts +26 -0
  14. package/dist/base64/index.js +106 -0
  15. package/dist/class/index.d.ts +2 -0
  16. package/dist/class/index.js +3 -0
  17. package/dist/class/prefix.d.ts +25 -0
  18. package/dist/class/prefix.js +15 -0
  19. package/dist/clone/cloneDeep.d.ts +30 -0
  20. package/dist/clone/cloneDeep.js +35 -0
  21. package/dist/clone/cloneDeepWith.d.ts +14 -0
  22. package/dist/clone/cloneDeepWith.js +150 -0
  23. package/dist/clone/getTag.d.ts +10 -0
  24. package/dist/clone/getTag.js +13 -0
  25. package/dist/clone/index.d.ts +3 -0
  26. package/dist/clone/index.js +4 -0
  27. package/dist/clone/symbols.d.ts +10 -0
  28. package/dist/clone/symbols.js +13 -0
  29. package/dist/clone/tags.d.ts +47 -0
  30. package/dist/clone/tags.js +48 -0
  31. package/dist/dom/event.d.ts +21 -0
  32. package/dist/dom/event.js +26 -0
  33. package/dist/dom/index.d.ts +5 -0
  34. package/dist/dom/index.js +6 -0
  35. package/dist/dom/measure.d.ts +19 -0
  36. package/dist/dom/measure.js +42 -0
  37. package/dist/dom/raf.d.ts +14 -0
  38. package/dist/dom/raf.js +44 -0
  39. package/dist/dom/scroll.d.ts +20 -0
  40. package/dist/dom/scroll.js +97 -0
  41. package/dist/file/config.d.ts +13 -0
  42. package/dist/file/config.js +81 -0
  43. package/dist/file/convert.d.ts +41 -0
  44. package/dist/file/convert.js +69 -0
  45. package/dist/file/index.d.ts +5 -0
  46. package/dist/file/index.js +6 -0
  47. package/dist/file/media.d.ts +35 -0
  48. package/dist/file/media.js +161 -0
  49. package/dist/file/type.d.ts +25 -0
  50. package/dist/file/type.js +58 -0
  51. package/dist/function/copy.d.ts +12 -0
  52. package/dist/function/copy.js +13 -0
  53. package/dist/function/getValue.d.ts +12 -0
  54. package/dist/function/getValue.js +19 -0
  55. package/dist/function/index.d.ts +5 -0
  56. package/dist/function/index.js +6 -0
  57. package/dist/function/object.d.ts +24 -0
  58. package/dist/function/object.js +33 -0
  59. package/dist/function/run.d.ts +11 -0
  60. package/dist/function/run.js +15 -0
  61. package/dist/index.d.ts +59 -26
  62. package/dist/index.js +61 -0
  63. package/dist/is/base64.d.ts +17 -0
  64. package/dist/is/base64.js +27 -0
  65. package/dist/is/browser.d.ts +9 -0
  66. package/dist/is/browser.js +14 -0
  67. package/dist/is/deepEqual.d.ts +13 -0
  68. package/dist/is/deepEqual.js +62 -0
  69. package/dist/is/device.d.ts +21 -0
  70. package/dist/is/device.js +37 -0
  71. package/dist/is/equal.d.ts +12 -0
  72. package/dist/is/equal.js +34 -0
  73. package/dist/is/img.d.ts +10 -0
  74. package/dist/is/img.js +13 -0
  75. package/dist/is/index.d.ts +16 -0
  76. package/dist/is/index.js +17 -0
  77. package/dist/is/nil.d.ts +17 -0
  78. package/dist/is/nil.js +22 -0
  79. package/dist/is/plainObject.d.ts +17 -0
  80. package/dist/is/plainObject.js +30 -0
  81. package/dist/is/primitive.d.ts +10 -0
  82. package/dist/is/primitive.js +13 -0
  83. package/dist/is/server.d.ts +9 -0
  84. package/dist/is/server.js +10 -0
  85. package/dist/is/type.d.ts +60 -0
  86. package/dist/is/type.js +84 -0
  87. package/dist/is/typedArray.d.ts +30 -0
  88. package/dist/is/typedArray.js +33 -0
  89. package/dist/is/unsafeProperty.d.ts +10 -0
  90. package/dist/is/unsafeProperty.js +18 -0
  91. package/dist/is/url.d.ts +10 -0
  92. package/dist/is/url.js +20 -0
  93. package/dist/is/valid.d.ts +17 -0
  94. package/dist/is/valid.js +23 -0
  95. package/dist/merge/index.d.ts +19 -5
  96. package/dist/merge/index.js +42 -0
  97. package/dist/merge/mergeWith.d.ts +12 -0
  98. package/dist/merge/mergeWith.js +31 -0
  99. package/dist/merge/useDeepMege.d.ts +46 -0
  100. package/dist/merge/useDeepMege.js +56 -0
  101. package/dist/number/chinese.d.ts +10 -0
  102. package/dist/number/chinese.js +46 -0
  103. package/dist/number/format.d.ts +27 -0
  104. package/dist/number/format.js +72 -0
  105. package/dist/number/index.d.ts +3 -0
  106. package/dist/number/index.js +4 -0
  107. package/dist/object/classNames.d.ts +10 -0
  108. package/dist/object/classNames.js +30 -0
  109. package/dist/object/index.d.ts +5 -0
  110. package/dist/object/index.js +6 -0
  111. package/dist/object/omitBoolean.d.ts +10 -0
  112. package/dist/object/omitBoolean.js +13 -0
  113. package/dist/object/omitUndefined.d.ts +12 -0
  114. package/dist/object/omitUndefined.js +18 -0
  115. package/dist/object/omitUndefinedAndEmptyArr.d.ts +10 -0
  116. package/dist/object/omitUndefinedAndEmptyArr.js +19 -0
  117. package/dist/pro-utils.esm.js +948 -0
  118. package/dist/pro-utils.js +1 -0
  119. package/dist/string/duration.d.ts +10 -0
  120. package/dist/string/duration.js +25 -0
  121. package/dist/string/empty.d.ts +14 -0
  122. package/dist/string/empty.js +26 -0
  123. package/dist/string/index.d.ts +5 -0
  124. package/dist/string/index.js +6 -0
  125. package/dist/string/nanoid.d.ts +9 -0
  126. package/dist/string/nanoid.js +32 -0
  127. package/dist/string/uuid.d.ts +34 -0
  128. package/dist/string/uuid.js +57 -0
  129. package/dist/table/column.d.ts +27 -0
  130. package/dist/table/column.js +42 -0
  131. package/dist/table/index.d.ts +3 -0
  132. package/dist/table/index.js +4 -0
  133. package/dist/table/page.d.ts +13 -0
  134. package/dist/table/page.js +23 -0
  135. package/dist/typing.d.ts +262 -0
  136. package/dist/typing.js +1 -0
  137. package/dist/vue/index.d.ts +2 -0
  138. package/dist/vue/index.js +3 -0
  139. package/dist/vue/slots.d.ts +56 -0
  140. package/dist/vue/slots.js +89 -0
  141. package/package.json +45 -64
  142. package/dist/classNames/index.d.ts +0 -2
  143. package/dist/components/FieldLabel/index.d.ts +0 -77
  144. package/dist/components/FieldLabel/index.less +0 -107
  145. package/dist/components/LabelIconTip/index.d.ts +0 -20
  146. package/dist/components/LabelIconTip/index.less +0 -38
  147. package/dist/design/ant-design-theme.less +0 -4
  148. package/dist/design/ant-design-vue.less +0 -1
  149. package/dist/design/config.less +0 -2
  150. package/dist/isBrowser/index.d.ts +0 -1
  151. package/dist/isDeepEqualReact/index.d.ts +0 -1
  152. package/dist/isServer.d.ts +0 -2
  153. package/dist/omitBoolean/index.d.ts +0 -6
  154. package/dist/omitUndefined/index.d.ts +0 -5
  155. package/dist/pro-utils.es.js +0 -1044
  156. package/dist/pro-utils.umd.js +0 -1
  157. package/dist/proUtils.less +0 -4
  158. package/dist/scroll/easings.d.ts +0 -1
  159. package/dist/scroll/getScroll.d.ts +0 -2
  160. package/dist/scroll/index.d.ts +0 -4
  161. package/dist/scroll/raf.d.ts +0 -9
  162. package/dist/scroll/scrollTo.d.ts +0 -10
  163. package/dist/scroll/throttleByAnimationFrame.d.ts +0 -5
  164. package/dist/slots/index.d.ts +0 -9
  165. package/dist/style/index.less +0 -2
  166. package/dist/style.css +0 -1
  167. package/dist/style.less +0 -3
  168. package/dist/typings/index.d.ts +0 -30
  169. package/dist/utils/config.d.ts +0 -8
  170. package/dist/utils/index.d.ts +0 -208
  171. package/dist/utils/validate.d.ts +0 -25
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 gx12358
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,76 @@
1
- # Pro Utils
1
+ <div align="center"><a name="readme-top"></a>
2
2
 
3
- ```shell
3
+ <img height="180" src="https://gx12358.cn/resource/img/favicon.ico">
4
+
5
+ <h1>Pro Utils</h1>
6
+
7
+ </div>
8
+
9
+ ## ✨ Features
10
+
11
+ - 🌈 Enterprise-class UI designed for web applications.
12
+ - 📦 A set of high-quality Vue3 components out of the box.
13
+ - 🛡 Written in TypeScript with predictable static types.
14
+ - ⚙️ Whole package of design resources and development tools.
15
+ - 🌍 Internationalization support for dozens of languages.
16
+ - 🎨 Powerful theme customization based on CSS-in-JS.
17
+
18
+ ## 🖥 Environment Support
19
+
20
+ - Modern browsers
21
+ - Server-side Rendering
22
+ - [Electron](https://www.electronjs.org/)
23
+
24
+ | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/electron/electron_48x48.png" alt="Electron" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Electron |
25
+ | --- | --- | --- | --- | --- |
26
+ | Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
27
+
28
+ ## 📦 Install
29
+
30
+ ```bash
31
+ npm install @gx-design-vue/pro-utils
32
+ ```
33
+
34
+ ```bash
35
+ yarn add @gx-design-vue/pro-utils
36
+ ```
37
+
38
+ ```bash
4
39
  pnpm add @gx-design-vue/pro-utils
5
40
  ```
41
+
42
+ ```bash
43
+ bun add @gx-design-vue/pro-utils
44
+ ```
45
+
46
+ ## Acknowledgements
47
+
48
+ Antdv Next is inspired by and built upon the following open-source projects.
49
+
50
+ - [Ant Design](https://ant.design/)
51
+ - [Vue.js](https://vuejs.org/)
52
+ - [Vite](https://vitejs.dev/)
53
+
54
+ ## Maintainer
55
+
56
+ [@gx12358](https://github.com/gx12358/vue3-antd-admin)
57
+
58
+ ## Contributors
59
+
60
+ <a href="https://github.com/gx12358/vue3-antd-admin/graphs/contributors">
61
+ <img alt="Contributors" src="https://contrib.rocks/image?repo=gx12358/vue3-antd-admin" />
62
+ </a>
63
+
64
+ ## Special Thanks
65
+
66
+ Thanks to the [vbenjs/vue-vben-admin](https://github.com/gx12358/vue3-antd-admin) project for providing inspiration and reference implementation.
67
+
68
+ ## License
69
+
70
+ [MIT © gx12358-2021](./LICENSE)
71
+
72
+ ## `Star`
73
+
74
+ Thank you very much for the stars from kind-hearted people, thank you for your support :heart:
75
+
76
+ [![Stargazers repo roster for @gx12358/vue3-antd-admin](https://bytecrank.com/nastyox/reporoster/php/stargazersSVG.php?user=gx12358&repo=vue3-antd-admin)](https://github.com/gx12358/vue3-antd-admin/stargazers)
@@ -0,0 +1,5 @@
1
+ import { arraySlice } from "./slice.js";
2
+ import { compareArray, compareArraySort, compareArrayTimeSort, compareTime } from "./sort.js";
3
+ import { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData } from "./tree.js";
4
+ import { arrayUnique } from "./unique.js";
5
+ export { arraySlice, arrayUnique, compareArray, compareArraySort, compareArrayTimeSort, compareTime, filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
@@ -0,0 +1,6 @@
1
+ import { arraySlice } from "./slice.js";
2
+ import { compareArray, compareArraySort, compareArrayTimeSort, compareTime } from "./sort.js";
3
+ import { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData } from "./tree.js";
4
+ import { arrayUnique } from "./unique.js";
5
+
6
+ export { arraySlice, arrayUnique, compareArray, compareArraySort, compareArrayTimeSort, compareTime, filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
@@ -0,0 +1,11 @@
1
+ //#region src/array/slice.d.ts
2
+ /**
3
+ * 数组切片,根据范围筛选数组元素
4
+ *
5
+ * @param data - 源数组
6
+ * @param range - 范围,可以是数字(前n个)或数组[start, end]
7
+ * @returns 筛选后的数组
8
+ */
9
+ declare function arraySlice<T = Record<string, any>>(data: T[], range: number | number[]): T[];
10
+ //#endregion
11
+ export { arraySlice };
@@ -0,0 +1,29 @@
1
+ import { isArray, isNumber } from "../is/type.js";
2
+ import "../is/index.js";
3
+
4
+ //#region src/array/slice.ts
5
+ /**
6
+ * 数组切片,根据范围筛选数组元素
7
+ *
8
+ * @param data - 源数组
9
+ * @param range - 范围,可以是数字(前n个)或数组[start, end]
10
+ * @returns 筛选后的数组
11
+ */
12
+ function arraySlice(data, range) {
13
+ if (!isArray(data)) return [];
14
+ return data?.filter((_, index) => {
15
+ if (isNumber(range)) return index <= range - 1;
16
+ else if (isArray(range) && range.length === 2) {
17
+ const r = range;
18
+ const start = r[0] - 1;
19
+ return index <= (r[1] ? r[1] - 1 : data.length - 1) && index >= start;
20
+ } else if (isArray(range) && range.length === 1) {
21
+ const start = range[0] - 1;
22
+ return index <= data.length - 1 && index >= start;
23
+ }
24
+ return true;
25
+ });
26
+ }
27
+
28
+ //#endregion
29
+ export { arraySlice };
@@ -0,0 +1,41 @@
1
+ //#region src/array/sort.d.ts
2
+ /**
3
+ * 比较数组元素(用于排序)
4
+ *
5
+ * @param obj1 - 第一个对象
6
+ * @param obj2 - 第二个对象
7
+ * @param key - 比较的键
8
+ * @param sort - 排序方向,0 从小到大,1 从大到小
9
+ * @returns 比较结果
10
+ */
11
+ declare function compareArray<T = Record<string, any>>(obj1: T, obj2: T, key: keyof T, sort?: 0 | 1): number;
12
+ /**
13
+ * 比较时间(用于排序)
14
+ *
15
+ * @param obj1 - 第一个对象
16
+ * @param obj2 - 第二个对象
17
+ * @param key - 比较的键
18
+ * @param sort - 排序方向,0 从小到大,1 从大到小
19
+ * @returns 比较结果
20
+ */
21
+ declare function compareTime<T = Record<string, any>>(obj1: T, obj2: T, key: keyof T, sort?: 0 | 1): number;
22
+ /**
23
+ * 数组排序
24
+ *
25
+ * @param dataSource - 数据源
26
+ * @param key - 排序键
27
+ * @param sort - 排序方向,0 从小到大,1 从大到小
28
+ * @returns 排序后的数组
29
+ */
30
+ declare function compareArraySort<T = Record<string, any>>(dataSource: T[], key: keyof T, sort?: 0 | 1): T[];
31
+ /**
32
+ * 按时间排序
33
+ *
34
+ * @param dataSource - 数据源
35
+ * @param key - 排序键
36
+ * @param sort - 排序方向,0 从小到大,1 从大到小
37
+ * @returns 排序后的数组
38
+ */
39
+ declare function compareArrayTimeSort<T = Record<string, any>>(dataSource: T[], key: keyof T, sort?: 0 | 1): T[];
40
+ //#endregion
41
+ export { compareArray, compareArraySort, compareArrayTimeSort, compareTime };
@@ -0,0 +1,65 @@
1
+ import { isNumber } from "../is/type.js";
2
+ import "../is/index.js";
3
+
4
+ //#region src/array/sort.ts
5
+ /**
6
+ * 比较数组元素(用于排序)
7
+ *
8
+ * @param obj1 - 第一个对象
9
+ * @param obj2 - 第二个对象
10
+ * @param key - 比较的键
11
+ * @param sort - 排序方向,0 从小到大,1 从大到小
12
+ * @returns 比较结果
13
+ */
14
+ function compareArray(obj1, obj2, key, sort = 0) {
15
+ const newType = isNumber(sort) ? sort === 0 || sort === 1 ? sort : 0 : 0;
16
+ const prev = obj1[key];
17
+ const next = obj2[key];
18
+ let result = 0;
19
+ if (prev < next) result = newType === 0 ? -1 : 0;
20
+ else if (prev > next) result = newType === 0 ? 0 : -1;
21
+ return result;
22
+ }
23
+ /**
24
+ * 比较时间(用于排序)
25
+ *
26
+ * @param obj1 - 第一个对象
27
+ * @param obj2 - 第二个对象
28
+ * @param key - 比较的键
29
+ * @param sort - 排序方向,0 从小到大,1 从大到小
30
+ * @returns 比较结果
31
+ */
32
+ function compareTime(obj1, obj2, key, sort = 0) {
33
+ const newType = isNumber(sort) ? sort === 0 || sort === 1 ? sort : 0 : 0;
34
+ const prev = new Date(obj1[key]);
35
+ const next = new Date(obj2[key]);
36
+ let result = 0;
37
+ if (prev < next) result = newType === 0 ? -1 : 0;
38
+ else if (prev > next) result = newType === 0 ? 0 : -1;
39
+ return result;
40
+ }
41
+ /**
42
+ * 数组排序
43
+ *
44
+ * @param dataSource - 数据源
45
+ * @param key - 排序键
46
+ * @param sort - 排序方向,0 从小到大,1 从大到小
47
+ * @returns 排序后的数组
48
+ */
49
+ function compareArraySort(dataSource, key, sort = 0) {
50
+ return dataSource.sort((a, b) => compareArray(a, b, key, sort));
51
+ }
52
+ /**
53
+ * 按时间排序
54
+ *
55
+ * @param dataSource - 数据源
56
+ * @param key - 排序键
57
+ * @param sort - 排序方向,0 从小到大,1 从大到小
58
+ * @returns 排序后的数组
59
+ */
60
+ function compareArrayTimeSort(dataSource, key, sort = 0) {
61
+ return dataSource.sort((a, b) => compareTime(a, b, key, sort));
62
+ }
63
+
64
+ //#endregion
65
+ export { compareArray, compareArraySort, compareArrayTimeSort, compareTime };
@@ -0,0 +1,83 @@
1
+ import { BasicTablePageConfig, RecordType } from "../typing.js";
2
+
3
+ //#region src/array/tree.d.ts
4
+ /**
5
+ * 获取树形结构最深的层级数
6
+ *
7
+ * @param data - 树形数据
8
+ * @param childrenKey - 子节点键名
9
+ * @returns 最大深度
10
+ */
11
+ declare function getMaxFloor<T>(data: T[], childrenKey?: keyof T): number;
12
+ /**
13
+ * 树形转平级
14
+ *
15
+ * @param data - 树形数据
16
+ * @param filed - 子节点键名
17
+ * @returns 平级数组
18
+ */
19
+ declare function getLevelData<T extends RecordType = RecordType>(data: T[], filed?: keyof T): T[];
20
+ /**
21
+ * 构造树型结构数据
22
+ *
23
+ * @param source - 数据源
24
+ * @param options - 配置选项
25
+ * @returns 树形数据
26
+ */
27
+ declare function treeData<T extends RecordType = RecordType>(source: T[], options?: {
28
+ id?: keyof T;
29
+ parentId?: keyof T;
30
+ children?: keyof T;
31
+ rootId?: number | false;
32
+ emptyChildren?: boolean;
33
+ }): T[];
34
+ /**
35
+ * 树形数组按照条件过滤
36
+ *
37
+ * @param tree - 树形数据
38
+ * @param predicate - 过滤条件
39
+ * @returns 过滤后的树
40
+ */
41
+ declare function filterTree<T = any>(tree: T[], predicate: (val: T) => boolean): any[];
42
+ /**
43
+ * 给定指定的 value 值,找到其所有的祖先节点
44
+ *
45
+ * @param tree - 树形数据
46
+ * @param targetValue - 目标值
47
+ * @param fieldNames - 字段名配置
48
+ * @returns 祖先节点值数组
49
+ */
50
+ declare function findValueAndAncestors<T = any>(tree: T[], targetValue: any, fieldNames?: {
51
+ value: 'value';
52
+ children: 'children';
53
+ }): any[];
54
+ /**
55
+ * 树形数组递归查找指定对象
56
+ *
57
+ * @param tree - 树形数据
58
+ * @param value - 目标值
59
+ * @param options - 配置选项
60
+ * @returns 找到的节点
61
+ */
62
+ declare function findSourceByTree<T>(tree: T[], value: any, options?: {
63
+ value: keyof T;
64
+ children: keyof T;
65
+ }): T | undefined;
66
+ /**
67
+ * 获取数组最后一个元素
68
+ *
69
+ * @param data - 数组
70
+ * @returns 最后一个元素
71
+ */
72
+ declare function getArrayLast<T = any>(data: any): T;
73
+ /**
74
+ * 数组(树形)添加序号
75
+ *
76
+ * @param data - 数据
77
+ * @param pageConfig - 分页配置
78
+ * @param childrenKey - 子节点键名
79
+ * @returns 添加序号后的数据
80
+ */
81
+ declare function getSortIndex<T = RecordType>(data: T[] | undefined, pageConfig: BasicTablePageConfig, childrenKey?: keyof T): any[];
82
+ //#endregion
83
+ export { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
@@ -0,0 +1,157 @@
1
+ import { isArray, isObject } from "../is/type.js";
2
+ import "../is/index.js";
3
+
4
+ //#region src/array/tree.ts
5
+ /**
6
+ * 获取树形结构最深的层级数
7
+ *
8
+ * @param data - 树形数据
9
+ * @param childrenKey - 子节点键名
10
+ * @returns 最大深度
11
+ */
12
+ function getMaxFloor(data, childrenKey) {
13
+ if (!Array.isArray(data) || data.length === 0) return 0;
14
+ const key = childrenKey || "children";
15
+ return Math.max(...data.map((item) => {
16
+ const children = item[key];
17
+ return 1 + (children ? getMaxFloor(children, key) : 0);
18
+ }));
19
+ }
20
+ /**
21
+ * 树形转平级
22
+ *
23
+ * @param data - 树形数据
24
+ * @param filed - 子节点键名
25
+ * @returns 平级数组
26
+ */
27
+ function getLevelData(data, filed = "children") {
28
+ let newData = [];
29
+ data.forEach((item) => {
30
+ newData.push(item);
31
+ if (isArray(item[filed]) && item[filed].length > 0) newData = newData.concat(getLevelData(item[filed], filed));
32
+ });
33
+ return newData;
34
+ }
35
+ /**
36
+ * 构造树型结构数据
37
+ *
38
+ * @param source - 数据源
39
+ * @param options - 配置选项
40
+ * @returns 树形数据
41
+ */
42
+ function treeData(source, options) {
43
+ if (!source || !isArray(source) || source?.length === 0) return [];
44
+ const { id = "id", parentId = "parentId", children = "children", emptyChildren = true } = options || {};
45
+ const rootId = options?.rootId ?? 0;
46
+ const cloneData = structuredClone(source);
47
+ return cloneData.map((item) => {
48
+ if (!emptyChildren && item[children] && item[children]?.length === 0) delete item[children];
49
+ return item;
50
+ }).filter((father) => {
51
+ const branchArr = cloneData.filter((child) => father[id] === child[parentId]);
52
+ if (branchArr.length > 0) father[children] = branchArr;
53
+ else if (emptyChildren) father[children] = [];
54
+ return rootId === false ? true : father[parentId] === rootId;
55
+ });
56
+ }
57
+ /**
58
+ * 树形数组按照条件过滤
59
+ *
60
+ * @param tree - 树形数据
61
+ * @param predicate - 过滤条件
62
+ * @returns 过滤后的树
63
+ */
64
+ function filterTree(tree, predicate) {
65
+ return tree.map((node) => {
66
+ const newNode = { ...node };
67
+ if (newNode.children) newNode.children = filterTree(newNode.children, predicate);
68
+ if (predicate(newNode) || newNode.children && newNode.children.length > 0) return newNode;
69
+ return null;
70
+ }).filter(Boolean);
71
+ }
72
+ /**
73
+ * 给定指定的 value 值,找到其所有的祖先节点
74
+ *
75
+ * @param tree - 树形数据
76
+ * @param targetValue - 目标值
77
+ * @param fieldNames - 字段名配置
78
+ * @returns 祖先节点值数组
79
+ */
80
+ function findValueAndAncestors(tree, targetValue, fieldNames) {
81
+ const { value, children } = fieldNames || {
82
+ value: "value",
83
+ children: "children"
84
+ };
85
+ let result = [];
86
+ function dfs(node, path) {
87
+ if (node[value] === targetValue) {
88
+ result = [...path, node[value]];
89
+ return true;
90
+ }
91
+ if (node[children]) {
92
+ for (const child of node[children]) if (dfs(child, [...path, node[value]])) return true;
93
+ }
94
+ return false;
95
+ }
96
+ for (const root of tree) if (dfs(root, [])) break;
97
+ return result;
98
+ }
99
+ /**
100
+ * 树形数组递归查找指定对象
101
+ *
102
+ * @param tree - 树形数据
103
+ * @param value - 目标值
104
+ * @param options - 配置选项
105
+ * @returns 找到的节点
106
+ */
107
+ function findSourceByTree(tree, value, options) {
108
+ const key = options?.value || "id";
109
+ const childrenKey = options?.children || "children";
110
+ for (const node of tree) {
111
+ if (node[key] === value) return node;
112
+ const children = node[childrenKey];
113
+ if (children) {
114
+ const result = findSourceByTree(children, value, options);
115
+ if (result) return result;
116
+ }
117
+ }
118
+ }
119
+ /**
120
+ * 获取数组最后一个元素
121
+ *
122
+ * @param data - 数组
123
+ * @returns 最后一个元素
124
+ */
125
+ function getArrayLast(data) {
126
+ if (data && isArray(data)) return data[data.length - 1];
127
+ return null;
128
+ }
129
+ /**
130
+ * 数组(树形)添加序号
131
+ *
132
+ * @param data - 数据
133
+ * @param pageConfig - 分页配置
134
+ * @param childrenKey - 子节点键名
135
+ * @returns 添加序号后的数据
136
+ */
137
+ function getSortIndex(data = [], pageConfig, childrenKey = "children") {
138
+ function getChildSortIndex(parentSort, data) {
139
+ return data.map((item, index) => {
140
+ const sortIndex = `${parentSort}-${index + 1}`;
141
+ if (item[childrenKey]) item[childrenKey] = getChildSortIndex(sortIndex, item[childrenKey]);
142
+ item.sortIndex = sortIndex;
143
+ return item;
144
+ });
145
+ }
146
+ return structuredClone(data).map((item, key) => {
147
+ const current = isObject(pageConfig) ? pageConfig.current || 1 : 1;
148
+ const pageSize = isObject(pageConfig) ? pageConfig.pageSize || 10 : 10;
149
+ const sortIndex = `${current ? (current - 1) * pageSize + (key + 1) : key + 1}`;
150
+ if (item[childrenKey]) item[childrenKey] = getChildSortIndex(`${sortIndex}`, item[childrenKey]);
151
+ item.sortIndex = sortIndex;
152
+ return item;
153
+ });
154
+ }
155
+
156
+ //#endregion
157
+ export { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
@@ -0,0 +1,12 @@
1
+ import { RecordType } from "../typing.js";
2
+
3
+ //#region src/array/unique.d.ts
4
+ /**
5
+ * 数组去重
6
+ *
7
+ * @param data - 源数组
8
+ * @returns 去重后的新数组
9
+ */
10
+ declare function arrayUnique<T = RecordType>(data: T[]): T[];
11
+ //#endregion
12
+ export { arrayUnique };
@@ -0,0 +1,14 @@
1
+ //#region src/array/unique.ts
2
+ /**
3
+ * 数组去重
4
+ *
5
+ * @param data - 源数组
6
+ * @returns 去重后的新数组
7
+ */
8
+ function arrayUnique(data) {
9
+ const set = new Set(data);
10
+ return Array.from(set);
11
+ }
12
+
13
+ //#endregion
14
+ export { arrayUnique };
@@ -0,0 +1,26 @@
1
+ //#region src/base64/index.d.ts
2
+ /**
3
+ * Base64 编解码类
4
+ */
5
+ declare class Base64 {
6
+ _keyStr: string;
7
+ constructor();
8
+ _utf8_encode(string: string): string;
9
+ _utf8_decode(utftext: string): string;
10
+ /**
11
+ * 加密方法
12
+ *
13
+ * @param input - 要加密的字符串
14
+ * @returns Base64 编码后的字符串
15
+ */
16
+ encode(input: string): string;
17
+ /**
18
+ * 解密方法
19
+ *
20
+ * @param input - 要解密的 Base64 字符串
21
+ * @returns 解码后的字符串
22
+ */
23
+ decode(input: string): string;
24
+ }
25
+ //#endregion
26
+ export { Base64 as default };
@@ -0,0 +1,106 @@
1
+ //#region src/base64/index.ts
2
+ /**
3
+ * Base64 编解码类
4
+ */
5
+ var Base64 = class {
6
+ _keyStr;
7
+ constructor() {
8
+ this._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
9
+ }
10
+ _utf8_encode(string) {
11
+ string = string.replace(/\r\n/g, "\n");
12
+ let utftext = "";
13
+ for (let n = 0; n < string.length; n++) {
14
+ const c = string.charCodeAt(n);
15
+ if (c < 128) utftext += String.fromCharCode(c);
16
+ else if (c > 127 && c < 2048) {
17
+ utftext += String.fromCharCode(c >> 6 | 192);
18
+ utftext += String.fromCharCode(c & 63 | 128);
19
+ } else {
20
+ utftext += String.fromCharCode(c >> 12 | 224);
21
+ utftext += String.fromCharCode(c >> 6 & 63 | 128);
22
+ utftext += String.fromCharCode(c & 63 | 128);
23
+ }
24
+ }
25
+ return utftext;
26
+ }
27
+ _utf8_decode(utftext) {
28
+ let string = "";
29
+ let i = 0;
30
+ let c = 0;
31
+ let c1 = 0;
32
+ let c2 = 0;
33
+ while (i < utftext.length) {
34
+ c = utftext.charCodeAt(i);
35
+ if (c < 128) {
36
+ string += String.fromCharCode(c);
37
+ i++;
38
+ } else if (c > 191 && c < 224) {
39
+ c1 = utftext.charCodeAt(i + 1);
40
+ string += String.fromCharCode((c & 31) << 6 | c1 & 63);
41
+ i += 2;
42
+ } else {
43
+ c1 = utftext.charCodeAt(i + 1);
44
+ c2 = utftext.charCodeAt(i + 2);
45
+ string += String.fromCharCode((c & 15) << 12 | (c1 & 63) << 6 | c2 & 63);
46
+ i += 3;
47
+ }
48
+ }
49
+ return string;
50
+ }
51
+ /**
52
+ * 加密方法
53
+ *
54
+ * @param input - 要加密的字符串
55
+ * @returns Base64 编码后的字符串
56
+ */
57
+ encode(input) {
58
+ let output = "";
59
+ let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
60
+ let i = 0;
61
+ input = this._utf8_encode(input);
62
+ while (i < input.length) {
63
+ chr1 = input.charCodeAt(i++);
64
+ chr2 = input.charCodeAt(i++);
65
+ chr3 = input.charCodeAt(i++);
66
+ enc1 = chr1 >> 2;
67
+ enc2 = (chr1 & 3) << 4 | chr2 >> 4;
68
+ enc3 = (chr2 & 15) << 2 | chr3 >> 6;
69
+ enc4 = chr3 & 63;
70
+ if (Number.isNaN(chr2)) enc3 = enc4 = 64;
71
+ else if (Number.isNaN(chr3)) enc4 = 64;
72
+ output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
73
+ }
74
+ return output;
75
+ }
76
+ /**
77
+ * 解密方法
78
+ *
79
+ * @param input - 要解密的 Base64 字符串
80
+ * @returns 解码后的字符串
81
+ */
82
+ decode(input) {
83
+ let output = "";
84
+ let chr1, chr2, chr3;
85
+ let enc1, enc2, enc3, enc4;
86
+ let i = 0;
87
+ input = input.replace(/[^A-Z0-9+/=]/gi, "");
88
+ while (i < input.length) {
89
+ enc1 = this._keyStr.indexOf(input.charAt(i++));
90
+ enc2 = this._keyStr.indexOf(input.charAt(i++));
91
+ enc3 = this._keyStr.indexOf(input.charAt(i++));
92
+ enc4 = this._keyStr.indexOf(input.charAt(i++));
93
+ chr1 = enc1 << 2 | enc2 >> 4;
94
+ chr2 = (enc2 & 15) << 4 | enc3 >> 2;
95
+ chr3 = (enc3 & 3) << 6 | enc4;
96
+ output = output + String.fromCharCode(chr1);
97
+ if (enc3 !== 64) output = output + String.fromCharCode(chr2);
98
+ if (enc4 !== 64) output = output + String.fromCharCode(chr3);
99
+ }
100
+ output = this._utf8_decode(output);
101
+ return output;
102
+ }
103
+ };
104
+
105
+ //#endregion
106
+ export { Base64 as default };
@@ -0,0 +1,2 @@
1
+ import { PrefixCls, getPrefixCls } from "./prefix.js";
2
+ export { PrefixCls, getPrefixCls };
@@ -0,0 +1,3 @@
1
+ import { getPrefixCls } from "./prefix.js";
2
+
3
+ export { getPrefixCls };