xmirror-components 1.0.30-alpha.8 → 1.0.30
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 +1129 -11
- package/build/dist/index.cjs +36 -36
- package/build/dist/index.mjs +1914 -1884
- package/build/es/components/ConfigProvider/index.js +11 -14
- package/build/es/components/ConfigProvider/types.d.ts +2 -0
- package/build/es/components/IntlProvider/FormattedMessage/index.d.ts +7 -0
- package/build/es/components/IntlProvider/FormattedMessage/index.js +8 -0
- package/build/es/components/IntlProvider/index.d.ts +12 -0
- package/build/es/components/IntlProvider/index.js +17 -0
- package/build/es/components/IntlProvider/types.d.ts +7 -0
- package/build/es/components/IntlProvider/types.js +1 -0
- package/build/es/components/IntlProvider/useIntl/index.d.ts +14 -0
- package/build/es/components/IntlProvider/useIntl/index.js +26 -0
- package/build/es/components/SearchArea/ToggleButton/index.js +2 -1
- package/build/es/components/SearchArea/index.js +6 -3
- package/build/es/components/Table/Footer/index.d.ts +1 -1
- package/build/es/components/Table/Footer/index.js +1 -1
- package/build/es/components/Table/PopoverSetColumns/index.js +1 -1
- package/build/es/hooks/useTable/index.js +1 -1
- package/build/es/locale/en-us.d.ts +25 -0
- package/build/es/locale/en-us.js +27 -0
- package/build/es/locale/index.d.ts +3 -0
- package/build/es/locale/index.js +7 -0
- package/build/es/locale/types.d.ts +9 -0
- package/build/es/locale/types.js +1 -0
- package/build/es/locale/zh-cn.d.ts +25 -0
- package/build/es/locale/zh-cn.js +28 -0
- package/build/lib/components/ConfigProvider/index.js +11 -14
- package/build/lib/components/IntlProvider/FormattedMessage/index.js +11 -0
- package/build/lib/components/IntlProvider/index.js +25 -0
- package/build/lib/components/IntlProvider/types.js +2 -0
- package/build/lib/components/IntlProvider/useIntl/index.js +31 -0
- package/build/lib/components/SearchArea/ToggleButton/index.js +2 -1
- package/build/lib/components/SearchArea/index.js +6 -3
- package/build/lib/components/Table/Footer/index.js +2 -2
- package/build/lib/components/Table/PopoverSetColumns/index.js +2 -2
- package/build/lib/hooks/useTable/index.js +2 -2
- package/build/lib/index.d.ts +3 -0
- package/build/lib/locale/en-us.d.ts +25 -0
- package/build/lib/locale/en-us.js +29 -0
- package/build/lib/locale/index.d.ts +3 -0
- package/build/lib/locale/index.js +13 -0
- package/build/lib/locale/types.d.ts +9 -0
- package/build/lib/locale/types.js +2 -0
- package/build/lib/locale/zh-cn.d.ts +25 -0
- package/build/lib/locale/zh-cn.js +30 -0
- package/build/package.json +1 -1
- package/build/types/components/ConfigProvider/types.d.ts +2 -0
- package/build/types/components/IntlProvider/FormattedMessage/index.d.ts +7 -0
- package/build/types/components/IntlProvider/index.d.ts +12 -0
- package/build/types/components/IntlProvider/types.d.ts +7 -0
- package/build/types/components/IntlProvider/useIntl/index.d.ts +14 -0
- package/build/types/components/Table/Footer/index.d.ts +1 -1
- package/build/types/locale/en-us.d.ts +25 -0
- package/build/types/locale/index.d.ts +3 -0
- package/build/types/locale/types.d.ts +9 -0
- package/build/types/locale/zh-cn.d.ts +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,31 +37,627 @@ npm install xmirror-components
|
|
|
37
37
|
## 🎯 核心组件
|
|
38
38
|
|
|
39
39
|
### AntdApp
|
|
40
|
-
|
|
40
|
+
|
|
41
|
+
Ant Design 应用的根组件,提供全局配置和主题支持。集成了全局加载状态管理和配置提供者功能。
|
|
42
|
+
|
|
43
|
+
#### 特性
|
|
44
|
+
- **全局状态管理**: 集成 message、notification、modal 等全局方法
|
|
45
|
+
- **配置支持**: 内置 ConfigProvider 配置支持
|
|
46
|
+
- **加载状态**: 集成 GlobalLoading 全局加载状态
|
|
47
|
+
- **类型安全**: 完整的 TypeScript 类型支持
|
|
48
|
+
|
|
49
|
+
#### 基本用法
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { App, message, notification, modal } from 'xmirror-components'
|
|
53
|
+
|
|
54
|
+
function MyApp() {
|
|
55
|
+
return (
|
|
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>
|
|
68
|
+
</App>
|
|
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
|
+
})
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### API 参考
|
|
88
|
+
|
|
89
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
90
|
+
|------|------|--------|------|
|
|
91
|
+
| `config` | `ConfigProviderConfigProps` | - | 全局配置选项 |
|
|
92
|
+
| `children` | `React.ReactNode` | - | 子组件 |
|
|
41
93
|
|
|
42
94
|
### ConfigProvider
|
|
43
|
-
|
|
95
|
+
|
|
96
|
+
配置提供者,用于设置国际化、主题等全局配置。支持组件级别的配置覆盖。
|
|
97
|
+
|
|
98
|
+
#### 特性
|
|
99
|
+
- **递归合并**: 支持配置的深度合并
|
|
100
|
+
- **类型安全**: 完整的 TypeScript 类型定义
|
|
101
|
+
- **组件配置**: 支持 IconButton、IconFont 等组件的全局配置
|
|
102
|
+
|
|
103
|
+
#### 基本用法
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { ConfigProvider } from 'xmirror-components'
|
|
107
|
+
|
|
108
|
+
function App() {
|
|
109
|
+
return (
|
|
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
|
+
)
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
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
|
+
```
|
|
44
154
|
|
|
45
155
|
### Table
|
|
46
|
-
|
|
156
|
+
|
|
157
|
+
功能强大的表格组件,支持排序、筛选、分页、列设置、列宽调整等功能。
|
|
158
|
+
|
|
159
|
+
#### 特性
|
|
160
|
+
- **列管理**: 支持列的显示/隐藏、排序、宽度调整
|
|
161
|
+
- **本地存储**: 自动保存用户的列配置到本地存储
|
|
162
|
+
- **响应式**: 支持响应式布局和滚动
|
|
163
|
+
- **可扩展**: 支持自定义渲染和样式
|
|
164
|
+
- **类型安全**: 完整的 TypeScript 泛型支持
|
|
165
|
+
|
|
166
|
+
#### 基本用法
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { Table } from 'xmirror-components'
|
|
170
|
+
|
|
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
|
+
]
|
|
196
|
+
|
|
197
|
+
const dataSource = [
|
|
198
|
+
{ id: 1, name: '张三', age: 25, email: 'zhangsan@example.com' },
|
|
199
|
+
{ id: 2, name: '李四', age: 30, email: 'lisi@example.com' }
|
|
200
|
+
]
|
|
201
|
+
|
|
202
|
+
return (
|
|
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"
|
|
216
|
+
/>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
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 参考
|
|
260
|
+
|
|
261
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
262
|
+
|------|------|--------|------|
|
|
263
|
+
| `columns` | `ColumnType[]` | `[]` | 表格列配置 |
|
|
264
|
+
| `dataSource` | `any[]` | `[]` | 数据源 |
|
|
265
|
+
| `columnsSort` | `boolean` | `false` | 是否启用列排序 |
|
|
266
|
+
| `columnsVisible` | `boolean` | `false` | 是否启用列显示/隐藏 |
|
|
267
|
+
| `columnsResizable` | `boolean` | `false` | 是否启用列宽调整 |
|
|
268
|
+
| `tableId` | `string` | `''` | 表格唯一标识,用于本地存储 |
|
|
47
269
|
|
|
48
270
|
### SearchArea
|
|
49
|
-
|
|
271
|
+
|
|
272
|
+
搜索区域组件,提供灵活的搜索和筛选功能。支持展开/收起动画和自定义布局。
|
|
273
|
+
|
|
274
|
+
#### 特性
|
|
275
|
+
- **动画效果**: 平滑的展开/收起动画
|
|
276
|
+
- **响应式布局**: 支持多种屏幕尺寸的响应式布局
|
|
277
|
+
- **自定义配置**: 支持自定义列布局和样式
|
|
278
|
+
- **Hook支持**: 提供 useSearchArea Hook 进行状态管理
|
|
279
|
+
|
|
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
|
+
}
|
|
293
|
+
|
|
294
|
+
return (
|
|
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
|
+
)
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
#### 使用 Hook 管理状态
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
import { SearchArea } from 'xmirror-components'
|
|
318
|
+
|
|
319
|
+
function AdvancedSearch() {
|
|
320
|
+
const searchArea = SearchArea.useSearchArea(false) // 默认收起
|
|
321
|
+
|
|
322
|
+
return (
|
|
323
|
+
<div>
|
|
324
|
+
<SearchArea.ToggleButton
|
|
325
|
+
onClick={searchArea.toggle}
|
|
326
|
+
show={searchArea.show}
|
|
327
|
+
>
|
|
328
|
+
高级搜索
|
|
329
|
+
</SearchArea.ToggleButton>
|
|
330
|
+
|
|
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` | `{}` | 行配置 |
|
|
50
353
|
|
|
51
354
|
### GlobalLoading
|
|
52
|
-
|
|
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 />
|
|
385
|
+
</div>
|
|
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>
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
#### API 参考
|
|
411
|
+
|
|
412
|
+
| 方法 | 类型 | 说明 |
|
|
413
|
+
|------|------|------|
|
|
414
|
+
| `setGlobalLoading` | `(loading: boolean) => void` | 设置全局加载状态 |
|
|
53
415
|
|
|
54
416
|
### IconButton
|
|
55
|
-
|
|
417
|
+
|
|
418
|
+
图标按钮组件,支持多种图标类型和自定义配置。
|
|
419
|
+
|
|
420
|
+
#### 特性
|
|
421
|
+
- **图标支持**: 支持 IconFont 和 React 图标组件
|
|
422
|
+
- **Tooltip 支持**: 内置 Tooltip 提示功能
|
|
423
|
+
- **权限控制**: 支持权限标识和隐藏控制
|
|
424
|
+
- **样式定制**: 支持自定义样式和主题
|
|
425
|
+
|
|
426
|
+
#### 基本用法
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
import { IconButton } from 'xmirror-components'
|
|
430
|
+
|
|
431
|
+
function ActionButtons() {
|
|
432
|
+
return (
|
|
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` | 加载状态 |
|
|
56
492
|
|
|
57
493
|
### IconFont
|
|
58
|
-
|
|
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` | - | 自定义样式 |
|
|
59
551
|
|
|
60
552
|
### SwitchValue
|
|
61
|
-
|
|
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` | - | 值变化回调 |
|
|
62
607
|
|
|
63
608
|
### CheckboxValue
|
|
64
|
-
|
|
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
|
+
)
|
|
648
|
+
}
|
|
649
|
+
```
|
|
650
|
+
|
|
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` | - | 值变化回调 |
|
|
65
661
|
|
|
66
662
|
## 🪝 核心 Hooks
|
|
67
663
|
|
|
@@ -205,16 +801,517 @@ console.log(rowSelection.selectedRowKeys)
|
|
|
205
801
|
|
|
206
802
|
### useRequest
|
|
207
803
|
|
|
208
|
-
基于 ahooks 的请求管理 Hook
|
|
804
|
+
基于 ahooks 的请求管理 Hook,提供请求状态管理和缓存功能。扩展了错误处理和数据处理能力。
|
|
805
|
+
|
|
806
|
+
#### 特性
|
|
807
|
+
- **错误处理**: 自动显示错误消息,支持自定义错误处理
|
|
808
|
+
- **数据处理**: 自动处理嵌套的响应数据结构
|
|
809
|
+
- **类型安全**: 完整的 TypeScript 泛型支持
|
|
810
|
+
- **缓存支持**: 基于 ahooks 的缓存机制
|
|
811
|
+
- **插件系统**: 支持 ahooks 插件生态
|
|
812
|
+
|
|
813
|
+
#### 基本用法
|
|
814
|
+
|
|
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(
|
|
1004
|
+
async (params) => {
|
|
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
|
+
)
|
|
1052
|
+
},
|
|
1053
|
+
{
|
|
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
|
+
)
|
|
1070
|
+
}
|
|
1071
|
+
]
|
|
1072
|
+
|
|
1073
|
+
return (
|
|
1074
|
+
<div>
|
|
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
|
+
/>
|
|
1100
|
+
</div>
|
|
1101
|
+
)
|
|
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
|
|
1121
|
+
```
|
|
209
1122
|
|
|
210
1123
|
## 🎨 样式系统
|
|
211
1124
|
|
|
212
1125
|
组件库使用 CSS-in-JS 方案,支持主题定制和样式覆盖。
|
|
213
1126
|
|
|
1127
|
+
### 主题定制
|
|
1128
|
+
|
|
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
|
+
)
|
|
1153
|
+
}
|
|
1154
|
+
```
|
|
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
|
+
|
|
214
1178
|
## 🌍 国际化
|
|
215
1179
|
|
|
216
1180
|
内置国际化支持,使用 react-intl 实现多语言切换。
|
|
217
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
|
+
|
|
218
1315
|
## 📚 开发指南
|
|
219
1316
|
|
|
220
1317
|
### 项目结构
|
|
@@ -273,7 +1370,27 @@ npm run lint
|
|
|
273
1370
|
|
|
274
1371
|
## 🔧 最近更新
|
|
275
1372
|
|
|
276
|
-
### v1.0.
|
|
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
|
+
- **完整示例**: 提供了完整的用户管理页面示例,展示组件库的实际应用
|
|
277
1394
|
|
|
278
1395
|
#### 样式系统优化
|
|
279
1396
|
- **ResizableColumns 样式转换**: 将 `index.less` 文件转换为 `@emotion/styled` 形式
|
|
@@ -287,6 +1404,7 @@ npm run lint
|
|
|
287
1404
|
- 统一了项目的样式系统,全部使用 `@emotion/styled`
|
|
288
1405
|
- 提升了代码的类型安全性和可维护性
|
|
289
1406
|
- 优化了组件库的构建和打包流程
|
|
1407
|
+
- 完善了组件库的文档体系,提供更好的开发体验
|
|
290
1408
|
|
|
291
1409
|
### v1.0.1 (2024-01-XX)
|
|
292
1410
|
|