cd-vue-filter 2.2.0 → 2.2.1

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 (2) hide show
  1. package/README.md +240 -76
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,16 @@
1
- # Vue Filter Component Package
1
+ # cd-vue-filter
2
2
 
3
- 一个功能强大的 Vue 3 过滤器组件包,包含 FilterComponent 和 FilterDialog 两个组件,支持多种字段类型和操作符。
3
+ 一个功能强大的 Vue 3 筛选器组件包,支持内联筛选、高级筛选、方案管理和列配置等功能。
4
+
5
+ ## 特性
6
+
7
+ - 🎯 **多种筛选模式**:支持内联筛选和高级筛选对话框
8
+ - 📋 **方案管理**:保存、编辑、复制、删除筛选方案
9
+ - 🎨 **灵活配置**:可自定义筛选字段数量和显示方式
10
+ - 📊 **列配置**:支持列的显示/隐藏、宽度调整和排序
11
+ - 🔄 **多种字段类型**:文本、数字、日期、下拉选择、省市区等
12
+ - 🎭 **丰富的操作符**:根据字段类型自动提供相应的操作符
13
+ - 💾 **方案共享**:支持方案的共享设置(私有/共享)
4
14
 
5
15
  ## 安装
6
16
 
@@ -12,14 +22,13 @@ yarn add cd-vue-filter
12
22
  pnpm add cd-vue-filter
13
23
  ```
14
24
 
15
- ## 使用方法
25
+ ## 快速开始
16
26
 
17
27
  ### 全局注册
18
28
 
19
29
  ```javascript
20
30
  import { createApp } from 'vue'
21
- import FilterComponents, { install } from 'cd-vue-filter'
22
- import 'cd-vue-filter/dist/style.css'
31
+ import { install } from 'cd-vue-filter'
23
32
 
24
33
  const app = createApp(App)
25
34
  app.use(install)
@@ -28,123 +37,278 @@ app.use(install)
28
37
  ### 按需导入
29
38
 
30
39
  ```javascript
31
- import { FilterDialog, FilterComponent } from 'cd-vue-filter'
32
- import 'cd-vue-filter/dist/style.css'
33
-
34
- export default {
35
- components: {
36
- FilterDialog,
37
- FilterComponent
38
- }
39
- }
40
+ import { CdFilterBar, CdFilter, FilterComponent } from 'cd-vue-filter'
40
41
  ```
41
42
 
42
43
  ## 组件说明
43
44
 
44
- ### FilterDialog
45
+ ### CdFilterBar
45
46
 
46
- 弹窗式过滤器组件,支持复杂的多条件筛选。
47
+ 筛选工具栏组件,是最常用的组件,集成了内联筛选、按钮操作和方案管理。
47
48
 
48
49
  #### Props
49
50
 
50
- - `visible` (Boolean): 控制弹窗显示/隐藏
51
- - `fieldOptions` (Array): 字段选项配置
52
- - `initialFilterCards` (Array, 可选): 初始筛选卡片
53
- - `initialType1` (String, 可选): 初始类型
51
+ | 参数 | 说明 | 类型 | 默认值 |
52
+ |------|------|------|--------|
53
+ | fieldOptions | 字段选项配置(必填) | Array | - |
54
+ | filterCount | 内联筛选字段数量 | Number | 2 |
55
+ | selectOptions | 下拉选择字段的选项数据 | Array | [] |
56
+ | planFilterOptions | 我的方案列表 | Array | [] |
57
+ | size | 组件大小 | String | 'small' |
58
+ | width | 对话框宽度 | String | '1000px' |
59
+ | visibleColumns | 可见列配置 | Array | [] |
54
60
 
55
61
  #### Events
56
62
 
