@lx-frontend/wrap-element-ui 1.0.0-beta.7 → 1.0.1-7.beta-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.
Files changed (30) hide show
  1. package/README.md +2 -2
  2. package/package.json +6 -5
  3. package/src/components/EditableTable/bizHooks/index.ts +7 -0
  4. package/src/components/EditableTable/{useCellHover.ts → bizHooks/useCellHover.ts} +1 -1
  5. package/src/components/EditableTable/bizHooks/useColumnHeaderOperation.ts +329 -0
  6. package/src/components/EditableTable/{useDefaultOperation.ts → bizHooks/useDefaultOperation.ts} +2 -2
  7. package/src/components/EditableTable/{useDragSort.ts → bizHooks/useDragSort.ts} +4 -4
  8. package/src/components/EditableTable/{usePagination.ts → bizHooks/usePagination.ts} +3 -3
  9. package/src/components/EditableTable/{useRowBgColor.ts → bizHooks/useRowBgColor.ts} +9 -16
  10. package/src/components/EditableTable/bizHooks/useViewSetting.ts +125 -0
  11. package/src/components/EditableTable/features/bizColorSelect.vue +63 -0
  12. package/src/components/EditableTable/features/bizEditCell.vue +44 -0
  13. package/src/components/EditableTable/features/bizTableHeaderPopover/BizCheckboxFilter.vue +40 -0
  14. package/src/components/EditableTable/features/bizTableHeaderPopover/BizColorRadioFilter.vue +56 -0
  15. package/src/components/EditableTable/features/bizTableHeaderPopover/BizDoubleDatePickerFilter.vue +91 -0
  16. package/src/components/EditableTable/features/bizTableHeaderPopover/BizInputFilter.vue +26 -0
  17. package/src/components/EditableTable/features/bizTableHeaderPopover/BizMonthDayPicker.helper.ts +131 -0
  18. package/src/components/EditableTable/features/bizTableHeaderPopover/BizMonthDayPicker.vue +115 -0
  19. package/src/components/EditableTable/features/bizTableHeaderPopover/BizRadioFilter.vue +39 -0
  20. package/src/components/EditableTable/features/bizTableHeaderPopover/BizSortFilter.vue +50 -0
  21. package/src/components/EditableTable/features/bizTableHeaderPopover/index.vue +155 -0
  22. package/src/components/EditableTable/features/bizTableOperatePopover.vue +67 -0
  23. package/src/components/EditableTable/features/bizViewSettingDialog.vue +137 -0
  24. package/src/components/EditableTable/index.less +524 -428
  25. package/src/components/EditableTable/index.vue +167 -456
  26. package/src/components/EditableTable/{types.ts → types/index.ts} +176 -116
  27. package/src/components/SearchForm/index.vue +7 -4
  28. package/src/components/SearchForm/types/index.ts +63 -0
  29. package/src/components/EditableTable/useColumnHeaderOperation.ts +0 -326
  30. package/src/components/EditableTable/useViewSetting.ts +0 -119
@@ -1,108 +1,32 @@
1
1
  <template>
2
2
  <div class="editable-table">
3
- <div class="view-setting">
3
+ <div class="editable-table-view-setting">
4
4
  <div
5
5
  v-if="!hideViewSettingBtn"
6
- class="view-setting__btn-wrapper"
6
+ class="editable-table-view-setting__btn-wrapper"
7
7
  >
8
8
  <div
9
- class="view-setting__btn btn-pointer"
9
+ class="editable-table-view-setting__btn btn-pointer"
10
10
  @click="handleViewSettingShow"
11
11
  >
12
12
  <i class="el-icon-setting" />
13
- <div class="view-setting__btn-text">
13
+ <div class="editable-table-view-setting__btn-text">
14
14
  显示设置
15
15
  </div>
16
16
  </div>
17
17
  </div>
18
18
 
