sard-uniapp 1.19.5 → 1.20.1

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 (177) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +1 -1
  3. package/components/calendar/README.md +20 -20
  4. package/components/calendar/calendar.vue +1 -1
  5. package/components/calendar-input/README.md +10 -10
  6. package/components/calendar-input/calendar-input.vue +2 -2
  7. package/components/calendar-month/calendar-month.vue +17 -21
  8. package/components/calendar-popout/calendar-popout.vue +1 -1
  9. package/components/card/README.md +16 -8
  10. package/components/card/card.vue +7 -1
  11. package/components/card/common.d.ts +2 -0
  12. package/components/card/index.scss +30 -2
  13. package/components/card/variables.scss +16 -1
  14. package/components/checkbox/common.d.ts +1 -0
  15. package/components/checkbox/common.js +1 -0
  16. package/components/checkbox-input/checkbox-input.vue +9 -0
  17. package/components/checkbox-popout/README.md +27 -6
  18. package/components/checkbox-popout/checkbox-popout.vue +113 -47
  19. package/components/checkbox-popout/common.d.ts +3 -0
  20. package/components/checkbox-popout/index.scss +16 -0
  21. package/components/config/index.d.ts +6 -0
  22. package/components/config/index.js +6 -0
  23. package/components/datetime-picker/README.md +1 -71
  24. package/components/datetime-picker/common.d.ts +1 -0
  25. package/components/datetime-picker/common.js +21 -8
  26. package/components/datetime-picker/datetime-picker.vue +3 -3
  27. package/components/datetime-picker-input/README.md +10 -10
  28. package/components/datetime-picker-input/datetime-picker-input.vue +2 -2
  29. package/components/datetime-picker-popout/datetime-picker-popout.vue +1 -1
  30. package/components/datetime-range-picker/datetime-range-picker.vue +12 -10
  31. package/components/datetime-range-picker-input/README.md +10 -10
  32. package/components/datetime-range-picker-input/datetime-range-picker-input.vue +2 -2
  33. package/components/datetime-range-picker-popout/README.md +0 -6
  34. package/components/datetime-range-picker-popout/datetime-range-picker-popout.vue +11 -8
  35. package/components/floating-bubble/floating-bubble.vue +3 -3
  36. package/components/form/README.md +19 -19
  37. package/components/form/form.vue +1 -1
  38. package/components/icon/icon.d.ts +1 -1
  39. package/components/indexes/README.md +4 -0
  40. package/components/indexes-nav/indexes-nav.vue +2 -2
  41. package/components/keyboard/common.d.ts +1 -2
  42. package/components/keyboard/common.js +2 -11
  43. package/components/keyboard/keyboard.d.ts +2 -2
  44. package/components/list-item/index.scss +4 -0
  45. package/components/locale/lang/en-US.d.ts +4 -0
  46. package/components/locale/lang/en-US.js +4 -0
  47. package/components/locale/lang/zh-CN.d.ts +4 -0
  48. package/components/locale/lang/zh-CN.js +4 -0
  49. package/components/marquee/README.md +8 -2
  50. package/components/marquee/marquee.vue +9 -1
  51. package/components/notice-bar/README.md +8 -2
  52. package/components/notice-bar/notice-bar.vue +14 -8
  53. package/components/notify/notify.d.ts +1 -1
  54. package/components/notify-agent/notify-agent.d.ts +1 -1
  55. package/components/pagination/pagination.vue +2 -2
  56. package/components/popover/utils.js +4 -4
  57. package/components/pull-down-refresh/common.d.ts +1 -1
  58. package/components/radio/common.d.ts +1 -0
  59. package/components/radio/common.js +1 -0
  60. package/components/radio-input/radio-input.vue +6 -0
  61. package/components/radio-popout/README.md +20 -6
  62. package/components/radio-popout/common.d.ts +2 -0
  63. package/components/radio-popout/index.scss +4 -0
  64. package/components/radio-popout/radio-popout.vue +91 -45
  65. package/components/read-more/README.md +82 -0
  66. package/components/read-more/common.d.ts +24 -0
  67. package/components/read-more/common.js +2 -0
  68. package/components/read-more/index.d.ts +1 -0
  69. package/components/read-more/index.js +1 -0
  70. package/components/read-more/index.scss +41 -0
  71. package/components/read-more/read-more.d.ts +20 -0
  72. package/components/read-more/read-more.vue +168 -0
  73. package/components/read-more/variables.scss +12 -0
  74. package/components/resize-sensor/README.md +55 -0
  75. package/components/resize-sensor/common.d.ts +19 -0
  76. package/components/resize-sensor/common.js +2 -0
  77. package/components/resize-sensor/index.d.ts +1 -0
  78. package/components/resize-sensor/index.js +1 -0
  79. package/components/resize-sensor/index.scss +33 -0
  80. package/components/resize-sensor/resize-sensor.d.ts +16 -0
  81. package/components/resize-sensor/resize-sensor.vue +152 -0
  82. package/components/scroll-list/README.md +79 -0
  83. package/components/scroll-list/common.d.ts +23 -0
  84. package/components/scroll-list/common.js +1 -0
  85. package/components/scroll-list/index.d.ts +1 -0
  86. package/components/scroll-list/index.js +1 -0
  87. package/components/scroll-list/index.scss +35 -0
  88. package/components/scroll-list/scroll-list.d.ts +20 -0
  89. package/components/scroll-list/scroll-list.vue +158 -0
  90. package/components/scroll-list/variables.scss +11 -0
  91. package/components/sidebar/README.md +8 -8
  92. package/components/sidebar/sidebar.vue +1 -1
  93. package/components/slider/slider.vue +4 -4
  94. package/components/stepper/stepper.vue +2 -2
  95. package/components/sticky/README.md +92 -0
  96. package/components/sticky/common.d.ts +15 -0
  97. package/components/sticky/common.js +1 -0
  98. package/components/sticky/index.d.ts +1 -0
  99. package/components/sticky/index.js +1 -0
  100. package/components/sticky/index.scss +18 -0
  101. package/components/sticky/sticky.d.ts +10 -0
  102. package/components/sticky/sticky.vue +190 -0
  103. package/components/sticky-box/common.d.ts +19 -0
  104. package/components/sticky-box/common.js +1 -0
  105. package/components/sticky-box/index.d.ts +1 -0
  106. package/components/sticky-box/index.js +1 -0
  107. package/components/sticky-box/index.scss +19 -0
  108. package/components/sticky-box/sticky-box.d.ts +10 -0
  109. package/components/sticky-box/sticky-box.vue +82 -0
  110. package/components/style/mixins/border.scss +101 -38
  111. package/components/style/variables-dark.scss +4 -0
  112. package/components/style/variables.scss +8 -0
  113. package/components/table/table.vue +2 -1
  114. package/components/table-fixation/table-fixation.vue +2 -1
  115. package/components/toast/toast.d.ts +1 -1
  116. package/components/toast-agent/toast-agent.d.ts +1 -1
  117. package/components/tree/tree.d.ts +1 -1
  118. package/components/tree-node/tree-node.vue +2 -2
  119. package/components/upload/README.md +23 -15
  120. package/components/upload/common.d.ts +7 -4
  121. package/components/upload/upload.d.ts +2 -0
  122. package/components/upload/upload.vue +52 -14
  123. package/components/upload/utils.d.ts +1 -0
  124. package/components/upload/utils.js +2 -0
  125. package/components/upload-preview/index.scss +3 -2
  126. package/components/upload-preview/upload-preview.d.ts +6 -4
  127. package/components/upload-preview/upload-preview.vue +17 -24
  128. package/global.d.ts +5 -0
  129. package/index.d.ts +5 -0
  130. package/index.js +5 -0
  131. package/index.scss +2 -0
  132. package/package.json +5 -3
  133. package/use/index.d.ts +4 -0
  134. package/use/index.js +4 -0
  135. package/use/useIndeterminate.d.ts +10 -0
  136. package/use/useIndeterminate.js +27 -0
  137. package/use/useIntersectionObserver.d.ts +16 -0
  138. package/use/useIntersectionObserver.js +52 -0
  139. package/use/useSimulatedClick.js +2 -2
  140. package/use/useSimulatedPress.js +2 -2
  141. package/use/useSingleTask.d.ts +6 -0
  142. package/use/useSingleTask.js +40 -0
  143. package/use/useWindowResize.d.ts +4 -0
  144. package/use/useWindowResize.js +15 -0
  145. package/utils/array.d.ts +28 -0
  146. package/utils/array.js +90 -0
  147. package/utils/common.d.ts +3 -0
  148. package/utils/common.js +1 -0
  149. package/utils/date.d.ts +84 -11
  150. package/utils/date.js +120 -63
  151. package/utils/dom.js +2 -0
  152. package/utils/geometry.d.ts +56 -38
  153. package/utils/geometry.js +56 -30
  154. package/utils/index.d.ts +8 -1
  155. package/utils/index.js +8 -1
  156. package/utils/is.d.ts +12 -0
  157. package/utils/is.js +16 -0
  158. package/utils/number.d.ts +24 -0
  159. package/utils/number.js +37 -0
  160. package/utils/object.d.ts +29 -0
  161. package/utils/object.js +139 -0
  162. package/utils/persist.d.ts +15 -0
  163. package/utils/persist.js +89 -0
  164. package/utils/physics.d.ts +34 -0
  165. package/utils/physics.js +66 -0
  166. package/utils/request.d.ts +227 -0
  167. package/utils/request.js +249 -0
  168. package/utils/router.d.ts +47 -0
  169. package/utils/router.js +115 -0
  170. package/utils/string.d.ts +46 -0
  171. package/utils/string.js +134 -0
  172. package/utils/url-query.d.ts +19 -0
  173. package/utils/url-query.js +95 -0
  174. package/utils/utils.d.ts +0 -166
  175. package/utils/utils.js +0 -441
  176. package/utils/case.d.ts +0 -4
  177. package/utils/case.js +0 -26