57
- - `update:visible`: 更新弹窗显示状态
58
- - `confirm`: 确认筛选条件
59
- - `cancel`: 取消筛选
63
+ | 事件名 | 说明 | 回调参数 |
64
+ |--------|------|----------|
65
+ | search | 内联搜索触发 | (result) |
66
+ | confirm | 高级筛选或方案选择确认 | (result) |
67
+ | reset | 重置筛选 | - |
68
+ | save-plan | 保存方案 | (payload) |
69
+ | delete-plan | 删除方案 | (plan) |
70
+ | copy-plan | 复制方案 | (plan) |
71
+ | set-default-plan | 设置默认方案 | (plan) |
72
+ | update-plan | 更新方案 | (payload) |
73
+ | column-change | 列配置变化 | (columns) |
74
+
75
+ ## 使用示例
60
76
 
61
- #### 使用示例
77
+ ### 示例1: 默认2个筛选字段
62
78
 
63
79
  ```vue
64
80
  <template>
65
- <div>
66
- <t-button @click="showDialog = true">打开筛选</t-button>
67
- <FilterDialog
68
- v-model:visible="showDialog"
69
- :field-options="fieldOptions"
70
- @confirm="handleConfirm"
71
- @cancel="handleCancel"
72
- />
73
- </div>
81
+ <cd-filter-bar
82
+ :field-options="fieldOptions"
83
+ :select-options="selectOptions"
84
+ :plan-filter-options="planFilterOptions"
85
+ @search="handleSearch"
86
+ @confirm="handleConfirm"
87
+ @save-plan="handleSavePlan"
88
+ @delete-plan="handleDeletePlan"
89
+ @update-plan="handleUpdatePlan"
90
+ />
74
91
  </template>
75
92
 
76
93
  <script setup>
77
94
  import { ref } from 'vue'
78
- import { FilterDialog } from 'cd-vue-filter'
95
+ import { CdFilterBar } from 'cd-vue-filter'
79
96
 
80
- const showDialog = ref(false)
97
+ const fieldOptions = ref([
98
+ { key: '客户名称', label: '客户名称', value: 'customerName', type: 'text' },
99
+ { key: '订单编号', label: '订单编号', value: 'orderNo', type: 'text' },
100
+ { key: '订单金额', label: '订单金额', value: 'orderAmount', type: 'number' },
101
+ { key: '订单日期', label: '订单日期', value: 'orderDate', type: 'date' },
102
+ { key: '订单状态', label: '订单状态', value: 'orderStatus', type: 'select' }
103
+ ])
81
104
 
82
- const fieldOptions = [
105
+ const selectOptions = ref([
83
106
  {
84
- label: '姓名',
85
- value: 'name',
86
- type: 'text'
87
- },
88
- {
89
- label: '年龄',
90
- value: 'age',
91
- type: 'number'
92
- },
107
+ columnName: 'orderStatus',
108
+ value: ['待审核', '已审核', '已发货', '已完成', '已取消']
109
+ }
110
+ ])
111
+
112
+ const planFilterOptions = ref([
93
113
  {
94
- label: '创建时间',
95
- value: 'createTime',
96
- type: 'date'
114
+ content: '本月新订单',
115
+ value: 'plan_1',
116
+ sqlConnectType: 'and',
117
+ precepts: [
118
+ {
119
+ id: 1,
120
+ connector: 'and',
121
+ conditions: [
122
+ { field: 'orderDate', operator: 'this_month', value: '' },
123
+ { field: 'orderStatus', operator: 'eq', value: '待审核' }
124
+ ]
125
+ }
126
+ ]
127
+ }
128
+ ])
129
+
130
+ const handleSearch = (result) => {
131
+ console.log('搜索结果:', result)
132
+ }
133
+
134
+ const handleConfirm = (result) => {
135
+ console.log('筛选结果:', result)
136
+ }
137
+
138
+ const handleSavePlan = (payload) => {
139
+ const newPlan = {
140
+ content: payload.name,
141
+ value: `plan_${Date.now()}`,
142
+ sqlConnectType: payload.topOp,
143
+ precepts: payload.precepts
97
144
  }
98
- ]
145
+ planFilterOptions.value.push(newPlan)
146
+ }
99
147
 
100
- const handleConfirm = (filterData) => {
101
- console.log('筛选条件:', filterData)
102
- showDialog.value = false
148
+ const handleDeletePlan = (plan) => {
149
+ const index = planFilterOptions.value.findIndex(p => p.value === plan.value)
150
+ if (index !== -1) {
151
+ planFilterOptions.value.splice(index, 1)
152
+ }
103
153
  }
104
154
 
105
- const handleCancel = () => {
106
- showDialog.value = false
155
+ const handleUpdatePlan = (payload) => {
156
+ const { name, precepts, topOp, plan } = payload
157
+ const index = planFilterOptions.value.findIndex(p => p.value === plan.value)
158
+ if (index !== -1) {
159
+ planFilterOptions.value[index] = {
160
+ ...planFilterOptions.value[index],
161
+ content: name,
162
+ precepts: precepts,
163
+ sqlConnectType: topOp
164
+ }
165
+ }
107
166
  }
108
167
  </script>
109
168
  ```
