zy-react-library 1.0.157 → 1.0.159

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.
@@ -71,8 +71,8 @@ export interface FormOption {
71
71
  label?: ReactNode;
72
72
  /** 渲染类型 */
73
73
  render?: FormItemRenderType;
74
- /** 占据栅格列数,默认 12,支持函数动态计算 */
75
- span?: number | string | ((formValues: FormValues) => number | string);
74
+ /** 占据栅格列数,默认 12 */
75
+ span?: number | string;
76
76
  /** 是否必填,默认 true,支持函数动态计算 */
77
77
  required?: boolean | ((formValues: FormValues) => boolean);
78
78
  /** 验证规则 */
@@ -206,17 +206,9 @@ const FormItemsRenderer = ({
206
206
  return collapse && index >= 3 ? { display: "none" } : undefined;
207
207
  };
208
208
 
209
- // 获取 span
210
- const getSpan = (span) => {
211
- // 支持动态计算 span
212
- return typeof span === "function"
213
- ? span(getFormValues())
214
- : span;
215
- }
216
-
217
209
  // 列数
218
210
  const getCol = (option) => {
219
- const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : (getSpan(option.span) ?? span);
211
+ const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : (option.span ?? span);
220
212
  const itemLabelCol = option.labelCol ?? (itemSpan === 24 ? { span: labelCol.span / 2 } : labelCol);
221
213
  const itemWrapperCol = option.wrapperCol ?? { span: 24 - itemLabelCol.span };
222
214
  return { span: itemSpan, labelCol: itemLabelCol, wrapperCol: itemWrapperCol };
@@ -0,0 +1,11 @@
1
+ export interface UseIdleOptions {
2
+ /** 空闲超时时间(毫秒),默认值 10000 */
3
+ timeout?: number;
4
+ /** 监听的事件列表,默认值 ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart', 'wheel'] */
5
+ events?: string[];
6
+ }
7
+
8
+ /**
9
+ * 检测用户是否处于空闲状态
10
+ */
11
+ export default function useIdle(options?: UseIdleOptions): boolean;
@@ -0,0 +1,51 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ /**
4
+ * 检测用户是否处于空闲状态
5
+ */
6
+ function useIdle(options = {}) {
7
+ const {
8
+ timeout = 10000,
9
+ events = [
10
+ "mousedown",
11
+ "mousemove",
12
+ "keypress",
13
+ "scroll",
14
+ "touchstart",
15
+ "wheel",
16
+ ],
17
+ } = options;
18
+
19
+ const [isIdle, setIsIdle] = useState(false);
20
+
21
+ useEffect(() => {
22
+ let idleTimer;
23
+
24
+ // 重置空闲计时器
25
+ const resetTimer = () => {
26
+ setIsIdle(false);
27
+ clearTimeout(idleTimer);
28
+ idleTimer = setTimeout(() => setIsIdle(true), timeout);
29
+ };
30
+
31
+ // 初始化计时器
32
+ resetTimer();
33
+
34
+ // 添加事件监听器
35
+ events.forEach((event) => {
36
+ window.addEventListener(event, resetTimer, { passive: true });
37
+ });
38
+
39
+ // 清理函数
40
+ return () => {
41
+ clearTimeout(idleTimer);
42
+ events.forEach((event) => {
43
+ window.removeEventListener(event, resetTimer);
44
+ });
45
+ };
46
+ }, [timeout, events]);
47
+
48
+ return isIdle;
49
+ }
50
+
51
+ export default useIdle;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.157",
4
+ "version": "1.0.159",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",