package/utils/geometry.js CHANGED
@@ -1,33 +1,29 @@
1
1
  /**
2
- ```
3
- page
4
-
5
- ╭───────────────╮ viewport
6
- ╭─│─ ─ ─ ─ ─ ─ ─ ─│─╮ ╱
7
- │ ╭───────────╮ │ │
8
- │ │ element │ │ │
9
- ╰───────────╯
10
- ╰─│─ ─ ─ ─ ─│─╯
11
-
12
-
13
- ╰───────────────╯
14
- ```
15
-
16
- # 参数
17
- - viewportHeight: viewport 高度
18
- - viewportScrollTop: viewport 垂直滚动值
19
- - elementHeight: element 高度
20
- - elementOffsetTop: element 距离页面顶部距离
21
-
22
- # 选项
23
- - position: element 在视窗中的位置(start, center, end, nearest)
24
- - startOffset: element 距离视窗顶部的偏移量
25
- - endOffset: element 距离视窗底部的偏移量
26
-
27
- # 结果值
28
- - viewportScrollTop: viewport 新的垂直滚动值
29
-
30
- */
2
+ * 根据最后位置计算 page 滚动到顶部的值。
3
+ *
4
+ * 也可计算水平方向的滚动值。
5
+ *
6
+ * page
7
+ * ╱
8
+ * ╭───────────────╮ viewport
9
+ * ╭─│─ ─ ─ ─ ─│─╮ ╱
10
+ * ╭───────────╮
11
+ * │ element │ │ │
12
+ * ╰───────────╯ │ │
13
+ * ╰─│─ ─ ─ ─ ─ ─ ─ ─│─╯
14
+ * │ │
15
+ * │ │
16
+ * ╰───────────────╯
17
+ *
18
+ * @param {number} viewportHeight viewport 高度
19
+ * @param {number} viewportScrollTop viewport 垂直滚动值
20
+ * @param {number} elementHeight element 高度
21
+ * @param {number} elementOffsetTop element 距离页面顶部距离
22
+ * @param {string} options.position element 在 viewport 中的位置,可选:'start' | 'center' | 'end' | 'nearest'
23
+ * @param {number} options.startOffset element 距离视窗顶部的偏移量
24
+ * @param {number} options.endOffset element 距离视窗底部的偏移量
25
+ * @return {number} viewport 新的垂直滚动值
26
+ */
31
27
  export function getScrollIntoViewValue(viewportHeight, viewportScrollTop, elementHeight, elementOffsetTop, options = {}) {
32
28
  const { startOffset = 0, endOffset = 0 } = options;
33
29
  let position = options.position || 'nearest';
@@ -68,7 +64,12 @@ export function getScrollIntoViewValue(viewportHeight, viewportScrollTop, elemen
68
64
  return nextScrollTop;
69
65
  }
70
66
  /**
71
- * @description: 匹配元素列表中第一个位于滚动盒子可视区域的元素
67
+ * 匹配元素列表中第一个位于滚动盒子可视区域的元素
68
+ *
69
+ * @param {array} rects NodeRect 类型数组
70
+ * @param {function} callback 匹配成功时调用,会接收匹配的元素的下标
71
+ * @param {number} options.offset 偏移量
72
+ * @param {number} options.errorValue 容错值
72
73
  */
73
74
  export async function matchScrollVisible(rects, callback, options = {}) {
74
75
  const { offset: optionOffset = 0, errorValue = 3 } = options;
@@ -92,6 +93,9 @@ export async function matchScrollVisible(rects, callback, options = {}) {
92
93
  }
93
94
  }
94
95
  }
