@yetuzi/vue3-query-components 1.0.1 → 1.0.2

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,15 +1,18 @@
1
- # Vue3 Query Components
1
+ # @yetuzi/vue3-query-components
2
2
 
3
- 基于 Vue 3 + Element Plus 的查询页面组件库,专注于表格查询场景,开箱即用。
3
+ 基于 Vue 3 + Element Plus 的企业级查询页面组件库,专注于表格查询场景,开箱即用。
4
4
 
5
5
  ## ✨ 特性
6
6
 
7
7
  - 🚀 **开箱即用** - 高度封装的业务组件,减少重复开发
8
- - 🎨 **统一设计** - 基于 Element Plus 设计语言
8
+ - 🎨 **统一设计** - 基于 Element Plus 设计语言,支持全局配置
9
9
  - 🔧 **高度可配置** - 灵活的配置选项,满足不同业务需求
10
- - 📦 **TypeScript 支持** - 完整的类型定义
10
+ - 📦 **TypeScript 支持** - 完整的类型定义,类型安全
11
11
  - 🌳 **Tree Shaking** - 按需引入,减小打包体积
12
12
  - 🔥 **热更新** - 支持开发模式热更新
13
+ - 🎯 **业务导向** - 专注于查询、表单、表格等常见业务场景
14
+ - 🔄 **状态管理** - 内置数据请求、分页、表单状态管理
15
+ - 🎨 **插槽支持** - 灵活的插槽系统,支持自定义扩展
13
16
 
14
17
  ## 📦 安装
15
18
 
@@ -29,6 +32,7 @@ pnpm add @yetuzi/vue3-query-components
29
32
  import { createApp } from 'vue'
30
33
  import Vue3QueryComponents from '@yetuzi/vue3-query-components'
31
34
  import '@yetuzi/vue3-query-components/dist/style.css'
35
+ import 'element-plus/theme-chalk/index.css' // 需要安装 Element Plus
32
36
 
33
37
  const app = createApp(App)
34
38
  app.use(Vue3QueryComponents)
@@ -37,129 +41,246 @@ app.use(Vue3QueryComponents)
37
41
  ### 2. 按需引入
38
42
 
39
43
  ```typescript
40
- import { CommonTable, CommonForm } from '@yetuzi/vue3-query-components'
44
+ import {
45
+ CommonQueryTable,
46
+ CommonTable,
47
+ CommonForm,
48
+ CommonConfigProvider
49
+ } from '@yetuzi/vue3-query-components'
41
50
  import '@yetuzi/vue3-query-components/dist/style.css'
51
+ import 'element-plus/theme-chalk/index.css' // 需要安装 Element Plus
42
52
  ```
43
53
 
44
54
  ### 3. 基础使用
45
55
 
46
- #### 表格组件
56
+ #### 完整查询表格组件(推荐)
57
+
58
+ `CommonQueryTable` 是一个高度集成的组件,包含表单查询、表格展示、分页功能。
47
59
 