19
- <el-dialog
20
- title="显示设置"
21
- :visible.sync="viewSettingVisible"
22
- width="750px"
23
- top="12vh"
24
- :close-on-click-modal="false"
25
- :append-to-body="true"
26
- custom-class="view-setting__dialog"
27
- >
28
- <div class="view-setting__content">
29
- <div class="view-setting__content-left">
30
- <div class="view-setting__content-left-title">
31
- 表头设置
32
- </div>
33
- <div class="view-setting__checkbox-wrapper">
34
- <el-checkbox-group v-model="columnsToBeShown">
35
- <el-checkbox
36
- v-for="item in columnConfig"
37
- :key="item.label"
38
- :label="item.prop"
39
- :disabled="item.isAlwaysShow"
40
- >
41
- <div class="view-setting__content-left-item">
42
- {{ item.label }}
43
- </div>
44
- </el-checkbox>
45
- </el-checkbox-group>
46
- </div>
47
- </div>
48
- <div class="view-setting__content-right">
49
- <div class="view-setting__content-right-title">
50
- 已选择
51
- <div class="view-setting__selected-count">
52
- {{ columnsToBeShown.length }}
53
- </div>
54
- </div>
55
- <div class="view-setting__content-right-frize">
56
- 冻结前
57
- <el-input
58
- class="view-setting__content-right-input"
59
- :value="tempLeftFixedColumnCount"
60
- @input="handleInputTempLeftFixedColumnCount"
61
- />
62
-
63
- </div>
64
- <div class="view-setting__content-right-selected">
65
- <div
66
- v-for="(item, index) in viewSettingDragSortOptions"
67
- :key="item.prop"
68
- class="view-setting__selected-item view-setting-draggable-item"
69
- >
70
- <div class="view-setting__selected-item-left">
71
- <div
72
- class="view-setting-drag-target view-setting__icon-wrapper"
73
- :data-index="index"
74
- >
75
- <div
76
- class="view-setting-drag-target editable-table-drag-icon"
77
- :data-index="index"
78
- />
79
- </div>
80
- <div class="view-setting__selected-item-name">
81
- {{ item.label }}
82
- </div>
83
- </div>
84
- <div
85
- :class="['view-setting__selected-item-close', item.isAlwaysShow ? 'view-setting__selected-item-close--disabled' : '']"
86
- @click="handleColumnClose(item)"
87
- >
88
- <i class="el-icon-close" />
89
- </div>
90
- </div>
91
- </div>
92
- </div>
93
- </div>
94
- <template #footer>
95
- <el-button @click="handleViewSettingClose">
96
- 取消
97
- </el-button>
98
- <el-button
99
- type="primary"
100
- @click="handleViewSettingConfirm"
101
- >
102
- 确认
103
- </el-button>
104
- </template>
105
- </el-dialog>
19
+ <biz-view-setting-dialog
20
+ ref="bizViewSettingDialogRef"
21
+ :props="props"
22
+ :actual-columns="actualColumns"
23
+ :showing-columns="showingColumns"
24
+ :view-setting-drag-sort-options="viewSettingDragSortOptions"
25
+ @update:leftFixedColumnCount="(val) => { leftFixedColumnCount = val }"
26
+ @update:showingColumns="(val) => { showingColumns = val }"
27
+ @update:viewSettingDragSortOptions="(val) => { viewSettingDragSortOptions = val }"
28
+ @tableDoLayout="doTableLayout"
29
+ />
106
30
  </div>
107
31
 
108
32
  <!-- 列表展示,属性透传,列编辑 -->
@@ -125,7 +49,7 @@
125
49
  v-if="rowDragAble"
126
50
  width="30px"
127
51
  class-name="editable-table__drag-cell no-inner-cell-border"
128
- :fixed="leftFixedColumnCount > 0 ? 'left' : ''"
52
+ :fixed="leftFixedColumnCount > 0 ? 'left' : false"
129
53
  >
130
54
  <template #default="scope">
131
55
  <div
@@ -145,7 +69,7 @@
145
69
  v-if="hasExpandRow"
146
70
  width="30px"
147
71
  type="expand"
148
- :fixed="leftFixedColumnCount > 0 ? 'left' : ''"
72
+ :fixed="leftFixedColumnCount > 0 ? 'left' : false"
149
73
  class-name="no-inner-cell-border"
150
74
  >
151
75
  <template #default="scope">
@@ -161,7 +85,7 @@
161
85
  width="45px"
162
86
  align="center"
163
87
  type="selection"
164
- :fixed="leftFixedColumnCount > 0 ? 'left' : ''"
88
+ :fixed="leftFixedColumnCount > 0 ? 'left' : false"
165
89
  class-name="no-inner-cell-border"
166
90
  />
167
91
  <!-- 编号列 -->
@@ -169,7 +93,7 @@
169
93
  v-if="hasIndexColumn"
170
94
  min-width="30px"
171
95
  type="index"
172
- :fixed="leftFixedColumnCount > 0 ? 'left' : ''"
96
+ :fixed="leftFixedColumnCount > 0 ? 'left' : false"
173
97
  class-name="no-inner-cell-border"
174
98
  />
175
99
  <!-- 颜色选择列 -->
