xmirror-components 1.0.29 → 1.0.30-alpha.10

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 (93) hide show
  1. package/README.md +1325 -152
  2. package/build/dist/index.cjs +258 -16
  3. package/build/dist/index.mjs +8364 -2872
  4. package/build/es/components/ConfigProvider/index.js +7 -2
  5. package/build/es/components/ConfigProvider/types.d.ts +2 -0
  6. package/build/es/components/SearchArea/Item/index.d.ts +10 -0
  7. package/build/es/components/SearchArea/Item/index.js +49 -0
  8. package/build/es/components/SearchArea/ToggleButton/index.d.ts +15 -0
  9. package/build/es/components/SearchArea/ToggleButton/index.js +32 -0
  10. package/build/es/components/SearchArea/index.d.ts +25 -0
  11. package/build/es/components/SearchArea/index.js +136 -0
  12. package/build/es/components/Table/Footer/index.d.ts +1 -2
  13. package/build/es/components/Table/Footer/index.js +20 -17
  14. package/build/es/components/Table/Footer/styles.d.ts +25 -0
  15. package/build/es/components/Table/Footer/styles.js +25 -0
  16. package/build/es/components/Table/PopoverSetColumns/index.d.ts +0 -1
  17. package/build/es/components/Table/PopoverSetColumns/index.js +2 -2
  18. package/build/es/components/Table/PopoverSetColumns/styles.d.ts +8 -0
  19. package/build/es/components/Table/PopoverSetColumns/styles.js +11 -0
  20. package/build/es/components/Table/ResizableColumns/index.d.ts +9 -0
  21. package/build/es/components/Table/ResizableColumns/index.js +76 -0
  22. package/build/es/components/Table/ResizableColumns/styles.d.ts +8 -0
  23. package/build/es/components/Table/ResizableColumns/styles.js +11 -0
  24. package/build/es/components/Table/index.d.ts +0 -1
  25. package/build/es/components/Table/index.js +5 -4
  26. package/build/es/components/Table/styles.d.ts +4 -0
  27. package/build/es/components/Table/styles.js +7 -0
  28. package/build/es/components/Table/types.d.ts +4 -0
  29. package/build/es/components/Table/utils.d.ts +6 -0
  30. package/build/es/components/Table/utils.js +13 -0
  31. package/build/es/hooks/useTable/index.d.ts +3 -0
  32. package/build/es/hooks/useTable/index.js +313 -0
  33. package/build/es/hooks/useTable/types.d.ts +123 -0
  34. package/build/es/hooks/useTable/types.js +1 -0
  35. package/build/es/index.d.ts +2 -0
  36. package/build/es/index.js +2 -0
  37. package/build/es/locale/en-us.d.ts +25 -0
  38. package/build/es/locale/en-us.js +27 -0
  39. package/build/es/locale/index.d.ts +3 -0
  40. package/build/es/locale/index.js +7 -0
  41. package/build/es/locale/types.d.ts +9 -0
  42. package/build/es/locale/types.js +1 -0
  43. package/build/es/locale/zh-cn.d.ts +25 -0
  44. package/build/es/locale/zh-cn.js +28 -0
  45. package/build/lib/components/ConfigProvider/index.js +7 -2
  46. package/build/lib/components/SearchArea/Item/index.js +54 -0
  47. package/build/lib/components/SearchArea/ToggleButton/index.js +70 -0
  48. package/build/lib/components/SearchArea/index.js +174 -0
  49. package/build/lib/components/Table/Footer/index.js +19 -16
  50. package/build/lib/components/Table/Footer/styles.js +31 -0
  51. package/build/lib/components/Table/PopoverSetColumns/index.js +2 -2
  52. package/build/lib/components/Table/PopoverSetColumns/styles.js +17 -0
  53. package/build/lib/components/Table/ResizableColumns/index.js +114 -0
  54. package/build/lib/components/Table/ResizableColumns/styles.js +17 -0
  55. package/build/lib/components/Table/index.js +5 -4
  56. package/build/lib/components/Table/styles.js +13 -0
  57. package/build/lib/components/Table/utils.js +17 -0
  58. package/build/lib/hooks/useTable/index.js +315 -0
  59. package/build/lib/hooks/useTable/types.js +2 -0
  60. package/build/lib/index.d.ts +179 -0
  61. package/build/lib/index.js +5 -1
  62. package/build/lib/locale/en-us.d.ts +25 -0
  63. package/build/lib/locale/en-us.js +29 -0
  64. package/build/lib/locale/index.d.ts +3 -0
  65. package/build/lib/locale/index.js +13 -0
  66. package/build/lib/locale/types.d.ts +9 -0
  67. package/build/lib/locale/types.js +2 -0
  68. package/build/lib/locale/zh-cn.d.ts +25 -0
  69. package/build/lib/locale/zh-cn.js +30 -0
  70. package/build/package.json +7 -5
  71. package/build/types/components/ConfigProvider/types.d.ts +2 -0
  72. package/build/types/components/SearchArea/Item/index.d.ts +10 -0
  73. package/build/types/components/SearchArea/ToggleButton/index.d.ts +15 -0
  74. package/build/types/components/SearchArea/index.d.ts +25 -0
  75. package/build/types/components/Table/Footer/index.d.ts +1 -2
  76. package/build/types/components/Table/Footer/styles.d.ts +25 -0
  77. package/build/types/components/Table/PopoverSetColumns/index.d.ts +0 -1
  78. package/build/types/components/Table/PopoverSetColumns/styles.d.ts +8 -0
  79. package/build/types/components/Table/ResizableColumns/index.d.ts +9 -0
  80. package/build/types/components/Table/ResizableColumns/styles.d.ts +8 -0
  81. package/build/types/components/Table/index.d.ts +0 -1
  82. package/build/types/components/Table/styles.d.ts +4 -0
  83. package/build/types/components/Table/types.d.ts +4 -0
  84. package/build/types/components/Table/utils.d.ts +6 -0
  85. package/build/types/hooks/useTable/index.d.ts +3 -0
  86. package/build/types/hooks/useTable/types.d.ts +123 -0
  87. package/build/types/index.d.ts +2 -0
  88. package/build/types/locale/en-us.d.ts +25 -0
  89. package/build/types/locale/index.d.ts +3 -0
  90. package/build/types/locale/types.d.ts +9 -0
  91. package/build/types/locale/zh-cn.d.ts +25 -0
  92. package/package.json +7 -5
  93. package/build/dist/index.css +0 -1
package/README.md CHANGED
@@ -1,266 +1,1439 @@
1
1
  # XMirror Components
2
2
 
3
- 一个基于 React 和 Ant Design 的高质量组件库,提供了一系列实用的 UI 组件和 Hooks,帮助开发者快速构建现代化的 Web 应用。
3
+ 一个基于 React + TypeScript + Ant Design 的现代化组件库,提供高质量、可复用的 UI 组件和 Hooks。
4
4
 
5
- ## ✨ 特性
5
+ ## 🚀 特性
6
6
 
7
- - 🚀 **基于 Ant Design 5.x** - 继承 Ant Design 的设计语言和交互体验
8
- - 📦 **开箱即用** - 提供常用的业务组件和工具函数
9
- - 🎯 **TypeScript 支持** - 完整的 TypeScript 类型定义
10
- - 🔧 **高度可定制** - 支持主题定制和样式覆盖
11
- - 📱 **响应式设计** - 适配各种屏幕尺寸
12
- - 🎨 **现代化 UI** - 符合当前设计趋势的组件样式
7
+ - **TypeScript 支持**: 完整的类型定义和类型安全
8
+ - **现代化架构**: 基于 React 18+ 和最新的前端技术栈
9
+ - **Ant Design 集成**: 与 Ant Design 5.x 完美集成
10
+ - **高性能**: 优化的渲染性能和内存管理
11
+ - **可扩展**: 模块化设计,易于扩展和定制
12
+ - **国际化**: 内置多语言支持
13
13
 