48
60
  ```vue
49
61
  <template>
50
- <CommonTable
51
- :columns="columns"
52
- :data="tableData"
53
- :loading="loading"
54
- :pagination="pagination"
55
- @page-change="handlePageChange"
56
- />
62
+ <CommonQueryTable :fetch="fetchData" :form="formConfig" :columns="tableColumns" />
57
63
  </template>
58
64
 
59
65
  <script setup>
60
- import { ref } from 'vue'
61
- import { CommonTable } from '@yetuzi/vue3-query-components'
66
+ import { CommonQueryTable } from '@yetuzi/vue3-query-components'
67
+
68
+ // 数据请求函数
69
+ const fetchData = async (params) => {
70
+ const { pageNo, pageSize, ...searchParams } = params
71
+ const response = await api.getList({
72
+ page: pageNo,
73
+ size: pageSize,
74
+ ...searchParams,
75
+ })
76
+ return {
77
+ list: response.data.list,
78
+ total: response.data.total,
79
+ }
80
+ }
62
81
 
63
- const columns = ref([
82
+ // 表单配置
83
+ const formConfig = [
84
+ {
85
+ is: 'input', // 组件类型
86
+ prop: 'name', // 字段名
87
+ formItem: {
88
+ label: '姓名', // 表单标签
89
+ },
90
+ initialValue: '', // 初始值
91
+ props: {
92
+ placeholder: '请输入姓名',
93
+ },
94
+ },
95
+ {
96
+ is: 'select',
97
+ prop: 'status',
98
+ formItem: {
99
+ label: '状态',
100
+ },
101
+ initialValue: 'all',
102
+ props: {
103
+ options: [
104
+ { value: 'all', label: '全部' },
105
+ { value: 'active', label: '激活' },
106
+ { value: 'inactive', label: '未激活' },
107
+ ],
108
+ },
109
+ },
110
+ {
111
+ is: 'date-picker',
112
+ prop: 'createTime',
113
+ formItem: {
114
+ label: '创建时间',
115
+ },
116
+ },
117
+ ]
118
+
119
+ // 表格列配置
120
+ const tableColumns = [
64
121
  { prop: 'name', label: '姓名' },
65
- { prop: 'age', label: '年龄' },
66
- { prop: 'email', label: '邮箱' }
67
- ])
68
-
69
- const tableData = ref([
70
- { name: '张三', age: 25, email: 'zhangsan@example.com' },
71
- { name: '李四', age: 30, email: 'lisi@example.com' }
72
- ])
73
-
74
- const loading = ref(false)
75
- const pagination = ref({
76
- current: 1,
77
- pageSize: 10,
78
- total: 100
79
- })
80
-
81
- function handlePageChange(page) {
82
- pagination.value.current = page
83
- // 加载数据
84
- }
122
+ { prop: 'email', label: '邮箱' },
123
+ { prop: 'status', label: '状态' },
124
+ {
125
+ prop: 'createTime',
126
+ label: '创建时间',
127
+ type: 'dateTime', // 自动格式化日期时间
128
+ },
129
+ ]
85
130
  </script>
86
131
  ```
87
132
 
88
- #### 表单组件
133
+ #### 高级配置示例
89
134
 
90
135
  ```vue
91
136
  <template>
92
- <CommonForm
93
- :model="formModel"
94
- :items="formItems"
95
- @submit="handleSubmit"
96
- @reset="handleReset"
97
- />
137
+ <CommonConfigProvider
138
+ :component="{
139
+ form: {
140
+ submitText: '查询',
141
+ resetText: '重置',
142
+ formItem: {
143
+ components: {
144
+ width: '240px',
145
+ },
146
+ },
147
+ },
148
+ pagination: {
149
+ defaultPageSize: 20,
150
+ defaultPageCount: 1,
151
+ },
152
+ table: {
153
+ headerCellStyle: {
154
+ backgroundColor: '#f5f7fa',
155
+ color: '#303133',
156
+ },
157
+ },
158
+ }"
159
+ >
160
+ <CommonQueryTable
161
+ v-bind="queryTableConfig"
162
+ :layouts="['form', 'toolbar', 'table', 'pagination']"
163
+ >
164
+ <!-- 自定义工具栏 -->
165
+ <template #toolbar>
166
+ <el-button type="primary" @click="handleAdd">新增</el-button>
167
+ <el-button @click="handleExport">导出</el-button>
168
+ </template>
169
+
170
+ <!-- 自定义表格列 -->
171
+ <template #table-action="{ row }">
172
+ <el-button link @click="handleEdit(row)">编辑</el-button>
173
+ <el-button link type="danger" @click="handleDelete(row)">删除</el-button>
174
+ </template>
175
+ </CommonQueryTable>
176
+ </CommonConfigProvider>
98
177
  </template>
99
178
 
100
179
  <script setup>
101
- import { ref } from 'vue'
102
- import { CommonForm } from '@yetuzi/vue3-query-components'
180
+ import { CommonConfigProvider, CommonQueryTable } from '@yetuzi/vue3-query-components'
181
+
182
+ const queryTableConfig = {
183
+ fetch: fetchData,
184
+ form: formConfig,
185
+ columns: [
186
+ { prop: 'name', label: '姓名' },
187
+ { prop: 'status', label: '状态' },
188
+ { label: '操作', prop: 'action', fixed: 'right', width: 150 },
189
+ ],
190
+ }
191
+ </script>
192
+ ```
103
193
 
