gzkx-package 0.1.48 → 0.1.50

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.
package/README.md CHANGED
@@ -146,6 +146,9 @@ export default MyPage;
146
146
  | `CustomTable` | 自定义表格组件 | `import { CustomTable } from 'gzkx-package'` |
147
147
  | `CustomForm` | 自定义表单组件 | `import { CustomForm } from 'gzkx-package'` |
148
148
  | `CustomAdd` | 新增/编辑弹窗组件 | `import { CustomAdd } from 'gzkx-package'` |
149
+ | `useHotkeyListener` | 组合键监听 Hook | `import { useHotkeyListener } from 'gzkx-package'` |
150
+ | `useTakeShotHotkey` | 截图专用组合键 Hook | `import { useTakeShotHotkey } from 'gzkx-package'` |
151
+ | `takeShot` | 截图接口 | `import { takeShot } from 'gzkx-package'` |
149
152
 
150
153
  ### 5. TypeScript 类型导出
151
154
 
@@ -155,6 +158,10 @@ import type {
155
158
  AddItemConfig, // 新增/编辑表单配置类型
156
159
  ValidateConfig, // 验证配置类型
157
160
  CommonPageHandle, // CommonPage Ref 类型
161
+ CustomTableHandle, // CustomTable Ref 类型
162
+ CustomColumnType, // 自定义表格列类型
163
+ CustomColumnsType, // 自定义表格列数组类型
164
+ HotkeyConfig, // 组合键配置类型
158
165
  } from 'gzkx-package';
159
166
  ```
160
167
 
@@ -162,7 +169,143 @@ import type {
162
169
 
163
170
  ## 组件列表
164
171
 
165
- ## 1. CommonPage 通用页面组件
172
+ ## 1. 工具 Hooks
173
+
174
+ ### 1.1 useHotkeyListener - 组合键监听 Hook
175
+
176
+ 用于监听键盘组合键(如 `Ctrl+S`、`Alt+F2`、`Ctrl+Shift+A` 等)。
177
+
178
+ #### 参数
179
+
180
+ | 参数名 | 类型 | 必填 | 默认值 | 说明 |
181
+ |--------|------|------|--------|------|
182
+ | `hotkeys` | `HotkeyConfig[]` | 是 | - | 监听的组合键配置数组 |
183
+ | `onTrigger` | `(hotkey: HotkeyConfig, event: KeyboardEvent) => void` | 是 | - | 组合键触发回调 |
184
+ | `preventDefault` | `boolean` | 否 | `false` | 是否阻止默认行为 |
185
+ | `stopPropagation` | `boolean` | 否 | `false` | 是否阻止事件冒泡 |
186
+
187
+ #### HotkeyConfig 配置
188
+
189
+ ```typescript
190
+ interface HotkeyConfig {
191
+ key: string; // 主键,如 'F2', 's', 'Enter'
192
+ ctrl?: boolean; // 是否按住 Ctrl
193
+ alt?: boolean; // 是否按住 Alt
194
+ shift?: boolean; // 是否按住 Shift
195
+ meta?: boolean; // 是否按住 Meta (Mac Command/Windows Win)
196
+ }
197
+ ```
198
+
199
+ #### 使用示例
200
+
201
+ ```tsx
202
+ import { useHotkeyListener } from 'gzkx-package';
203
+
204
+ const MyComponent = () => {
205
+ // 监听多个组合键
206
+ useHotkeyListener({
207
+ hotkeys: [
208
+ { key: 'F2' }, // 单独 F2
209
+ { key: 'F2', ctrl: true }, // Ctrl+F2
210
+ { key: 's', ctrl: true, shift: true }, // Ctrl+Shift+S
211
+ { key: 'a', alt: true }, // Alt+A
212
+ ],
213
+ onTrigger: (hotkey, event) => {
214
+ console.log('组合键触发:', hotkey);
215
+ // 根据触发的组合键执行不同操作
216
+ },
217
+ preventDefault: true, // 阻止默认行为(如 Ctrl+S 保存页面)
218
+ });
219
+
220
+ return <div>按 F2 或 Ctrl+F2 触发</div>;
221
+ };
222
+ ```
223
+
224
+ ### 1.2 useTakeShotHotkey - 截图专用组合键 Hook
225
+
226
+ 专门用于截图功能的组合键监听 Hook,是 `useHotkeyListener` 的简化封装。
227
+
228
+ #### 参数
229
+
230
+ | 参数名 | 类型 | 必填 | 默认值 | 说明 |
231
+ |--------|------|------|--------|------|
232
+ | `onTakeShot` | `() => void` | 是 | - | 截图触发回调 |
233
+ | `hotkeys` | `HotkeyConfig[]` | 否 | `[{ key: 'F2' }]` | 监听的组合键配置 |
234
+
235
+ #### 使用示例
236
+
237
+ ```tsx
238
+ import { useTakeShotHotkey, takeShot } from 'gzkx-package';
239
+ import { message } from 'antd';
240
+
241
+ const UltrasoundWorkstation = () => {
242
+ // 使用默认 F2 键截图
243
+ useTakeShotHotkey(async () => {
244
+ const result = await takeShot();
245
+ if (result.code === 200) {
246
+ message.success('截图成功');
247
+ console.log('截图数据:', result.data?.imageBase64);
248
+ } else {
249
+ message.error(`截图失败: ${result.msg}`);
250
+ }
251
+ });
252
+
253
+ // 或者自定义组合键
254
+ useTakeShotHotkey(
255
+ async () => {
256
+ const result = await takeShot();
257
+ // 处理截图结果...
258
+ },
259
+ [
260
+ { key: 'F9' }, // F9 截图
261
+ { key: 'p', ctrl: true }, // Ctrl+P 截图
262
+ { key: 's', ctrl: true, shift: true }, // Ctrl+Shift+S 截图
263
+ ]
264
+ );
265
+
266
+ return <div>超声工作站 - 按 F9 或 Ctrl+P 截图</div>;
267
+ };
268
+ ```
269
+
270
+ ### 1.3 takeShot - 截图接口
271
+
272
+ 调用本地截图服务进行截图。
273
+
274
+ #### 配置方法
275
+
276
+ ```tsx
277
+ import { setTakeShotConfig, takeShot } from 'gzkx-package';
278
+
279
+ // 配置截图服务(通常在应用初始化时)
280
+ setTakeShotConfig({
281
+ host: 'localhost', // 截图服务主机
282
+ port: 28081, // 截图服务端口
283
+ timeout: 10000, // 请求超时时间(ms)
284
+ });
285
+ ```
286
+
287
+ #### 使用示例
288
+
289
+ ```tsx
290
+ const handleCapture = async () => {
291
+ const result = await takeShot({
292
+ format: 'png', // 图片格式
293
+ quality: 100, // 图片质量
294
+ });
295
+
296
+ if (result.code === 200) {
297
+ // result.data.imageBase64 - Base64 图片数据
298
+ // result.data.imagePath - 图片保存路径
299
+ console.log('截图成功:', result.data);
300
+ } else {
301
+ console.error('截图失败:', result.msg);
302
+ }
303
+ };
304
+ ```
305
+
306
+ ---
307
+
308
+ ## 2. CommonPage 通用页面组件
166
309
 
167
310
  ### 1.1 组件概述
168
311
 
@@ -252,6 +395,10 @@ interface CommonPageHandle {
252
395
  reload: () => void; // 重新加载列表
253
396
  getSearchFieldsValue: () => any; // 获取搜索表单值
254
397
  setSearchFieldsValue: (values: any) => void; // 设置搜索表单值
398
+ /** 打开表格配置弹窗 */
399
+ openSettingModal: () => void; // 打开表格配置弹窗
400
+ /** 关闭表格配置弹窗 */
401
+ closeSettingModal: () => void; // 关闭表格配置弹窗
255
402
  }
256
403
  ```