14
14
  ## 📦 安装
15
15
 
16
16
  ```bash
17
17
  npm install xmirror-components
18
- # 或
19
- yarn add xmirror-components
20
- # 或
21
- pnpm add xmirror-components
22
18
  ```
23
19
 
24
20
  ## 🔧 依赖要求
25
21
 
26
- - React >= 16.9.0
27
- - React DOM >= 16.9.0
28
- - Ant Design >= 5.0.0
22
+ ```json
23
+ {
24
+ "peerDependencies": {
25
+ "antd": ">=5.0.0",
26
+ "react": ">=18.0.0",
27
+ "react-dom": ">=18.0.0",
28
+ "@ant-design/icons": ">=5.0.0",
29
+ "ahooks": ">=3.0.0",
30
+ "lodash-es": ">=4.17.0",
31
+ "react-intl": ">=7.0.0",
32
+ "react-transition-group": ">=4.4.0"
33
+ }
34
+ }
35
+ ```
29
36
 
30
- ## 🚀 快速开始
37
+ ## 🎯 核心组件
31
38
 
32
- ### 1. 引入组件
39
+ ### AntdApp
33
40
 
34
- ```tsx
35
- import { App, CheckboxValue, SwitchValue, IconFont, IconButton, useRequest } from 'xmirror-components';
36
- ```
41
+ Ant Design 应用的根组件,提供全局配置和主题支持。集成了全局加载状态管理和配置提供者功能。
42
+
43
+ #### 特性
44
+ - **全局状态管理**: 集成 message、notification、modal 等全局方法
45
+ - **配置支持**: 内置 ConfigProvider 配置支持
46
+ - **加载状态**: 集成 GlobalLoading 全局加载状态
47
+ - **类型安全**: 完整的 TypeScript 类型支持
37
48
 
38
- ### 2. 使用 App 组件包装应用
49
+ #### 基本用法
39
50
 
40
- ```tsx
41
- import React from 'react';
42
- import { App } from 'xmirror-components';
51
+ ```typescript
52
+ import { App, message, notification, modal } from 'xmirror-components'
43
53
 
44
54
  function MyApp() {
45
55
  return (
46
- <App>
47
- <YourAppContent />
56
+ <App
57
+ config={{
58
+ iconButton: {
59
+ size: 'small',
60
+ style: { color: '#1890ff' }
61
+ },
62
+ iconFont: {
63
+ className: 'my-iconfont'
64
+ }
65
+ }}
66
+ >
67
+ <div>你的应用内容</div>
48
68
  </App>
49
- );
69
+ )
70
+ }
71
+
72
+ // 使用全局方法
73
+ const handleClick = () => {
74
+ message.success('操作成功')
75
+ notification.info({
76
+ message: '通知',
77
+ description: '这是一个通知消息'
78
+ })
79
+ modal.confirm({
80
+ title: '确认',
81
+ content: '确定要执行此操作吗?',
82
+ onOk: () => console.log('确认')
83
+ })
50
84
  }
51
85
  ```
52
86
 
53
- ## 📚 组件文档
87
+ #### API 参考
88
+
89
+ | 属性 | 类型 | 默认值 | 说明 |
90
+ |------|------|--------|------|
91
+ | `config` | `ConfigProviderConfigProps` | - | 全局配置选项 |
92
+ | `children` | `React.ReactNode` | - | 子组件 |
54
93
 
55
- ### App 组件
94
+ ### ConfigProvider
56
95
 
57
- Ant Design 5.x 的 App 组件封装,提供全局的 message、notification、modal 等静态方法。
96
+ 配置提供者,用于设置国际化、主题等全局配置。支持组件级别的配置覆盖。
58
97
 
59
- ```tsx
60
- import { App, message, notification, modal } from 'xmirror-components';
98
+ #### 特性
99
+ - **递归合并**: 支持配置的深度合并
100
+ - **类型安全**: 完整的 TypeScript 类型定义
101
+ - **组件配置**: 支持 IconButton、IconFont 等组件的全局配置
61
102
 