@@ -177,44 +101,41 @@
177
101
  v-if="colorList && colorList.length > 0"
178
102
  width="22px"
179
103
  class-name="editable-table__color-column no-inner-cell-border"
180
- :fixed="leftFixedColumnCount > 0 ? 'left' : ''"
104
+ :fixed="leftFixedColumnCount > 0 ? 'left' : false"
105
+ :filtered-value="Array.isArray(filteredValue[colorFilterConfig?.prop]) ? filteredValue[colorFilterConfig?.prop] : []"
181
106
  >
182
107
  <template #header>
183
- <div class="editable-table__color-icon" />
184
- </template>
185
- <template #default="scope">
186
- <el-popover
187
- ref="colorPopoverRef"
188
- placement="right"
189
- trigger="click"
190
- popper-class="color-popover"
108
+ <biz-table-header-popover
109
+ v-if="colorFilterConfig"
110
+ :head-active="isColumnHeadActive(colorFilterConfig)"
111
+ :column="colorFilterConfig"
112
+ :showing-columns="showingColumns"
113
+ :temp-summary-list="tempSummaryList"
114
+ :temp-sort-prop="tempSortProp"
115
+ :temp-sort-type="tempSortType"
116
+ :temp-filtered-value="tempFilteredValue"
117
+ @update:tempSummaryList="val => { tempSummaryList = val }"
118
+ @update:tempFilteredValue="(key, value) => { $set(tempFilteredValue, key, value) }"
119
+ @popover-show="() => handleHeaderPopoverShow(colorFilterConfig)"
120
+ @update:sort="handleSort"
121
+ @reset="() => handleHeaderOperationReset(colorFilterConfig)"
122
+ @confirm="() => handleHeaderOperationConfirm(colorFilterConfig)"
191
123
  >
192
- <div class="color-list">
193
- <div
194
- v-for="color in colorList"
195
- :key="color.id"
196
- class="color-list__item"
197
- :style="{ backgroundColor: color.sampleColor }"
198
- @click="handleColorChange(color.id, scope)"
199
- >
200
- <span :style="{color: color.textColor}">{{ color.name }}</span>
201
- </div>
202
- </div>
203
- <template slot="reference">
204
- <!-- 没有这个包裹的div标签,在拖动换行之后,无法调起颜色选择弹窗 -->
205
- <div>
206
- <div
207
- v-if="isDefaultColor(scope.row.colorId)"
208
- class="editable-table__color-icon"
209
- />
210
- <div
211
- v-else
212
- class="editable-table__selected-color"
213
- :style="{ backgroundColor: getColorById(scope.row.colorId, 'sample') }"
214
- />
215
- </div>
124
+ <template #custom>
125
+ <div class="editable-table__color-icon" />
216
126
  </template>
217
- </el-popover>
127
+ </biz-table-header-popover>
128
+ <div
129
+ v-else
130
+ class="editable-table__color-icon"
131
+ />
132
+ </template>
133
+ <template #default="scope">
134
+ <biz-color-select
135
+ :color-list="colorList"
136
+ :scope="scope"
137
+ @row-bg-change="(params) => emit('row-bg-change', params)"
138
+ />
218
139
  </template>
219
140
  </el-table-column>
220
141
  <!-- 这里的key很重要,必须保证每次生成的key都不一样,这样列排序功能才能生效,否则,即使actualColumns数组元素顺序发生变化,列顺序也不会改变。原因未知 -->
@@ -227,232 +148,66 @@
227
148
  v-bind="getColumnBindProps(column)"
228
149
  >
229
150
  <template
151
+ #header
230
152
  v-if="showColumnHeadSortIcon(column)"
231
- #header="scope"
232
153
  >
233
- <el-popover
234
- ref="sortFilterPopoverRef"
235
- placement="bottom"
236
- trigger="click"
237
- popper-class="editable-table__sort-filter"
238
- :data-prop="column.prop"
239
- @show="handleHeaderPopoverShow(column)"
154
+ <biz-table-header-popover
155
+ :head-active="isColumnHeadActive(column)"
156
+ :column="column"
157
+ :showing-columns="showingColumns"
158
+ :temp-summary-list="tempSummaryList"
159
+ :temp-sort-prop="tempSortProp"
160
+ :temp-sort-type="tempSortType"
161
+ :temp-filtered-value="tempFilteredValue"
162
+ @update:tempSummaryList="val => { tempSummaryList = val }"
163
+ @update:tempFilteredValue="(key, value) => { $set(tempFilteredValue, key, value) }"
164
+ @popover-show="() => handleHeaderPopoverShow(column)"
165
+ @update:sort="handleSort"
166
+ @reset="() => handleHeaderOperationReset(column)"
167
+ @confirm="() => handleHeaderOperationConfirm(column)"
240
168
  >