110
169
 
111
- ### FilterComponent
170
+ ### 示例2: 自定义3个筛选字段
112
171
 
113
- 内联式过滤器组件,适用于简单的单条件筛选。
172
+ ```vue
173
+ <cd-filter-bar
174
+ :field-options="fieldOptions"
175
+ :select-options="selectOptions"
176
+ :plan-filter-options="planFilterOptions"
177
+ :filter-count="3"
178
+ @search="handleSearch"
179
+ @confirm="handleConfirm"
180
+ />
181
+ ```
114
182
 
115
- #### Props
183
+ ### 示例3: 只有按钮没有内联筛选
116
184
 
117
- - `fieldOptions` (Array): 字段选项配置
118
- - `filterCondition` (Object): 筛选条件
119
- - `selectOptions` (Object, 可选): 下拉选项数据
185
+ 当设置 `filter-count="0"` 时,不显示内联筛选字段,只显示方案选择和操作按钮:
120
186
 
121
- #### Events
187
+ ```vue
188
+ <cd-filter-bar
189
+ :field-options="fieldOptions"
190
+ :select-options="selectOptions"
191
+ :plan-filter-options="planFilterOptions"
192
+ :filter-count="0"
193
+ @search="handleSearch"
194
+ @confirm="handleConfirm"
195
+ />
196
+ ```
197
+
198
+ ### 示例4: 自定义对话框宽度
122
199
 
123
- - `update:filterCondition`: 更新筛选条件
200
+ ```vue
201
+ <cd-filter-bar
202
+ :field-options="fieldOptions"
203
+ :select-options="selectOptions"
204
+ :plan-filter-options="planFilterOptions"
205
+ width="400px"
206
+ @search="handleSearch"
207
+ @confirm="handleConfirm"
208
+ />
209
+ ```
124
210
 
125
211
  ## 字段类型支持
126
212
 
127
- - `text`: 文本类型
128
- - `number`: 数字类型
129
- - `money`: 金额类型
130
- - `date`: 日期类型
131
- - `datetime`: 日期时间类型
132
- - `select`: 下拉选择
133
- - `province`: 省市区级联选择
213
+ | 类型 | 说明 | 示例 |
214
+ |------|------|------|
215
+ | text | 文本类型 | 客户名称、订单编号 |
216
+ | number | 数字类型 | 数量、金额 |
217
+ | date | 日期类型 | 订单日期 |
218
+ | time | 日期时间类型 | 创建时间 |
219
+ | select | 下拉选择 | 订单状态、客户等级 |
220
+ | selectProvince | 省市区选择 | 所在地区 |
134
221
 
135
222
  ## 操作符支持
136
223
 
