@lx-frontend/wrap-element-ui 1.0.20 → 1.0.21-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.20",
3
+ "version": "1.0.21-beta.2",
4
4
  "description": "wrap-element-ui",
5
5
  "author": "",
6
6
  "main": "src/components/index.ts",
@@ -92,6 +92,10 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
92
92
  return !!(filteredValue.value[item.prop] as any[]).length
93
93
  }
94
94
 
95
+ if (item.type === 'slot') {
96
+ return item.active()
97
+ }
98
+
95
99
  return !!filteredValue.value[item.prop]
96
100
  }
97
101
  )
@@ -139,15 +143,17 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
139
143
  const params: Record<string, any> = {};
140
144
 
141
145
  const processFilter = (filters: FilterListType) => {
142
- filters.forEach((item) => {
143
- if (item.type === 'doubleDatePicker' || item.type === 'monthDayPicker') {
144
- const [start, end] = item.prop
145
- params[start] = filteredValue.value[start];
146
- params[end] = filteredValue.value[end];
147
- } else {
148
- params[item.prop] = filteredValue.value[item.prop];
149
- }
150
- });
146
+ filters
147
+ .filter(item => item.type !== 'slot')
148
+ .forEach((item) => {
149
+ if (item.type === 'doubleDatePicker' || item.type === 'monthDayPicker') {
150
+ const [start, end] = item.prop
151
+ params[start] = filteredValue.value[start];
152
+ params[end] = filteredValue.value[end];
153
+ } else {
154
+ params[item.prop] = filteredValue.value[item.prop];
155
+ }
156
+ });
151
157
  }
152
158
 
153
159
  // 仅提交显示的列的相关数据
@@ -242,6 +248,7 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
242
248
 