104
- const formModel = ref({
105
- name: '',
106
- email: '',
107
- age: null
108
- })
194
+ ## 📚 组件文档
109
195
 
110
- const formItems = ref([
111
- {
112
- prop: 'name',
113
- label: '姓名',
114
- type: 'input',
115
- rules: [{ required: true, message: '请输入姓名' }]
116
- },
117
- {
118
- prop: 'email',
119
- label: '邮箱',
120
- type: 'input',
121
- rules: [{ type: 'email', message: '请输入正确的邮箱格式' }]
122
- },
123
- {
124
- prop: 'age',
125
- label: '年龄',
126
- type: 'number'
127
- }
128
- ])
196
+ ### CommonQueryTable Props
129
197
 
130
- function handleSubmit() {
131
- console.log('提交表单:', formModel.value)
132
- }
198
+ | 参数 | 说明 | 类型 | 默认值 |
199
+ | ------- | ------------ | ------------------------------------------------------------------------ | --------------------------------- |
200
+ | fetch | 数据请求函数 | `(params: ListParam) => Promise<{ list: T[], total: string \| number }>` | - |
201
+ | form | 表单配置数组 | `CommonFormPropForm[]` | [] |
202
+ | columns | 表格列配置 | `CommonTableColumn[]` | - |
203
+ | layouts | 布局顺序 | `Array<'header'\|'form'\|'toolbar'\|'table'\|'pagination'\|'footer'>` | `['form', 'table', 'pagination']` |
204
+
205
+ ### 表单组件类型支持
206
+
207
+ 支持以下表单组件类型:
208
+
209
+ - `input` - 输入框
210
+ - `select` - 下拉选择
211
+ - `date-picker` - 日期选择器
212
+ - `radio` - 单选框组
213
+ - `check-box` - 复选框组
214
+ - `switch` - 开关
133
215
 