96
+ /**
97
+ * 保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取。
98
+ */
95
99
  export function getAspectFillSize(origWidth, origHeight, containerWidth, containerHeight) {
96
100
  let width = 0;
97
101
  let height = 0;
@@ -107,6 +111,9 @@ export function getAspectFillSize(origWidth, origHeight, containerWidth, contain
107
111
  }
108
112
  return [width, height];
109
113
  }
114
+ /**
115
+ * 保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来。
116
+ */
110
117
  export function getAspectFitSize(origWidth, origHeight, containerWidth, containerHeight) {
111
118
  let width = 0;
112
119
  let height = 0;
@@ -122,6 +129,25 @@ export function getAspectFitSize(origWidth, origHeight, containerWidth, containe
122
129
  }
123
130
  return [width, height];
124
131
  }
132
+ /**
133
+ * 获取两点间的距离
134
+ */
125
135
  export function getTwoPointsDistance(p1, p2) {
126
136
  return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
127
137
  }
138
+ /**
139
+ * @description: 根据原始坐标尺寸和缩放后的坐标尺寸算出转换的原点
140
+ * @param {Rect} rect
141
+ * @param {Rect} scaleRect
142
+ * @return {[number, number]}
143
+ */
144
+ export function getTransformOrigin(rect, scaleRect) {
145
+ const ratio = scaleRect.width / rect.width;
146
+ const originX = (rect.x + rect.width / 2 - scaleRect.x - scaleRect.width / 2) /
147
+ (ratio - 1) +
148
+ rect.width / 2;
149
+ const originY = (rect.y + rect.height / 2 - scaleRect.y - scaleRect.height / 2) /
150
+ (ratio - 1) +
151
+ rect.height / 2;
152
+ return [originX, originY];
153
+ }
package/utils/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './bem';
2
- export * from './case';
3
2
  export * from './date';