257
404
 
@@ -399,7 +546,7 @@ export default DemoPage;
399
546
 
400
547
  ---
401
548
 
402
- ## 2. CustomTable 自定义表格组件
549
+ ## 4. CustomTable 自定义表格组件
403
550
 
404
551
  ### 2.1 组件概述
405
552
 
@@ -428,7 +575,45 @@ export default DemoPage;
428
575
  3. **树形数据支持**:支持展开/收起树形数据。
429
576
  4. **Tooltip 支持**:单元格内容过长时自动显示 Tooltip。
430
577
 
431
- ### 2.4 使用示例
578
+ ### 2.4 Ref 暴露的方法
579
+
580
+ 使用 `ref` 可以调用组件内部方法:
581
+
582
+ ```typescript
583
+ interface CustomTableHandle {
584
+ openSettingModal: () => void; // 打开表格配置弹窗
585
+ closeSettingModal: () => void; // 关闭表格配置弹窗
586
+ }
587
+ ```
588
+
589
+ **使用示例:**
590
+
591
+ ```tsx
592
+ import { useRef } from 'react';
593
+ import CustomTable, { CustomTableHandle } from '@/components/customComponents/CustomTable';
594
+
595
+ const Demo = () => {
596
+ const tableRef = useRef<CustomTableHandle>(null);
597
+
598
+ const handleOpenConfig = () => {
599
+ tableRef.current?.openSettingModal();
600
+ };
601
+
602
+ return (
603
+ <>
604
+ <Button onClick={handleOpenConfig}>打开表格配置</Button>
605
+ <CustomTable
606
+ ref={tableRef}
607
+ columns={columns}
608
+ dataSource={dataSource}
609
+ tableId="my-table"
610
+ />
611
+ </>
612
+ );
613
+ };
614
+ ```
615
+
616
+ ### 2.5 使用示例
432
617
 
