@lx-frontend/wrap-element-ui 1.0.14-beta.1 → 1.0.14-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lx-frontend/wrap-element-ui",
3
- "version": "1.0.14-beta.1",
3
+ "version": "1.0.14-beta.2",
4
4
  "description": "wrap-element-ui",
5
5
  "author": "",
6
6
  "main": "src/components/index.ts",
@@ -16,11 +16,11 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
16
16
 
17
17
  // 生效中的排序配置
18
18
  const sortType = ref<'ascending' | 'descending' | null>(null);
19
- const sortingColumn = ref<IColumnConfig | null>(null);
19
+ const sortProp = ref('')
20
20
 
21
21
  // 临时的排序配置
22
22
  const tempSortType = ref<'ascending' | 'descending' | ''>('');
23
- const tempSortingColumn = ref<IColumnConfig | null>(null);
23
+ const tempSortProp = ref('')
24
24
 
25
25
  // 生效中的过滤配置 和 临时过滤配置
26
26
  const filteredValue = ref<Record<string, string | number | number[] | string[]>>({});
@@ -78,20 +78,28 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
78
78
  && (searchValue.value[column.doubleDatePicker.props[0]] || searchValue.value[column.doubleDatePicker.props[1]])
79
79
  )
80
80
 
81
- return (
82
- !!(column.filters && (Array.isArray(column.filters)
83
- ? (filteredValue.value[column.prop] as any[]).length
84
- : column.filters.type === 'radio'
85
- ? filteredValue.value[column.filters.prop || column.prop]
86
- : (filteredValue.value[column.filters.prop || column.prop] as any[]).length))
87
- ) || (
88
- !!(column.search
89
- ? Array.isArray(column.search) && column.search?.some(v => {
81
+ const isUseFilter = !!(column.filters && (Array.isArray(column.filters)
82
+ ? (filteredValue.value[column.prop] as any[]).length
83
+ : column.filters.type === 'radio'
84
+ ? filteredValue.value[column.filters.prop || column.prop]
85
+ : (filteredValue.value[column.filters.prop || column.prop] as any[]).length))
86
+
87
+ const isUseSort = Array.isArray(column._sortable)
88
+ ? column._sortable.some(v => v.prop === sortProp.value)
89
+ : sortProp.value === column.prop
90
+
91
+ const isUseSearch = Array.isArray(column.search)
92
+ ? column.search?.some(v => {
90
93
  const props = typeof v.prop === 'string' ? [v.prop] : v.prop
91
94
  return props.some(p => searchValue.value[p])
92
95
  })
93
- : searchValue.value[column.prop])
94
- ) || hasPickerParams || sortingColumn.value?.prop === column.prop || summaryList.value.includes(column.prop);
96
+ : !!searchValue.value[column.prop]
97
+
98
+ return isUseFilter
99
+ || isUseSearch
100
+ || hasPickerParams
101
+ || isUseSort
102
+ || summaryList.value.includes(column.prop);
95
103
  }
96
104
 
97
105
  const handleHeaderPopoverShow = (column: IColumnConfig) => {
@@ -100,7 +108,7 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
100
108
  tempFilteredValue.value = { ...filteredValue.value };
101
109
  tempSearchValue.value = { ...searchValue.value };
102
110
  tempSortType.value = sortType.value || '';
103
- tempSortingColumn.value = sortingColumn.value ? { ...sortingColumn.value } as IColumnConfig : null;
111
+ tempSortProp.value = sortProp.value || '';
104
112
  // 临时合计项设置成实际的合计项
105
113
  tempSummaryList.value = [...summaryList.value];
106
114
  }
@@ -113,9 +121,9 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
113
121
  });
114
122
  }
115
123
 