241
- <template slot="reference">
242
- <!-- 筛选中,或排序中,高亮 -->
243
- <span :class="['editable-table__sort-reference', isColumnHeadActive(column) && 'editable-table__sort-reference--active']">
169
+ <template #summay-item>
170
+ <slot
171
+ :name="column.prop + '-summay-item'"
172
+ v-bind="column"
173
+ >
244
174
  {{ column.label }}
245
- <div :class="['editable-table__sort-icon', isColumnHeadActive(column) && 'editable-table__sort-icon--active']" />
246
- </span>
175
+ </slot>
247
176
  </template>
248
- <div class="sort-filter">
249
- <div class="sort-filter__column-title">
250
- {{ column.label }}
251
- </div>
252
- <div
253
- v-if="column.isColumnSortable"
254
- class="sort-filter__sort"
255
- >
256
- <div class="sort-filter__sort-title">
257
- 排序
258
- </div>
259
- <div class="sort-filter__sort-btns">
260
- <el-button
261
- :class="['sort-filter__sort-btn', tempSortingColumn?.prop === column.prop && tempSortType === 'ascending' && 'sort-filter__sort-btn--active']"
262
- @click="handleSort('ascending', column)"
263
- >
264
- 升序
265
- </el-button>
266
- <el-button
267
- :class="['sort-filter__sort-btn', tempSortingColumn?.prop === column.prop && tempSortType === 'descending' && 'sort-filter__sort-btn--active']"
268
- @click="handleSort('descending', column)"
269
- >
270
- 降序
271
- </el-button>
272
- </div>
273
- </div>
274
- <div
275
- v-if="column.search && !Array.isArray(column.search)"
276
- class="sort-filter__search"
277
- >
278
- <div class="sort-filter__search-title">
279
- 搜索
280
- </div>
281
- <el-input
282
- v-model="tempSearchValue[column.prop]"
283
- class="sort-filter__search-input"
284
- placeholder="请输入内容"
285
- />
286
- </div>
287
-
288
- <div
289
- v-if="column.search && Array.isArray(column.search)"
290
- class="sort-filter__search"
291
- style="display: flex;flex-direction: column;gap: 12px;"
292
- >
293
- <div
294
- v-for="item in column.search"
295
- :key="item.prop"
296
- >
297
- <div class="sort-filter__search-title">
298
- {{ item.label }}
299
- </div>
300
- <el-input
301
- v-model="tempSearchValue[item.prop]"
302
- class="sort-filter__search-input"
303
- placeholder="请输入内容"
304
- />
305
- </div>
306
- </div>
307
-
308
- <div
309
- v-if="column.filters && ((Array.isArray(column.filters) ? column.filters : column.filters.options).length > 0)"
310
- class="sort-filter__filter"
311
- >
312
- <div class="sort-filter__filter-title">
313
- 筛选
314
- </div>
315
- <el-checkbox-group
316
- v-if="column.filters && (Array.isArray(column.filters) || column.filters.type === 'checkbox')"
317
- v-model="tempFilteredValue[column.prop]"
318
- class="sort-filter__filter-checkbox-group"
319
- >
320
- <el-checkbox
321
- v-for="item in (Array.isArray(column.filters) ? column.filters : column.filters.options)"
322
- :key="item.value"
323
- :label="item.value"
324
- class="sort-filter__filter-checkbox"
325
- >
326
- <slot
327
- :name="column.prop + '-filter-item'"
328
- v-bind="item"
329
- >
330
- {{ item.text }}
331
- </slot>
332
- </el-checkbox>
333
- </el-checkbox-group>
334
-
335
- <el-radio-group
336
- v-if="column.filters && !Array.isArray(column.filters) && column.filters.type === 'radio'"
337
- v-model="tempFilteredValue[column.prop]"
338
- style="display: flex;flex-direction: column;gap: 6px;"
339
- >
340
- <el-radio
341
- v-for="item in column.filters.options"
342
- :key="item.value"
343
- :label="item.value"
344
- >
345
- <slot
346
- :name="column.prop + '-filter-item'"
347
- v-bind="item"
348
- >
349
- {{ item.text }}
350
- </slot>
351
- </el-radio>
352
- </el-radio-group>
353
- </div>
354
- <div
355
- v-if="column.summary"
356
- class="sort-filter__filter"
357
- >
358
- <div class="sort-filter__filter-title">
359
- 统计
360
- </div>
361
- <el-checkbox-group
362
- v-model="tempSummaryList"
363
- class="sort-filter__filter-checkbox-group"
364
- >
365
- <el-checkbox
366
- :label="column.prop"
367
- class="sort-filter__filter-checkbox"
368
- >
369
- <slot
370
- :name="column.prop + '-summay-item'"
371
- v-bind="column"
372
- >
373
- {{ column.label }}
374
- </slot>
375
- </el-checkbox>
376
- </el-checkbox-group>
377
- </div>
378
- <div class="sort-filter__footer">
379
- <el-button
380
- class="sort-filter__reset-btn"
381
- @click="handleHeaderOperationReset(column, scope)"
382
- >
383
- 重置
384
- </el-button>
385
- <el-button
386
- class="sort-filter__confirm-btn"
387
- type="primary"
388
- @click="handleHeaderOperationConfirm(column, scope)"
389
- >
390
- 确定
391
- </el-button>
392
- </div>
393
- </div>
394
- </el-popover>
177
+ </biz-table-header-popover>
395
178
  </template>