4
3
  export * from './dom';
5
4
  export * from './file';
@@ -9,5 +8,13 @@ export * from './lwa.slim';
9
8
  export * from './qrcode';
10
9
  export * from './system';
11
10
  export * from './object';
11
+ export * from './array';
12
+ export * from './string';
13
+ export * from './number';
12
14
  export * from './geometry';
15
+ export * from './physics';
13
16
  export * from './inertialAnimate';
17
+ export * from './persist';
18
+ export * from './request';
19
+ export * from './url-query';
20
+ export * from './router';
package/utils/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './bem';
2
- export * from './case';
3
2
  export * from './date';
4
3
  export * from './dom';
5
4
  export * from './file';
@@ -9,5 +8,13 @@ export * from './lwa.slim';
9
8
  export * from './qrcode';
10
9
  export * from './system';
11
10
  export * from './object';
11
+ export * from './array';
12
+ export * from './string';
13
+ export * from './number';
12
14
  export * from './geometry';
15
+ export * from './physics';
13
16
  export * from './inertialAnimate';
17
+ export * from './persist';
18
+ export * from './request';
19
+ export * from './url-query';
20
+ export * from './router';
package/utils/is.d.ts CHANGED
@@ -4,6 +4,12 @@
4
4
  * @return {boolean}
5
5
  */
6
6
  export declare function isPlainObject(target: any): target is Record<PropertyKey, any>;