134
- function handleReset() {
135
- console.log('重置表单')
216
+ ### 表单配置项类型
217
+
218
+ ```typescript
219
+ interface FormItemConfig {
220
+ is: string // 组件类型
221
+ prop: string // 字段名
222
+ formItem: {
223
+ // ElFormItem 配置
224
+ label: string
225
+ [key: string]: any
226
+ }
227
+ initialValue?: any // 初始值
228
+ props?: {
229
+ // 组件属性
230
+ [key: string]: any
231
+ }
136
232
  }
137
- </script>
138
233
  ```
139
234
 
140
- ## 📚 API 文档
235
+ ### 表格列配置类型
141
236
 
142
- ### CommonTable Props
237
+ ```typescript
238
+ interface TableColumn {
239
+ prop: string // 列属性名
240
+ label: string // 列标题
241
+ type?: 'dateTime' // 特殊类型:自动格式化日期时间
242
+ width?: string \| number // 列宽度
243
+ fixed?: boolean \| 'left' \| 'right' // 固定列
244
+ [key: string]: any // 其他 ElTableColumn 属性
245
+ }
246
+ ```
143
247
 
144
- | 参数 | 说明 | 类型 | 默认值 |
145
- |------|------|------|--------|
146
- | columns | 表格列配置 | `Column[]` | - |
147
- | data | 表格数据 | `any[]` | [] |
148
- | loading | 加载状态 | `boolean` | false |
149
- | pagination | 分页配置 | `PaginationConfig` | - |
150
- | border | 是否显示边框 | `boolean` | true |
151
- | stripe | 是否显示斑马纹 | `boolean` | true |
248
+ ## 🎨 全局配置
152
249
 
153
- ### CommonForm Props
250
+ 使用 `CommonConfigProvider` 可以全局配置组件样式和行为:
154
251
 
155
- | 参数 | 说明 | 类型 | 默认值 |
156
- |------|------|------|--------|
157
- | model | 表单数据对象 | `object` | - |
158
- | items | 表单项配置 | `FormItem[]` | - |
159
- | labelWidth | 标签宽度 | `string \| number` | '100px' |
160
- | inline | 是否行内表单 | `boolean` | false |
161
- | submitText | 提交按钮文本 | `string` | '提交' |
162
- | resetText | 重置按钮文本 | `string` | '重置' |
252
+ ```vue
253
+ <template>
254
+ <CommonConfigProvider
255
+ :component="{
256
+ placeholder: '暂无数据', // 空值占位
257
+ pagination: {
258
+ defaultPageCount: 1, // 默认起始页
259
+ defaultPageSize: 10, // 默认每页条数
260
+ },
261
+ table: {
262
+ headerCellStyle: {
263
+ // 表头样式
264
+ backgroundColor: '#f1f6ff',
265
+ color: '#000000',
266
+ height: '48px',
267
+ },
268
+ },
269
+ form: {
270
+ submitText: '搜索', // 提交按钮文本
271
+ resetText: '重置', // 重置按钮文本
272
+ formItem: {
273
+ components: {
274
+ width: '200px', // 表单组件宽度
275
+ },
276
+ },
277
+ },
278
+ }"
279
+ >
280
+ <YourApp />
281
+ </CommonConfigProvider>
282
+ </template>
283
+ ```
163
284
 
164
285
  ## 🛠️ 开发
165
286
 
@@ -168,13 +289,14 @@ function handleReset() {
168
289
  - Node.js >= 16.0.0
169
290
  - Vue 3.5+
170
291
  - Element Plus 2.11+
292
+ - TypeScript 5.9+
171
293
 
172
294
  ### 本地开发
173
295
 
174
296
  ```bash
175
297
  # 克隆项目
176
298
  git clone https://gitee.com/yetuzi/vue3-common.git
177
- cd vue3-common/common
299
+ cd vue3-common/vue3-query-components
178
300
 
179
301
  # 安装依赖
180
302
  npm install
@@ -193,15 +315,36 @@ npm run format
193
315
 
194
316
  # Lint
195
317
  npm run lint
318
+
319
+ # 测试
320
+ npm test
196
321
  ```
197
322
 
198
- ### 测试
323
+ ### 依赖说明
199
324
 
200
- ```bash
201
- # 运行测试
202
- npm test
325
+ ```json
326
+ {
327
+ "peerDependencies": {
328
+ "vue": "^3.5.0", // Vue 3 - 需要宿主项目安装
329
+ "element-plus": "^2.11.5" // Element Plus UI 库 - 需要宿主项目安装
330
+ },
331
+ "dependencies": {
332
+ "dayjs": "^1.11.18", // 日期处理库
333
+ "lodash-es": "^4.17.21", // 工具函数库
334
+ "vue-hooks-plus": "^2.4.1" // Vue 组合式 API 工具库
335
+ }
336
+ }
203
337
  ```
204
338
 
339
+ ## 🎯 使用场景
340
+
341
+ 本组件库特别适用于:
342
+
343
+ - **企业后台管理系统** - 大量数据查询、展示、分页场景
344
+ - **数据报表页面** - 需要复杂查询条件的数据展示
345
+ - **CRUD 操作页面** - 增删改查的标准业务页面
346
+ - **列表展示页面** - 各种数据列表的展示和筛选
347
+
205
348
  ## 📄 许可证
206
349
 
207
350
  [MIT](./LICENSE)
@@ -214,9 +357,16 @@ npm test
214
357
 
215
358
  如有问题,请提交 [Issue](https://gitee.com/yetuzi/vue3-common/issues)
216
359
 
217
- ## 🗺️ 路线图
360
+ ## 🗺️ 更新日志
361
+
362
+ ### v1.0.1 (2024-12-10)
363
+
364
+ - 📝 更新 README.md 包名引用
365
+ - ✨ 完善文档和使用示例
366
+ - 🔧 优化组件配置系统
367
+
368
+ ### v1.0.0
218
369
 
219
- - [ ] 更多业务组件(抽屉、模态框等)
220
- - [ ] 国际化支持
221
- - [ ] 主题定制功能
222
- - [ ] 单元测试覆盖
370
+ - 🎉 初始版本发布
371
+ - 包含完整的查询表格组件体系
372
+ - 📦 支持全局配置和主题定制