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 CHANGED
@@ -1,266 +1,291 @@
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
29
-
30
- ## 🚀 快速开始
31
-
32
- ### 1. 引入组件
33
-
34
- ```tsx
35
- import { App, CheckboxValue, SwitchValue, IconFont, IconButton, useRequest } from 'xmirror-components';
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
- ### 2. 使用 App 组件包装应用
37
+ ## 🎯 核心组件
39
38
 
40
- ```tsx
41
- import React from 'react';
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
- ### App 组件
45
+ ### Table
46
+ 功能强大的表格组件,支持排序、筛选、分页、列设置等功能。
56
47
 
57
- Ant Design 5.x 的 App 组件封装,提供全局的 message、notification、modal 等静态方法。
48
+ ### SearchArea
49
+ 搜索区域组件,提供灵活的搜索和筛选功能。
58
50
 
59
- ```tsx
60
- import { App, message, notification, modal } from 'xmirror-components';
51
+ ### GlobalLoading
52
+ 全局加载状态管理组件。
61
53
 
62
- function MyComponent() {
63
- const handleClick = () => {
64
- message.success('操作成功!');
65
- notification.info('这是一条通知');
66
- modal.confirm({
67
- title: '确认删除',
68
- content: '确定要删除这条记录吗?',
69
- });
70
- };
54
+ ### IconButton
55
+ 图标按钮组件,支持多种图标类型。
71
56
 
72
- return (
73
- <App>
74
- <button onClick={handleClick}>显示消息</button>
75
- </App>
76
- );
77
- }
78
- ```
57
+ ### IconFont
58
+ 图标字体组件,支持自定义图标。
79
59
 
80
- ### CheckboxValue 组件
60
+ ### SwitchValue
61
+ 开关值组件,用于布尔值的切换。
81
62
 
82
- 支持自定义选中/未选中值的复选框组件。
63
+ ### CheckboxValue
64
+ 复选框值组件,用于多选值的管理。
83
65
 
84
- ```tsx
85
- import { CheckboxValue } from 'xmirror-components';
66
+ ## 🪝 核心 Hooks
86
67
 
87
- function MyForm() {
88
- const [status, setStatus] = useState('Y');
68
+ ### useTable
89
69
 
90
- return (
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
- **Props:**
72
+ #### 特性
104
73
 
105
- | 参数 | 说明 | 类型 | 默认值 |
106
- |------|------|------|--------|
107
- | checked | 当前选中值 | any | - |
108
- | onChange | 变化时回调 | (value, event) => void | - |
109
- | trueValue | 选中时的值 | any | true |
110
- | falseValue | 未选中时的值 | any | false |
111
- | trueLabel | 选中时显示的文本 | string | '' |
112
- | falseLabel | 未选中时显示的文本 | string | '' |
74
+ - **类型安全**: 完整的 TypeScript 泛型支持
75
+ - **数据管理**: 自动处理数据获取、缓存和更新
76
+ - **分页支持**: 内置分页逻辑和状态管理
77
+ - **排序筛选**: 支持列排序和条件筛选
78
+ - **多选支持**: 支持行选择和跨页选择
79
+ - **定时刷新**: 可配置的定时数据刷新
80
+ - **错误处理**: 完善的错误处理和用户提示
81
+ - **性能优化**: 使用 useMemoizedFn 和 useCallback 优化性能
113
82
 
114
- ### SwitchValue 组件
83
+ #### 基本用法
115
84
 
116
- 支持自定义开关值的开关组件。
85
+ ```typescript
86
+ import { useTable } from 'xmirror-components/hooks/useTable'
117
87
 
118
- ```tsx
119
- import { SwitchValue } from 'xmirror-components';
88
+ interface User {
89
+ id: number
90
+ name: string
91
+ email: string
92
+ status: 'active' | 'inactive'
93
+ }
120
94
 
121
- function MyComponent() {
122
- const [enabled, setEnabled] = useState(1);
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
- <SwitchValue
126
- checked={enabled}
127
- trueValue={1}
128
- falseValue={0}
129
- onChange={(value) => setEnabled(value)}
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
- ### IconFont 组件
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
- 图标字体组件,支持 symbol 模式和普通模式。
156
+ #### API 参考
138
157
 
139
- ```tsx
140
- import { IconFont } from 'xmirror-components';
158
+ ##### OptionsProps<T>
141
159
 