7
+ /**
8
+ * @description: 判断是否为空数组
9
+ * @param {any} target
10
+ * @return {boolean}
11
+ */
12
+ export declare function isEmptyArray(target: any): boolean;
7
13
  /**
8
14
  * @description: 判断是否为对象
9
15
  * @param {any} target
@@ -54,3 +60,9 @@ export declare function isNullish(target: any): target is null | undefined;
54
60
  * @return {boolean}
55
61
  */
56
62
  export declare function isPrimitive(target: any): target is string | number | boolean;
63
+ /**
64
+ * @description: 判断是否为日期类型
65
+ * @param {any} target
66
+ * @return {boolean}
67
+ */
68
+ export declare function isDate(target: any): target is Date;
package/utils/is.js CHANGED
@@ -6,6 +6,14 @@
6
6
  export function isPlainObject(target) {
7
7
  return Object.prototype.toString.call(target) === '[object Object]';
8
8
  }
9
+ /**
10
+ * @description: 判断是否为空数组
11
+ * @param {any} target
12
+ * @return {boolean}
13
+ */
14
+ export function isEmptyArray(target) {
15
+ return Array.isArray(target) && target.length === 0;
16
+ }
9
17
  /**
10
18
  * @description: 判断是否为对象
11
19
  * @param {any} target
@@ -70,3 +78,11 @@ export function isNullish(target) {
70
78
  export function isPrimitive(target) {
71
79
  return isString(target) || isNumber(target) || isBoolean(target);
72
80
  }
81
+ /**
82
+ * @description: 判断是否为日期类型
83
+ * @param {any} target
84
+ * @return {boolean}
85
+ */
86
+ export function isDate(target) {
87
+ return target instanceof Date;
88
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 限定数值范围
3
+ */
4
+ export declare function clamp(n: number, min: number, max: number): number;
5
+ /**
6
+ * 把一个数四舍五入到指定位数小数。
7
+ */
8
+ export declare function round(n: number, precision?: number): number;
9
+ /**
10
+ * 获取小数位数
11
+ */
12
+ export declare function getDecimalsLength(n: number | string): number;
13
+ /**
14
+ * 把一个数舍入到指定数的倍数
15
+ */
16
+ export declare function mround(n: number, m: number): number;
17
+ /**
18
+ * 生成两数间的一个随机整数
19
+ */
20
+ export declare function random(min: number, max: number): number;
21
+ /**
22
+ * 判断一个数是否在指定范围内。
23
+ */
24
+ export declare function inRange(n: number, min: number, max: number): boolean;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 限定数值范围
3
+ */
4
+ export function clamp(n, min, max) {
5
+ return n < min ? min : n > max ? max : n;
6
+ }
7
+ /**
8
+ * 把一个数四舍五入到指定位数小数。
9
+ */
10
+ export function round(n, precision = 0) {
11
+ return Math.round(+(n + 'e' + precision)) / 10 ** precision;
12
+ }
13
+ /**
14
+ * 获取小数位数
15
+ */
16
+ export function getDecimalsLength(n) {
17
+ n = n.toString().split('.')[1];
18
+ return n ? n.length : 0;
19
+ }
20
+ /**
21
+ * 把一个数舍入到指定数的倍数
22
+ */
23
+ export function mround(n, m) {
24
+ return round(n - (n % m) + Math.round((n % m) / m) * m, getDecimalsLength(m));
25
+ }
26
+ /**
27
+ * 生成两数间的一个随机整数
28
+ */
29
+ export function random(min, max) {
30
+ return min + Math.floor(Math.random() * (max - min + 1));
31
+ }
32
+ /**
33
+ * 判断一个数是否在指定范围内。
34
+ */
35
+ export function inRange(n, min, max) {
36
+ return n > min && n < max;
37
+ }
package/utils/object.d.ts CHANGED
@@ -1,4 +1,33 @@
1
+ import { AnyObject } from './common';
1
2
  /**
2
3
  * 此方法创建一个对象,该对象由自己不可省略的属性组成。
3
4
  */
4
5
  export declare function omit<T extends object, U extends keyof T>(object: T, paths: U[]): Omit<T, U>;
6
+ /**
7
+ * 深度克隆对象,仅克隆数组和无格式对象,其他类型会被直接返回
8
+ */
9
+ export declare function deepClone(target: any): any;
10
+ /**
11
+ * 深拷贝其他对象到第一个对象
12
+ */
13
+ export declare function extend(...args: any[]): any;
14
+ export declare function treeToMap(tree: AnyObject[], keyName: string, childrenName: string, parentName: string): {
15
+ [p: string]: AnyObject;
16
+ };
17
+ /**
18
+ * @description: 链式获取对象值
19
+ * @param object
20
+ * @param chain 通过点分割的字符串或者字符串数组
21
+ */
22
+ export declare function chainGet(object: any, chain?: string | string[]): any;
23
+ /**
24
+ * @description: 链式设置对象值
25
+ * @param object
26
+ * @param chain 通过点分割的字符串或者字符串数组
27
+ * @param value 要设置的值
28
+ */
29
+ export declare function chainSet(object: any, chain: string | string[], value: any): void;
30
+ export declare function nestedToMulti(nested: any[], values: (number | string)[], fieldKeys: {
31
+ value: string;
32
+ children: string;
33
+ }): any[];
package/utils/object.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isPlainObject } from './is';
1
2
  /**
2
3
  * 此方法创建一个对象,该对象由自己不可省略的属性组成。
3
4
  */