433
618
  ```tsx
434
619
  import CustomTable from '@/components/customComponents/CustomTable';
@@ -483,7 +668,7 @@ const DemoTable = () => {
483
668
  };
484
669
  ```
485
670
 
486
- ### 2.5 列配置弹窗说明
671
+ ### 2.6 列配置弹窗说明
487
672
 
488
673
  当 `showTableConfig={true}` 时,序号列旁边会显示设置图标,点击后打开配置弹窗,可以配置:
489
674
 
@@ -498,7 +683,7 @@ const DemoTable = () => {
498
683
 
499
684
  ---
500
685
 
501
- ## 3. CustomForm 自定义表单组件
686
+ ## 5. CustomForm 自定义表单组件
502
687
 
503
688
  ### 3.1 组件概述
504
689
 
@@ -642,7 +827,7 @@ const DemoForm = () => {
642
827
 
643
828
  ---
644
829
 
645
- ## 4. CustomAdd 新增/编辑弹窗组件
830
+ ## 6. CustomAdd 新增/编辑弹窗组件
646
831
 
647
832
  ### 4.1 组件概述
648
833
 
@@ -948,7 +1133,7 @@ const validateConfig: ValidateConfig = {
948
1133
 
949
1134
  ---
950
1135
 
951
- ## 5. 常见使用场景
1136
+ ## 7. 常见使用场景
952
1137
 
953
1138
  ### 5.1 完整的 CRUD 页面
954
1139
 
@@ -1075,7 +1260,7 @@ const UserManagePage = () => {
1075
1260
 
1076
1261
  ---
1077
1262
 
1078
- ## 6. 注意事项
1263
+ ## 8. 注意事项
1079
1264
 
1080
1265
  ### 6.1 表单字段命名
1081
1266
 
@@ -1102,7 +1287,7 @@ const UserManagePage = () => {
1102
1287
 
1103
1288
  ---
1104
1289
 
1105
- ## 7. 常见问题
1290
+ ## 9. 常见问题
1106
1291
 
1107
1292
  ### Q1: 如何在表单提交前进行自定义验证?
1108
1293
 
@@ -1156,8 +1341,9 @@ formRef.current?.setFieldsValue({ name: '张三' });
1156
1341
 
1157
1342
  ---
1158
1343
 
1159
- ## 8. 更新日志
1344
+ ## 10. 更新日志
1160
1345
 
1346
+ - **2026-04-14**: 新增组合键监听 Hooks (`useHotkeyListener`, `useTakeShotHotkey`) 和截图接口 (`takeShot`)
1161
1347
  - **2025-11-24**: CustomTable 添加了表格配置保存功能
1162
1348
  - **2025-04-27**: CommonPage 组件创建
1163
1349
  - **2025-04-23**: CustomTable 组件创建
@@ -11,6 +11,12 @@ interface CustomColumnType<T = any> extends ColumnType<T> {
11
11
  contentAlignment?: 'left' | 'center' | 'right';
12
12
  }
13
13
  type CustomColumnsType<T = any> = CustomColumnType<T>[];
14
+ export interface CustomTableHandle {
15
+ /** 打开表格配置弹窗 */
16
+ openSettingModal: () => void;
17
+ /** 关闭表格配置弹窗 */
18
+ closeSettingModal: () => void;
19
+ }
14
20
  interface CustomTableProps {
15
21
  columns: CustomColumnsType;
16
22
  dataSource: any[];
@@ -24,6 +30,6 @@ interface CustomTableProps {
24
30
  showTableConfig?: boolean;
25
31
  [key: string]: any;
26
32
  }
27
- declare const CustomTable: React.FC<CustomTableProps>;
33
+ declare const CustomTable: React.ForwardRefExoticComponent<Omit<CustomTableProps, "ref"> & React.RefAttributes<CustomTableHandle>>;
28
34
  export default CustomTable;
29
35
  export type { CustomColumnType, CustomColumnsType };
@@ -9,6 +9,10 @@ export interface CommonPageHandle {
9
9
  reload: () => void;
10
10
  getSearchFieldsValue: () => any;
11
11
  setSearchFieldsValue: (values: any) => void;
12
+ /** 打开表格配置弹窗 */
13
+ openSettingModal: () => void;
14
+ /** 关闭表格配置弹窗 */
15
+ closeSettingModal: () => void;
12
16
  }
13
17
  interface CommonPageProps {
14
18
  onSearchFormChange?: (name: string, value: any) => void;