142
- function MyComponent() {
143
- return (
144
- <div>
145
- {/* 普通模式 */}
146
- <IconFont type="icon-user" />
147
-
148
- {/* Symbol 模式 */}
149
- <IconFont type="icon-home" symbol />
150
- </div>
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
- ### IconButton 组件
171
+ ##### ReturnData<T>
156
172
 
157
- 图标按钮组件,提供更好的交互体验。
173
+ | 属性 | 类型 | 说明 |
174
+ |------|------|------|
175
+ | `loading` | `boolean` | 加载状态 |
176
+ | `tableProps` | `object` | 表格组件的 props |
177
+ | `search` | `object` | 搜索相关功能 |
178
+ | `rowSelection` | `object` | 行选择相关功能 |
158
179
 
159
- ```tsx
160
- import { IconButton } from 'xmirror-components';
180
+ #### 搜索和筛选
161
181
 
162
- function MyComponent() {
163
- return (
164
- <IconButton
165
- icon="icon-edit"
166
- onClick={() => console.log('编辑')}
167
- tooltip="编辑"
168
- />
169
- );
170
- }
171
- ```
182
+ ```typescript
183
+ // 提交搜索
184
+ search.submit({ status: 'active', keyword: 'john' })
185
+
186
+ // 刷新数据
187
+ search.refresh()
172
188
 
173
- ### GlobalLoading 组件
189
+ // 获取当前搜索参数
190
+ console.log(search.params)
174
191
 
175
- 全局加载组件,用于页面级别的加载状态。
192
+ // 获取分页信息
193
+ console.log(search.pagination)
194
+ ```
176
195
 
177
- ```tsx
178
- import { GlobalLoading } from 'xmirror-components';
196
+ #### 行选择
179
197
 
180
- function MyComponent() {
181
- const [loading, setLoading] = useState(false);
198
+ ```typescript
199
+ // 获取选中的行
200
+ console.log(rowSelection.selectedRows)
182
201
 
183
- return (
184
- <GlobalLoading loading={loading}>
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 的 useRequest 封装,提供统一的错误处理和数据处理。
208
+ 基于 ahooks 的请求管理 Hook,提供请求状态管理和缓存功能。
196
209
 
197
- ```tsx
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
- return (
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
- 组件库支持通过 CSS 变量进行主题定制:
216
+ 内置国际化支持,使用 react-intl 实现多语言切换。
226
217
 
227
- ```css
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/ # App 组件
239
- │ ├── CheckboxValue/ # 复选框组件
240
- │ ├── SwitchValue/ # 开关组件
241
- │ ├── IconFont/ # 图标组件
242
- │ ├── IconButton/ # 图标按钮组件
243
- │ └── GlobalLoading/ # 全局加载组件
225
+ │ ├── AntdApp/ # 应用根组件
226
+ │ ├── ConfigProvider/ # 配置提供者
227
+ │ ├── Table/ # 表格组件
228
+ │ ├── SearchArea/ # 搜索区域
229
+ │ └── ... # 其他组件
244
230
  ├── hooks/ # Hooks 目录
245
- │ └── useRequest/ # 请求 Hook
246
- └── index.ts # 入口文件
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
- - 🐛 Bug 报告
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
- 本项目基于 [MIT](LICENSE) 许可证开源。
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
- - [Ant Design](https://ant.design/) - 优秀的 React UI 组件库
265
- - [ahooks](https://ahooks.js.org/) - 实用的 React Hooks 库
266
- - [React](https://reactjs.org/) - 用于构建用户界面的 JavaScript 库
291
+ **XMirror Components** - 让前端开发更简单、更高效! 🚀