396
179
  <!-- 默认操作按钮,defaultOperations属性不为空数组时展示。编辑状态下隐藏 -->
397
180
  <template
398
181
  v-if="column.prop === '$$operation'"
399
182
  #default="scope"
400
183
  >
401
- <el-popover
184
+ <biz-table-operate-popover
402
185
  v-if="editingRowIndex !== scope.$index"
403
186
  ref="operationPopoverRef"
404
- placement="bottom"
405
- trigger="click"
406
- popper-class="operation-popover"
187
+ :default-operations="defaultOperations"
188
+ :scope="scope"
189
+ @edit="() => handleEdit(scope)"
190
+ @delete="() => handleDelete(scope.row, scope.$index)"
191
+ @rowPinToTop="() => handleRowPinToTop(scope)"
407
192
  >
408
- <div
409
- slot="reference"
410
- class="operation-popover__operation-reference btn-pointer"
411
- >
412
- <el-button :class="['operation-popover__operation-btn', hoveringCellInfo.rowIndex === scope.$index && 'operation-popover__operation-btn--active']">
413
- 操作
414
- </el-button>
415
- </div>
416
- <div class="operation-popover__operation">
417
- <div
418
- v-if="defaultOperations.includes('delete')"
419
- class="operation-popover__operation-item btn-pointer"
420
- @click="handleDelete(scope.row, scope.$index)"
421
- >
422
- 删除
423
- </div>
424
- <div
425
- v-if="defaultOperations.includes('edit')"
426
- class="operation-popover__operation-item btn-pointer"
427
- @click="handleEdit(scope)"
428
- >
429
- 编辑
430
- </div>
431
- <div
432
- v-if="defaultOperations.includes('top')"
433
- class="operation-popover__operation-item btn-pointer"
434
- @click="handleRowPinToTop(scope)"
435
- >
436
- 置顶
437
- </div>
438
- <slot
439
- name="custom-operation"
440
- v-bind="scope"
441
- />
442
- </div>
443
- </el-popover>
193
+ <slot
194
+ name="custom-operation"
195
+ v-bind="scope"
196
+ />
197
+ </biz-table-operate-popover>
198
+
444
199
  <div
445
200
  v-else
446
- class="operation-popover__save-cancel"
201
+ class="editable-table-operation-popover__save-cancel"
447
202
  >
448
203
  <div
449
- class="btn-pointer operation-popover__btn"
204
+ class="btn-pointer editable-table-operation-popover__btn"
450
205
  @click="handleEditSave(scope.row)"
451
206
  >
452
207
  保存
453
208
  </div>
454
209
  <div
455
- class="btn-pointer operation-popover__btn"
210
+ class="btn-pointer editable-table-operation-popover__btn"
456
211
  @click="handleEditCancel(scope.row)"
457
212
  >
458
213
  取消
@@ -480,30 +235,11 @@
480
235
  :name="column.editSlotName"
481
236
  />
482
237
  <!-- 内置编辑类型 -->
