gzkx-package 0.1.47 → 0.1.49

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
@@ -1,269 +1,1214 @@
1
- # CommonPage 组件库
1
+ # 自定义组件使用文档
2
2
 
3
- 一个基于 React 和 Ant Design 的通用页面组件库,提供完整的 CRUD 功能。
3
+ 本文档详细介绍了项目中四个核心自定义组件的使用方法和参数说明。
4
+
5
+ ---
6
+
7
+ ## 目录
8
+
9
+ - [安装](#安装)
10
+ - [快速开始](#快速开始)
11
+ - [组件列表](#组件列表)
12
+ 1. [CommonPage 通用页面组件](#1-commonpage-通用页面组件)
13
+ 2. [CustomTable 自定义表格组件](#2-customtable-自定义表格组件)
14
+ 3. [CustomForm 自定义表单组件](#3-customform-自定义表单组件)
15
+ 4. [CustomAdd 新增/编辑弹窗组件](#4-customadd-新增编辑弹窗组件)
16
+
17
+ ---
4
18
 
5
19
  ## 安装
6
20
 
21
+ ### 使用 npm
22
+
7
23
  ```bash
8
24
  npm install gzkx-package
9
- # 或
25
+ ```
26
+
27
+ ### 使用 yarn
28
+
29
+ ```bash
10
30
  yarn add gzkx-package
11
- # 或
31
+ ```
32
+
33
+ ### 使用 pnpm
34
+
35
+ ```bash
12
36
  pnpm add gzkx-package
13
37
  ```
14
38
 
15
- ## 使用
39
+ ---
40
+
41
+ ## 快速开始
42
+
43
+ ### 1. 安装依赖
44
+
45
+ 确保项目中已安装以下依赖(peerDependencies):
46
+
47
+ ```bash
48
+ npm install antd axios dayjs lodash pinyin-pro react react-dom
49
+ ```
50
+
51
+ **版本要求:**
52
+ - `antd`: ^5.0.0
53
+ - `axios`: ^1.0.0
54
+ - `dayjs`: ^1.11.0
55
+ - `lodash`: ^4.17.0
56
+ - `pinyin-pro`: ^3.0.0
57
+ - `react`: ^18.0.0 或 ^19.0.0
58
+ - `react-dom`: ^18.0.0 或 ^19.0.0
59
+
60
+ ### 2. 引入样式
61
+
62
+ 在项目入口文件(如 `main.tsx` 或 `App.tsx`)中引入样式:
63
+
64
+ ```tsx
65
+ // 引入 Ant Design 样式
66
+ import 'antd/dist/reset.css';
67
+
68
+ // 引入组件库样式
69
+ import 'gzkx-package/style';
70
+
71
+ ```
72
+
73
+ ### 3. 基本使用
16
74
 
17
- ### 基础用法
75
+ 导入并使用组件:
18
76
 
19
77
  ```tsx
20
- import React from 'react';
21
78
  import { CommonPage } from 'gzkx-package';
22
- // 引入样式文件(推荐使用直接路径)
79
+ import type { FormItemConfig } from 'gzkx-package';
80
+ import type { AddItemConfig } from 'gzkx-package';
23
81
  import 'gzkx-package/dist/style.css';
24
82
 
25
- function App() {
26
- const searchFormConfig = [
83
+
84
+ const MyPage = () => {
85
+ // 搜索表单配置
86
+ const searchFormConfig: FormItemConfig[] = [
87
+ {
88
+ type: 'input',
89
+ label: '姓名',
90
+ name: 'name',
91
+ colSpan: 6,
92
+ },
93
+ ];
94
+
95
+ // 新增/编辑表单配置
96
+ const addFormConfig: AddItemConfig[] = [
97
+ {
98
+ type: 'input',
99
+ label: '姓名',
100
+ name: 'name',
101
+ rules: [{ required: true, message: '请输入姓名' }],
102
+ colSpan: 12,
103
+ },
104
+ ];
105
+
106
+ // 表格列配置
107
+ const tableColumns = [
108
+ {
109
+ title: '姓名',
110
+ dataIndex: 'name',
111
+ key: 'name',
112
+ width: 150,
113
+ },
114
+ ];
115
+
116
+ // API 地址配置
117
+ const URL = {
118
+ search: '/user/list',
119
+ add: '/user/add',
120
+ edit: '/user/edit',
121
+ delete: '/user/delete',
122
+ };
123
+
124
+ return (
125
+ <CommonPage
126
+ searchFormConfig={searchFormConfig}
127
+ addFormConfig={addFormConfig}
128
+ tableColumns={tableColumns}
129
+ URL={URL}
130
+ tableId="my-table"
131
+ isReset={true}
132
+ />
133
+ );
134
+ };
135
+
136
+ export default MyPage;
137
+ ```
138
+
139
+ ### 4. 导出组件列表
140
+
141
+ 本组件库主要导出以下组件:
142
+
143
+ | 组件名 | 说明 | 导入方式 |
144
+ |--------|------|---------|
145
+ | `CommonPage` | 通用页面组件 | `import { CommonPage } from 'gzkx-package'` |
146
+ | `CustomTable` | 自定义表格组件 | `import { CustomTable } from 'gzkx-package'` |
147
+ | `CustomForm` | 自定义表单组件 | `import { CustomForm } from 'gzkx-package'` |
148
+ | `CustomAdd` | 新增/编辑弹窗组件 | `import { CustomAdd } from 'gzkx-package'` |
149
+
150
+ ### 5. TypeScript 类型导出
151
+
152
+ ```tsx
153
+ import type {
154
+ FormItemConfig, // 搜索表单配置类型
155
+ AddItemConfig, // 新增/编辑表单配置类型
156
+ ValidateConfig, // 验证配置类型
157
+ CommonPageHandle, // CommonPage Ref 类型
158
+ CustomTableHandle, // CustomTable Ref 类型
159
+ CustomColumnType, // 自定义表格列类型
160
+ CustomColumnsType, // 自定义表格列数组类型
161
+ } from 'gzkx-package';
162
+ ```
163
+
164
+ ---
165
+
166
+ ## 组件列表
167
+
168
+ ## 1. CommonPage 通用页面组件
169
+
170
+ ### 1.1 组件概述
171
+
172
+ `CommonPage` 是一个集成了搜索表单、数据表格、新增/编辑弹窗的通用页面组件,适用于大部分 CRUD 操作场景。
173
+
174
+ ### 1.2 Props 参数
175
+
176
+ | 参数名 | 类型 | 必填 | 默认值 | 说明 |
177
+ |--------|------|------|--------|------|
178
+ | `searchFormConfig` | `FormItemConfig[] \| null` | 是 | - | 搜索表单配置项数组 |
179
+ | `addFormConfig` | `AddItemConfig[]` | 是 | - | 新增/编辑表单配置项数组 |
180
+ | `tableColumns` | `any[]` | 是 | - | 表格列配置数组 |
181
+ | `URL` | `object` | 是 | - | API 接口地址配置,包含 `search`, `add`, `edit`, `delete`, `view` |
182
+ | `tableId` | `string` | 否 | - | 表格唯一 ID,用于保存用户的表格配置 |
183
+ | `isnopage` | `boolean` | 否 | `false` | 是否不分页 |
184
+ | `topHeight` | `number` | 否 | - | 顶部高度(像素) |
185
+ | `tableHeight` | `number` | 否 | `150` | 表格高度调整参数 |
186
+ | `actionWidth` | `number` | 否 | `150` | 操作列宽度 |
187
+ | `editText` | `string` | 否 | `'编辑'` | 编辑按钮文本 |
188
+ | `viewText` | `string` | 否 | `'查看'` | 查看按钮文本 |
189
+ | `delText` | `string` | 否 | `'删除'` | 删除按钮文本 |
190
+ | `isaddtab` | `boolean` | 否 | `false` | 新增/编辑表单是否分 Tab 显示 |
191
+ | `isReset` | `boolean` | 否 | `false` | 是否显示重置按钮 |
192
+ | `addisdisabled` | `object` | 否 | `{ isdisabled: false, message: '' }` | 新增按钮禁用配置 |
193
+ | `postParams` | `object` | 否 | - | 请求参数配置对象 |
194
+ | `limit` | `object` | 否 | 全部为 `true` | 操作权限限制配置 |
195
+ | `CustomOperations` | `ReactNode \| Function` | 否 | - | 自定义操作列内容 |
196
+ | `PropOtherButton` | `ReactNode \| Function` | 否 | - | 搜索表单右侧的其他按钮 |
197
+ | `CustomModalFooter` | `Function` | 否 | - | 自定义弹窗底部按钮 |
198
+ | `proplist` | `any[]` | 否 | - | 假数据(用于测试) |
199
+ | `editdclickback` | `Function` | 否 | - | 点击编辑/新增时的回调函数 |
200
+ | `oneditFormChange` | `Function` | 否 | - | 编辑表单值变化时的回调 |
201
+ | `onSearchFormChange` | `Function` | 否 | - | 搜索表单值变化时的回调 |
202
+ | `onRowClick` | `Function` | 否 | - | 表格行点击回调 |
203
+ | `onDelete` | `Function` | 否 | - | 删除成功后的回调 |
204
+ | `onSearch` | `Function` | 否 | - | 搜索按钮点击后的回调 |
205
+ | `onReset` | `Function` | 否 | - | 重置按钮点击后的回调 |
206
+ | `onView` | `Function` | 否 | - | 查看按钮点击后的回调 |
207
+ | `validateConfig` | `ValidateConfig` | 否 | - | 表单验证配置 |
208
+ | `tableConfig` | `any` | 否 | - | 表格额外配置 |
209
+
210
+ #### 1.2.1 详细参数说明
211
+
212
+ **postParams 对象结构:**
213
+
214
+ ```typescript
215
+ {
216
+ addParams?: any; // 新增时额外携带的参数
217
+ delParams?: any; // 删除时额外携带的参数
218
+ editParams?: any; // 编辑时额外携带的参数
219
+ searchParams?: any; // 搜索时额外携带的参数
220
+ }
221
+ ```
222
+
223
+ **limit 对象结构:**
224
+
225
+ ```typescript
226
+ {
227
+ addLimit?: boolean; // 是否显示新增按钮,默认 true
228
+ delLimit?: boolean; // 是否显示删除按钮,默认 true
229
+ editLimit?: boolean; // 是否显示编辑按钮,默认 true
230
+ searchLimit?: boolean; // 是否显示搜索功能,默认 true
231
+ }
232
+ ```
233
+
234
+ **URL 对象结构:**
235
+
236
+ ```typescript
237
+ {
238
+ search: string; // 查询接口地址
239
+ add?: string; // 新增接口地址
240
+ edit?: string; // 编辑接口地址
241
+ delete?: string; // 删除接口地址
242
+ view?: string; // 查看接口地址(可选,如果没有则使用 edit)
243
+ }
244
+ ```
245
+
246
+ ### 1.3 Ref 暴露的方法
247
+
248
+ 使用 `ref` 可以调用组件内部方法:
249
+
250
+ ```typescript
251
+ interface CommonPageHandle {
252
+ getList: (parentParams?: any) => Promise<void>; // 刷新列表
253
+ setFieldsValue: (values: any) => void; // 设置表单字段值
254
+ getFieldsValue: () => any; // 获取表单字段值
255
+ reload: () => void; // 重新加载列表
256
+ getSearchFieldsValue: () => any; // 获取搜索表单值
257
+ setSearchFieldsValue: (values: any) => void; // 设置搜索表单值
258
+ /** 打开表格配置弹窗 */
259
+ openSettingModal: () => void; // 打开表格配置弹窗
260
+ /** 关闭表格配置弹窗 */
261
+ closeSettingModal: () => void; // 关闭表格配置弹窗
262
+ }
263
+ ```
264
+
265
+ ### 1.4 使用示例
266
+
267
+ ```tsx
268
+ import { useRef } from 'react';
269
+ import CommonPage, { CommonPageHandle } from '@/components/customComponents/commonPage';
270
+ import { FormItemConfig } from '@/components/customComponents/CustomForm';
271
+ import { AddItemConfig } from '@/components/customComponents/CustomAdd';
272
+
273
+ const DemoPage = () => {
274
+ const pageRef = useRef<CommonPageHandle>(null);
275
+
276
+ // 搜索表单配置
277
+ const searchFormConfig: FormItemConfig[] = [
27
278
  {
28
279
  type: 'input',
29
- label: '名称',
280
+ label: '姓名',
30
281
  name: 'name',
31
- placeholder: '请输入名称',
282
+ placeholder: '请输入姓名',
283
+ colSpan: 6,
32
284
  },
33
285
  {
34
286
  type: 'select',
35
287
  label: '状态',
36
288
  name: 'status',
37
289
  options: [
38
- { label: '启用', value: '1' },
39
- { label: '禁用', value: '0' },
290
+ { label: '启用', value: 1 },
291
+ { label: '禁用', value: 0 },
40
292
  ],
293
+ colSpan: 6,
294
+ },
295
+ {
296
+ type: 'rangePicker',
297
+ label: '日期范围',
298
+ name: 'createTime/endTime',
299
+ colSpan: 6,
41
300
  },
42
301
  ];
43
302
 
44
- const addFormConfig = [
303
+ // 新增/编辑表单配置
304
+ const addFormConfig: AddItemConfig[] = [
45
305
  {
46
306
  type: 'input',
47
- label: '名称',
307
+ label: '姓名',
48
308
  name: 'name',
49
- rules: [{ required: true, message: '请输入名称' }],
309
+ rules: [{ required: true, message: '请输入姓名' }],
310
+ colSpan: 12,
311
+ },
312
+ {
313
+ type: 'InputNumber',
314
+ label: '年龄',
315
+ name: 'age',
316
+ colSpan: 12,
317
+ },
318
+ {
319
+ type: 'Radio',
320
+ label: '性别',
321
+ name: 'gender',
322
+ options: [
323
+ { label: '男', value: 1 },
324
+ { label: '女', value: 0 },
325
+ ],
326
+ colSpan: 12,
327
+ },
328
+ {
329
+ type: 'textarea',
330
+ label: '备注',
331
+ name: 'remark',
332
+ colSpan: 24,
50
333
  },
51
334
  ];
52
335
 
336
+ // 表格列配置
53
337
  const tableColumns = [
54
338
  {
55
- title: 'ID',
56
- dataIndex: 'id',
57
- key: 'id',
58
- },
59
- {
60
- title: '名称',
339
+ title: '姓名',
61
340
  dataIndex: 'name',
62
341
  key: 'name',
342
+ width: 150,
343
+ },
344
+ {
345
+ title: '年龄',
346
+ dataIndex: 'age',
347
+ key: 'age',
348
+ width: 100,
349
+ },
350
+ {
351
+ title: '性别',
352
+ dataIndex: 'gender',
353
+ key: 'gender',
354
+ width: 100,
355
+ render: (text: number) => (text === 1 ? '男' : '女'),
356
+ },
357
+ {
358
+ title: '创建时间',
359
+ dataIndex: 'createTime',
360
+ key: 'createTime',
361
+ width: 180,
63
362
  },
64
363
  ];
65
364
 
365
+ // API 地址配置
66
366
  const URL = {
67
- search: '/api/search',
68
- add: '/api/add',
69
- edit: '/api/edit',
70
- delete: '/api/delete',
367
+ search: '/api/user/list',
368
+ add: '/api/user/add',
369
+ edit: '/api/user/edit',
370
+ delete: '/api/user/delete',
71
371
  };
72
372
 
73
373
  return (
74
374
  <CommonPage
375
+ ref={pageRef}
75
376
  searchFormConfig={searchFormConfig}
76
377
  addFormConfig={addFormConfig}
77
378
  tableColumns={tableColumns}
78
379
  URL={URL}
380
+ tableId="user-table"
381
+ isReset={true}
382
+ postParams={{
383
+ searchParams: { orgId: '123' },
384
+ }}
385
+ onRowClick={(record) => {
386
+ console.log('点击了行:', record);
387
+ }}
388
+ onDelete={(record) => {
389
+ console.log('删除了:', record);
390
+ }}
391
+ onSearch={() => {
392
+ console.log('搜索触发');
393
+ }}
394
+ onReset={() => {
395
+ console.log('重置触发');
396
+ }}
397
+ onView={(record) => {
398
+ console.log('查看了:', record);
399
+ }}
79
400
  />
80
401
  );
81
- }
402
+ };
82
403
 
83
- export default App;
404
+ export default DemoPage;
84
405
  ```
85
406
 
86
- ### 使用 ref 调用组件方法
407
+ ---
87
408
 
88
- ```tsx
89
- import React, { useRef } from 'react';
90
- import { CommonPage, CommonPageHandle } from 'gzkx-package';
409
+ ## 2. CustomTable 自定义表格组件
91
410
 
92
- function App() {
93
- const commonPageRef = useRef<CommonPageHandle>(null);
411
+ ### 2.1 组件概述
94
412
 
95
- const handleRefresh = () => {
96
- commonPageRef.current?.reload();
97
- };
413
+ `CustomTable` 是对 Ant Design Table 组件的增强封装,支持用户自定义表格列配置、保存配置到后端、序号列、树形数据等功能。
414
+
415
+ ### 2.2 Props 参数
416
+
417
+ | 参数名 | 类型 | 必填 | 默认值 | 说明 |
418
+ |--------|------|------|--------|------|
419
+ | `columns` | `ColumnsType<any>` | 是 | - | 表格列配置 |
420
+ | `dataSource` | `any[]` | 是 | - | 表格数据源 |
421
+ | `loading` | `boolean` | 否 | `false` | 加载状态 |
422
+ | `pagination` | `object \| false` | 否 | - | 分页配置 |
423
+ | `handleTableChange` | `Function` | 否 | - | 表格变化回调 |
424
+ | `size` | `'small' \| 'middle' \| 'large'` | 否 | `'middle'` | 表格尺寸 |
425
+ | `tableId` | `string` | 否 | - | 表格唯一 ID,用于保存列配置 |
426
+ | `onRowClick` | `Function` | 否 | - | 行点击回调 |
427
+ | `page` | `object` | 否 | - | 分页信息(用于序号计算) |
428
+ | `showTableConfig` | `boolean` | 否 | `true` | 是否显示表格配置按钮和序号列 |
429
+ | `...rest` | `any` | 否 | - | 其他 Ant Design Table 原生属性 |
430
+
431
+ ### 2.3 特色功能
98
432
 
99
- const handleSetFormValues = () => {
100
- commonPageRef.current?.setFieldsValue({
101
- name: '测试名称',
102
- });
433
+ 1. **表格配置功能**:用户可以自定义列的显示、宽度、对齐方式、排序等,配置会保存到后端。
434
+ 2. **自动序号列**:自动添加序号列(可通过 `showTableConfig` 控制)。
435
+ 3. **树形数据支持**:支持展开/收起树形数据。
436
+ 4. **Tooltip 支持**:单元格内容过长时自动显示 Tooltip。
437
+
438
+ ### 2.4 Ref 暴露的方法
439
+
440
+ 使用 `ref` 可以调用组件内部方法:
441
+
442
+ ```typescript
443
+ interface CustomTableHandle {
444
+ openSettingModal: () => void; // 打开表格配置弹窗
445
+ closeSettingModal: () => void; // 关闭表格配置弹窗
446
+ }
447
+ ```
448
+
449
+ **使用示例:**
450
+
451
+ ```tsx
452
+ import { useRef } from 'react';
453
+ import CustomTable, { CustomTableHandle } from '@/components/customComponents/CustomTable';
454
+
455
+ const Demo = () => {
456
+ const tableRef = useRef<CustomTableHandle>(null);
457
+
458
+ const handleOpenConfig = () => {
459
+ tableRef.current?.openSettingModal();
103
460
  };
104
461
 
105
462
  return (
106
463
  <>
107
- <button onClick={handleRefresh}>刷新列表</button>
108
- <button onClick={handleSetFormValues}>设置表单值</button>
109
- <CommonPage
110
- ref={commonPageRef}
111
- searchFormConfig={searchFormConfig}
112
- addFormConfig={addFormConfig}
113
- tableColumns={tableColumns}
114
- URL={URL}
464
+ <Button onClick={handleOpenConfig}>打开表格配置</Button>
465
+ <CustomTable
466
+ ref={tableRef}
467
+ columns={columns}
468
+ dataSource={dataSource}
469
+ tableId="my-table"
115
470
  />
116
471
  </>
117
472
  );
473
+ };
474
+ ```
475
+
476
+ ### 2.5 使用示例
477
+
478
+ ```tsx
479
+ import CustomTable from '@/components/customComponents/CustomTable';
480
+
481
+ const DemoTable = () => {
482
+ const [dataSource, setDataSource] = useState([]);
483
+ const [loading, setLoading] = useState(false);
484
+ const [pagination, setPagination] = useState({
485
+ current: 1,
486
+ pageSize: 10,
487
+ total: 0,
488
+ });
489
+
490
+ const columns = [
491
+ {
492
+ title: '姓名',
493
+ dataIndex: 'name',
494
+ key: 'name',
495
+ width: 150,
496
+ },
497
+ {
498
+ title: '年龄',
499
+ dataIndex: 'age',
500
+ key: 'age',
501
+ width: 100,
502
+ },
503
+ {
504
+ title: '地址',
505
+ dataIndex: 'address',
506
+ key: 'address',
507
+ width: 300,
508
+ },
509
+ ];
510
+
511
+ return (
512
+ <CustomTable
513
+ columns={columns}
514
+ dataSource={dataSource}
515
+ loading={loading}
516
+ pagination={pagination}
517
+ tableId="demo-table"
518
+ page={pagination}
519
+ showTableConfig={true}
520
+ onRowClick={(record) => {
521
+ console.log('点击行:', record);
522
+ }}
523
+ handleTableChange={(newPagination) => {
524
+ setPagination(newPagination);
525
+ }}
526
+ />
527
+ );
528
+ };
529
+ ```
530
+
531
+ ### 2.6 列配置弹窗说明
532
+
533
+ 当 `showTableConfig={true}` 时,序号列旁边会显示设置图标,点击后打开配置弹窗,可以配置:
534
+
535
+ - **显示名称**:列的显示标题
536
+ - **表头对齐**:左/中/右对齐
537
+ - **内容对齐**:左/中/右对齐
538
+ - **数据格式**:字符串/数字/日期
539
+ - **宽度**:列宽
540
+ - **是否启用**:是否显示该列
541
+ - **允许排序**:是否允许排序
542
+ - **排序**:列的显示顺序
543
+
544
+ ---
545
+
546
+ ## 3. CustomForm 自定义表单组件
547
+
548
+ ### 3.1 组件概述
549
+
550
+ `CustomForm` 是一个基于配置的表单组件,通过传入配置数组即可快速生成表单,支持多种表单项类型。
551
+
552
+ ### 3.2 Props 参数
553
+
554
+ | 参数名 | 类型 | 必填 | 默认值 | 说明 |
555
+ |--------|------|------|--------|------|
556
+ | `config` | `FormItemConfig[]` | 是 | - | 表单项配置数组 |
557
+ | `onFinish` | `Function` | 否 | - | 表单提交回调 |
558
+ | `onSearch` | `Function` | 否 | - | 搜索按钮点击回调 |
559
+ | `onReset` | `Function` | 否 | - | 重置按钮点击回调 |
560
+ | `initialValues` | `object` | 否 | - | 表单初始值 |
561
+ | `layout` | `'horizontal' \| 'vertical' \| 'inline'` | 否 | `'horizontal'` | 表单布局 |
562
+ | `labelCol` | `object` | 否 | `{ span: 5 }` | label 栅格布局 |
563
+ | `wrapperCol` | `object` | 否 | `{ span: 19 }` | 控件栅格布局 |
564
+ | `submitButtonText` | `string` | 否 | `'搜索'` | 提交按钮文本 |
565
+ | `resetButtonText` | `string` | 否 | `'重置'` | 重置按钮文本 |
566
+ | `isReset` | `boolean` | 否 | `false` | 是否显示重置按钮 |
567
+ | `OtherButton` | `ReactNode \| Function` | 否 | - | 其他按钮 |
568
+ | `onSearchFormChange` | `Function` | 否 | - | 表单值变化回调 |
569
+ | `...restFormProps` | `any` | 否 | - | 其他 Ant Design Form 原生属性 |
570
+
571
+ ### 3.3 FormItemConfig 配置项
572
+
573
+ ```typescript
574
+ interface FormItemConfig {
575
+ type: 'input' | 'select' | 'rangePicker' | 'datePicker' | 'password' |
576
+ 'treeSelect' | 'radio' | 'deptSelect' | 'orgSelect';
577
+ label: string; // 标签文本
578
+ name: string; // 字段名
579
+ placeholder?: string; // 占位符
580
+ options?: FormItemOption[]; // 选项(用于 select、radio 等)
581
+ rules?: any[]; // 验证规则
582
+ colSpan?: number; // 栅格占位(默认 6,即一行 4 个)
583
+ labelCol?: number; // label 栅格占位(默认 5)
584
+ wrapperCol?: number; // 控件栅格占位(默认 19)
585
+ initialValue?: any; // 初始值
586
+ defaultValue?: any; // 默认值
587
+ [key: string]: any; // 其他属性
588
+ }
589
+
590
+ interface FormItemOption {
591
+ label: React.ReactNode;
592
+ value: string | number;
118
593
  }
119
594
  ```
120
595
 
121
- ## API
122
-
123
- ### CommonPage Props
124
-
125
- | 属性 | 说明 | 类型 | 默认值 |
126
- |------|------|------|--------|
127
- | searchFormConfig | 搜索表单配置 | FormItemConfig[] \| null | null |
128
- | addFormConfig | 新增/编辑表单配置 | AddItemConfig[] | - |
129
- | tableColumns | 表格列配置 | any[] | - |
130
- | URL | API 接口地址配置 | { search?: string; add?: string; edit?: string; delete?: string; view?: string } | - |
131
- | topHeight | 顶部高度 | number | - |
132
- | isnopage | 是否不分页 | boolean | false |
133
- | tableHeight | 表格高度 | number | 150 |
134
- | actionWidth | 操作列宽度 | number | 150 |
135
- | delText | 删除按钮文本 | string | '删除' |
136
- | editText | 编辑按钮文本 | string | '编辑' |
137
- | viewText | 查看按钮文本 | string | '查看' |
138
- | CustomOperations | 自定义操作列 | React.ReactNode \| ((record: any) => React.ReactNode) | - |
139
- | PropOtherButton | 其他按钮 | React.ReactNode \| ((record: any) => React.ReactNode) | - |
140
- | CustomModalFooter | 自定义模态框底部 | ((record: any) => React.ReactNode) | - |
141
- | addisdisabled | 是否禁用新增按钮 | { isdisabled: boolean; message: string } | { isdisabled: false, message: '' } |
142
- | postParams | POST 请求参数 | { addParams?: any; delParams?: any; editParams?: any; searchParams?: any } | - |
143
- | limit | 权限控制 | { addLimit?: boolean; delLimit?: boolean; editLimit?: boolean; searchLimit?: boolean } | { addLimit: true, delLimit: true, editLimit: true, searchLimit: true } |
144
- | proplist | 假数据(用于测试) | any[] | - |
145
- | editdclickback | 编辑/新增点击回调 | (record?: any) => void | - |
146
- | oneditFormChange | 表单值变化回调 | (changedValues: any, allValues: any) => void | - |
147
- | onRowClick | 行点击回调 | (record: any, event: any) => void | - |
148
- | tableId | 表格ID(用于保存表格配置) | string | - |
149
- | isaddtab | 是否使用 Tab 表单 | boolean | false |
150
-
151
- ### CommonPageHandle Methods
152
-
153
- | 方法 | 说明 | 类型 |
154
- |------|------|------|
155
- | getList | 获取列表数据 | (parentParams?: any) => Promise<void> |
156
- | setFieldsValue | 设置表单值 | (values: any) => void |
157
- | getFieldsValue | 获取表单值 | () => any |
158
- | reload | 重新加载列表 | () => void |
159
-
160
- ## 注意事项
161
-
162
- ### 依赖要求
163
-
164
- 本组件库依赖以下 peer dependencies,请确保在使用前已安装:
165
-
166
- - `react` >= 18.0.0
167
- - `react-dom` >= 18.0.0
168
- - `antd` >= 5.0.0
169
- - `lodash` >= 4.17.0
170
- - `dayjs` >= 1.11.0
171
- - `pinyin-pro` >= 3.0.0
172
- - `axios` >= 1.0.0
173
-
174
- ### API 请求配置
175
-
176
- 组件内部使用 `commonPost` 函数进行 API 请求。由于组件依赖项目特定的 API 函数,您需要:
177
-
178
- 1. **提供 `commonPost` 函数**:组件需要从 `@/api/common` 导入 `commonPost` 函数。如果您的项目结构不同,需要:
179
- - 创建对应的 API 文件,或
180
- - 修改组件中的导入路径
181
-
182
- 2. **提供 `auth` 工具**:组件需要从 `@/utils/auth` 导入 `auth` 对象。如果您的项目结构不同,需要:
183
- - 创建对应的工具文件,或
184
- - 修改组件中的导入路径
185
-
186
- 3. **API 响应格式**:确保 API 返回符合以下格式:
596
+ ### 3.4 支持的表单类型
597
+
598
+ | type 值 | 说明 | 额外属性 |
599
+ |---------|------|---------|
600
+ | `input` | 普通输入框 | - |
601
+ | `password` | 密码输入框 | - |
602
+ | `select` | 下拉选择 | `options` |
603
+ | `radio` | 单选框 | `options` |
604
+ | `rangePicker` | 日期范围选择 | - |
605
+ | `datePicker` | 日期选择 | - |
606
+ | `treeSelect` | 树形选择 | `options` (treeData 格式) |
607
+ | `deptSelect` | 科室选择(自动加载数据) | - |
608
+ | `orgSelect` | 机构选择(自动加载数据) | - |
609
+
610
+ ### 3.5 Ref 暴露的方法
187
611
 
188
612
  ```typescript
189
- {
190
- code: 200,
191
- msg: 'success',
192
- data: {
193
- list: [], // 或直接是数组
194
- pageNum: 1,
195
- pageSize: 15,
196
- total: 0
197
- }
613
+ interface CustomFormHandle {
614
+ setFieldsValue: (values: any) => void; // 设置表单值
615
+ getFieldsValue: () => any; // 获取表单值
616
+ }
617
+ ```
618
+
619
+ ### 3.6 使用示例
620
+
621
+ ```tsx
622
+ import { useRef } from 'react';
623
+ import CustomForm, { FormItemConfig } from '@/components/customComponents/CustomForm';
624
+
625
+ const DemoForm = () => {
626
+ const formRef = useRef<any>(null);
627
+
628
+ const formConfig: FormItemConfig[] = [
629
+ {
630
+ type: 'input',
631
+ label: '用户名',
632
+ name: 'username',
633
+ placeholder: '请输入用户名',
634
+ colSpan: 6,
635
+ rules: [{ required: true, message: '请输入用户名' }],
636
+ },
637
+ {
638
+ type: 'select',
639
+ label: '角色',
640
+ name: 'role',
641
+ options: [
642
+ { label: '管理员', value: 'admin' },
643
+ { label: '普通用户', value: 'user' },
644
+ ],
645
+ colSpan: 6,
646
+ },
647
+ {
648
+ type: 'rangePicker',
649
+ label: '日期范围',
650
+ name: 'dateRange',
651
+ colSpan: 6,
652
+ },
653
+ {
654
+ type: 'orgSelect',
655
+ label: '机构',
656
+ name: 'orgId',
657
+ colSpan: 6,
658
+ },
659
+ ];
660
+
661
+ const handleSearch = (values: any) => {
662
+ console.log('搜索参数:', values);
663
+ };
664
+
665
+ const handleReset = (form: any) => {
666
+ console.log('重置表单');
667
+ };
668
+
669
+ return (
670
+ <CustomForm
671
+ ref={formRef}
672
+ config={formConfig}
673
+ onSearch={handleSearch}
674
+ onReset={handleReset}
675
+ isReset={true}
676
+ submitButtonText="查询"
677
+ resetButtonText="重置"
678
+ OtherButton={
679
+ <Button onClick={() => console.log(formRef.current?.getFieldsValue())}>
680
+ 获取表单值
681
+ </Button>
682
+ }
683
+ />
684
+ );
685
+ };
686
+ ```
687
+
688
+ ---
689
+
690
+ ## 4. CustomAdd 新增/编辑弹窗组件
691
+
692
+ ### 4.1 组件概述
693
+
694
+ `CustomAdd` 是一个功能强大的弹窗表单组件,支持新增、编辑、查看三种模式,支持多种表单项类型、表单验证、Tab 分组等。
695
+
696
+ ### 4.2 Props 参数
697
+
698
+ | 参数名 | 类型 | 必填 | 默认值 | 说明 |
699
+ |--------|------|------|--------|------|
700
+ | `visible` | `boolean` | 是 | - | 弹窗是否可见 |
701
+ | `mode` | `'add' \| 'edit' \| 'view'` | 是 | - | 模式:新增/编辑/查看 |
702
+ | `config` | `AddItemConfig[]` | 是 | - | 表单项配置数组 |
703
+ | `initialValues` | `object` | 否 | - | 初始值(编辑/查看模式) |
704
+ | `onOk` | `Function` | 是 | - | 确定按钮回调 |
705
+ | `onCancel` | `Function` | 是 | - | 取消按钮回调 |
706
+ | `title` | `string` | 否 | 自动生成 | 弹窗标题 |
707
+ | `loading` | `boolean` | 否 | `false` | 确定按钮加载状态 |
708
+ | `tab` | `boolean` | 否 | `false` | 是否分 Tab 显示 |
709
+ | `modalProps` | `object` | 否 | - | Modal 额外属性 |
710
+ | `oneditFormChange` | `Function` | 否 | - | 表单值变化回调 |
711
+ | `CustomModalFooter` | `Function` | 否 | - | 自定义底部按钮 |
712
+ | `validateConfig` | `ValidateConfig` | 否 | - | 验证配置 |
713
+
714
+ ### 4.3 AddItemConfig 配置项
715
+
716
+ ```typescript
717
+ interface AddItemConfig {
718
+ type: 'input' | 'inputoption' | 'inputnumberoption' | 'select' |
719
+ 'rangePicker' | 'datePicker' | 'password' | 'InputNumber' |
720
+ 'Radio' | 'upload' | 'textarea' | 'area' | 'treeSelect' |
721
+ 'richText' | 'doubleValue' | 'file' | 'deptSelect' |
722
+ 'orgSelect' | 'uploadByte';
723
+ label: string; // 标签文本
724
+ name: string; // 字段名
725
+ placeholder?: string; // 占位符
726
+ options?: FormItemOption[]; // 选项
727
+ rules?: any[]; // 验证规则
728
+ colSpan?: number; // 栅格占位(默认 6)
729
+ defaultValue?: any; // 默认值
730
+
731
+ // 特殊字段(根据 type 使用)
732
+ optionname?: string; // inputoption 类型的下拉框字段名
733
+ labelName?: string; // select 类型保存 label 的字段名
734
+ firstLabel?: string; // doubleValue 第一个输入框字段名
735
+ secondLabel?: string; // doubleValue 第二个输入框字段名
736
+ separator?: string; // doubleValue 分隔符
737
+ dateFormat?: string; // 日期格式化字符串
738
+
739
+ [key: string]: any; // 其他属性
740
+ }
741
+ ```
742
+
743
+ ### 4.4 支持的表单类型
744
+
745
+ | type 值 | 说明 | 额外配置 |
746
+ |---------|------|---------|
747
+ | `input` | 普通输入框 | 支持拼音码自动生成 |
748
+ | `password` | 密码输入框 | - |
749
+ | `textarea` | 多行文本 | - |
750
+ | `InputNumber` | 数字输入框 | - |
751
+ | `select` | 下拉选择 | `options`, `labelName` |
752
+ | `Radio` | 单选框 | `options` |
753
+ | `datePicker` | 日期选择 | `dateFormat` |
754
+ | `rangePicker` | 日期范围 | `dateFormat`,name 格式:"startDate/endDate" |
755
+ | `treeSelect` | 树形选择 | `options`, `multiple` |
756
+ | `upload` | 图片上传 | - |
757
+ | `file` | 文件上传 | - |
758
+ | `uploadByte` | 字节流上传 | - |
759
+ | `area` | 地址选择器 | - |
760
+ | `richText` | 富文本编辑器 | - |
761
+ | `deptSelect` | 科室选择 | - |
762
+ | `orgSelect` | 机构选择 | - |
763
+ | `inputoption` | 输入框+下拉框组合 | `optionname`, `options` |
764
+ | `inputnumberoption` | 数字输入框+下拉框组合 | `optionname`, `options` |
765
+ | `doubleValue` | 双输入框(如范围) | `firstLabel`, `secondLabel`, `separator` |
766
+
767
+ ### 4.5 ValidateConfig 验证配置
768
+
769
+ ```typescript
770
+ interface ValidateConfig {
771
+ validateApi: string; // 验证接口地址
772
+ validateFields: string[]; // 需要验证的字段名数组
773
+ validateMethod?: 'GET' | 'POST'; // 请求方法,默认 POST
774
+ validateParams?: (values: any) => any; // 自定义验证参数处理函数
775
+ validateMessage?: string; // 验证失败提示,默认 "验证失败"
776
+ union?: boolean; // 是否联合验证,默认 true
777
+ realtime?: boolean; // 是否实时验证,默认 false
778
+ realtimeDelay?: number; // 实时验证防抖延迟(毫秒),默认 500
779
+ group?: string[][]; // 分组验证配置
198
780
  }
199
781
  ```
200
782
 
201
- ### 项目结构要求
783
+ ### 4.6 Ref 暴露的方法
784
+
785
+ ```typescript
786
+ interface CustomAddHandle {
787
+ setFieldsValue: (values: any) => void; // 设置表单值
788
+ getFieldsValue: () => any; // 获取表单值
789
+ }
790
+ ```
791
+
792
+ ### 4.7 使用示例
793
+
794
+ #### 4.7.1 基础使用
795
+
796
+ ```tsx
797
+ import { useState, useRef } from 'react';
798
+ import CustomAdd, { AddItemConfig } from '@/components/customComponents/CustomAdd';
799
+
800
+ const Demo = () => {
801
+ const [visible, setVisible] = useState(false);
802
+ const [mode, setMode] = useState<'add' | 'edit' | 'view'>('add');
803
+ const [initialValues, setInitialValues] = useState<any>(null);
804
+ const addRef = useRef<any>(null);
805
+
806
+ const addFormConfig: AddItemConfig[] = [
807
+ {
808
+ type: 'input',
809
+ label: '姓名',
810
+ name: 'name',
811
+ rules: [{ required: true, message: '请输入姓名' }],
812
+ colSpan: 12,
813
+ },
814
+ {
815
+ type: 'InputNumber',
816
+ label: '年龄',
817
+ name: 'age',
818
+ colSpan: 12,
819
+ },
820
+ {
821
+ type: 'Radio',
822
+ label: '性别',
823
+ name: 'gender',
824
+ options: [
825
+ { label: '男', value: 1 },
826
+ { label: '女', value: 0 },
827
+ ],
828
+ colSpan: 12,
829
+ defaultValue: 1,
830
+ },
831
+ {
832
+ type: 'datePicker',
833
+ label: '出生日期',
834
+ name: 'birthDate',
835
+ dateFormat: 'YYYY-MM-DD',
836
+ colSpan: 12,
837
+ },
838
+ {
839
+ type: 'orgSelect',
840
+ label: '所属机构',
841
+ name: 'orgId',
842
+ rules: [{ required: true, message: '请选择机构' }],
843
+ colSpan: 12,
844
+ },
845
+ {
846
+ type: 'deptSelect',
847
+ label: '所属科室',
848
+ name: 'deptId',
849
+ colSpan: 12,
850
+ },
851
+ {
852
+ type: 'textarea',
853
+ label: '备注',
854
+ name: 'remark',
855
+ colSpan: 24,
856
+ },
857
+ ];
858
+
859
+ const handleOk = async (values: any) => {
860
+ console.log('提交的值:', values);
861
+ // 调用接口...
862
+ setVisible(false);
863
+ };
864
+
865
+ return (
866
+ <>
867
+ <Button onClick={() => { setMode('add'); setVisible(true); }}>
868
+ 新增
869
+ </Button>
870
+
871
+ <CustomAdd
872
+ ref={addRef}
873
+ visible={visible}
874
+ mode={mode}
875
+ config={addFormConfig}
876
+ initialValues={initialValues}
877
+ onOk={handleOk}
878
+ onCancel={() => setVisible(false)}
879
+ loading={false}
880
+ />
881
+ </>
882
+ );
883
+ };
884
+ ```
202
885
 
203
- 组件使用路径别名 `@/` 来导入依赖。如果您的项目结构不同,需要:
886
+ #### 4.7.2 分 Tab 使用
204
887
 
205
- 1. 在 `tsconfig.json` 中配置路径别名:
206
- ```json
888
+ ```tsx
889
+ const tabFormConfig = [
890
+ {
891
+ label: '基本信息',
892
+ children: [
893
+ {
894
+ type: 'input',
895
+ label: '姓名',
896
+ name: 'name',
897
+ rules: [{ required: true, message: '请输入姓名' }],
898
+ colSpan: 12,
899
+ },
900
+ {
901
+ type: 'InputNumber',
902
+ label: '年龄',
903
+ name: 'age',
904
+ colSpan: 12,
905
+ },
906
+ ],
907
+ },
908
+ {
909
+ label: '详细信息',
910
+ children: [
911
+ {
912
+ type: 'textarea',
913
+ label: '个人简介',
914
+ name: 'bio',
915
+ colSpan: 24,
916
+ },
917
+ ],
918
+ },
919
+ ];
920
+
921
+ <CustomAdd
922
+ visible={visible}
923
+ mode={mode}
924
+ config={tabFormConfig}
925
+ tab={true} // 启用 Tab
926
+ onOk={handleOk}
927
+ onCancel={() => setVisible(false)}
928
+ />
929
+ ```
930
+
931
+ #### 4.7.3 带验证配置
932
+
933
+ ```tsx
934
+ const validateConfig: ValidateConfig = {
935
+ validateApi: '/api/user/validate',
936
+ validateFields: ['username', 'email'],
937
+ validateMethod: 'POST',
938
+ union: true, // 联合验证
939
+ realtime: true, // 实时验证
940
+ realtimeDelay: 500, // 500ms 防抖
941
+ validateMessage: '字段重复',
942
+ };
943
+
944
+ <CustomAdd
945
+ visible={visible}
946
+ mode={mode}
947
+ config={addFormConfig}
948
+ validateConfig={validateConfig}
949
+ onOk={handleOk}
950
+ onCancel={() => setVisible(false)}
951
+ />
952
+ ```
953
+
954
+ #### 4.7.4 特殊类型示例
955
+
956
+ ```tsx
957
+ // 双输入框(范围)
207
958
  {
208
- "compilerOptions": {
209
- "paths": {
210
- "@/*": ["src/*"]
211
- }
212
- }
959
+ type: 'doubleValue',
960
+ label: '价格范围',
961
+ name: 'priceRange',
962
+ firstLabel: 'minPrice',
963
+ secondLabel: 'maxPrice',
964
+ firstPlaceholder: '最低价',
965
+ secondPlaceholder: '最高价',
966
+ separator: '至',
967
+ lastUnit: '元',
968
+ colSpan: 24,
969
+ }
970
+
971
+ // 输入框+下拉框组合
972
+ {
973
+ type: 'inputoption',
974
+ label: '剂量',
975
+ name: 'dosage',
976
+ optionname: 'dosageUnit',
977
+ options: [
978
+ { label: 'mg', value: 'mg' },
979
+ { label: 'g', value: 'g' },
980
+ ],
981
+ colSpan: 12,
982
+ }
983
+
984
+ // 日期范围(自动拆分为两个字段)
985
+ {
986
+ type: 'rangePicker',
987
+ label: '有效期',
988
+ name: 'startDate/endDate', // 会自动拆分为 startDate 和 endDate
989
+ dateFormat: 'YYYY-MM-DD',
990
+ colSpan: 12,
213
991
  }
214
992
  ```
215
993
 
216
- 2. 确保以下文件存在:
217
- - `src/api/common.ts` - 包含 `commonPost` 函数
218
- - `src/utils/auth.ts` - 包含 `auth` 对象
219
- - `src/utils/request.ts` - 包含 `post` 和 `get` 函数
220
- - `src/utils/pycode.ts` - 包含拼音转换函数
221
- - `src/api/table.ts` - 包含表格配置相关的 API 函数
994
+ ---
995
+
996
+ ## 5. 常见使用场景
997
+
998
+ ### 5.1 完整的 CRUD 页面
999
+
1000
+ ```tsx
1001
+ import { useRef } from 'react';
1002
+ import CommonPage from '@/components/customComponents/commonPage';
222
1003
 
223
- ### 业务组件依赖
1004
+ const UserManagePage = () => {
1005
+ const pageRef = useRef<any>(null);
224
1006
 
225
- 组件还依赖以下业务组件(如果使用相关功能):
226
- - `AreaSelector` - 地址选择器
227
- - `ImageUploadComponent` - 图片上传组件
228
- - `FileUploadComponent` - 文件上传组件
229
- - `RichText` - 富文本编辑器
1007
+ const searchFormConfig = [
1008
+ { type: 'input', label: '用户名', name: 'username', colSpan: 6 },
1009
+ { type: 'input', label: '手机号', name: 'phone', colSpan: 6 },
1010
+ {
1011
+ type: 'select',
1012
+ label: '状态',
1013
+ name: 'status',
1014
+ options: [
1015
+ { label: '启用', value: 1 },
1016
+ { label: '禁用', value: 0 },
1017
+ ],
1018
+ colSpan: 6,
1019
+ },
1020
+ ];
230
1021
 
231
- 如果您的项目中没有这些组件,需要:
232
- 1. 创建对应的组件,或
233
- 2. 在表单配置中避免使用相关类型(`area`、`upload`、`file`、`richText`)
1022
+ const addFormConfig = [
1023
+ {
1024
+ type: 'input',
1025
+ label: '用户名',
1026
+ name: 'username',
1027
+ rules: [{ required: true, message: '请输入用户名' }],
1028
+ colSpan: 12,
1029
+ },
1030
+ {
1031
+ type: 'password',
1032
+ label: '密码',
1033
+ name: 'password',
1034
+ rules: [{ required: true, message: '请输入密码' }],
1035
+ colSpan: 12,
1036
+ },
1037
+ { type: 'input', label: '手机号', name: 'phone', colSpan: 12 },
1038
+ { type: 'input', label: '邮箱', name: 'email', colSpan: 12 },
1039
+ {
1040
+ type: 'Radio',
1041
+ label: '状态',
1042
+ name: 'status',
1043
+ options: [
1044
+ { label: '启用', value: 1 },
1045
+ { label: '禁用', value: 0 },
1046
+ ],
1047
+ defaultValue: 1,
1048
+ colSpan: 12,
1049
+ },
1050
+ ];
234
1051
 
235
- ### 样式引入
1052
+ const tableColumns = [
1053
+ { title: '用户名', dataIndex: 'username', key: 'username', width: 150 },
1054
+ { title: '手机号', dataIndex: 'phone', key: 'phone', width: 150 },
1055
+ { title: '邮箱', dataIndex: 'email', key: 'email', width: 200 },
1056
+ {
1057
+ title: '状态',
1058
+ dataIndex: 'status',
1059
+ key: 'status',
1060
+ width: 100,
1061
+ render: (text: number) => text === 1 ? '启用' : '禁用',
1062
+ },
1063
+ { title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
1064
+ ];
236
1065
 
237
- 请确保在使用组件前引入样式文件。有两种方式:
1066
+ const URL = {
1067
+ search: '/api/user/list',
1068
+ add: '/api/user/add',
1069
+ edit: '/api/user/edit',
1070
+ delete: '/api/user/delete',
1071
+ };
1072
+
1073
+ return (
1074
+ <CommonPage
1075
+ ref={pageRef}
1076
+ searchFormConfig={searchFormConfig}
1077
+ addFormConfig={addFormConfig}
1078
+ tableColumns={tableColumns}
1079
+ URL={URL}
1080
+ tableId="user-management-table"
1081
+ isReset={true}
1082
+ />
1083
+ );
1084
+ };
1085
+ ```
1086
+
1087
+ ### 5.2 自定义操作列
238
1088
 
239
- **方式1(推荐):**
240
1089
  ```tsx
241
- import 'gzkx-package/dist/style.css';
1090
+ <CommonPage
1091
+ searchFormConfig={searchFormConfig}
1092
+ addFormConfig={addFormConfig}
1093
+ tableColumns={tableColumns}
1094
+ URL={URL}
1095
+ CustomOperations={(record) => (
1096
+ <>
1097
+ <a onClick={() => handleResetPassword(record)}>重置密码</a>
1098
+ <a onClick={() => handleAssignRole(record)}>分配角色</a>
1099
+ </>
1100
+ )}
1101
+ />
242
1102
  ```
243
1103
 
244
- **方式2:**
1104
+ ### 5.3 带权限控制
1105
+
245
1106
  ```tsx
246
- import 'gzkx-package/style';
1107
+ <CommonPage
1108
+ searchFormConfig={searchFormConfig}
1109
+ addFormConfig={addFormConfig}
1110
+ tableColumns={tableColumns}
1111
+ URL={URL}
1112
+ limit={{
1113
+ addLimit: hasPermission('user:add'),
1114
+ editLimit: hasPermission('user:edit'),
1115
+ delLimit: hasPermission('user:delete'),
1116
+ searchLimit: true,
1117
+ }}
1118
+ />
247
1119
  ```
248
1120
 
249
- **注意:** 如果遇到样式文件找不到的错误,请使用方式1直接引入 `dist/style.css`。
1121
+ ---
250
1122
 
251
- ## 开发
1123
+ ## 6. 注意事项
252
1124
 
253
- ```bash
254
- # 安装依赖
255
- npm install
1125
+ ### 6.1 表单字段命名
1126
+
1127
+ 1. **日期范围字段**:使用 `/` 分隔,如 `startDate/endDate`,组件会自动拆分为两个字段。
1128
+ 2. **输入框+下拉框组合**:使用 `name` 和 `optionname` 分别定义两个字段。
1129
+ 3. **双输入框**:使用 `firstLabel` 和 `secondLabel` 定义两个字段名。
1130
+
1131
+ ### 6.2 数据格式
1132
+
1133
+ 1. **日期数据**:后端返回的日期字符串会自动转换为 dayjs 对象,提交时根据 `dateFormat` 格式化。
1134
+ 2. **树形选择多选**:多选时,后端返回逗号分隔的字符串(如 "1,2,3"),组件会自动转换为数组。
1135
+
1136
+ ### 6.3 性能优化
1137
+
1138
+ 1. **tableId**:为表格设置唯一 ID,用户的列配置会保存到后端,避免每次都重新配置。
1139
+ 2. **防抖**:组件内部已对列表刷新、实时验证等操作做了防抖处理。
256
1140
 
257
- # 开发模式
258
- npm run dev
1141
+ ### 6.4 样式定制
259
1142
 
260
- # 构建库
261
- npm run build:lib
1143
+ 组件使用了 CSS Modules,如需定制样式,可以:
1144
+ 1. 通过 `className` 传入自定义类名
1145
+ 2. 通过 `style` 传入内联样式
1146
+ 3. 修改组件的 `.less` 文件
262
1147
 
263
- # 发布到 npm
264
- npm publish
1148
+ ---
1149
+
1150
+ ## 7. 常见问题
1151
+
1152
+ ### Q1: 如何在表单提交前进行自定义验证?
1153
+
1154
+ 使用 `validateConfig` 配置,指定验证接口和字段:
1155
+
1156
+ ```tsx
1157
+ const validateConfig = {
1158
+ validateApi: '/api/validate',
1159
+ validateFields: ['username'],
1160
+ realtime: true,
1161
+ };
265
1162
  ```
266
1163
 
267
- ## License
1164
+ ### Q2: 如何实现联动选择(如省市区)?
1165
+
1166
+ 1. 在 `CustomForm` 中使用 `onSearchFormChange` 监听字段变化
1167
+ 2. 在 `CustomAdd` 中使用 `oneditFormChange` 监听字段变化
1168
+
1169
+ ```tsx
1170
+ <CustomAdd
1171
+ oneditFormChange={(changedValues, allValues) => {
1172
+ if (changedValues.provinceId) {
1173
+ // 加载对应的城市列表
1174
+ loadCities(changedValues.provinceId);
1175
+ }
1176
+ }}
1177
+ />
1178
+ ```
1179
+
1180
+ ### Q3: 如何获取/设置表单值?
1181
+
1182
+ 使用 `ref` 调用组件方法:
1183
+
1184
+ ```tsx
1185
+ const formRef = useRef<any>(null);
1186
+
1187
+ // 获取值
1188
+ const values = formRef.current?.getFieldsValue();
1189
+
1190
+ // 设置值
1191
+ formRef.current?.setFieldsValue({ name: '张三' });
1192
+ ```
1193
+
1194
+ ### Q4: 查看模式如何支持双击复制?
1195
+
1196
+ `CustomAdd` 组件在 `view` 模式下,大部分字段支持双击复制功能,会自动将字段值复制到剪贴板。
1197
+
1198
+ ### Q5: 如何实现表格行高亮选中?
1199
+
1200
+ 在 `CommonPage` 中,点击的行会自动高亮,通过 `currentRecord` 状态和 `rowClassName` 实现。
1201
+
1202
+ ---
1203
+
1204
+ ## 8. 更新日志
1205
+
1206
+ - **2025-11-24**: CustomTable 添加了表格配置保存功能
1207
+ - **2025-04-27**: CommonPage 组件创建
1208
+ - **2025-04-23**: CustomTable 组件创建
1209
+
1210
+ ---
1211
+
1212
+ ## 9. 技术支持
268
1213
 
269
- MIT
1214
+ 如有问题,请联系开发团队或查看源代码注释。