xmirror-components 1.0.30-alpha.5 → 1.0.30-alpha.7
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 +215 -190
- package/build/dist/index.cjs +30 -30
- package/build/dist/index.mjs +1395 -1255
- package/build/es/hooks/useTable/index.d.ts +3 -0
- package/build/es/hooks/useTable/index.js +307 -0
- package/build/es/hooks/useTable/types.d.ts +144 -0
- package/build/es/hooks/useTable/types.js +1 -0
- package/build/es/index.d.ts +1 -0
- package/build/es/index.js +1 -0
- package/build/lib/hooks/useTable/index.js +309 -0
- package/build/lib/hooks/useTable/types.js +2 -0
- package/build/lib/index.d.ts +157 -0
- package/build/lib/index.js +3 -1
- package/build/package.json +1 -1
- package/build/types/hooks/useTable/index.d.ts +3 -0
- package/build/types/hooks/useTable/types.d.ts +144 -0
- package/build/types/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,266 +1,291 @@
|
|
|
1
1
|
# XMirror Components
|
|
2
2
|
|
|
3
|
-
一个基于 React
|
|
3
|
+
一个基于 React + TypeScript + Ant Design 的现代化组件库,提供高质量、可复用的 UI 组件和 Hooks。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 🚀 特性
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
}
|
|
36
35
|
```
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
## 🎯 核心组件
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import { App } from 'xmirror-components';
|
|
43
|
-
|
|
44
|
-
function MyApp() {
|
|
45
|
-
return (
|
|
46
|
-
<App>
|
|
47
|
-
<YourAppContent />
|
|
48
|
-
</App>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
```
|
|
39
|
+
### AntdApp
|
|
40
|
+
Ant Design 应用的根组件,提供全局配置和主题支持。
|
|
52
41
|
|
|
53
|
-
|
|
42
|
+
### ConfigProvider
|
|
43
|
+
配置提供者,用于设置国际化、主题等全局配置。
|
|
54
44
|
|
|
55
|
-
###
|
|
45
|
+
### Table
|
|
46
|
+
功能强大的表格组件,支持排序、筛选、分页、列设置等功能。
|
|
56
47
|
|
|
57
|
-
|
|
48
|
+
### SearchArea
|
|
49
|
+
搜索区域组件,提供灵活的搜索和筛选功能。
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
### GlobalLoading
|
|
52
|
+
全局加载状态管理组件。
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
message.success('操作成功!');
|
|
65
|
-
notification.info('这是一条通知');
|
|
66
|
-
modal.confirm({
|
|
67
|
-
title: '确认删除',
|
|
68
|
-
content: '确定要删除这条记录吗?',
|
|
69
|
-
});
|
|
70
|
-
};
|
|
54
|
+
### IconButton
|
|
55
|
+
图标按钮组件,支持多种图标类型。
|
|
71
56
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
<button onClick={handleClick}>显示消息</button>
|
|
75
|
-
</App>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
```
|
|
57
|
+
### IconFont
|
|
58
|
+
图标字体组件,支持自定义图标。
|
|
79
59
|
|
|
80
|
-
###
|
|
60
|
+
### SwitchValue
|
|
61
|
+
开关值组件,用于布尔值的切换。
|
|
81
62
|
|
|
82
|
-
|
|
63
|
+
### CheckboxValue
|
|
64
|
+
复选框值组件,用于多选值的管理。
|
|
83
65
|
|
|
84
|
-
|
|
85
|
-
import { CheckboxValue } from 'xmirror-components';
|
|
66
|
+
## 🪝 核心 Hooks
|
|
86
67
|
|
|
87
|
-
|
|
88
|
-
const [status, setStatus] = useState('Y');
|
|
68
|
+
### useTable
|
|
89
69
|
|
|
90
|
-
|
|
91
|
-
<CheckboxValue
|
|
92
|
-
checked={status}
|
|
93
|
-
trueValue="Y"
|
|
94
|
-
falseValue="N"
|
|
95
|
-
trueLabel="已启用"
|
|
96
|
-
falseLabel="未启用"
|
|
97
|
-
onChange={(value) => setStatus(value)}
|
|
98
|
-
/>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
```
|
|
70
|
+
一个功能强大的表格数据管理 Hook,提供完整的数据获取、分页、排序、筛选、多选等功能。
|
|
102
71
|
|
|
103
|
-
|
|
72
|
+
#### 特性
|
|
104
73
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
74
|
+
- **类型安全**: 完整的 TypeScript 泛型支持
|
|
75
|
+
- **数据管理**: 自动处理数据获取、缓存和更新
|
|
76
|
+
- **分页支持**: 内置分页逻辑和状态管理
|
|
77
|
+
- **排序筛选**: 支持列排序和条件筛选
|
|
78
|
+
- **多选支持**: 支持行选择和跨页选择
|
|
79
|
+
- **定时刷新**: 可配置的定时数据刷新
|
|
80
|
+
- **错误处理**: 完善的错误处理和用户提示
|
|
81
|
+
- **性能优化**: 使用 useMemoizedFn 和 useCallback 优化性能
|
|
113
82
|
|
|
114
|
-
|
|
83
|
+
#### 基本用法
|
|
115
84
|
|
|
116
|
-
|
|
85
|
+
```typescript
|
|
86
|
+
import { useTable } from 'xmirror-components/hooks/useTable'
|
|
117
87
|
|
|
118
|
-
|
|
119
|
-
|
|
88
|
+
interface User {
|
|
89
|
+
id: number
|
|
90
|
+
name: string
|
|
91
|
+
email: string
|
|
92
|
+
status: 'active' | 'inactive'
|
|
93
|
+
}
|
|
120
94
|
|
|
121
|
-
function
|
|
122
|
-
const
|
|
95
|
+
function UserTable() {
|
|
96
|
+
const { tableProps, search, rowSelection } = useTable<User>(
|
|
97
|
+
// 请求函数
|
|
98
|
+
async (params) => {
|
|
99
|
+
const response = await fetchUsers(params)
|
|
100
|
+
return {
|
|
101
|
+
records: response.data,
|
|
102
|
+
total: response.total,
|
|
103
|
+
current: response.current,
|
|
104
|
+
size: response.pageSize
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
// 配置选项
|
|
108
|
+
{
|
|
109
|
+
rowKey: 'id',
|
|
110
|
+
immediate: true,
|
|
111
|
+
showRowSelection: true,
|
|
112
|
+
defaultPagination: {
|
|
113
|
+
current: 1,
|
|
114
|
+
pageSize: 20
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
)
|
|
123
118
|
|
|
124
119
|
return (
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
120
|
+
<Table
|
|
121
|
+
{...tableProps}
|
|
122
|
+
columns={[
|
|
123
|
+
{ title: 'ID', dataIndex: 'id', key: 'id' },
|
|
124
|
+
{ title: '姓名', dataIndex: 'name', key: 'name' },
|
|
125
|
+
{ title: '邮箱', dataIndex: 'email', key: 'email' },
|
|
126
|
+
{ title: '状态', dataIndex: 'status', key: 'status' }
|
|
127
|
+
]}
|
|
130
128
|
/>
|
|
131
|
-
)
|
|
129
|
+
)
|
|
132
130
|
}
|
|
133
131
|
```
|
|
134
132
|
|
|
135
|
-
|
|
133
|
+
#### 高级用法
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const { tableProps, search, rowSelection } = useTable<User>(
|
|
137
|
+
fetchUsers,
|
|
138
|
+
{
|
|
139
|
+
rowKey: 'id',
|
|
140
|
+
interval: 30000, // 30秒自动刷新
|
|
141
|
+
multiPageSelection: true, // 支持跨页选择
|
|
142
|
+
onBeforeRequest: async (params) => {
|
|
143
|
+
// 请求前处理
|
|
144
|
+
console.log('请求参数:', params)
|
|
145
|
+
return params
|
|
146
|
+
},
|
|
147
|
+
onAfterRequest: async (response) => {
|
|
148
|
+
// 响应后处理
|
|
149
|
+
console.log('响应数据:', response)
|
|
150
|
+
return response.records
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
)
|
|
154
|
+
```
|
|
136
155
|
|
|
137
|
-
|
|
156
|
+
#### API 参考
|
|
138
157
|
|
|
139
|
-
|
|
140
|
-
import { IconFont } from 'xmirror-components';
|
|
158
|
+
##### OptionsProps<T>
|
|
141
159
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
```
|
|
160
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
161
|
+
|------|------|--------|------|
|
|
162
|
+
| `rowKey` | `keyof T \| string` | `'id'` | 行数据的唯一标识字段 |
|
|
163
|
+
| `interval` | `false \| number` | `false` | 定时刷新间隔(毫秒) |
|
|
164
|
+
| `immediate` | `boolean` | `true` | 是否立即执行首次请求 |
|
|
165
|
+
| `defaultPagination` | `object` | `{current: 1, pageSize: 10}` | 默认分页配置 |
|
|
166
|
+
| `showRowSelection` | `boolean` | `false` | 是否显示行选择 |
|
|
167
|
+
| `multiPageSelection` | `boolean` | `false` | 是否支持跨页选择 |
|
|
168
|
+
| `onBeforeRequest` | `function` | - | 请求前回调函数 |
|
|
169
|
+
| `onAfterRequest` | `function` | - | 响应后回调函数 |
|
|
154
170
|
|
|
155
|
-
|
|
171
|
+
##### ReturnData<T>
|
|
156
172
|
|
|
157
|
-
|
|
173
|
+
| 属性 | 类型 | 说明 |
|
|
174
|
+
|------|------|------|
|
|
175
|
+
| `loading` | `boolean` | 加载状态 |
|
|
176
|
+
| `tableProps` | `object` | 表格组件的 props |
|
|
177
|
+
| `search` | `object` | 搜索相关功能 |
|
|
178
|
+
| `rowSelection` | `object` | 行选择相关功能 |
|
|
158
179
|
|
|
159
|
-
|
|
160
|
-
import { IconButton } from 'xmirror-components';
|
|
180
|
+
#### 搜索和筛选
|
|
161
181
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
/>
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
```
|
|
182
|
+
```typescript
|
|
183
|
+
// 提交搜索
|
|
184
|
+
search.submit({ status: 'active', keyword: 'john' })
|
|
185
|
+
|
|
186
|
+
// 刷新数据
|
|
187
|
+
search.refresh()
|
|
172
188
|
|
|
173
|
-
|
|
189
|
+
// 获取当前搜索参数
|
|
190
|
+
console.log(search.params)
|
|
174
191
|
|
|
175
|
-
|
|
192
|
+
// 获取分页信息
|
|
193
|
+
console.log(search.pagination)
|
|
194
|
+
```
|
|
176
195
|
|
|
177
|
-
|
|
178
|
-
import { GlobalLoading } from 'xmirror-components';
|
|
196
|
+
#### 行选择
|
|
179
197
|
|
|
180
|
-
|
|
181
|
-
|
|
198
|
+
```typescript
|
|
199
|
+
// 获取选中的行
|
|
200
|
+
console.log(rowSelection.selectedRows)
|
|
182
201
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
<YourContent />
|
|
186
|
-
</GlobalLoading>
|
|
187
|
-
);
|
|
188
|
-
}
|
|
202
|
+
// 获取选中的行键
|
|
203
|
+
console.log(rowSelection.selectedRowKeys)
|
|
189
204
|
```
|
|
190
205
|
|
|
191
|
-
## 🎣 Hooks
|
|
192
|
-
|
|
193
206
|
### useRequest
|
|
194
207
|
|
|
195
|
-
基于 ahooks
|
|
208
|
+
基于 ahooks 的请求管理 Hook,提供请求状态管理和缓存功能。
|
|
196
209
|
|
|
197
|
-
|
|
198
|
-
import { useRequest } from 'xmirror-components';
|
|
199
|
-
|
|
200
|
-
function MyComponent() {
|
|
201
|
-
const { data, loading, run } = useRequest(
|
|
202
|
-
async (params) => {
|
|
203
|
-
const response = await fetch('/api/data', { params });
|
|
204
|
-
return response.json();
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
manual: true,
|
|
208
|
-
errorMessage: true, // 自动显示错误信息
|
|
209
|
-
}
|
|
210
|
-
);
|
|
210
|
+
## 🎨 样式系统
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
<div>
|
|
214
|
-
<button onClick={() => run({ page: 1 })} disabled={loading}>
|
|
215
|
-
{loading ? '加载中...' : '获取数据'}
|
|
216
|
-
</button>
|
|
217
|
-
{data && <pre>{JSON.stringify(data, null, 2)}</pre>}
|
|
218
|
-
</div>
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
```
|
|
212
|
+
组件库使用 CSS-in-JS 方案,支持主题定制和样式覆盖。
|
|
222
213
|
|
|
223
|
-
##
|
|
214
|
+
## 🌍 国际化
|
|
224
215
|
|
|
225
|
-
|
|
216
|
+
内置国际化支持,使用 react-intl 实现多语言切换。
|
|
226
217
|
|
|
227
|
-
|
|
228
|
-
:root {
|
|
229
|
-
--primary-color: #1890ff;
|
|
230
|
-
}
|
|
231
|
-
```
|
|
218
|
+
## 📚 开发指南
|
|
232
219
|
|
|
233
220
|
### 项目结构
|
|
234
221
|
|
|
235
222
|
```
|
|
236
223
|
src/
|
|
237
224
|
├── components/ # 组件目录
|
|
238
|
-
│ ├── AntdApp/ #
|
|
239
|
-
│ ├──
|
|
240
|
-
│ ├──
|
|
241
|
-
│ ├──
|
|
242
|
-
│
|
|
243
|
-
│ └── GlobalLoading/ # 全局加载组件
|
|
225
|
+
│ ├── AntdApp/ # 应用根组件
|
|
226
|
+
│ ├── ConfigProvider/ # 配置提供者
|
|
227
|
+
│ ├── Table/ # 表格组件
|
|
228
|
+
│ ├── SearchArea/ # 搜索区域
|
|
229
|
+
│ └── ... # 其他组件
|
|
244
230
|
├── hooks/ # Hooks 目录
|
|
245
|
-
│
|
|
246
|
-
└──
|
|
231
|
+
│ ├── useTable/ # 表格数据管理 Hook
|
|
232
|
+
│ └── useRequest/ # 请求管理 Hook
|
|
233
|
+
└── index.ts # 主入口文件
|
|
247
234
|
```
|
|
248
235
|
|
|
249
|
-
|
|
236
|
+
### 开发环境
|
|
250
237
|
|
|
251
|
-
|
|
238
|
+
```bash
|
|
239
|
+
# 安装依赖
|
|
240
|
+
npm install
|
|
252
241
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
242
|
+
# 启动开发服务器
|
|
243
|
+
npm run dev
|
|
244
|
+
|
|
245
|
+
# 构建项目
|
|
246
|
+
npm run build
|
|
247
|
+
|
|
248
|
+
# 代码检查
|
|
249
|
+
npm run lint
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### 添加新组件
|
|
253
|
+
|
|
254
|
+
1. 在 `src/components/` 目录下创建组件目录
|
|
255
|
+
2. 实现组件逻辑和类型定义
|
|
256
|
+
3. 在 `src/index.ts` 中导出组件
|
|
257
|
+
4. 更新文档和示例
|
|
258
|
+
|
|
259
|
+
### 添加新 Hook
|
|
260
|
+
|
|
261
|
+
1. 在 `src/hooks/` 目录下创建 Hook 目录
|
|
262
|
+
2. 实现 Hook 逻辑和类型定义
|
|
263
|
+
3. 在 `src/index.ts` 中导出 Hook
|
|
264
|
+
4. 更新文档和示例
|
|
265
|
+
|
|
266
|
+
## 🤝 贡献指南
|
|
267
|
+
|
|
268
|
+
我们欢迎所有形式的贡献!请查看 [CONTRIBUTING.md](./CONTRIBUTING.md) 了解详情。
|
|
257
269
|
|
|
258
270
|
## 📄 许可证
|
|
259
271
|
|
|
260
|
-
|
|
272
|
+
本项目采用 MIT 许可证 - 查看 [LICENSE](./LICENSE) 文件了解详情。
|
|
273
|
+
|
|
274
|
+
## 🔗 相关链接
|
|
275
|
+
|
|
276
|
+
- [React 官方文档](https://react.dev/)
|
|
277
|
+
- [Ant Design 官方文档](https://ant.design/)
|
|
278
|
+
- [TypeScript 官方文档](https://www.typescriptlang.org/)
|
|
279
|
+
- [Vite 官方文档](https://vitejs.dev/)
|
|
280
|
+
|
|
281
|
+
## 📞 联系我们
|
|
282
|
+
|
|
283
|
+
如有问题或建议,请通过以下方式联系我们:
|
|
284
|
+
|
|
285
|
+
- 提交 Issue: [GitHub Issues](https://github.com/your-org/xmirror-components/issues)
|
|
286
|
+
- 提交 PR: [GitHub Pull Requests](https://github.com/your-org/xmirror-components/pulls)
|
|
287
|
+
- 邮箱: your-email@example.com
|
|
261
288
|
|
|
262
|
-
|
|
289
|
+
---
|
|
263
290
|
|
|
264
|
-
|
|
265
|
-
- [ahooks](https://ahooks.js.org/) - 实用的 React Hooks 库
|
|
266
|
-
- [React](https://reactjs.org/) - 用于构建用户界面的 JavaScript 库
|
|
291
|
+
**XMirror Components** - 让前端开发更简单、更高效! 🚀
|