@kengic/uni 0.3.4-beta.1 → 0.3.4

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.
@@ -5,14 +5,28 @@ export * from './http-client';
5
5
 
6
6
  type IUseKgAutoFocusInput = {
7
7
  /** 文本框的内容. */
8
- text: Ref<string>;
8
+ kgAutoFocusInputText: Ref<string>;
9
+
10
+ /**
11
+ * 失去焦点事件.
12
+ * @param fn 回调函数.
13
+ */
14
+ onKgAutoFocusInputBlur(fn: () => void): void;
9
15
  };
10
16
 
11
17
  /**
12
18
  * 自动聚焦的文本框.
13
19
  */
14
20
  function useKgAutoFocusInput(): IUseKgAutoFocusInput {
15
- const text = ref('');
21
+ // 文本框的内容
22
+ const kgAutoFocusInputText = ref('');
23
+ // 失去焦点时的回调函数, 外部传入
24
+ let onBlur: (() => void) | null = null;
25
+
26
+ /** 监听失去焦点事件. */
27
+ function onKgAutoFocusInputBlur(_fn: () => void) {
28
+ onBlur = _fn;
29
+ }
16
30
 
17
31
  /* #ifdef APP-PLUS */
18
32
  const inputID = uuid();
@@ -37,6 +51,9 @@ function useKgAutoFocusInput(): IUseKgAutoFocusInput {
37
51
  // @ts-ignore
38
52
  clearInterval(interval);
39
53
  view.close();
54
+ if (onBlur) {
55
+ onBlur();
56
+ }
40
57
  },
41
58
  },
42
59
  inputID,
@@ -54,11 +71,11 @@ function useKgAutoFocusInput(): IUseKgAutoFocusInput {
54
71
 
55
72
  // @ts-ignore
56
73
  const interval = setInterval(() => {
57
- text.value = view.getInputValueById(inputID) ?? '';
74
+ kgAutoFocusInputText.value = view.getInputValueById(inputID) ?? '';
58
75
  }, 10);
59
76
  /* #endif */
60
77
 
61
- return { text };
78
+ return { kgAutoFocusInputText: kgAutoFocusInputText, onKgAutoFocusInputBlur: onKgAutoFocusInputBlur };
62
79
  }
63
80
 
64
81
  export { type IUseKgAutoFocusInput, useKgAutoFocusInput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kengic/uni",
3
- "version": "0.3.4-beta.1",
3
+ "version": "0.3.4",
4
4
  "scripts": {
5
5
  "build": "rimraf dist && vue-tsc && vite build",
6
6
  "build:dev": "rimraf dist && vue-tsc && vite build --mode development",