116
- const handleSort = (type: 'ascending' | 'descending', column) => {
124
+ const handleSort = (type: 'ascending' | 'descending', prop: string) => {
117
125
  tempSortType.value = type;
118
- tempSortingColumn.value = column;
126
+ tempSortProp.value = prop;
119
127
  }
120
128
 
121
129
  const columnMap = computed(() => {
@@ -192,18 +200,18 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
192
200
  }
193
201
 
194
202
  summaryList.value = [...tempSummaryList.value];
195
- sortingColumn.value = tempSortingColumn.value ? { ...tempSortingColumn.value } : null;
203
+ sortProp.value = tempSortProp.value || '';
196
204
  sortType.value = tempSortType.value || null;
197
205
 
198
- if (sortingColumn.value) { // 确认时提交排序
206
+ if (sortProp.value) { // 确认时提交排序
199
207
  if (props.localSort) {
200
208
  // 恢复列配置的sortable属性,只有列配置的sortable为true,才能用下面的sort方法
201
209
  inSorting.value = true;
202
210
  await nextTick();
203
- tableDomRef.value?.sort(sortingColumn.value.prop, sortType.value);
211
+ tableDomRef.value?.sort(sortProp.value, sortType.value);
204
212
  inSorting.value = false
205
213
  } else {
206
- emit('sort-change', { order: sortType.value, prop: sortingColumn.value.prop });
214
+ emit('sort-change', { order: sortType.value, prop: sortProp.value });
207
215
  }
208
216
  }
209
217
 
@@ -223,7 +231,7 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
223
231
  }
224
232
 
225
233
  const clearSort = () => {
226
- sortingColumn.value = null;
234
+ sortProp.value = '';
227
235
  sortType.value = null;
228
236
  if (props.localSort) { // 前端过滤
229
237
  tableDomRef.value?.clearSort();
@@ -233,9 +241,12 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
233
241
  }
234
242
 
235
243
  const setSort = (params: { order: 'ascending' | 'descending', prop: string }) => {
236
- const column = props.columnConfig.find(c => c.prop === params.prop);
244
+ const column = props.columnConfig.find(c => Array.isArray(c.sortable)
245
+ ? c.sortable.some(v => v.prop === params.prop)
246
+ : c.prop === params.prop);
247
+
237
248
  if (column) {
238
- sortingColumn.value = column;
249
+ sortProp.value = params.prop
239
250
  sortType.value = params.order;
240
251
  if (props.localSort) {
241
252
  tableDomRef.value?.sort(params.prop, params.order);
@@ -256,7 +267,12 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
256
267
  }
257
268
 
258
269
  const handleHeaderOperationReset = async (column: IColumnConfig, scope) => {
259
- if (sortingColumn.value && sortingColumn.value.prop === column.prop) {
270
+ if (
271
+ sortProp.value &&
272
+ (Array.isArray(column._sortable)
273
+ ? column._sortable.some(v => v.prop === sortProp.value)
274
+ : sortProp.value === column.prop)
275
+ ) {
260
276
  clearSort();
261
277
  }
262
278
 
@@ -368,12 +384,12 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
368
384
  tableSummaryMethod,
369
385
  filteredValue,
370
386
  showColumnHeadSortIcon,
371
- tempSortingColumn,
387
+ tempSortProp,
372
388
  tempSearchValue,
373
389
  tempFilteredValue,
374
390
  tempSummaryList,
375
391
  tempSortType,
376
- sortingColumn,
392
+ sortProp,
377
393
  isColumnFiltering,
378
394
  searchValue,
379
395
  inSorting,
@@ -26,50 +26,42 @@
26
26
  <div class="editable-table-sort-filter__column-title">
27
27
  {{ column.label }}
28
28
  </div>
29
+
29
30
  <div
30
31
  v-if="column.isColumnSortable"
31
32
  class="editable-table-sort-filter__sort"
32
33
  >
33
- <div class="editable-table-sort-filter__sort-title">
34
- 排序
35
- </div>
36
- <div class="editable-table-sort-filter__sort-btns">
37
- <el-button
38
- :class="['editable-table-sort-filter__sort-btn', tempSortingColumn?.prop === column.prop && tempSortType === 'ascending' && 'editable-table-sort-filter__sort-btn--active']"
39
- @click="() => emit('update:sort', 'ascending')"
40
- >
41
- 升序
42
- </el-button>
43
- <el-button
44
- :class="['editable-table-sort-filter__sort-btn', tempSortingColumn?.prop === column.prop && tempSortType === 'descending' && 'editable-table-sort-filter__sort-btn--active']"
45
- @click="() => emit('update:sort', 'descending')"
46
- >
47
- 降序
48
- </el-button>
49
- </div>
50
- </div>
51
- <div
52
- v-if="column.search && !Array.isArray(column.search)"
53
- class="editable-table-sort-filter__search"
54
- >
55
- <div class="editable-table-sort-filter__search-title">
56
- 搜索
34
+ <div
35
+ v-for="item in sortConfigs"
36
+ :key="item.prop"
37
+ >
38
+ <div class="editable-table-sort-filter__sort-title">
39
+ {{ item.label }}
40
+ </div>
41
+ <div class="editable-table-sort-filter__sort-btns">
42
+ <el-button
43
+ :class="['editable-table-sort-filter__sort-btn', checkActiveProp('ascending', item.prop) && 'editable-table-sort-filter__sort-btn--active']"
44
+ @click="() => emit('update:sort', 'ascending', item.prop)"
45
+ >
46
+ 升序
47
+ </el-button>
48
+ <el-button
49
+ :class="['editable-table-sort-filter__sort-btn', checkActiveProp('descending', item.prop) && 'editable-table-sort-filter__sort-btn--active']"
50
+ @click="() => emit('update:sort', 'descending', item.prop)"
51
+ >
52
+ 降序
53
+ </el-button>
54
+ </div>
57
55
  </div>
58
- <el-input
59
- class="editable-table-sort-filter__search-input"
60
- placeholder="请输入内容"
61
- :value="tempSearchValue[column.prop]"
62
- @input="val => emit('update:tempSearchValue', column.prop, val)"
63
- />
64
56
  </div>
65
57
 
66
58
  <div
67
- v-if="column.search && Array.isArray(column.search)"
59
+ v-if="!!column.search"
68
60
  class="editable-table-sort-filter__search"
69
61
  style="display: flex;flex-direction: column;gap: 12px;"
70
62
  >
71
63
  <div
72
- v-for="item in column.search"
64
+ v-for="item in searchConfigs"
73
65
  :key="item.label"
74
66
  >
75
67
  <div class="editable-table-sort-filter__search-title">
@@ -83,10 +75,8 @@
83
75
  @input="val => emit('update:tempSearchValue', item.prop, val)"
84
76
  />
85
77
  </template>
86
- <template v-if="item.type === 'dateRange'">
87
- <div
88
- style="display: flex;flex-direction: column;gap: 12px;"
89
- >
78
+ <template v-if="item.type === 'doubleDatePicker'">
79
+ <div class="editable-table-sort-filter__search__date-range">
90
80
  <el-date-picker
91
81
  @input="val => emit('update:tempSearchValue', item.prop[0], val || '')"
92
82
  :value="tempSearchValue[item.prop[0]]"
@@ -95,6 +85,7 @@
95
85
  type="date"
96
86
  size="small"
97
87
  placeholder="开始日期"
88
+ :picker-options="item.pickerOptions ?? {}"
98
89
  />
99
90
  <el-date-picker
100
91
  @input="val => emit('update:tempSearchValue', item.prop[1], val || '')"
@@ -104,6 +95,7 @@
104
95
  size="small"
105
96
  type="date"
106
97
  placeholder="结束日期"
98
+ :picker-options="item.pickerOptions ?? {}"
107
99
  />
108
100
  </div>
109
101
  </template>
@@ -122,7 +114,7 @@
122
114
  style="display: flex;flex-direction: column;gap: 12px;"
123
115
  >
124
116
  <el-date-picker
125
- @input="val => emit('update:tempSearchValue', column.doubleDatePicker.props[0], val || '')"
117
+ @input="val => emit('update:tempSearchValue', column.doubleDatePicker!.props[0], val || '')"
126
118
  :value="tempSearchValue[column.doubleDatePicker.props[0]]"
127
119
  value-format="yyyy-MM-dd"
128
120
  format="yyyy-MM-dd"
@@ -131,7 +123,7 @@
131
123
  placeholder="开始日期"
132
124
  />
133
125
  <el-date-picker
134
- @input="val => emit('update:tempSearchValue', column.doubleDatePicker.props[1], val || '')"
126
+ @input="val => emit('update:tempSearchValue', column.doubleDatePicker!.props[1], val || '')"
135
127
  :value="tempSearchValue[column.doubleDatePicker.props[1]]"
136
128
  value-format="yyyy-MM-dd"
137
129
  format="yyyy-MM-dd"
@@ -192,6 +184,7 @@
192
184
  </el-radio>
193
185
  </el-radio-group>
194
186
  </div>
187
+
195
188
  <div
196
189
  v-if="column.summary"
197
190
  class="editable-table-sort-filter__filter"
@@ -217,6 +210,7 @@
217
210
  </el-checkbox>
218
211
  </el-checkbox-group>
219
212
  </div>
213
+
220
214
  <div class="editable-table-sort-filter__footer">
221
215
  <el-button
222
216
  class="editable-table-sort-filter__reset-btn"
@@ -237,15 +231,15 @@
237
231
  </template>
238
232
 
239
233
  <script setup lang="ts">
240
- import { ref } from 'vue'
234
+ import { computed, ref } from 'vue'
241
235
  import { IColumnConfig } from '../types'
242
236
 
243
- defineProps<{
237
+ const props = defineProps<{
244
238
  headActive: boolean
245
239
  column: IColumnConfig
246
240
  tempSummaryList: string[]
247
- tempSortingColumn: IColumnConfig | null
248
241
  tempSortType: 'ascending' | 'descending' | ''
242
+ tempSortProp: string
249
243
  tempSearchValue: Record<string, string>
250
244
  tempFilteredValue: Record<string, string | number | number[] | string[]>
251
245
  }>()
@@ -254,7 +248,7 @@ const emit = defineEmits<{
254
248
  (e: 'update:tempSearchValue', key: string, value: string): void
255
249
  (e: 'update:tempFilteredValue', key: string, value: string): void
256
250
  (e: 'update:tempSummaryList', value: string[]): void
257
- (e: 'update:sort', type: 'ascending' | 'descending'): void
251
+ (e: 'update:sort', type: 'ascending' | 'descending', prop: string): void
258
252
  (e: 'popover-show'): void
259
253
  (e: 'reset'): void
260
254
  (e: 'confirm'): void
@@ -262,6 +256,20 @@ const emit = defineEmits<{
262
256
 
263
257
  const popoverRef = ref(null as any)
264
258
 
259
+ const searchConfigs = computed(() => {
260
+ if (Array.isArray(props.column.search)) return props.column.search
261
+ return [{ prop: props.column.prop, label: '搜索' }]
262
+ })
263
+
264
+ const sortConfigs = computed(() => {
265
+ if (Array.isArray(props.column._sortable)) return props.column._sortable
266
+ return [{ ...props.column, label: '排序' }]
267
+ })
268
+
269
+ const checkActiveProp = (type: 'ascending' | 'descending', prop: string) => {
270
+ return props.tempSortType === type && props.tempSortProp === prop
271
+ }
272
+
265
273
  defineExpose({
266
274
  close: () => {
267
275
  popoverRef.value?.doClose()
@@ -388,7 +388,6 @@
388
388
  }
389
389
 
390
390
  &__filter,
391
- &__sort,
392
391
  &__search {
393
392
  padding: 14px;
394
393
 
@@ -433,6 +432,13 @@
433
432
  }
434
433
  }
435
434
 
435
+ &__sort {
436
+ padding: 14px;
437
+ display: flex;
438
+ flex-direction: column;
439
+ gap: 8px;
440
+ }
441
+
436
442
  &__filter-title,
437
443
  &__sort-title,
438
444
  &__search-title {
@@ -442,9 +448,20 @@
442
448
  margin-bottom: 10px;
443
449
  }
444
450
 
445
- &__search-input {
446
- & .el-input__inner {
447
- height: 32px;
451
+ &__search {
452
+ &-input {
453
+ & .el-input__inner {
454
+ height: 32px;
455
+ }
456
+ }
457
+ &__date-range {
458
+ display: flex;
459
+ flex-direction: column;
460
+ gap: 12px;
461
+
462
+ .el-date-editor.el-input, .el-date-editor.el-input__inner {
463
+ width: 100%;
464
+ }
448
465
  }
449
466
  }
450
467
 
@@ -111,7 +111,7 @@
111
111
  :column="colorFilterConfig"
112
112
  :showing-columns="showingColumns"
113
113
  :temp-summary-list="tempSummaryList"
114
- :temp-sorting-column="tempSortingColumn"
114
+ :temp-sort-prop="tempSortProp"
115
115
  :temp-sort-type="tempSortType"
116
116
  :temp-filtered-value="tempFilteredValue"
117
117
  :temp-search-value="tempSearchValue"
@@ -119,7 +119,7 @@
119
119
  @update:tempFilteredValue="(key, value) => { $set(tempFilteredValue, key, value) }"
120
120
  @update:tempSearchValue="(key, value) => { $set(tempSearchValue, key, value) }"
121
121
  @popover-show="() => handleHeaderPopoverShow(colorFilterConfig)"
122
- @update:sort="(type) => handleSort(type, colorFilterConfig)"
122
+ @update:sort="handleSort"
123
123
  @reset="() => handleHeaderOperationReset(colorFilterConfig, scope)"
124
124
  @confirm="() => handleHeaderOperationConfirm(colorFilterConfig, scope)"
125
125
  >
@@ -166,7 +166,7 @@
166
166
  :column="column"
167
167
  :showing-columns="showingColumns"
168
168
  :temp-summary-list="tempSummaryList"
169
- :temp-sorting-column="tempSortingColumn"
169
+ :temp-sort-prop="tempSortProp"
170
170
  :temp-sort-type="tempSortType"
171
171
  :temp-filtered-value="tempFilteredValue"
172
172
  :temp-search-value="tempSearchValue"
@@ -174,7 +174,7 @@
174
174
  @update:tempFilteredValue="(key, value) => { $set(tempFilteredValue, key, value) }"
175
175
  @update:tempSearchValue="(key, value) => { $set(tempSearchValue, key, value) }"
176
176
  @popover-show="() => handleHeaderPopoverShow(column)"
177
- @update:sort="(type) => handleSort(type, column)"
177
+ @update:sort="handleSort"
178
178
  @reset="() => handleHeaderOperationReset(column, scope)"
179
179
  @confirm="() => handleHeaderOperationConfirm(column, scope)"
180
180
  >
@@ -453,8 +453,9 @@ const actualColumns = computed(() => {
453
453
  const rawItem = props.columnConfig.find(c => c.prop === prop) ?? {} as IColumnConfig;
454
454
  const item: IColumnConfig = {
455
455
  ...rawItem,
456
- isColumnSortable: rawItem.sortable,
457
- sortable: inSorting.value ? rawItem.sortable : false
456
+ isColumnSortable: !!rawItem.sortable,
457
+ sortable: inSorting.value ? !!rawItem.sortable : false,
458
+ _sortable: rawItem.sortable,
458
459
  };
459
460
  if (cnt > 0) {
460
461
  item.fixed = 'left';
@@ -543,12 +544,12 @@ const {
543
544
  tableSummaryMethod,
544
545
  filteredValue,
545
546
  showColumnHeadSortIcon,
546
- tempSortingColumn,
547
+ sortProp,
547
548
  tempSearchValue,
548
549
  tempFilteredValue,
549
550
  tempSummaryList,
550
551
  tempSortType,
551
- sortingColumn,
552
+ tempSortProp,
552
553
  isColumnFiltering,
553
554
  searchValue,
554
555
  inSorting,
@@ -562,7 +563,7 @@ const {
562
563
  /************ 表格行拖拽和显示设置列拖拽 ************ */
563
564
  const beforeDragStart = () => {
564
565
  // 如果有列存在排序,不允许拖拽
565
- if (sortingColumn.value) {
566
+ if (sortProp.value) {
566
567
  Message.warning('已有列正在排序,不允许拖拽。');
567
568
  return false;
568
569
  }
@@ -1,4 +1,4 @@
1
- import type { TableColumn } from 'element-ui'
1
+ import type { TableColumn, DatePicker } from 'element-ui'
2
2
 
3
3
  export enum IEditType {
4
4
  INPUT = 'input',
@@ -11,7 +11,8 @@ type _IColumnConfigRequired = {
11
11
  label: string;
12
12
  editType?: IEditType; // 编辑格式
13
13
  editSlotName?: string; // 编辑时,自定义编辑组件的slotName
14
- sortable?: boolean; // 该列是否允许排序,ture则表头弹窗会显示升降序按钮
14
+ sortable?: boolean | ISortOption[]; // 该列是否允许排序,ture则表头弹窗会显示升降序按钮
15
+ _sortable?: _IColumnConfigRequired['sortable']; // 内部使用,el-table 的 sortable 不支持数组,用来同步 sortable
15
16
  /** 内部使用, */
16
17
  isColumnSortable?: boolean;
17
18
  slotName?: string; // 如果要自定义,传入 slotName
@@ -48,22 +49,26 @@ export type IColumnConfigRequired = _IColumnConfigRequired & Partial<Omit<TableC
48
49
 
49
50
  type FiltersOption = { value: string | number; text: string; [key: string]: any }
50
51
 
52
+ type ISortOption = {
53
+ prop: string
54
+ label: string
55
+ }
56
+
51
57
  type InputSearchOption = {
52
- prop: string,
53
- label: string,
58
+ prop: string
59
+ label: string
54
60
  validator?: (value: string) => boolean
55
- type?: 'input',
61
+ type?: 'input'
56
62
  }
57
63
 
58
- type DateRangeSearchOption = {
59
- prop: [string, string],
60
- label: string,
61
- type: 'dateRange',
62
- // max?: string,
63
- // min?: string,
64
+ type DoubleDatePickerSearchOption = {
65
+ prop: [string, string]
66
+ label: string
67
+ type: 'doubleDatePicker'
68
+ pickerOptions?: DatePicker['pickerOptions']
64
69
  }
65
70
 
66
- type ISearchOptions = (InputSearchOption | DateRangeSearchOption)[]
71
+ type ISearchOptions = (InputSearchOption | DoubleDatePickerSearchOption)[]
67
72
 
68
73
  type IInputColumn = IColumnConfigRequired & {
69
74
  inputType: string | number;