137
- 根据字段类型自动提供相应的操作符:
224
+ ### 文本类型
225
+ - `eq`: 等于
226
+ - `ne`: 不等于
227
+ - `contains`: 包含
228
+ - `starts_with`: 开头是
229
+ - `ends_with`: 结尾是
230
+
231
+ ### 数字类型
232
+ - `eq`: 等于
233
+ - `ne`: 不等于
234
+ - `gt`: 大于
235
+ - `gte`: 大于等于
236
+ - `lt`: 小于
237
+ - `lte`: 小于等于
238
+
239
+ ### 日期类型
240
+ - `eq`: 等于
241
+ - `ne`: 不等于
242
+ - `gt`: 在此之后
243
+ - `gte`: 在此之后(含)
244
+ - `lt`: 在此之前
245
+ - `lte`: 在此之前(含)
246
+ - `today`: 今天
247
+ - `yesterday`: 昨天
248
+ - `tomorrow`: 明天
249
+ - `this_week`: 本周
250
+ - `last_week`: 上周
251
+ - `next_week`: 下周
252
+ - `this_month`: 本月
253
+ - `last_month`: 上月
254
+ - `next_month`: 下月
255
+ - `this_year`: 今年
256
+ - `last_year`: 去年
257
+ - `next_year`: 明年
258
+
259
+ ### 下拉选择类型
260
+ - `eq`: 等于
261
+ - `ne`: 不等于
262
+
263
+ ### 省市区类型
264
+ - `eq`: 等于
265
+ - `ne`: 不等于
266
+ - `contains`: 包含
267
+ - `not_contains`: 不包含
268
+ - `one_of`: 等于其中之一
269
+
270
+ ## 方案数据结构
138
271
 
139
- - 文本类型: 等于、不等于、包含、不包含、为空、不为空
140
- - 数字类型: 等于、不等于、大于、小于、大于等于、小于等于、为空、不为空
141
- - 日期类型: 等于、不等于、大于、小于、大于等于、小于等于、为空、不为空
142
- - 选择类型: 等于、不等于、包含、不包含、为空、不为空
272
+ ```javascript
273
+ {
274
+ content: '方案名称',
275
+ value: 'plan_1',
276
+ sqlConnectType: 'and', // 顶层连接符:'and' 或 'or'
277
+ precepts: [
278
+ {
279
+ id: 1,
280
+ connector: 'and', // 卡片内连接符:'and' 或 'or'
281
+ conditions: [
282
+ {
283
+ field: 'orderDate',
284
+ operator: 'this_month',
285
+ value: ''
286
+ },
287
+ {
288
+ field: 'orderStatus',
289
+ operator: 'eq',
290
+ value: '待审核'
291
+ }
292
+ ]
293
+ }
294
+ ],
295
+ columns: [ // 可选:列配置
296
+ {
297
+ value: 'customerName',
298
+ show: true,
299
+ width: '150px'
300
+ }
301
+ ]
302
+ }
303
+ ```
143
304
 
144
305
  ## 版本历史
145
306
 
146
- - 1.1.0: 添加 FilterDialog 组件支持,同时保持 FilterComponent 兼容性
147
- - 1.0.x: 初始版本,包含 FilterComponent 组件
307
+ - **2.2.0**: 修复 filterCount prop 问题,优化 filter-count=0 模式,添加筛选图标按钮
308
+ - **2.1.0**: 添加列配置功能,支持列的显示/隐藏、宽度调整和排序
309
+ - **2.0.0**: 重构组件架构,添加 CdFilterBar 组件
310
+ - **1.1.0**: 添加 FilterDialog 组件支持
311
+ - **1.0.x**: 初始版本,包含 FilterComponent 组件
148
312
 
149
313
  ## 许可证
150
314
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cd-vue-filter",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "type": "module",
5
5
  "description": "一个功能强大的 Vue 3 过滤器组件,支持多种字段类型和操作符",
6
6
  "main": "src/index.ts",