243
249
  function handleResetFilterValue (column: IColumnConfig) {
244
250
  (column.filters || [])
251
+ .filter(item => item.type !== 'slot')
245
252
  .forEach(
246
253
  (item) => {
247
254
  if (item.type === 'radio' || item.type === 'checkbox') {
@@ -287,6 +294,7 @@ export function useColumnHeaderOperation({ props, tableDomRef, emit, showingColu
287
294
  // 设置搜索和过滤参数时,如果使用 showingColumns 遍历,会导致通过外部设置未显示的列的搜索和过滤参数丢失
288
295
  [props.colorFilterConfig, ...props.columnConfig].forEach(column => {
289
296
  (column?.filters ?? [])
297
+ .filter(item => item.type !== 'slot')
290
298
  .forEach(
291
299
  (item) => {
292
300
  if (item.type === 'doubleDatePicker' || item.type === 'monthDayPicker') {
@@ -9,14 +9,14 @@
9
9
  v-bind="datePickerCommonProps"
10
10
  placeholder="开始日期"
11
11
  :value="tempFilteredValue[config.prop[0]]"
12
- :picker-options="startDateDisabledOptions"
12
+ :picker-options="genStartDateDisabledOptions(tempFilteredValue[config.prop[1]], config.limit)"
13
13
  @input="handleStartDateChange"
14
14
  />
15
15
  <el-date-picker
16
16
  v-bind="datePickerCommonProps"
17
17
  placeholder="结束日期"
18
18
  :value="tempFilteredValue[config.prop[1]]"
19
- :picker-options="endDateDisabledOptions"
19
+ :picker-options="genEndDateDisabledOptions(tempFilteredValue[config.prop[0]], config.limit)"
20
20
  @input="handleEndDateChange"
21
21
  />
22
22
  </div>
@@ -24,10 +24,8 @@
24
24
  </template>
25
25
 
26
26
  <script setup lang="ts">
27
- import { computed } from 'vue';
28
27
  import { IFilterDoubleDatePicker } from '../../types';
29
- import dayjs from 'dayjs';
30
- import type { DatePickerOptions } from 'element-ui/types/date-picker';
28
+ import { genStartDateDisabledOptions, genEndDateDisabledOptions } from '../../../helper';
31
29
 
32
30
  interface IFilterDoubleDatePickerProps {
33
31
  /** 日期选择器配置 */
@@ -51,34 +49,6 @@ const datePickerCommonProps = {
51
49
  editable: false,
52
50
  } as const;
53
51
 
54
- /** 开始日期禁用配置 */
55
- const startDateDisabledOptions = computed<DatePickerOptions>(() => {
56
- const endDate = props.tempFilteredValue[props.config.prop[1]];
57
-
58
- return {
59
- disabledDate: (time: Date) => {
60
- if (!endDate) return false;
61
-
62
- const currentDate = dayjs(time);
63
- return currentDate.isAfter(dayjs(endDate), 'day');
64
- }
65
- };
66
- });
67
-
68
- /** 结束日期禁用配置 */
69
- const endDateDisabledOptions = computed<DatePickerOptions>(() => {
70
- const startDate = props.tempFilteredValue[props.config.prop[0]];
71
-
72
- return {
73
- disabledDate: (time: Date) => {
74
- if (!startDate) return false;
75
-
76
- const currentDate = dayjs(time);
77
- return currentDate.isBefore(dayjs(startDate), 'day');
78
- }
79
- };
80
- });
81
-
82
52
  /** 处理开始日期变更 */
83
53
  const handleStartDateChange = (val: string | null) => {
84
54
  emit('update:tempFilteredValue', props.config.prop[0], val || '');
@@ -40,7 +40,12 @@
40
40
  :key="index"
41
41
  class="editable-table-sort-filter__item editable-table__filter-group__filter"
42
42
  >
43
+ <slot
44
+ v-if="filterItem.type === 'slot'"
45
+ :name="filterItem.slotName"
46
+ />
43
47
  <component
48
+ v-else
44
49
  :is="componentMap[filterItem.type]"
45
50
  :config="filterItem"
46
51
  :temp-filtered-value="tempFilteredValue"
@@ -125,7 +130,7 @@ const emit = defineEmits<{
125
130
  }>()
126
131
 
127
132
  // 把 filterItem.type 映射到组件
128
- const componentMap: Record<FilterItem['type'], any> = {
133
+ const componentMap: Record<Exclude<FilterItem['type'], 'slot'>, any> = {
129
134
  /** 输入框 */
130
135
  input: BizInputFilter,
131
136
  /** 日期范围 */
@@ -162,10 +162,10 @@
162
162
  :temp-filtered-value="tempFilteredValue"
163
163
  @update:tempSummaryList="val => { tempSummaryList = val }"
164
164
  @update:tempFilteredValue="(key, value) => { $set(tempFilteredValue, key, value) }"
165
- @popover-show="() => handleHeaderPopoverShow(column)"
165
+ @popover-show="() => handleOpenFilter(column)"
166
166
  @update:sort="handleSort"
167
- @reset="() => handleHeaderOperationReset(column)"
168
- @confirm="() => handleHeaderOperationConfirm(column)"
167
+ @reset="() => handleResetFilter(column)"
168
+ @confirm="() => handleConfirmFilter(column)"
169
169
  >
170
170
  <template #summay-item>
171
171
  <slot
@@ -175,6 +175,16 @@
175
175
  {{ column.label }}
176
176
  </slot>
177
177
  </template>
178
+ <!-- 动态地将父组件传递的所有slot下发给孙子组件(biz-table-header-popover),以实现slot的透传 -->
179
+ <template
180
+ v-for="(_, name) in $slots"
181
+ #[name]="slotProps"
182
+ >
183
+ <slot
184
+ :name="name"
185
+ v-bind="slotProps || column"
186
+ />
187
+ </template>
178
188
  </biz-table-header-popover>
179
189
  </template>
180
190
  <!-- 默认操作按钮,defaultOperations属性不为空数组时展示。编辑状态下隐藏 -->
@@ -397,6 +407,12 @@ interface IEmits {
397
407
  (e: 'sort-change', param: { order: 'descending' | 'ascending' | null, prop: string }): void
398
408
  /** 双击某一行 */
399
409
  (e: 'row-dblclick', param: any): void
410
+ /** 筛选条件打开 */
411
+ (e: 'open-filter', prop: string): void
412
+ /** 重置筛选 */
413
+ (e: 'reset-filter', prop: string): void
414
+ /** 筛选条件确认 */
415
+ (e: 'confirm-filter', prop: string): void
400
416
  }
401
417
 
402
418
  const props = withDefaults(defineProps<IProps>(), {
@@ -565,7 +581,8 @@ const beforeDragStart = () => {
565
581
  return true;
566
582
  };
567
583
 
568
- // @ts-ignore
584
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
585
+ // @ts-ignore ts-plugin存在间歇性抛出「类型实例化过深,且可能无限」的错误
569
586
  useDragSort({
570
587
  emit,
571
588
  props,
@@ -609,6 +626,27 @@ const handleRowDblClick = (e) => {
609
626
  emit('row-dblclick', e);
610
627
  };
611
628
 
629
+ const handleOpenFilter = (column: IColumnConfig) => {
630
+ emit('open-filter', column.prop);
631
+ nextTick(() => {
632
+ handleHeaderPopoverShow(column)
633
+ })
634
+ }
635
+
636
+ const handleResetFilter = (column: IColumnConfig) => {
637
+ emit('reset-filter', column.prop);
638
+ nextTick(() => {
639
+ handleHeaderOperationReset(column)
640
+ })
641
+ }
642
+
643
+ const handleConfirmFilter = (column: IColumnConfig) => {
644
+ emit('confirm-filter', column.prop);
645
+ nextTick(() => {
646
+ handleHeaderOperationConfirm(column)
647
+ })
648
+ }
649
+
612
650
  const bizViewSettingDialogRef = ref(null as unknown as InstanceType<typeof BizViewSettingDialog>)
613
651
  const handleViewSettingShow = () => bizViewSettingDialogRef.value.open()
614
652
 
@@ -40,7 +40,9 @@ export interface IFilterDoubleDatePicker {
40
40
  type: 'doubleDatePicker',
41
41
  prop: [string, string],
42
42
  label?: string,
43
- pickerOptions?: DatePicker['pickerOptions']
43
+ pickerOptions?: DatePicker['pickerOptions'],
44
+ /** 限制天数范围 */
45
+ limit?: number
44
46
  }
45
47
 
46
48
  /** 筛选组件 - 月日选择器 */
@@ -60,7 +62,13 @@ export interface IFilterColorRadio {
60
62
  options: Array<IFilterSelectOptions & { color: string }>
61
63
  }
62
64
 
63
- export type FilterItem = IFilterInput | IFilterSelect | IFilterDoubleDatePicker | IFilterMonthDayPicker | IFilterColorRadio
65
+ export interface IFilterSolt {
66
+ type: 'slot',
67
+ slotName: string,
68
+ active: () => boolean
69
+ }
70
+
71
+ export type FilterItem = IFilterInput | IFilterSelect | IFilterDoubleDatePicker | IFilterMonthDayPicker | IFilterColorRadio | IFilterSolt
64
72
 
65
73
  /** 筛选组件类型 */
66
74
  export type FilterListType = Array<FilterItem>
@@ -8,7 +8,7 @@
8
8
  v-for="({
9
9
  isEmpty = true, key, type, prop, label, placeholder, candidate, filterable=false, withoutAll=false, collapseTags=false,
10
10
  clearable=false, multiple=false, multipleLimit=0, changeCb, inputLimitCallback, slotName, dateType='date',
11
- doubleIsInline = true, maxlength = 255,
11
+ doubleIsInline = true, maxlength = 255, doubleDatePickerLimit
12
12
  }) in config"
13
13
  :key="label"
14
14
  :label="showLabel ? label : ''"
@@ -84,7 +84,9 @@
84
84
  value-format="yyyy-MM-dd"
85
85
  format="yyyy-MM-dd"
86
86
  type="date"
87
+ :editable="false"
87
88
  :placeholder="(placeholder || [])[0] || '开始日期'"
89
+ :picker-options="genStartDateDisabledOptions(formData[prop[1]], doubleDatePickerLimit)"
88
90
  />
89
91
  <el-date-picker
90
92
  @input="val => handleInput(val, prop[1], '', key)"
@@ -93,7 +95,9 @@
93
95
  value-format="yyyy-MM-dd"
94
96
  format="yyyy-MM-dd"
95
97
  type="date"
98
+ :editable="false"
96
99
  :placeholder="(placeholder || [])[1] || '结束日期'"
100
+ :picker-options="genEndDateDisabledOptions(formData[prop[0]], doubleDatePickerLimit)"
97
101
  />
98
102
  <el-checkbox
99
103
  :value="checkedIds[key]"
@@ -124,6 +128,8 @@
124
128
  </template>
125
129
 
126
130
  <script>
131
+ import { genStartDateDisabledOptions, genEndDateDisabledOptions } from '../helper';
132
+
127
133
  export default {
128
134
  name: 'SearchForm',
129
135
  props: {
@@ -187,6 +193,8 @@ export default {
187
193
  this.initialData = Object.freeze({ ...this.formData })
188
194
  },
189
195
  methods: {
196
+ genStartDateDisabledOptions,
197
+ genEndDateDisabledOptions,
190
198
  handleInput (val, prop, inputLimitCallback, key) {
191
199
  if (inputLimitCallback && !inputLimitCallback(val)) return false
192
200
  if (val) {
@@ -0,0 +1,37 @@
1
+ import dayjs from "dayjs";
2
+
3
+ /** 开始日期禁用配置 */
4
+ export function genStartDateDisabledOptions(endDate: string, limit: number = 0) {
5
+ return {
6
+ disabledDate: (time: Date) => {
7
+ if (!endDate) return false;
8
+
9
+ const currentDate = dayjs(time);
10
+ const baseOption = currentDate.isAfter(dayjs(endDate), 'day');
11
+
12
+ if (!limit) {
13
+ return baseOption
14
+ }
15
+
16
+ return baseOption || currentDate.isBefore(dayjs(endDate).subtract(limit - 1, 'day'), 'day');
17
+ }
18
+ };
19
+ }
20
+
21
+ /** 结束日期禁用配置 */
22
+ export function genEndDateDisabledOptions(startDate: string, limit: number = 0) {
23
+ return {
24
+ disabledDate: (time: Date) => {
25
+ if (!startDate) return false;
26
+
27
+ const currentDate = dayjs(time);
28
+ const baseOption = currentDate.isBefore(dayjs(startDate), 'day');
29
+
30
+ if (!limit) {
31
+ return baseOption
32
+ }
33
+
34
+ return baseOption || currentDate.isAfter(dayjs(startDate).add(limit - 1, 'day'), 'day');
35
+ }
36
+ };
37
+ }