62
- function MyComponent() {
63
- const handleClick = () => {
64
- message.success('操作成功!');
65
- notification.info('这是一条通知');
66
- modal.confirm({
67
- title: '确认删除',
68
- content: '确定要删除这条记录吗?',
69
- });
70
- };
103
+ #### 基本用法
71
104
 
105
+ ```typescript
106
+ import { ConfigProvider } from 'xmirror-components'
107
+
108
+ function App() {
72
109
  return (
73
- <App>
74
- <button onClick={handleClick}>显示消息</button>
75
- </App>
76
- );
110
+ <ConfigProvider
111
+ config={{
112
+ iconButton: {
113
+ size: 'middle',
114
+ style: {
115
+ color: '#1890ff',
116
+ borderRadius: '4px'
117
+ },
118
+ className: 'custom-icon-button'
119
+ },
120
+ iconFont: {
121
+ className: 'my-iconfont',
122
+ style: { fontSize: '16px' }
123
+ }
124
+ }}
125
+ >
126
+ <div>你的应用内容</div>
127
+ </ConfigProvider>
128
+ )
77
129
  }
78
130
  ```
79
131
 
80
- ### CheckboxValue 组件
132
+ #### API 参考
133
+
134
+ | 属性 | 类型 | 默认值 | 说明 |
135
+ |------|------|--------|------|
136
+ | `config` | `ConfigProviderConfigProps` | - | 配置对象 |
137
+
138
+ ##### ConfigProviderConfigProps
139
+
140
+ ```typescript
141
+ interface ConfigProviderConfigProps {
142
+ iconButton?: {
143
+ size?: 'small' | 'middle' | 'large'
144
+ style?: React.CSSProperties
145
+ className?: string
146
+ render?: (props: any) => React.ReactNode
147
+ }
148
+ iconFont?: {
149
+ className?: string
150
+ style?: React.CSSProperties
151
+ }
152
+ }
153
+ ```
154
+
155
+ ### Table
156
+
157
+ 功能强大的表格组件,支持排序、筛选、分页、列设置、列宽调整等功能。
158
+
159
+ #### 特性
160
+ - **列管理**: 支持列的显示/隐藏、排序、宽度调整
161
+ - **本地存储**: 自动保存用户的列配置到本地存储
162
+ - **响应式**: 支持响应式布局和滚动
163
+ - **可扩展**: 支持自定义渲染和样式
164
+ - **类型安全**: 完整的 TypeScript 泛型支持
165
+
166
+ #### 基本用法
81
167
 
82
- 支持自定义选中/未选中值的复选框组件。
168
+ ```typescript
169
+ import { Table } from 'xmirror-components'
83
170
 
84
- ```tsx
85
- import { CheckboxValue } from 'xmirror-components';
171
+ function UserTable() {
172
+ const columns = [
173
+ {
174
+ title: '姓名',
175
+ dataIndex: 'name',
176
+ key: 'name',
177
+ sorter: true,
178
+ filters: [
179
+ { text: '张三', value: 'zhangsan' },
180
+ { text: '李四', value: 'lisi' }
181
+ ]
182
+ },
183
+ {
184
+ title: '年龄',
185
+ dataIndex: 'age',
186
+ key: 'age',
187
+ sorter: true
188
+ },
189
+ {
190
+ title: '邮箱',
191
+ dataIndex: 'email',
192
+ key: 'email',
193
+ ellipsis: true
194
+ }
195
+ ]
86
196
 
87
- function MyForm() {
88
- const [status, setStatus] = useState('Y');
197
+ const dataSource = [
198
+ { id: 1, name: '张三', age: 25, email: 'zhangsan@example.com' },
199
+ { id: 2, name: '李四', age: 30, email: 'lisi@example.com' }
200
+ ]
89
201
 
90
202
  return (
91
- <CheckboxValue
92
- checked={status}
93
- trueValue="Y"
94
- falseValue="N"
95
- trueLabel="已启用"
96
- falseLabel="未启用"
97
- onChange={(value) => setStatus(value)}
203
+ <Table
204
+ columns={columns}
205
+ dataSource={dataSource}
206
+ rowKey="id"
207
+ pagination={{
208
+ current: 1,
209
+ pageSize: 10,
210
+ total: 100
211
+ }}
212
+ columnsSort={true}
213
+ columnsVisible={true}
214
+ columnsResizable={true}
215
+ tableId="user-table"
98
216
  />
99
- );
217
+ )
100
218
  }
101
219
  ```
102
220
 
103
- **Props:**
221
+ #### 高级用法
222
+
223
+ ```typescript
224
+ // 自定义列渲染
225
+ const columns = [
226
+ {
227
+ title: '状态',
228
+ dataIndex: 'status',
229
+ key: 'status',
230
+ render: (status: string) => (
231
+ <Tag color={status === 'active' ? 'green' : 'red'}>
232
+ {status === 'active' ? '激活' : '禁用'}
233
+ </Tag>
234
+ )
235
+ },
236
+ {
237
+ title: '操作',
238
+ key: 'action',
239
+ render: (_, record) => (
240
+ <Space>
241
+ <IconButton icon="edit" onClick={() => handleEdit(record)} />
242
+ <IconButton icon="delete" onClick={() => handleDelete(record)} />
243
+ </Space>
244
+ )
245
+ }
246
+ ]
247
+
248
+ // 使用本地存储的列配置
249
+ <Table
250
+ columns={columns}
251
+ dataSource={dataSource}
252
+ columnsSort={true} // 启用列排序
253
+ columnsVisible={true} // 启用列显示/隐藏
254
+ columnsResizable={true} // 启用列宽调整
255
+ tableId="unique-table-id" // 唯一标识,用于本地存储
256
+ />
257
+ ```
258
+
259
+ #### API 参考
104
260
 
105
- | 参数 | 说明 | 类型 | 默认值 |
106
- |------|------|------|--------|
107
- | checked | 当前选中值 | any | - |
108
- | onChange | 变化时回调 | (value, event) => void | - |
109
- | trueValue | 选中时的值 | any | true |
110
- | falseValue | 未选中时的值 | any | false |
111
- | trueLabel | 选中时显示的文本 | string | '' |
112
- | falseLabel | 未选中时显示的文本 | string | '' |
261
+ | 属性 | 类型 | 默认值 | 说明 |
262
+ |------|------|--------|------|
263
+ | `columns` | `ColumnType[]` | `[]` | 表格列配置 |
264
+ | `dataSource` | `any[]` | `[]` | 数据源 |
265
+ | `columnsSort` | `boolean` | `false` | 是否启用列排序 |
266
+ | `columnsVisible` | `boolean` | `false` | 是否启用列显示/隐藏 |
267
+ | `columnsResizable` | `boolean` | `false` | 是否启用列宽调整 |
268
+ | `tableId` | `string` | `''` | 表格唯一标识,用于本地存储 |
113
269
 
114
- ### SwitchValue 组件
270
+ ### SearchArea
115
271
 
116
- 支持自定义开关值的开关组件。
272
+ 搜索区域组件,提供灵活的搜索和筛选功能。支持展开/收起动画和自定义布局。
117
273
 
118
- ```tsx
119
- import { SwitchValue } from 'xmirror-components';
274
+ #### 特性
275
+ - **动画效果**: 平滑的展开/收起动画
276
+ - **响应式布局**: 支持多种屏幕尺寸的响应式布局
277
+ - **自定义配置**: 支持自定义列布局和样式
278
+ - **Hook支持**: 提供 useSearchArea Hook 进行状态管理
120
279
 
121
- function MyComponent() {
122
- const [enabled, setEnabled] = useState(1);
280
+ #### 基本用法
281
+
282
+ ```typescript
283
+ import { SearchArea } from 'xmirror-components'
284
+
285
+ function SearchForm() {
286
+ const handleSearch = (values: any) => {
287
+ console.log('搜索参数:', values)
288
+ }
289
+
290
+ const handleReset = () => {
291
+ console.log('重置搜索')
292
+ }
123
293
 
124
294
  return (
125
- <SwitchValue
126
- checked={enabled}
127
- trueValue={1}
128
- falseValue={0}
129
- onChange={(value) => setEnabled(value)}
130
- />
131
- );
295
+ <SearchArea
296
+ onSearch={handleSearch}
297
+ onReset={handleReset}
298
+ loading={false}
299
+ >
300
+ <SearchArea.Item name="name" label="姓名">
301
+ <Input placeholder="请输入姓名" />
302
+ </SearchArea.Item>
303
+ <SearchArea.Item name="status" label="状态">
304
+ <Select placeholder="请选择状态">
305
+ <Option value="active">激活</Option>
306
+ <Option value="inactive">禁用</Option>
307
+ </Select>
308
+ </SearchArea.Item>
309
+ </SearchArea>
310
+ )
132
311
  }
133
312
  ```
134
313
 
135
- ### IconFont 组件
314
+ #### 使用 Hook 管理状态
136
315
 
137
- 图标字体组件,支持 symbol 模式和普通模式。
316
+ ```typescript
317
+ import { SearchArea } from 'xmirror-components'
138
318
 
139
- ```tsx
140
- import { IconFont } from 'xmirror-components';
319
+ function AdvancedSearch() {
320
+ const searchArea = SearchArea.useSearchArea(false) // 默认收起
141
321
 
142
- function MyComponent() {
143
322
  return (
144
323
  <div>
145
- {/* 普通模式 */}
146
- <IconFont type="icon-user" />
324
+ <SearchArea.ToggleButton
325
+ onClick={searchArea.toggle}
326
+ show={searchArea.show}
327
+ >
328
+ 高级搜索
329
+ </SearchArea.ToggleButton>
147
330
 
148
- {/* Symbol 模式 */}
149
- <IconFont type="icon-home" symbol />
331
+ <SearchArea
332
+ instance={searchArea}
333
+ onSearch={handleSearch}
334
+ >
335
+ {/* 搜索表单项 */}
336
+ </SearchArea>
337
+ </div>
338
+ )
339
+ }
340
+ ```
341
+
342
+ #### API 参考
343
+
344
+ | 属性 | 类型 | 默认值 | 说明 |
345
+ |------|------|--------|------|
346
+ | `onSearch` | `(data: any) => void` | - | 搜索回调函数 |
347
+ | `onReset` | `() => void` | - | 重置回调函数 |
348
+ | `onClose` | `() => void` | - | 收起回调函数 |
349
+ | `loading` | `boolean` | `false` | 加载状态 |
350
+ | `instance` | `SearchAreaHooks` | - | 外部状态管理实例 |
351
+ | `col` | `ColProps` | `{}` | 列配置 |
352
+ | `row` | `RowProps` | `{}` | 行配置 |
353
+
354
+ ### GlobalLoading
355
+
356
+ 全局加载状态管理组件,提供美观的加载动画和全局状态控制。
357
+
358
+ #### 特性
359
+ - **动画效果**: 流畅的进入/退出动画
360
+ - **全局控制**: 通过 setGlobalLoading 函数全局控制
361
+ - **美观设计**: 现代化的加载动画效果
362
+ - **高性能**: 使用 CSSTransition 优化性能
363
+
364
+ #### 基本用法
365
+
366
+ ```typescript
367
+ import { GlobalLoading, setGlobalLoading } from 'xmirror-components'
368
+
369
+ function App() {
370
+ const handleAsyncOperation = async () => {
371
+ setGlobalLoading(true)
372
+ try {
373
+ await fetchData()
374
+ } finally {
375
+ setGlobalLoading(false)
376
+ }
377
+ }
378
+
379
+ return (
380
+ <div>
381
+ <button onClick={handleAsyncOperation}>
382
+ 执行异步操作
383
+ </button>
384
+ <GlobalLoading />
150
385
  </div>
151
- );
386
+ )
387
+ }
388
+ ```
389
+
390
+ #### 在 AntdApp 中使用
391
+
392
+ ```typescript
393
+ import { App, setGlobalLoading } from 'xmirror-components'
394
+
395
+ // AntdApp 已内置 GlobalLoading,可直接使用
396
+ function MyApp() {
397
+ const handleRequest = async () => {
398
+ setGlobalLoading(true)
399
+ try {
400
+ await api.getData()
401
+ } finally {
402
+ setGlobalLoading(false)
403
+ }
404
+ }
405
+
406
+ return <App>{/* 你的应用 */}</App>
152
407
  }
153
408
  ```
154
409
 
155
- ### IconButton 组件
410
+ #### API 参考
411
+
412
+ | 方法 | 类型 | 说明 |
413
+ |------|------|------|
414
+ | `setGlobalLoading` | `(loading: boolean) => void` | 设置全局加载状态 |
415
+
416
+ ### IconButton
417
+
418
+ 图标按钮组件,支持多种图标类型和自定义配置。
419
+
420
+ #### 特性
421
+ - **图标支持**: 支持 IconFont 和 React 图标组件
422
+ - **Tooltip 支持**: 内置 Tooltip 提示功能
423
+ - **权限控制**: 支持权限标识和隐藏控制
424
+ - **样式定制**: 支持自定义样式和主题
156
425
 
157
- 图标按钮组件,提供更好的交互体验。
426
+ #### 基本用法
158
427
 
159
- ```tsx
160
- import { IconButton } from 'xmirror-components';
428
+ ```typescript
429
+ import { IconButton } from 'xmirror-components'
161
430
 
162
- function MyComponent() {
431
+ function ActionButtons() {
163
432
  return (
164
- <IconButton
165
- icon="icon-edit"
166
- onClick={() => console.log('编辑')}
167
- tooltip="编辑"
168
- />
169
- );
433
+ <Space>
434
+ <IconButton
435
+ icon="edit"
436
+ title="编辑"
437
+ onClick={() => console.log('编辑')}
438
+ />
439
+ <IconButton
440
+ icon="delete"
441
+ title="删除"
442
+ disabled
443
+ disabledReason="无权限删除"
444
+ onClick={() => console.log('删除')}
445
+ />
446
+ <IconButton
447
+ icon={<CustomIcon />}
448
+ title="自定义图标"
449
+ size="large"
450
+ loading
451
+ />
452
+ </Space>
453
+ )
454
+ }
455
+ ```
456
+
457
+ #### 使用 React 图标
458
+
459
+ ```typescript
460
+ import { EditOutlined, DeleteOutlined } from '@ant-design/icons'
461
+
462
+ function CustomButtons() {
463
+ return (
464
+ <Space>
465
+ <IconButton
466
+ icon={<EditOutlined />}
467
+ title="编辑"
468
+ onClick={handleEdit}
469
+ />
470
+ <IconButton
471
+ icon={<DeleteOutlined />}
472
+ title="删除"
473
+ onClick={handleDelete}
474
+ />
475
+ </Space>
476
+ )
477
+ }
478
+ ```
479
+
480
+ #### API 参考
481
+
482
+ | 属性 | 类型 | 默认值 | 说明 |
483
+ |------|------|--------|------|
484
+ | `icon` | `React.ReactNode \| string` | - | 图标 |
485
+ | `title` | `React.ReactNode` | - | 提示内容 |
486
+ | `onClick` | `(e: React.MouseEvent) => void` | - | 点击事件 |
487
+ | `disabled` | `boolean` | `false` | 是否禁用 |
488
+ | `disabledReason` | `React.ReactNode` | - | 禁用原因 |
489
+ | `hide` | `boolean` | `false` | 是否隐藏 |
490
+ | `size` | `'small' \| 'middle' \| 'large'` | `'small'` | 按钮大小 |
491
+ | `loading` | `boolean` | `false` | 加载状态 |
492
+
493
+ ### IconFont
494
+
495
+ 图标字体组件,支持自定义图标字体。
496
+
497
+ #### 特性
498
+ - **字体图标**: 支持 iconfont 字体图标
499
+ - **Symbol 模式**: 支持 SVG Symbol 模式
500
+ - **样式定制**: 支持自定义样式和类名
501
+ - **类型安全**: 完整的 TypeScript 类型支持
502
+
503
+ #### 基本用法
504
+
505
+ ```typescript
506
+ import { IconFont } from 'xmirror-components'
507
+
508
+ function IconExamples() {
509
+ return (
510
+ <Space>
511
+ {/* 字体图标模式 */}
512
+ <IconFont type="icon-home" />
513
+ <IconFont type="icon-user" size={24} />
514
+
515
+ {/* Symbol 模式 */}
516
+ <IconFont type="icon-setting" symbol />
517
+ </Space>
518
+ )
519
+ }
520
+ ```
521
+
522
+ #### 配置全局样式
523
+
524
+ ```typescript
525
+ import { ConfigProvider } from 'xmirror-components'
526
+
527
+ function App() {
528
+ return (
529
+ <ConfigProvider
530
+ config={{
531
+ iconFont: {
532
+ className: 'my-iconfont',
533
+ style: { fontSize: '16px', color: '#1890ff' }
534
+ }
535
+ }}
536
+ >
537
+ <IconFont type="icon-custom" />
538
+ </ConfigProvider>
539
+ )
540
+ }
541
+ ```
542
+
543
+ #### API 参考
544
+
545
+ | 属性 | 类型 | 默认值 | 说明 |
546
+ |------|------|--------|------|
547
+ | `type` | `string` | - | 图标类型 |
548
+ | `symbol` | `boolean` | `false` | 是否使用 Symbol 模式 |
549
+ | `className` | `string` | - | 自定义类名 |
550
+ | `style` | `React.CSSProperties` | - | 自定义样式 |
551
+
552
+ ### SwitchValue
553
+
554
+ 开关值组件,支持自定义选中和未选中的值。
555
+
556
+ #### 特性
557
+ - **自定义值**: 支持任意类型的选中/未选中值
558
+ - **类型安全**: 完整的 TypeScript 泛型支持
559
+ - **简单易用**: 与原生 Switch 组件 API 一致
560
+
561
+ #### 基本用法
562
+
563
+ ```typescript
564
+ import { SwitchValue } from 'xmirror-components'
565
+
566
+ function SwitchExamples() {
567
+ const [status, setStatus] = useState('active')
568
+
569
+ return (
570
+ <Space direction="vertical">
571
+ {/* 字符串值 */}
572
+ <SwitchValue
573
+ checked={status}
574
+ trueValue="active"
575
+ falseValue="inactive"
576
+ onChange={(value) => setStatus(value)}
577
+ />
578
+
579
+ {/* 数字值 */}
580
+ <SwitchValue
581
+ checked={isEnabled}
582
+ trueValue={1}
583
+ falseValue={0}
584
+ onChange={(value) => setIsEnabled(value)}
585
+ />
586
+
587
+ {/* 对象值 */}
588
+ <SwitchValue
589
+ checked={config}
590
+ trueValue={{ enabled: true, level: 'high' }}
591
+ falseValue={{ enabled: false, level: 'low' }}
592
+ onChange={(value) => setConfig(value)}
593
+ />
594
+ </Space>
595
+ )
596
+ }
597
+ ```
598
+
599
+ #### API 参考
600
+
601
+ | 属性 | 类型 | 默认值 | 说明 |
602
+ |------|------|--------|------|
603
+ | `checked` | `T \| F` | - | 当前值 |
604
+ | `trueValue` | `T` | `true` | 选中值 |
605
+ | `falseValue` | `F` | `false` | 未选中值 |
606
+ | `onChange` | `(value: T \| F, event) => void` | - | 值变化回调 |
607
+
608
+ ### CheckboxValue
609
+
610
+ 复选框值组件,支持自定义选中值和标签。
611
+
612
+ #### 特性
613
+ - **自定义值**: 支持任意类型的选中/未选中值
614
+ - **自定义标签**: 支持自定义显示标签
615
+ - **类型安全**: 完整的 TypeScript 泛型支持
616
+
617
+ #### 基本用法
618
+
619
+ ```typescript
620
+ import { CheckboxValue } from 'xmirror-components'
621
+
622
+ function CheckboxExamples() {
623
+ const [agreed, setAgreed] = useState(false)
624
+
625
+ return (
626
+ <Space direction="vertical">
627
+ {/* 基本用法 */}
628
+ <CheckboxValue
629
+ checked={agreed}
630
+ trueValue={true}
631
+ falseValue={false}
632
+ trueLabel="同意协议"
633
+ falseLabel="不同意协议"
634
+ onChange={(value) => setAgreed(value)}
635
+ />
636
+
637
+ {/* 自定义值 */}
638
+ <CheckboxValue
639
+ checked={permission}
640
+ trueValue="admin"
641
+ falseValue="user"
642
+ trueLabel="管理员权限"
643
+ falseLabel="普通用户权限"
644
+ onChange={(value) => setPermission(value)}
645
+ />
646
+ </Space>
647
+ )
170
648
  }
171
649
  ```
172
650
 
173
- ### GlobalLoading 组件
651
+ #### API 参考
652
+
653
+ | 属性 | 类型 | 默认值 | 说明 |
654
+ |------|------|--------|------|
655
+ | `checked` | `T \| F` | - | 当前值 |
656
+ | `trueValue` | `T` | `true` | 选中值 |
657
+ | `falseValue` | `F` | `false` | 未选中值 |
658
+ | `trueLabel` | `string` | `''` | 选中标签 |
659
+ | `falseLabel` | `string` | `''` | 未选中标签 |
660
+ | `onChange` | `(value: T \| F, event) => void` | - | 值变化回调 |
661
+
662
+ ## 🪝 核心 Hooks
663
+
664
+ ### useTable
665
+
666
+ 一个功能强大的表格数据管理 Hook,提供完整的数据获取、分页、排序、筛选、多选等功能。
174
667
 
175
- 全局加载组件,用于页面级别的加载状态。
668
+ #### 特性
176
669
 
177
- ```tsx
178
- import { GlobalLoading } from 'xmirror-components';
670
+ - **类型安全**: 完整的 TypeScript 泛型支持
671
+ - **数据管理**: 自动处理数据获取、缓存和更新
672
+ - **分页支持**: 内置分页逻辑和状态管理
673
+ - **排序筛选**: 支持列排序和条件筛选
674
+ - **多选支持**: 支持行选择和跨页选择
675
+ - **定时刷新**: 可配置的定时数据刷新
676
+ - **错误处理**: 完善的错误处理和用户提示
677
+ - **性能优化**: 使用 useMemoizedFn 和 useCallback 优化性能
179
678
 
180
- function MyComponent() {
181
- const [loading, setLoading] = useState(false);
679
+ #### 基本用法
680
+
681
+ ```typescript
682
+ import { useTable } from 'xmirror-components/hooks/useTable'
683
+
684
+ interface User {
685
+ id: number
686
+ name: string
687
+ email: string
688
+ status: 'active' | 'inactive'
689
+ }
690
+
691
+ function UserTable() {
692
+ const { tableProps, search, rowSelection } = useTable<User>(
693
+ // 请求函数
694
+ async (params) => {
695
+ const response = await fetchUsers(params)
696
+ return {
697
+ records: response.data,
698
+ total: response.total,
699
+ current: response.current,
700
+ size: response.pageSize
701
+ }
702
+ },
703
+ // 配置选项
704
+ {
705
+ rowKey: 'id',
706
+ immediate: true,
707
+ showRowSelection: true,
708
+ defaultPagination: {
709
+ current: 1,
710
+ pageSize: 20
711
+ }
712
+ }
713
+ )
182
714
 
183
715
  return (
184
- <GlobalLoading loading={loading}>
185
- <YourContent />
186
- </GlobalLoading>
187
- );
716
+ <Table
717
+ {...tableProps}
718
+ columns={[
719
+ { title: 'ID', dataIndex: 'id', key: 'id' },
720
+ { title: '姓名', dataIndex: 'name', key: 'name' },
721
+ { title: '邮箱', dataIndex: 'email', key: 'email' },
722
+ { title: '状态', dataIndex: 'status', key: 'status' }
723
+ ]}
724
+ />
725
+ )
188
726
  }
189
727
  ```
190
728
 
191
- ## 🎣 Hooks
729
+ #### 高级用法
730
+
731
+ ```typescript
732
+ const { tableProps, search, rowSelection } = useTable<User>(
733
+ fetchUsers,
734
+ {
735
+ rowKey: 'id',
736
+ interval: 30000, // 30秒自动刷新
737
+ multiPageSelection: true, // 支持跨页选择
738
+ onBeforeRequest: async (params) => {
739
+ // 请求前处理
740
+ console.log('请求参数:', params)
741
+ return params
742
+ },
743
+ onAfterRequest: async (response) => {
744
+ // 响应后处理
745
+ console.log('响应数据:', response)
746
+ return response.records
747
+ }
748
+ }
749
+ )
750
+ ```
751
+
752
+ #### API 参考
753
+
754
+ ##### OptionsProps<T>
755
+
756
+ | 属性 | 类型 | 默认值 | 说明 |
757
+ |------|------|--------|------|
758
+ | `rowKey` | `keyof T \| string` | `'id'` | 行数据的唯一标识字段 |
759
+ | `interval` | `false \| number` | `false` | 定时刷新间隔(毫秒) |
760
+ | `immediate` | `boolean` | `true` | 是否立即执行首次请求 |
761
+ | `defaultPagination` | `object` | `{current: 1, pageSize: 10}` | 默认分页配置 |
762
+ | `showRowSelection` | `boolean` | `false` | 是否显示行选择 |
763
+ | `multiPageSelection` | `boolean` | `false` | 是否支持跨页选择 |
764
+ | `onBeforeRequest` | `function` | - | 请求前回调函数 |
765
+ | `onAfterRequest` | `function` | - | 响应后回调函数 |
766
+
767
+ ##### ReturnData<T>
768
+
769
+ | 属性 | 类型 | 说明 |
770
+ |------|------|------|
771
+ | `loading` | `boolean` | 加载状态 |
772
+ | `tableProps` | `object` | 表格组件的 props |
773
+ | `search` | `object` | 搜索相关功能 |
774
+ | `rowSelection` | `object` | 行选择相关功能 |
775
+
776
+ #### 搜索和筛选
777
+
778
+ ```typescript
779
+ // 提交搜索
780
+ search.submit({ status: 'active', keyword: 'john' })
781
+
782
+ // 刷新数据
783
+ search.refresh()
784
+
785
+ // 获取当前搜索参数
786
+ console.log(search.params)
787
+
788
+ // 获取分页信息
789
+ console.log(search.pagination)
790
+ ```
791
+
792
+ #### 行选择
793
+
794
+ ```typescript
795
+ // 获取选中的行
796
+ console.log(rowSelection.selectedRows)
797
+
798
+ // 获取选中的行键
799
+ console.log(rowSelection.selectedRowKeys)
800
+ ```
192
801
 
193
802
  ### useRequest
194
803
 
195
- 基于 ahooks 的 useRequest 封装,提供统一的错误处理和数据处理。
804
+ 基于 ahooks 的请求管理 Hook,提供请求状态管理和缓存功能。扩展了错误处理和数据处理能力。
805
+
806
+ #### 特性
807
+ - **错误处理**: 自动显示错误消息,支持自定义错误处理
808
+ - **数据处理**: 自动处理嵌套的响应数据结构
809
+ - **类型安全**: 完整的 TypeScript 泛型支持
810
+ - **缓存支持**: 基于 ahooks 的缓存机制
811
+ - **插件系统**: 支持 ahooks 插件生态
196
812
 
197
- ```tsx
198
- import { useRequest } from 'xmirror-components';
813
+ #### 基本用法
199
814
 
200
- function MyComponent() {
201
- const { data, loading, run } = useRequest(
815
+ ```typescript
816
+ import { useEffect } from 'react'
817
+ import { Select } from 'antd'
818
+ import { useRequest } from 'xmirror-components'
819
+ import { getUserOptions } from '@/api/home/user'
820
+
821
+
822
+ function Index ({ ...props }) {
823
+ const {
824
+ loading,
825
+ data
826
+ } = useRequest(getUserOptions)
827
+
828
+ return (
829
+ <Select
830
+ className="w-180"
831
+ loading={loading}
832
+ placeholder="请选择"
833
+ options={data}
834
+ {...props}
835
+ />
836
+ )
837
+ }
838
+
839
+ export default Index
840
+ ```
841
+
842
+ ```typescript
843
+ import { useEffect } from 'react'
844
+ import { Select } from 'antd'
845
+ import { useRequest } from 'xmirror-components'
846
+ import { getProfitOptions } from '@/api/home/vendor/credit/detail/listing-information'
847
+
848
+ interface Props {
849
+ vendorId: string
850
+
851
+ [prop: string]: any
852
+ }
853
+
854
+ function Index ({ vendorId, ...props }: Props) {
855
+ const {
856
+ loading,
857
+ data,
858
+ run
859
+ } = useRequest(() => {
860
+ return getProfitOptions(vendorId)
861
+ }, {
862
+ manual: true // 关闭自动进入页面自动请求
863
+ })
864
+
865
+ useEffect(() => {
866
+ if (vendorId) {
867
+ run()
868
+ }
869
+ }, [vendorId])
870
+
871
+ return (
872
+ <Select
873
+ className="w-180"
874
+ loading={loading}
875
+ placeholder="请选择季度"
876
+ options={data}
877
+ {...props}
878
+ />
879
+ )
880
+ }
881
+
882
+ export default Index
883
+ ```
884
+
885
+ #### 处理嵌套数据结构
886
+
887
+ ```typescript
888
+ // 当 API 返回 { code: 200, data: [...], success: true } 格式时
889
+ const { data } = useRequest(
890
+ async () => {
891
+ const response = await fetch('/api/users')
892
+ return response.json() // 返回 { code: 200, data: [...], success: true }
893
+ }
894
+ )
895
+
896
+ // data 将直接是用户数组,而不是 { code, data, success } 对象
897
+ console.log(data) // [...]
898
+ ```
899
+
900
+ #### 自定义错误处理
901
+
902
+ ```typescript
903
+ const { data, loading } = useRequest(
904
+ fetchUsers,
905
+ {
906
+ errorMessage: false, // 禁用自动错误消息
907
+ onError: (error) => {
908
+ // 自定义错误处理
909
+ console.error('请求失败:', error)
910
+ notification.error({
911
+ message: '自定义错误提示',
912
+ description: error.message
913
+ })
914
+ }
915
+ }
916
+ )
917
+ ```
918
+
919
+ #### 使用插件
920
+
921
+ ```typescript
922
+ import { useRequest } from 'xmirror-components'
923
+ import { useDebouncePlugin, usePollingPlugin } from 'ahooks'
924
+
925
+ function SearchComponent() {
926
+ const [keyword, setKeyword] = useState('')
927
+
928
+ const { data, loading } = useRequest(
929
+ (params) => searchUsers(params),
930
+ {
931
+ errorMessage: true,
932
+ refreshDeps: [keyword]
933
+ },
934
+ [
935
+ useDebouncePlugin({ wait: 300 }), // 防抖
936
+ usePollingPlugin({ interval: 5000 }) // 轮询
937
+ ]
938
+ )
939
+
940
+ return (
941
+ <div>
942
+ <Input
943
+ value={keyword}
944
+ onChange={(e) => setKeyword(e.target.value)}
945
+ placeholder="搜索用户"
946
+ />
947
+ {/* 搜索结果 */}
948
+ </div>
949
+ )
950
+ }
951
+ ```
952
+
953
+ #### API 参考
954
+
955
+ | 属性 | 类型 | 默认值 | 说明 |
956
+ |------|------|--------|------|
957
+ | `errorMessage` | `boolean` | `true` | 是否显示错误消息 |
958
+ | `onError` | `(error: Error, params: any[]) => void` | - | 错误回调函数 |
959
+
960
+ ##### 返回值
961
+
962
+ | 属性 | 类型 | 说明 |
963
+ |------|------|------|
964
+ | `data` | `TData` | 处理后的数据 |
965
+ | `loading` | `boolean` | 加载状态 |
966
+ | `error` | `Error \| undefined` | 错误信息 |
967
+ | `refresh` | `() => void` | 刷新函数 |
968
+ | `mutate` | `(data: TData) => void` | 手动设置数据 |
969
+ | `cancel` | `() => void` | 取消请求 |
970
+
971
+ ##### 扩展选项
972
+
973
+ useRequest 支持所有 ahooks useRequest 的选项,包括:
974
+
975
+ - `cacheKey`: 缓存键
976
+ - `refreshDeps`: 依赖刷新
977
+ - `pollingInterval`: 轮询间隔
978
+ - `ready`: 是否准备就绪
979
+ - `onSuccess`: 成功回调
980
+ - `onError`: 错误回调
981
+ - `onFinally`: 完成回调
982
+
983
+ ## 🚀 快速开始
984
+
985
+ ### 完整示例
986
+
987
+ ```typescript
988
+ import React from 'react'
989
+ import {
990
+ App,
991
+ Table,
992
+ SearchArea,
993
+ IconButton,
994
+ useTable,
995
+ useRequest,
996
+ message
997
+ } from 'xmirror-components'
998
+ import { Input, Select, Button, Space } from 'antd'
999
+
1000
+ // 用户管理页面示例
1001
+ function UserManagement() {
1002
+ // 使用 useTable Hook 管理表格数据
1003
+ const { tableProps, search, rowSelection } = useTable(
202
1004
  async (params) => {
203
- const response = await fetch('/api/data', { params });
204
- return response.json();
1005
+ const response = await fetch('/api/users', {
1006
+ method: 'POST',
1007
+ body: JSON.stringify(params)
1008
+ })
1009
+ return response.json()
1010
+ },
1011
+ {
1012
+ rowKey: 'id',
1013
+ showRowSelection: true,
1014
+ defaultPagination: { current: 1, pageSize: 20 }
1015
+ }
1016
+ )
1017
+
1018
+ // 使用 useRequest Hook 处理删除操作
1019
+ const { run: deleteUser } = useRequest(
1020
+ async (id: number) => {
1021
+ await fetch(`/api/users/${id}`, { method: 'DELETE' })
1022
+ },
1023
+ {
1024
+ onSuccess: () => {
1025
+ message.success('删除成功')
1026
+ search.refresh() // 刷新表格
1027
+ }
1028
+ }
1029
+ )
1030
+
1031
+ const columns = [
1032
+ {
1033
+ title: '姓名',
1034
+ dataIndex: 'name',
1035
+ key: 'name',
1036
+ sorter: true
1037
+ },
1038
+ {
1039
+ title: '邮箱',
1040
+ dataIndex: 'email',
1041
+ key: 'email'
1042
+ },
1043
+ {
1044
+ title: '状态',
1045
+ dataIndex: 'status',
1046
+ key: 'status',
1047
+ render: (status: string) => (
1048
+ <span style={{ color: status === 'active' ? 'green' : 'red' }}>
1049
+ {status === 'active' ? '激活' : '禁用'}
1050
+ </span>
1051
+ )
205
1052
  },
206
1053
  {
207
- manual: true,
208
- errorMessage: true, // 自动显示错误信息
1054
+ title: '操作',
1055
+ key: 'action',
1056
+ render: (_, record) => (
1057
+ <Space>
1058
+ <IconButton
1059
+ icon="edit"
1060
+ title="编辑"
1061
+ onClick={() => handleEdit(record)}
1062
+ />
1063
+ <IconButton
1064
+ icon="delete"
1065
+ title="删除"
1066
+ onClick={() => deleteUser(record.id)}
1067
+ />
1068
+ </Space>
1069
+ )
209
1070
  }
210
- );
1071
+ ]
211
1072
 
212
1073
  return (
213
1074
  <div>
214
- <button onClick={() => run({ page: 1 })} disabled={loading}>
215
- {loading ? '加载中...' : '获取数据'}
216
- </button>
217
- {data && <pre>{JSON.stringify(data, null, 2)}</pre>}
1075
+ {/* 搜索区域 */}
1076
+ <SearchArea
1077
+ onSearch={(values) => search.submit(values)}
1078
+ onReset={() => search.submit({})}
1079
+ >
1080
+ <SearchArea.Item name="name" label="姓名">
1081
+ <Input placeholder="请输入姓名" />
1082
+ </SearchArea.Item>
1083
+ <SearchArea.Item name="status" label="状态">
1084
+ <Select placeholder="请选择状态">
1085
+ <Select.Option value="active">激活</Select.Option>
1086
+ <Select.Option value="inactive">禁用</Select.Option>
1087
+ </Select>
1088
+ </SearchArea.Item>
1089
+ </SearchArea>
1090
+
1091
+ {/* 表格 */}
1092
+ <Table
1093
+ {...tableProps}
1094
+ columns={columns}
1095
+ columnsSort={true}
1096
+ columnsVisible={true}
1097
+ columnsResizable={true}
1098
+ tableId="user-management"
1099
+ />
218
1100
  </div>
219
- );
1101
+ )
220
1102
  }
1103
+
1104
+ // 应用入口
1105
+ function App() {
1106
+ return (
1107
+ <App
1108
+ config={{
1109
+ iconButton: {
1110
+ size: 'small',
1111
+ style: { color: '#1890ff' }
1112
+ }
1113
+ }}
1114
+ >
1115
+ <UserManagement />
1116
+ </App>
1117
+ )
1118
+ }
1119
+
1120
+ export default App
221
1121
  ```
222
1122
 
223
- ## 🎨 主题定制
1123
+ ## 🎨 样式系统
1124
+
1125
+ 组件库使用 CSS-in-JS 方案,支持主题定制和样式覆盖。
224
1126
 
225
- 组件库支持通过 CSS 变量进行主题定制:
1127
+ ### 主题定制
226
1128
 
227
- ```css
228
- :root {
229
- --primary-color: #1890ff;
1129
+ ```typescript
1130
+ import { ConfigProvider } from 'xmirror-components'
1131
+
1132
+ function App() {
1133
+ return (
1134
+ <ConfigProvider
1135
+ config={{
1136
+ iconButton: {
1137
+ style: {
1138
+ color: '#1890ff',
1139
+ borderRadius: '6px'
1140
+ }
1141
+ },
1142
+ iconFont: {
1143
+ style: {
1144
+ fontSize: '16px',
1145
+ color: '#666'
1146
+ }
1147
+ }
1148
+ }}
1149
+ >
1150
+ {/* 你的应用 */}
1151
+ </ConfigProvider>
1152
+ )
230
1153
  }
231
1154
  ```
232
1155
 
1156
+ ### 自定义样式
1157
+
1158
+ ```typescript
1159
+ import styled from '@emotion/styled'
1160
+ import { Table } from 'xmirror-components'
1161
+
1162
+ const CustomTable = styled(Table)`
1163
+ .ant-table-thead > tr > th {
1164
+ background-color: #f5f5f5;
1165
+ font-weight: 600;
1166
+ }
1167
+
1168
+ .ant-table-tbody > tr:hover > td {
1169
+ background-color: #f0f9ff;
1170
+ }
1171
+ `
1172
+
1173
+ function MyTable() {
1174
+ return <CustomTable {...props} />
1175
+ }
1176
+ ```
1177
+
1178
+ ## 🌍 国际化
1179
+
1180
+ 内置国际化支持,使用 react-intl 实现多语言切换。
1181
+
1182
+ ### 基本配置
1183
+
1184
+ ```typescript
1185
+ import { ConfigProvider } from 'xmirror-components'
1186
+ import { IntlProvider } from 'react-intl'
1187
+ import zhCN from 'antd/locale/zh_CN'
1188
+ import enUS from 'antd/locale/en_US'
1189
+
1190
+ const messages = {
1191
+ 'zh-CN': require('./locales/zh-CN.json'),
1192
+ 'en-US': require('./locales/en-US.json')
1193
+ }
1194
+
1195
+ function App() {
1196
+ const [locale, setLocale] = useState('zh-CN')
1197
+
1198
+ return (
1199
+ <IntlProvider locale={locale} messages={messages[locale]}>
1200
+ <ConfigProvider locale={locale === 'zh-CN' ? zhCN : enUS}>
1201
+ {/* 你的应用 */}
1202
+ </ConfigProvider>
1203
+ </IntlProvider>
1204
+ )
1205
+ }
1206
+ ```
1207
+
1208
+ ## 📋 最佳实践
1209
+
1210
+ ### 1. 组件组合使用
1211
+
1212
+ ```typescript
1213
+ // 推荐:组合使用多个组件
1214
+ function DataTable() {
1215
+ const { tableProps, search } = useTable(fetchData)
1216
+
1217
+ return (
1218
+ <div>
1219
+ <SearchArea onSearch={search.submit}>
1220
+ {/* 搜索表单项 */}
1221
+ </SearchArea>
1222
+ <Table {...tableProps} />
1223
+ </div>
1224
+ )
1225
+ }
1226
+ ```
1227
+
1228
+ ### 2. 错误处理
1229
+
1230
+ ```typescript
1231
+ // 推荐:统一的错误处理
1232
+ const { data, loading, error } = useRequest(fetchData, {
1233
+ errorMessage: true, // 自动显示错误消息
1234
+ onError: (error) => {
1235
+ // 记录错误日志
1236
+ console.error('API Error:', error)
1237
+ }
1238
+ })
1239
+ ```
1240
+
1241
+ ### 3. 性能优化
1242
+
1243
+ ```typescript
1244
+ // 推荐:使用 useMemo 优化渲染
1245
+ const columns = useMemo(() => [
1246
+ {
1247
+ title: '姓名',
1248
+ dataIndex: 'name',
1249
+ render: (text) => <span>{text}</span>
1250
+ }
1251
+ ], [])
1252
+
1253
+ // 推荐:使用 useCallback 优化事件处理
1254
+ const handleEdit = useCallback((record) => {
1255
+ // 编辑逻辑
1256
+ }, [])
1257
+ ```
1258
+
1259
+ ### 4. 类型安全
1260
+
1261
+ ```typescript
1262
+ // 推荐:定义完整的类型
1263
+ interface User {
1264
+ id: number
1265
+ name: string
1266
+ email: string
1267
+ status: 'active' | 'inactive'
1268
+ }
1269
+
1270
+ const { tableProps } = useTable<User>(fetchUsers, {
1271
+ rowKey: 'id'
1272
+ })
1273
+ ```
1274
+
1275
+ ## 🔧 常见问题
1276
+
1277
+ ### Q: 如何自定义表格样式?
1278
+
1279
+ A: 使用 styled-components 或 emotion 包装 Table 组件:
1280
+
1281
+ ```typescript
1282
+ import styled from '@emotion/styled'
1283
+ import { Table } from 'xmirror-components'
1284
+
1285
+ const CustomTable = styled(Table)`
1286
+ .ant-table-thead > tr > th {
1287
+ background-color: #f5f5f5;
1288
+ }
1289
+ `
1290
+ ```
1291
+
1292
+ ### Q: 如何处理大量数据?
1293
+
1294
+ A: 使用虚拟滚动或分页加载:
1295
+
1296
+ ```typescript
1297
+ const { tableProps } = useTable(fetchData, {
1298
+ defaultPagination: { current: 1, pageSize: 50 }
1299
+ })
1300
+ ```
1301
+
1302
+ ### Q: 如何实现权限控制?
1303
+
1304
+ A: 使用 IconButton 的权限属性:
1305
+
1306
+ ```typescript
1307
+ <IconButton
1308
+ icon="delete"
1309
+ hide={!hasPermission('delete')}
1310
+ disabled={!hasPermission('delete')}
1311
+ disabledReason="无删除权限"
1312
+ />
1313
+ ```
1314
+
1315
+ ## 📚 开发指南
1316
+
233
1317
  ### 项目结构
234
1318
 
235
1319
  ```
236
1320
  src/
237
1321
  ├── components/ # 组件目录
238
- │ ├── AntdApp/ # App 组件
239
- │ ├── CheckboxValue/ # 复选框组件
240
- │ ├── SwitchValue/ # 开关组件
241
- │ ├── IconFont/ # 图标组件
242
- │ ├── IconButton/ # 图标按钮组件
243
- │ └── GlobalLoading/ # 全局加载组件
1322
+ │ ├── AntdApp/ # 应用根组件
1323
+ │ ├── ConfigProvider/ # 配置提供者
1324
+ │ ├── Table/ # 表格组件
1325
+ │ ├── SearchArea/ # 搜索区域
1326
+ │ └── ... # 其他组件
244
1327
  ├── hooks/ # Hooks 目录
245
- │ └── useRequest/ # 请求 Hook
246
- └── index.ts # 入口文件
1328
+ │ ├── useTable/ # 表格数据管理 Hook
1329
+ │ └── useRequest/ # 请求管理 Hook
1330
+ └── index.ts # 主入口文件
247
1331
  ```
248
1332
 
249
- ## 🤝 贡献指南
1333
+ ### 开发环境
250
1334
 
251
- 我们欢迎所有形式的贡献,包括但不限于:
1335
+ ```bash
1336
+ # 安装依赖
1337
+ npm install
1338
+
1339
+ # 启动开发服务器
1340
+ npm run dev
1341
+
1342
+ # 构建项目
1343
+ npm run build
1344
+
1345
+ # 代码检查
1346
+ npm run lint
1347
+ ```
252
1348
 
253
- - 🐛 Bug 报告
254
- - 💡 新功能建议
255
- - 📝 文档改进
256
- - 🔧 代码贡献
1349
+ ### 添加新组件
1350
+
1351
+ 1. 在 `src/components/` 目录下创建组件目录
1352
+ 2. 实现组件逻辑和类型定义
1353
+ 3. 在 `src/index.ts` 中导出组件
1354
+ 4. 更新文档和示例
1355
+
1356
+ ### 添加新 Hook
1357
+
1358
+ 1. 在 `src/hooks/` 目录下创建 Hook 目录
1359
+ 2. 实现 Hook 逻辑和类型定义
1360
+ 3. 在 `src/index.ts` 中导出 Hook
1361
+ 4. 更新文档和示例
1362
+
1363
+ ## 🤝 贡献指南
1364
+
1365
+ 我们欢迎所有形式的贡献!请查看 [CONTRIBUTING.md](./CONTRIBUTING.md) 了解详情。
257
1366
 
258
1367
  ## 📄 许可证
259
1368
 
260
- 本项目基于 [MIT](LICENSE) 许可证开源。
1369
+ 本项目采用 MIT 许可证 - 查看 [LICENSE](./LICENSE) 文件了解详情。
1370
+
1371
+ ## 🔧 最近更新
1372
+
1373
+ ### v1.0.30-alpha.10 (2024-01-XX)
1374
+
1375
+ #### 修复
1376
+ - **TypeScript 导入路径修复**: 修复了所有文件中的 TypeScript 导入路径问题
1377
+ - 移除了 `src/locale/index.ts` 中的 `.ts` 扩展名
1378
+ - 移除了 `src/components/Table/Footer/index.tsx` 中的 `.ts` 扩展名
1379
+ - 移除了 `src/locale/types.ts` 中的 `.ts` 扩展名
1380
+ - 移除了 `src/main.tsx` 中的 `.tsx` 扩展名
1381
+ - 修复了 React 导入问题,确保 JSX 正常工作
1382
+
1383
+ #### 改进
1384
+ - 解决了 TypeScript 编译错误,确保项目能够正常构建
1385
+ - 提升了代码的兼容性和可维护性
1386
+ - 统一了项目的导入规范
1387
+
1388
+ ### v1.0.30-alpha.8 (2024-01-XX)
1389
+
1390
+ #### 新增功能
1391
+ - **完整文档**: 为所有组件和 Hook 编写了详细的使用文档和 API 参考
1392
+ - **最佳实践**: 添加了组件组合使用、错误处理、性能优化等最佳实践指南
1393
+ - **完整示例**: 提供了完整的用户管理页面示例,展示组件库的实际应用
1394
+
1395
+ #### 样式系统优化
1396
+ - **ResizableColumns 样式转换**: 将 `index.less` 文件转换为 `@emotion/styled` 形式
1397
+ - 创建了 `styles.ts` 文件,使用 `@emotion/styled` 实现样式组件
1398
+ - 添加了 `react-resizable` 和 `@types/react-resizable` 依赖
1399
+ - 创建了 `utils.ts` 工具文件,提供 `dataIndexToString` 函数
1400
+ - 修复了所有 TypeScript 类型错误,提升了类型安全性
1401
+ - 删除了不再需要的 `index.less` 文件
1402
+
1403
+ #### 改进
1404
+ - 统一了项目的样式系统,全部使用 `@emotion/styled`
1405
+ - 提升了代码的类型安全性和可维护性
1406
+ - 优化了组件库的构建和打包流程
1407
+ - 完善了组件库的文档体系,提供更好的开发体验
1408
+
1409
+ ### v1.0.1 (2024-01-XX)
1410
+
1411
+ #### 修复
1412
+ - **useTable Hook 类型兼容性修复**: 修复了 `onChangeTable` 函数与 Antd Table 组件 `onChange` 回调的类型不匹配问题
1413
+ - 更新了 `TableChangeParams` 类型,使 `current` 和 `pageSize` 属性可选
1414
+ - 更新了 `FilterParams` 和 `SortParams` 类型,提高与 Antd 类型的兼容性
1415
+ - 优化了排序参数处理逻辑,支持数组形式的排序信息
1416
+ - 修复了行选择回调函数的类型定义
1417
+
1418
+ #### 改进
1419
+ - 提升了类型安全性,减少了 TypeScript 编译错误
1420
+ - 优化了代码的可维护性和扩展性
1421
+
1422
+ ## 🔗 相关链接
1423
+
1424
+ - [React 官方文档](https://react.dev/)
1425
+ - [Ant Design 官方文档](https://ant.design/)
1426
+ - [TypeScript 官方文档](https://www.typescriptlang.org/)
1427
+ - [Vite 官方文档](https://vitejs.dev/)
1428
+
1429
+ ## 📞 联系我们
1430
+
1431
+ 如有问题或建议,请通过以下方式联系我们:
1432
+
1433
+ - 提交 Issue: [GitHub Issues](https://github.com/your-org/xmirror-components/issues)
1434
+ - 提交 PR: [GitHub Pull Requests](https://github.com/your-org/xmirror-components/pulls)
1435
+ - 邮箱: your-email@example.com
261
1436
 
262
- ## 🙏 致谢
1437
+ ---
263
1438
 
264
- - [Ant Design](https://ant.design/) - 优秀的 React UI 组件库
265
- - [ahooks](https://ahooks.js.org/) - 实用的 React Hooks 库
266
- - [React](https://reactjs.org/) - 用于构建用户界面的 JavaScript 库
1439
+ **XMirror Components** - 让前端开发更简单、更高效! 🚀