483
- <div v-else-if="column.editType">
484
- <div v-if="column.editType === 'input'">
485
- <el-input
486
- v-model="editingRowData[column.prop]"
487
- clearable
488
- />
489
- </div>
490
- <div v-if="column.editType === 'select'">
491
- <el-select v-model="editingRowData[column.prop]">
492
- <el-option
493
- v-for="item in column.selectOptions"
494
- :key="item.label"
495
- :label="item.label"
496
- :value="item.value"
497
- />
498
- </el-select>
499
- </div>
500
- <el-date-picker
501
- v-if="column.editType === 'date'"
502
- v-model="editingRowData[column.prop]"
503
- type="date"
504
- placeholder="选择日期"
505
- />
506
- </div>
238
+ <biz-edit-cell
239
+ v-else-if="column.editType"
240
+ v-model="editingRowData[column.prop]"
241
+ :column="column"
242
+ />
507
243
  <!-- 不支持编辑 -->
508
244
  <slot
509
245
  v-else
@@ -518,32 +254,11 @@
518
254
  #default="scope"
519
255
  >
520
256
  <!-- 当前行编辑中,内置编辑类型 -->
521
- <template v-if="editingRowIndex === scope.$index && column.editType">
522
- <div v-if="column.editType === 'input'">
523
- <el-input
524
- v-model="editingRowData[column.prop]"
525
- clearable
526
- type="text"
527
- />
528
- </div>
529
- <div v-if="column.editType === 'select'">
530
- <el-select v-model="editingRowData[column.prop]">
531
- <el-option
532
- v-for="item in column.selectOptions"
533
- :key="item.value"
534
- :label="item.label"
535
- :value="item.value"
536
- />
537
- </el-select>
538
- </div>
539
- <div v-if="column.editType === 'date'">
540
- <el-date-picker
541
- v-model="editingRowData[column.prop]"
542
- type="date"
543
- placeholder="选择日期"
544
- />
545
- </div>
546
- </template>
257
+ <biz-edit-cell
258
+ v-if="editingRowIndex === scope.$index && column.editType"
259
+ v-model="editingRowData[column.prop]"
260
+ :column="column"
261
+ />
547
262
  <!-- 当前行编辑中,自定义编辑类型 -->
548
263
  <slot
549
264
  v-else-if="column.editSlotName && scope.$index === editingRowIndex"
@@ -581,7 +296,7 @@
581
296
  <el-pagination
582
297
  background
583
298
  layout="sizes, prev, pager, next, jumper"
584
- :page-sizes="[10, 15, 30, 60, 100]"
299
+ :page-sizes="pageSizes"
585
300
  :page-size.sync="pageSize"
586
301
  :pager-count="11"
587
302
  :current-page="currentPage"
@@ -594,15 +309,25 @@
594
309
  </template>
595
310
 
596
311
  <script lang="ts" setup>
312
+ import BizColorSelect from './features/bizColorSelect.vue';
313
+ import BizViewSettingDialog from './features/bizViewSettingDialog.vue'
314
+ import BizTableHeaderPopover from './features/bizTableHeaderPopover/index.vue'
315
+ import BizEditCell from './features/bizEditCell.vue'
316
+ import BizTableOperatePopover from './features/bizTableOperatePopover.vue'
317
+
597
318
  import { computed, nextTick, ref, watch } from 'vue';
598
- import { Message } from 'element-ui'
599
- import usePagination from './usePagination';
600
- import useCellHover from './useCellHover';
601
- import useViewSetting from './useViewSetting';
602
- import useRowBgColor from './useRowBgColor';
603
- import useDefaultOperation from './useDefaultOperation'
604
- import useColumnHeaderOperation from './useColumnHeaderOperation';
605
- import useDragSort from './useDragSort';
319
+ import { Message } from 'element-ui';
320
+ import omit from 'lodash/omit';
321
+
322
+ import {
323
+ usePagination,
324
+ useCellHover,
325
+ useRowBgColor,
326
+ useDefaultOperation,
327
+ useColumnHeaderOperation,
328
+ useDragSort,
329
+ } from './bizHooks'
330
+
606
331
  import { ITableDataItem, IColumnConfig, IDefaultOperationType, IColorList } from './types';
607
332
 
608
333
  // defineProps泛型参数如果从外部传入,编译报错