@@ -11,3 +12,141 @@ export function omit(object, paths) {
11
12
  });
12
13
  return newObj;
13
14
  }
15
+ /**
16
+ * 深度克隆对象,仅克隆数组和无格式对象,其他类型会被直接返回
17
+ */
18
+ export function deepClone(target) {
19
+ if (Array.isArray(target)) {
20
+ return target.map((item) => {
21
+ return deepClone(item);
22
+ });
23
+ }
24
+ if (isPlainObject(target)) {
25
+ const obj = {};
26
+ Object.keys(target).forEach((k) => {
27
+ obj[k] = deepClone(target[k]);
28
+ });
29
+ return obj;
30
+ }
31
+ return target;
32
+ }
33
+ /**
34
+ * 深拷贝其他对象到第一个对象
35
+ */
36
+ export function extend(...args) {
37
+ const target = args[0], l = args.length;
38
+ let i = 1, options, name, src, copy, copyIsArray, clone;
39
+ for (; i < l; i++) {
40
+ options = args[i];
41
+ if (options !== null && options !== undefined) {
42
+ for (name in options) {
43
+ src = target[name];
44
+ copy = options[name];
45
+ // 防止有环
46
+ if (target === copy) {
47
+ continue;
48
+ }
49
+ // 深复制
50
+ if (copy &&
51
+ (isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) {
52
+ if (copyIsArray) {
53
+ copyIsArray = false;
54
+ clone = src && Array.isArray(src) ? src : [];
55
+ }
56
+ else {
57
+ clone = isPlainObject(src) ? src : {};
58
+ }
59
+ // 只克隆对象,不移动
60
+ target[name] = extend(clone, copy);
61
+ // 不添加未定义的值
62
+ }
63
+ else if (copy !== undefined) {
64
+ target[name] = copy;
65
+ }
66
+ }
67
+ }
68
+ }
69
+ return target;
70
+ }
71
+ export function treeToMap(tree, keyName, childrenName, parentName) {
72
+ const map = {};
73
+ function recurse(children, parent) {
74
+ children.forEach((node) => {
75
+ map[node[keyName]] = node;
76
+ node[parentName] = parent;
77
+ if (Array.isArray(node[childrenName])) {
78
+ recurse(node[childrenName], node);
79
+ }
80
+ });
81
+ }
82
+ recurse(tree, null);
83
+ return map;
84
+ }
85
+ /**
86
+ * @description: 链式获取对象值
87
+ * @param object
88
+ * @param chain 通过点分割的字符串或者字符串数组
89
+ */
90
+ export function chainGet(object, chain) {
91
+ let target = object;
92
+ if (chain) {
93
+ chain = typeof chain === 'string' ? chain.split('.') : chain;
94
+ for (const key of chain) {
95
+ if (target && typeof target === 'object') {
96
+ target = target[key];
97
+ }
98
+ else {
99
+ return target;
100
+ }
101
+ }
102
+ }
103
+ return target;
104
+ }
105
+ /**
106
+ * @description: 链式设置对象值
107
+ * @param object
108
+ * @param chain 通过点分割的字符串或者字符串数组
109
+ * @param value 要设置的值
110
+ */
111
+ export function chainSet(object, chain, value) {
112
+ let target = object;
113
+ chain = typeof chain === 'string' ? chain.split('.') : chain;
114
+ if (chain.length === 0) {
115
+ return;
116
+ }
117
+ for (let i = 0, l = chain.length; i < l; i++) {
118
+ if (target && typeof target === 'object') {
119
+ const key = chain[i];
120
+ if (i === l - 1) {
121
+ target[key] = value;
122
+ return;
123
+ }
124
+ else {
125
+ target = target[key];
126
+ }
127
+ }
128
+ else {
129
+ return;
130
+ }
131
+ }
132
+ }
133
+ // 将嵌套数据结构转换为多维数组
134
+ export function nestedToMulti(nested, values, fieldKeys) {
135
+ const columns = [];
136
+ function recurse(list, index = 0) {
137
+ columns.push(list);
138
+ const selectedValue = values[index];
139
+ let selectedOption = list.find((option) => option[fieldKeys.value] === selectedValue);
140
+ if (!selectedOption) {
141
+ selectedOption = list[0];
142
+ }
143
+ if (selectedOption) {
144
+ const nextList = selectedOption[fieldKeys.children];
145
+ if (Array.isArray(nextList)) {
146
+ recurse(nextList, ++index);
147
+ }
148
+ }
149
+ }
150
+ recurse(nested);
151
+ return columns;
152
+ }
@@ -0,0 +1,15 @@
1
+ export declare class Persist {
2
+ name: string;
3
+ prefix: string;
4
+ cache: Record<string, {
5
+ ttl: number;
6
+ value: any;
7
+ }>;
8
+ constructor(name: string);
9
+ private getCache;
10
+ private save;
11
+ get(key: string): any;
12
+ set(key: string, value: any, ttl?: number): void;
13
+ remove(key: string): void;
14
+ clear(): void;
15
+ }
@@ -0,0 +1,89 @@
1
+ export class Persist {
2
+ name;
3
+ prefix;
4
+ cache = {};
5
+ constructor(name) {
6
+ this.name = name;
7
+ this.prefix = name + '#';
8
+ this.cache = this.getCache();
9
+ }
10
+ getCache() {
11
+ const cache = {};
12
+ const res = uni.getStorageInfoSync();
13
+ for (let i = 0; i < res.keys.length; i++) {
14
+ const key = res.keys[i];
15
+ if (key && key.startsWith(this.prefix)) {
16
+ const value = uni.getStorageSync(key);
17
+ if (value) {
18
+ try {
19
+ const result = JSON.parse(value);
20
+ if (result &&
21
+ typeof result === 'object' &&
22
+ !Array.isArray(result)) {
23
+ cache[key] = result;
24
+ }
25
+ }
26
+ catch {
27
+ void 0;
28
+ }
29
+ }
30
+ }
31
+ }
32
+ return cache;
33
+ }
34
+ save(fullKey) {
35
+ if (fullKey) {
36
+ if (fullKey in this.cache) {
37
+ uni.setStorageSync(fullKey, JSON.stringify(this.cache[fullKey]));
38
+ }
39
+ else {
40
+ uni.removeStorageSync(fullKey);
41
+ }
42
+ }
43
+ else {
44
+ const res = uni.getStorageInfoSync();
45
+ for (let i = 0; i < res.keys.length; i++) {
46
+ const key = res.keys[i];
47
+ if (key && key.startsWith(this.prefix)) {
48
+ if (!(key in this.cache)) {
49
+ uni.removeStorageSync(key);
50
+ i--;
51
+ }
52
+ }
53
+ }
54
+ Object.keys(this.cache).forEach((key) => {
55
+ uni.setStorageSync(key, JSON.stringify(this.cache[key]));
56
+ });
57
+ }
58
+ }
59
+ get(key) {
60
+ const item = this.cache[this.prefix + key];
61
+ if (item) {
62
+ if (item.ttl > 0 && item.ttl < Date.now()) {
63
+ this.remove(key);
64
+ }
65
+ else {
66
+ return item.value;
67
+ }
68
+ }
69
+ }
70
+ set(key, value, ttl = 0) {
71
+ const fullKey = this.prefix + key;
72
+ this.cache[fullKey] = {
73
+ ttl: ttl > 0 ? ttl * 1000 + Date.now() : 0,
74
+ value,
75
+ };
76
+ this.save(fullKey);
77
+ }
78
+ remove(key) {
79
+ const fullKey = this.prefix + key;
80
+ if (fullKey in this.cache) {
81
+ delete this.cache[fullKey];
82
+ this.save(fullKey);
83
+ }
84
+ }
85
+ clear() {
86
+ this.cache = {};
87
+ this.save();
88
+ }
89
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @description: 获取阻尼值
3
+ * @param {number} value
4
+ * @param {number} min
5
+ * @param {number} max
6
+ * @param {number} damping
7
+ * @return {number}
8
+ */
9
+ export declare function getDampingValue(value: number, min: number, max: number, damping: number): number;
10
+ /**
11
+ * @description: 获取矩形阻尼值
12
+ * @param {number} offset 当前的偏移量
13
+ * @param {number} areaSize 范围值
14
+ * @param {number} viewSize 范围内某个视图尺寸值
15
+ * @param {number} damping 阻尼系数
16
+ * @return {number}
17
+ */
18
+ export declare function getRectDampingValue(offset: number, areaSize: number, viewSize: number, damping: number): number;
19
+ /**
20
+ * @description: 获取范围值
21
+ * @param {number} offset 当前的偏移量
22
+ * @param {number} areaSize 范围值
23
+ * @param {number} viewSize 范围内某个视图尺寸值
24
+ * @return {number}
25
+ */
26
+ export declare function getInBoundValue(offset: number, areaSize: number, viewSize: number): number;
27
+ /**
28
+ * @description: 获取溢出值范围
29
+ * @param {number} overflow 最大溢出值
30
+ * @param {number} areaSize 范围值
31
+ * @param {number} viewSize 范围内某个视图尺寸值
32
+ * @return {*}
33
+ */
34
+ export declare function getOverflowRangeInArea(overflow: number, areaSize: number, viewSize: number): [number, number];
@@ -0,0 +1,66 @@
1
+ import { clamp } from './number';
2
+ /**
3
+ * @description: 获取阻尼值
4
+ * @param {number} value
5
+ * @param {number} min
6
+ * @param {number} max
7
+ * @param {number} damping
8
+ * @return {number}
9
+ */
10
+ export function getDampingValue(value, min, max, damping) {
11
+ if (value < min) {
12
+ return min + (value - min) * damping;
13
+ }
14
+ if (value > max) {
15
+ return max + (value - max) * damping;
16
+ }
17
+ return value;
18
+ }
19
+ /**
20
+ * @description: 获取矩形阻尼值
21
+ * @param {number} offset 当前的偏移量
22
+ * @param {number} areaSize 范围值
23
+ * @param {number} viewSize 范围内某个视图尺寸值
24
+ * @param {number} damping 阻尼系数
25
+ * @return {number}
26
+ */
27
+ export function getRectDampingValue(offset, areaSize, viewSize, damping) {
28
+ const diff = areaSize - viewSize;
29
+ let min, max;
30
+ if (diff < 0) {
31
+ min = diff;
32
+ max = 0;
33
+ }
34
+ else {
35
+ min = 0;
36
+ max = diff;
37
+ }
38
+ return getDampingValue(offset, min, max, damping);
39
+ }
40
+ /**
41
+ * @description: 获取范围值
42
+ * @param {number} offset 当前的偏移量
43
+ * @param {number} areaSize 范围值
44
+ * @param {number} viewSize 范围内某个视图尺寸值
45
+ * @return {number}
46
+ */
47
+ export function getInBoundValue(offset, areaSize, viewSize) {
48
+ const diff = areaSize - viewSize;
49
+ const [min, max] = [0, diff].sort((a, b) => a - b);
50
+ return clamp(offset, min, max);
51
+ }
52
+ /**
53
+ * @description: 获取溢出值范围
54
+ * @param {number} overflow 最大溢出值
55
+ * @param {number} areaSize 范围值
56
+ * @param {number} viewSize 范围内某个视图尺寸值
57
+ * @return {*}
58
+ */
59
+ export function getOverflowRangeInArea(overflow, areaSize, viewSize) {
60
+ if (areaSize > viewSize) {
61
+ return [-overflow, areaSize + overflow];
62
+ }
63
+ else {
64
+ return [areaSize - viewSize - overflow, overflow];
65
+ }
66
+ }