@@ -625,6 +350,8 @@ interface IProps {
625
350
  defaultOperations?: IDefaultOperationType[];
626
351
  /** 行背景色列表 */
627
352
  colorList?: IColorList;
353
+ /** 自定义颜色列的表头筛选 */
354
+ colorFilterConfig?: IColumnConfig;
628
355
  /** 左侧固定列数 */
629
356
  leftFixedCount?: number;
630
357
  /** 性能优化参数,调整拖拽的范围 */
@@ -641,6 +368,7 @@ interface IProps {
641
368
  localFilter?: boolean
642
369
  /** 页码 */
643
370
  currentPage: number
371
+ pageSizes?: number[]
644
372
  }
645
373
 
646
374
  interface IEmits {
@@ -678,6 +406,7 @@ const props = withDefaults(defineProps<IProps>(), {
678
406
  total: 0,
679
407
  defaultOperations: () => [],
680
408
  colorList: () => [],
409
+ colorFilterConfig: undefined,
681
410
  leftFixedCount: 1,
682
411
  dragSemiRange: 15,
683
412
  loading: false,
@@ -686,24 +415,28 @@ const props = withDefaults(defineProps<IProps>(), {
686
415
  localSort: false,
687
416
  localFilter: false,
688
417
  currentPage: 1,
689
- })
418
+ pageSizes: () => [10, 15, 30, 60, 100],
419
+ });
690
420
 
691
421
  // 同defineProps一样,不支持泛型参数从外部导入
692
- const emit = defineEmits<IEmits>()
422
+ const emit = defineEmits<IEmits>();
693
423
 
694
424
  const showingColumns = ref<string[]>([]); // 表格中实际展示的列
425
+ const leftFixedColumnCount = ref(0) // 左侧固定列数量
426
+ const viewSettingDragSortOptions = ref<IColumnConfig[]>([])
695
427
 
696
428
  const actualColumns = computed(() => {
697
429
  const res: IColumnConfig[] = [];
698
- let cnt = leftFixedColumnCount.value
430
+ let cnt = leftFixedColumnCount.value;
699
431
 
700
432
  // 列排序和列过滤
701
433
  for (const prop of showingColumns.value) {
702
434
  const rawItem = props.columnConfig.find(c => c.prop === prop) ?? {} as IColumnConfig;
703
435
  const item: IColumnConfig = {
704
436
  ...rawItem,
705
- isColumnSortable: rawItem.sortable,
706
- sortable: inSorting.value ? rawItem.sortable : false
437
+ isColumnSortable: !!rawItem.sortable,
438
+ sortable: inSorting.value ? !!rawItem.sortable : false,
439
+ _sortable: rawItem.sortable,
707
440
  };
708
441
  if (cnt > 0) {
709
442
  item.fixed = 'left';
@@ -720,22 +453,21 @@ const actualColumns = computed(() => {
720
453
  res.push({
721
454
  label: '操作',
722
455
  prop: '$$operation',
723
- 'min-width': '100px',
456
+ minWidth: '100px',
724
457
  fixed: 'right'
725
458
  });
726
459
  }
727
460
 
728
461
  return res;
729
- })
462
+ });
730
463
 
731
- const sortFilterPopoverRef = ref<any>(null);
732
464
  const tableDomRef = ref<any>(null);
733
465
  const currScope = ref<any>(null);
734
466
 
735
467
  /************ 分页相关 *************/
736
468
  const beforePageChange = () => {
737
- searchValue.value = {};
738
- }
469
+ // searchValue.value = {};
470
+ };
739
471
  const {
740
472
  pageSize,
741
473
  handleCurrPageChange,
@@ -743,26 +475,22 @@ const {
743
475
  } = usePagination({
744
476
  emit,
745
477
  beforePageChange
746
- })
478
+ });
747
479
 
748
480
  /************ 表格单元格hover事件相关 ************ */
749
481
  const {
750
482
  hoveringCellInfo,
751
483
  setCellClassName,
752
484
  debouncedHoverHandler
753
- } = useCellHover(tableDomRef)
485
+ } = useCellHover(tableDomRef);
754
486
 
755
487
  /************ 行背景色设置相关 ************ */
756
488
  const {
757
- isDefaultColor,
758
- getColorById,
759
489
  setRowStyle,
760
- handleColorChange,
761
- colorPopoverRef
762
490
  } = useRowBgColor({
763
- colorList: props.colorList,
491
+ colorList: props.colorList || [],
764
492
  emit
765
- })
493
+ });
766
494
 
767
495
  /************ 默认的操作相关 ************ */
768
496
  const {
@@ -781,25 +509,7 @@ const {
781
509
  pageSize,
782
510
  props,
783
511
  hasExpandRow: props.hasExpandRow
784
- })
785
-
786
- /************ 显示设置相关 ************ */
787
- const {
788
- viewSettingDragSortOptions,
789
- columnsToBeShown,
790
- viewSettingVisible,
791
- leftFixedColumnCount,
792
- tempLeftFixedColumnCount,
793
- handleInputTempLeftFixedColumnCount,
794
- handleViewSettingShow,
795
- handleViewSettingClose,
796
- handleViewSettingConfirm
797
- } = useViewSetting({
798
- tableDomRef,
799
- showingColumns,
800
- actualColumns,
801
- props
802
- })
512
+ });
803
513
 
804
514
  /************ 列头部操作相关 ************ */
805
515
  const {
@@ -815,27 +525,24 @@ const {
815
525
  tableSummaryMethod,
816
526
  filteredValue,
817
527
  showColumnHeadSortIcon,
818
- tempSortingColumn,
819
- tempSearchValue,
528
+ sortProp,
820
529
  tempFilteredValue,
821
530
  tempSummaryList,
822
531
  tempSortType,
823
- sortingColumn,
532
+ tempSortProp,
824
533
  isColumnFiltering,
825
- searchValue,
826
534
  inSorting,
827
535
  } = useColumnHeaderOperation({
828
536
  tableDomRef,
829
- sortFilterPopoverRef,
830
537
  props,
831
538
  emit,
832
539
  showingColumns,
833
- })
540
+ });
834
541
 
835
542
  /************ 表格行拖拽和显示设置列拖拽 ************ */
836
543
  const beforeDragStart = () => {
837
544
  // 如果有列存在排序,不允许拖拽
838
- if (sortingColumn.value) {
545
+ if (sortProp.value) {
839
546
  Message.warning('已有列正在排序,不允许拖拽。');
840
547
  return false;
841
548
  }
@@ -848,8 +555,8 @@ const beforeDragStart = () => {
848
555
 
849
556
  editingRowIndex.value = -1; // 关闭编辑状态
850
557
 
851
- return true
852
- }
558
+ return true;
559
+ };
853
560
 
854
561
  useDragSort({
855
562
  emit,
@@ -859,36 +566,39 @@ useDragSort({
859
566
  pageSize,
860
567
  currScope,
861
568
  tableDomRef,
862
- })
569
+ });
863
570
 
864
571
  const doTableLayout = async () => {
865
572
  await nextTick();
866
573
  tableDomRef.value?.doLayout();
867
- }
574
+ };
868
575
 
869
576
  // 过滤出自定义属性,将其它属性全部透传给 el-table-column
870
577
  const getColumnBindProps = (column: IColumnConfig) => {
871
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
872
- const { editAble, editType, slotName, inputType, options, filters, ...rest } = column;
873
- return rest;
874
- }
578
+ // 过滤掉自定义属性,只保留 el-table-column 支持的属性
579
+ return omit(column, [
580
+ 'editType',
581
+ 'slotName',
582
+ 'inputType',
583
+ 'options',
584
+ 'filters'
585
+ ]);
586
+ };
875
587
 
876
588
  const setRowClassName = (scope) => {
877
589
  return `
878
- custom-row-classname
879
- custom-row-classname-${scope.rowIndex}
590
+ custom-row-classname
591
+ custom-row-classname-${scope.rowIndex}
880
592
  ${scope.row.isPinned ? 'custom-row-classname-pinned' : ''}
881
- `
882
- }
593
+ `;
594
+ };
883
595
 
884
596
  const handleSelectionChange = (e) => {
885
597
  emit('selection-change', e);
886
- }
598
+ };
887
599
 
888
- const handleColumnClose = (item) => {
889
- if (item.isAlwaysShow) return;
890
- columnsToBeShown.value = columnsToBeShown.value.filter(c => c !== item.prop);
891
- }
600
+ const bizViewSettingDialogRef = ref(null as unknown as InstanceType<typeof BizViewSettingDialog>)
601
+ const handleViewSettingShow = () => bizViewSettingDialogRef.value.open()
892
602
 
893
603
  defineExpose({
894
604
  closeAllExpandedRows,
@@ -897,19 +607,20 @@ defineExpose({
897
607
  setSort,
898
608
  clearSort,
899
609
  setSearchParams,
900
- })
610
+ });
901
611
 
902
612
  // loading 结束和页码变化时滚动到顶部
903
613
  watch([
904
614
  () => props.loading,
905
615
  () => props.currentPage,
616
+ () => pageSize,
906
617
  ], ([loading]) => {
907
618
  if (loading) return;
908
- tableDomRef.value.$el.querySelector('.el-table__body-wrapper').scrollTop = 0
909
- })
619
+ tableDomRef.value.$el.querySelector('.el-table__body-wrapper').scrollTop = 0;
620
+ });
910
621
 
911
622
  </script>
912
623
 
913
624
  <style lang="less">
914
625
  @import './index.less';
915
- </style>
626
+ </style>