@lx-frontend/wrap-element-ui 1.0.0-beta.8 → 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 (31) hide show
  1. package/README.md +2 -2
  2. package/package.json +6 -5
  3. package/src/components/AddMembers/index.vue +32 -40
  4. package/src/components/EditableTable/bizHooks/index.ts +7 -0
  5. package/src/components/EditableTable/{useCellHover.ts → bizHooks/useCellHover.ts} +1 -1
  6. package/src/components/EditableTable/bizHooks/useColumnHeaderOperation.ts +329 -0
  7. package/src/components/EditableTable/{useDefaultOperation.ts → bizHooks/useDefaultOperation.ts} +2 -2
  8. package/src/components/EditableTable/{useDragSort.ts → bizHooks/useDragSort.ts} +4 -4
  9. package/src/components/EditableTable/{usePagination.ts → bizHooks/usePagination.ts} +3 -3
  10. package/src/components/EditableTable/{useRowBgColor.ts → bizHooks/useRowBgColor.ts} +9 -16
  11. package/src/components/EditableTable/bizHooks/useViewSetting.ts +125 -0
  12. package/src/components/EditableTable/features/bizColorSelect.vue +63 -0
  13. package/src/components/EditableTable/features/bizEditCell.vue +44 -0
  14. package/src/components/EditableTable/features/bizTableHeaderPopover/BizCheckboxFilter.vue +40 -0
  15. package/src/components/EditableTable/features/bizTableHeaderPopover/BizColorRadioFilter.vue +56 -0
  16. package/src/components/EditableTable/features/bizTableHeaderPopover/BizDoubleDatePickerFilter.vue +91 -0
  17. package/src/components/EditableTable/features/bizTableHeaderPopover/BizInputFilter.vue +26 -0
  18. package/src/components/EditableTable/features/bizTableHeaderPopover/BizMonthDayPicker.helper.ts +131 -0
  19. package/src/components/EditableTable/features/bizTableHeaderPopover/BizMonthDayPicker.vue +115 -0
  20. package/src/components/EditableTable/features/bizTableHeaderPopover/BizRadioFilter.vue +39 -0
  21. package/src/components/EditableTable/features/bizTableHeaderPopover/BizSortFilter.vue +50 -0
  22. package/src/components/EditableTable/features/bizTableHeaderPopover/index.vue +155 -0
  23. package/src/components/EditableTable/features/bizTableOperatePopover.vue +67 -0
  24. package/src/components/EditableTable/features/bizViewSettingDialog.vue +137 -0
  25. package/src/components/EditableTable/index.less +524 -428
  26. package/src/components/EditableTable/index.vue +167 -456
  27. package/src/components/EditableTable/{types.ts → types/index.ts} +176 -116
  28. package/src/components/SearchForm/index.vue +7 -4
  29. package/src/components/SearchForm/types/index.ts +63 -0
  30. package/src/components/EditableTable/useColumnHeaderOperation.ts +0 -326
  31. package/src/components/EditableTable/useViewSetting.ts +0 -119
@@ -0,0 +1,125 @@
1
+ import { ref, watch, Ref, computed, nextTick } from "vue"
2
+ import { IColumnConfig, IProps } from "../types"
3
+
4
+ interface IViewSettingParams {
5
+ showingColumns: Ref<string[]>
6
+ actualColumns: Ref<IColumnConfig[]>
7
+ viewSettingDragSortOptions: Ref<IColumnConfig[]>
8
+ props: IProps
9
+ emit: {
10
+ (e: 'update:leftFixedColumnCount', val: number): void
11
+ (e: 'update:showingColumns', val: string[]): void
12
+ (e: 'update:viewSettingDragSortOptions', val: IColumnConfig[]): void
13
+ (e: 'tableDoLayout'): void
14
+ }
15
+ }
16
+
17
+ export function useViewSetting({
18
+ showingColumns,
19
+ actualColumns,
20
+ props,
21
+ viewSettingDragSortOptions,
22
+ emit
23
+ }: IViewSettingParams) {
24
+ const columnsToBeShown = ref<string[]>([]); // 显示设置弹窗中勾选的列
25
+ const viewSettingVisible = ref(false);
26
+ const leftFixedColumnCount = ref(0);
27
+ const tempLeftFixedColumnCount = ref(0);
28
+
29
+ const updateShowingColumns = (val: string[]) => emit('update:showingColumns', val);
30
+
31
+ const storageKey = computed(() => `@lx-frontend/wrap-element-ui/table_setting_cloumns/${props.settingStorgeKey || (location.pathname === '/' ? location.hash : location.pathname)}`);
32
+
33
+ const saveSettingToStorge = async() => {
34
+ await nextTick()
35
+ localStorage.setItem(storageKey.value, JSON.stringify({
36
+ showingColumns: showingColumns.value,
37
+ leftFixedColumnCount: leftFixedColumnCount.value
38
+ }))
39
+ };
40
+
41
+ const handleViewSettingShow = () => {
42
+ emit('update:viewSettingDragSortOptions', [...actualColumns.value.filter(v => v?.prop !== '$$operation')]);
43
+ tempLeftFixedColumnCount.value = leftFixedColumnCount.value;
44
+ viewSettingVisible.value = true;
45
+ columnsToBeShown.value = [...showingColumns.value];
46
+ }
47
+
48
+ const handleViewSettingClose = () => {
49
+ viewSettingVisible.value = false;
50
+ }
51
+
52
+ const handleViewSettingConfirm = async () => {
53
+ viewSettingVisible.value = false;
54
+ updateShowingColumns(viewSettingDragSortOptions.value.map(c => c.prop));
55
+ leftFixedColumnCount.value = tempLeftFixedColumnCount.value;
56
+ await saveSettingToStorge()
57
+ emit('tableDoLayout')
58
+ }
59
+
60
+ const handleInputTempLeftFixedColumnCount = (value: string) => {
61
+ const _value = Number(value)
62
+ if (isNaN(_value)) return
63
+ tempLeftFixedColumnCount.value = Math.max(0, Math.min(columnsToBeShown.value.length, Math.floor(_value)))
64
+ }
65
+
66
+ watch(
67
+ () => props.columnConfig,
68
+ async(val) => {
69
+ const _keys = new Set(val.map(c => (c.prop)));
70
+ const _cache = localStorage.getItem(storageKey.value);
71
+ const setColumns = () => updateShowingColumns(val.filter(v => !v.defaultHide).map(c => c.prop));
72
+ if (!_cache) {
73
+ setColumns();
74
+ leftFixedColumnCount.value = props.leftFixedCount as number;
75
+ } else {
76
+ try {
77
+ // 缓存数据字段可能随着更新导致对不上,清理无效数据,防止出问题
78
+ const cache = JSON.parse(_cache);
79
+ if (!cache.showingColumns || !Array.isArray(cache.showingColumns)) {
80
+ setColumns();
81
+ } else {
82
+ updateShowingColumns(cache.showingColumns.filter(key => _keys.has(key)))
83
+ }
84
+ const _leftFixedColumnCount = Number(cache?.leftFixedColumnCount)
85
+ leftFixedColumnCount.value = isNaN(_leftFixedColumnCount) ? (props.leftFixedCount as number) : _leftFixedColumnCount;
86
+ // 写入清理后的数据
87
+ saveSettingToStorge();
88
+ } catch (error) {
89
+ console.error(error);
90
+ localStorage.removeItem(storageKey.value);
91
+ setColumns();
92
+ }
93
+ }
94
+ },
95
+ { immediate: true }
96
+ )
97
+
98
+ watch(columnsToBeShown, (val, oldVal) => {
99
+ if (val.length === oldVal?.length) return // 排序调整时不做处理,避免出现死循环
100
+ const _map = new Map<string, IColumnConfig>()
101
+ props.columnConfig.forEach(c => _map.set(c.prop, c))
102
+ // 展示时保留顺序
103
+ emit('update:viewSettingDragSortOptions', val.map(prop => _map.get(prop)!))
104
+ if (tempLeftFixedColumnCount.value > val.length) tempLeftFixedColumnCount.value = val.length
105
+ }, { immediate: true })
106
+
107
+ // 拖拽调整排序时,同时更新勾选数组的顺序,避免出现拖拽排序操作过程后再勾选新列时被还原成拖拽前的顺序的问题
108
+ watch(viewSettingDragSortOptions, (val, oldVal) => {
109
+ if (!val.length || val.length !== oldVal?.length) return // 不是排序调整
110
+ columnsToBeShown.value = val.map(c => c.prop)
111
+ }, { deep: true })
112
+
113
+ watch(leftFixedColumnCount, (val) => emit('update:leftFixedColumnCount', val), { immediate: true });
114
+
115
+ return {
116
+ columnsToBeShown,
117
+ viewSettingVisible,
118
+ leftFixedColumnCount,
119
+ tempLeftFixedColumnCount,
120
+ handleInputTempLeftFixedColumnCount,
121
+ handleViewSettingShow,
122
+ handleViewSettingClose,
123
+ handleViewSettingConfirm,
124
+ }
125
+ }
@@ -0,0 +1,63 @@
1
+ <!-- 行颜色选择组件 -->
2
+ <template>
3
+ <el-popover
4
+ v-model="visible"
5
+ placement="right"
6
+ trigger="click"
7
+ popper-class="editable-table-color-popover"
8
+ >
9
+ <div class="color-list">
10
+ <div
11
+ v-for="color in colorList"
12
+ :key="color.id"
13
+ class="color-list__item"
14
+ :style="{ backgroundColor: color.sampleColor }"
15
+ @click="() => {
16
+ visible = false
17
+ handleColorChange(color.id, scope)
18
+ }"
19
+ >
20
+ <span :style="{color: color.textColor}">{{ color.name }}</span>
21
+ </div>
22
+ </div>
23
+
24
+ <div slot="reference">
25
+ <div
26
+ v-if="isDefaultColor(scope.row.colorId)"
27
+ class="editable-table__color-icon"
28
+ />
29
+ <div
30
+ v-else
31
+ class="editable-table__selected-color"
32
+ :style="{ backgroundColor: getColorById(scope.row.colorId, 'sample') }"
33
+ />
34
+ </div>
35
+ </el-popover>
36
+ </template>
37
+
38
+ <script setup lang="ts">
39
+ import { ref } from 'vue';
40
+ import { IColorList, IEmits, ITableDataItem } from '../types';
41
+ import { useRowBgColor } from '../bizHooks';
42
+
43
+ const props = defineProps<{
44
+ colorList: IColorList,
45
+ scope: any
46
+ }>();
47
+
48
+ const emit = defineEmits<{
49
+ (e: 'row-bg-change', param: { colorId: number; row: ITableDataItem; rowIndex: number }): void
50
+ }>();
51
+
52
+ const {
53
+ getColorById,
54
+ isDefaultColor,
55
+ handleColorChange,
56
+ } = useRowBgColor({
57
+ colorList: props.colorList,
58
+ emit: emit as IEmits,
59
+ });
60
+
61
+ const visible = ref(false);
62
+
63
+ </script>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <div>
3
+ <el-input
4
+ v-if="column.editType === 'input'"
5
+ clearable
6
+ :value="value"
7
+ @input="val => emit('input', val)"
8
+ />
9
+
10
+ <el-select
11
+ v-if="column.editType === 'select'"
12
+ :value="value"
13
+ @input="val => emit('input', val)"
14
+ >
15
+ <el-option
16
+ v-for="item in column.selectOptions"
17
+ :key="item.label"
18
+ :label="item.label"
19
+ :value="item.value"
20
+ />
21
+ </el-select>
22
+
23
+ <el-date-picker
24
+ v-if="column.editType === 'date'"
25
+ type="date"
26
+ placeholder="选择日期"
27
+ :value="value"
28
+ @input="val => emit('input', val)"
29
+ />
30
+ </div>
31
+ </template>
32
+
33
+ <script setup lang="ts">
34
+ import { IColumnConfig } from '../types'
35
+
36
+ defineProps<{
37
+ column: IColumnConfig;
38
+ value: any;
39
+ }>()
40
+
41
+ const emit = defineEmits<{
42
+ (e: 'input', value: any): void;
43
+ }>()
44
+ </script>
@@ -0,0 +1,40 @@
1
+ <!-- 复选框 -->
2
+ <template>
3
+ <div class="editable-table-sort-filter__filter">
4
+ <div class="editable-table-sort-filter__filter-title">
5
+ {{ config.label || '筛选' }}
6
+ </div>
7
+ <el-checkbox-group
8
+ class="editable-table-sort-filter__filter-checkbox-group"
9
+ :value="tempFilteredValue[config.prop]"
10
+ @input="val => emit('update:tempFilteredValue', config.prop, val)"
11
+ >
12
+ <el-checkbox
13
+ v-for="item in config.options"
14
+ :key="item.value"
15
+ :label="item.value"
16
+ :title="item.text"
17
+ class="editable-table-sort-filter__filter-checkbox"
18
+ >
19
+ {{ item.text }}
20
+ </el-checkbox>
21
+ </el-checkbox-group>
22
+ </div>
23
+ </template>
24
+
25
+ <script setup lang="ts">
26
+ import { IFilterSelect } from '../../types';
27
+
28
+ defineProps<{
29
+ config: IFilterSelect
30
+ tempFilteredValue: Record<string, string>
31
+ }>()
32
+
33
+ const emit = defineEmits<{
34
+ (e: 'update:tempFilteredValue', key: string, value: string): void
35
+ }>()
36
+ </script>
37
+
38
+ <style scoped lang="less">
39
+
40
+ </style>
@@ -0,0 +1,56 @@
1
+ <!-- 单选框 -->
2
+ <template>
3
+ <div class="editable-table-sort-filter__filter">
4
+ <div class="editable-table-sort-filter__filter-title">
5
+ {{ config.label || '筛选' }}
6
+ </div>
7
+ <el-radio-group
8
+ style="display: flex;flex-direction: column;gap: 6px;"
9
+ :value="tempFilteredValue[config.prop]"
10
+ @input="val => emit('update:tempFilteredValue', config.prop, val)"
11
+ >
12
+ <el-radio
13
+ v-for="item in config.options"
14
+ :key="item.value"
15
+ :label="item.value"
16
+ :title="item.text"
17
+ >
18
+ <span class="color-option">
19
+ <span
20
+ class="icon"
21
+ :style="{ background: item.color }"
22
+ />
23
+ <span>{{ item.text }}</span>
24
+ </span>
25
+ </el-radio>
26
+ </el-radio-group>
27
+ </div>
28
+ </template>
29
+
30
+ <script setup lang="ts">
31
+ import { IFilterColorRadio } from '../../types';
32
+
33
+ defineProps<{
34
+ config: IFilterColorRadio
35
+ tempFilteredValue: Record<string, string>
36
+ }>()
37
+
38
+ const emit = defineEmits<{
39
+ (e: 'update:tempFilteredValue', key: string, value: string): void
40
+ }>()
41
+ </script>
42
+
43
+ <style scoped lang="less">
44
+ .color-option {
45
+ display: flex;
46
+ align-items: center;
47
+
48
+ .icon {
49
+ border-radius: 50%;
50
+ width: 1em;
51
+ height: 1em;
52
+ margin-right: 0.3em;
53
+ border: 1px solid #ccc;
54
+ }
55
+ }
56
+ </style>
@@ -0,0 +1,91 @@
1
+ <!-- 日期范围选择(分开的两个日期选择器) -->
2
+ <template>
3
+ <div class="editable-table-sort-filter__sort">
4
+ <div class="editable-table-sort-filter__search-title">
5
+ {{ config.label || '筛选' }}
6
+ </div>
7
+ <div class="editable-table-sort-filter__date-picker-content">
8
+ <el-date-picker
9
+ v-bind="datePickerCommonProps"
10
+ placeholder="开始日期"
11
+ :value="tempFilteredValue[config.prop[0]]"
12
+ :picker-options="startDateDisabledOptions"
13
+ @input="handleStartDateChange"
14
+ />
15
+ <el-date-picker
16
+ v-bind="datePickerCommonProps"
17
+ placeholder="结束日期"
18
+ :value="tempFilteredValue[config.prop[1]]"
19
+ :picker-options="endDateDisabledOptions"
20
+ @input="handleEndDateChange"
21
+ />
22
+ </div>
23
+ </div>
24
+ </template>
25
+
26
+ <script setup lang="ts">
27
+ import { computed } from 'vue';
28
+ import { IFilterDoubleDatePicker } from '../../types';
29
+ import dayjs from 'dayjs';
30
+ import type { DatePickerOptions } from 'element-ui/types/date-picker';
31
+
32
+ interface IFilterDoubleDatePickerProps {
33
+ /** 日期选择器配置 */
34
+ config: IFilterDoubleDatePicker;
35
+ /** 临时筛选值 */
36
+ tempFilteredValue: Record<string, string>;
37
+ }
38
+
39
+ const props = defineProps<IFilterDoubleDatePickerProps>();
40
+
41
+ const emit = defineEmits<{
42
+ (e: 'update:tempFilteredValue', key: string, value: string): void;
43
+ }>();
44
+
45
+ /** 日期选择器通用配置 */
46
+ const datePickerCommonProps = {
47
+ valueFormat: 'yyyy-MM-dd',
48
+ format: 'yyyy-MM-dd',
49
+ type: 'date',
50
+ size: 'small',
51
+ editable: false,
52
+ } as const;
53
+
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
+ /** 处理开始日期变更 */
83
+ const handleStartDateChange = (val: string | null) => {
84
+ emit('update:tempFilteredValue', props.config.prop[0], val || '');
85
+ };
86
+
87
+ /** 处理结束日期变更 */
88
+ const handleEndDateChange = (val: string | null) => {
89
+ emit('update:tempFilteredValue', props.config.prop[1], val || '');
90
+ };
91
+ </script>
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <div class="editable-table-sort-filter__search">
3
+ <div class="editable-table-sort-filter__search-title">
4
+ {{ config.label || '搜索' }}
5
+ </div>
6
+ <el-input
7
+ class="editable-table-sort-filter__search-input"
8
+ :placeholder="config.placeholder || '请输入内容'"
9
+ :value="tempFilteredValue[config.prop]"
10
+ @input="val => emit('update:tempFilteredValue', config.prop, val)"
11
+ />
12
+ </div>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import { IFilterInput } from '../../types';
17
+
18
+ defineProps<{
19
+ config: IFilterInput
20
+ tempFilteredValue: Record<string, string>
21
+ }>()
22
+
23
+ const emit = defineEmits<{
24
+ (e: 'update:tempFilteredValue', key: string, value: string): void
25
+ }>()
26
+ </script>
@@ -0,0 +1,131 @@
1
+ import dayjs from 'dayjs';
2
+
3
+ // 月份配置 - 月份对应的天数
4
+ const monthConfig = [
5
+ { month: 1, day: 31 },
6
+ { month: 2, day: 29 },
7
+ { month: 3, day: 31 },
8
+ { month: 4, day: 30 },
9
+ { month: 5, day: 31 },
10
+ { month: 6, day: 30 },
11
+ { month: 7, day: 31 },
12
+ { month: 8, day: 31 },
13
+ { month: 9, day: 30 },
14
+ { month: 10, day: 31 },
15
+ { month: 11, day: 30 },
16
+ { month: 12, day: 31 },
17
+ ];
18
+
19
+ /**
20
+ * 组装极联选择组件默认选项
21
+ * example: [
22
+ * {
23
+ * value: '1',
24
+ * label: '1月',
25
+ * children: [
26
+ * { value: '1', label: '1日' },
27
+ * ... // 1月份的每一天
28
+ * ]
29
+ * },
30
+ * ... // 其他月份的选项
31
+ * ]
32
+ */
33
+ export function getMonthDayPickerDefaultOptions() {
34
+ return monthConfig.map(
35
+ (item) => ({
36
+ value: item.month.toString(),
37
+ label: `${ item.month }月`,
38
+ children: Array.from(
39
+ { length: item.day },
40
+ (_, i) => (
41
+ { value: `${ i + 1 }`, label: `${ i + 1 }日` }
42
+ )
43
+ )
44
+ })
45
+ );
46
+ }
47
+
48
+ /**
49
+ * 组装日期范围级联选择组件禁用选项
50
+ * @param date 日期 - 级联选择组件值
51
+ * @param isStartDate 区分传递的date是 开始日期 / 结束日期
52
+ * @param digits 时间范围 n个月
53
+ */
54
+ export function disableOutOfRangeOptions({
55
+ date = [],
56
+ isStartDate = false,
57
+ digits = 3
58
+ }: { date: string[], isStartDate?: boolean, digits: number }) {
59
+ // 写死一个闰年年份 仅用于比较时间
60
+ // 如果非闰年 dayjs('year-02-29') 会输出 year-3-1 导致日期范围选择器出错
61
+ const year = 2024;
62
+ const baseMonthDay = 30;
63
+ const options = getMonthDayPickerDefaultOptions();
64
+
65
+ return options.map(
66
+ (month) => {
67
+ const children = month.children.map(
68
+ (day) => {
69
+ // 组装日期 - 当前这个选项对应的完整日期
70
+ const currentDate = dayjs([year, month.value, day.value].join('-'));
71
+
72
+ // 是否需要禁用当前日期
73
+ let disabled = false;
74
+
75
+ // 如果有传入日期,则判断是否在禁用日期范围内
76
+ if (date.length > 0) {
77
+ // 组装日期 - 传入日期对应的完整日期
78
+ const baseDate = dayjs([year, ...date].join('-'));
79
+
80
+ // 如果是开始时间,则结束时间范围为 baseDate + digits
81
+ // 如果是结束时间,则开始时间范围为 baseDate - digits
82
+ if (isStartDate) {
83
+ const maxDate = baseDate.add(digits * baseMonthDay - 1, 'day');
84
+ // 推算时间范围超过12月31号,结束时间可选年初时间
85
+ if (maxDate.year() > year) {
86
+ disabled = currentDate.isAfter(maxDate.subtract(366, 'day'), 'day') && currentDate.isBefore(baseDate, 'day');
87
+ } else {
88
+ disabled = currentDate.isAfter(maxDate, 'day') || currentDate.isBefore(baseDate, 'day');
89
+ }
90
+ } else {
91
+ const minDate = baseDate.subtract(digits * baseMonthDay - 1, 'day');
92
+ // 推算时间范围在1月1号前,开始时间可选年末时间
93
+ if (minDate.year() < year) {
94
+ disabled = currentDate.isBefore(minDate.add(366, 'day'), 'day') && currentDate.isAfter(baseDate, 'day');
95
+ } else {
96
+ disabled = currentDate.isBefore(minDate, 'day') || currentDate.isAfter(baseDate, 'day');
97
+ }
98
+ }
99
+ }
100
+
101
+ return {
102
+ ...day,
103
+ disabled
104
+ };
105
+ }
106
+ );
107
+
108
+ // 如果当前月份每天都是禁用日期,则整个月份禁用
109
+ const disabled = children.every((day) => day.disabled);
110
+
111
+ return {
112
+ ...month,
113
+ disabled,
114
+ children
115
+ };
116
+ }
117
+ );
118
+ }
119
+
120
+ /**
121
+ * 格式化月日级联选择组件值 MM-dd
122
+ * @param date 日期 - 级联选择组件值
123
+ * @returns 格式化后的日期字符串
124
+ */
125
+ export function formatMonthDayPickerValue(date: string[]) {
126
+ return date
127
+ .map(
128
+ (str) => str.padStart(2, '0')
129
+ )
130
+ .join('-');
131
+ }
@@ -0,0 +1,115 @@
1
+ <!-- 月/日选择器 -->
2
+ <template>
3
+ <div class="editable-table-sort-filter__sort">
4
+ <div class="editable-table-sort-filter__search-title">
5
+ {{ config.label || '筛选' }}
6
+ </div>
7
+ <div class="editable-table-sort-filter__date-picker-content">
8
+ <el-cascader
9
+ clearable
10
+ :value="startDate"
11
+ separator=""
12
+ size="small"
13
+ placeholder="开始日期"
14
+ popper-class="month-day-picker"
15
+ :options="startDateOptions"
16
+ @change="value => handleDateChange(config.prop[0], value)"
17
+ />
18
+ <el-cascader
19
+ clearable
20
+ :value="endDate"
21
+ separator=""
22
+ size="small"
23
+ placeholder="结束日期"
24
+ popper-class="month-day-picker"
25
+ :options="endDateOptions"
26
+ @change="value => handleDateChange(config.prop[1], value)"
27
+ />
28
+ </div>
29
+ </div>
30
+ </template>
31
+ <script setup lang="ts">
32
+ import {
33
+ disableOutOfRangeOptions, formatMonthDayPickerValue,
34
+ getMonthDayPickerDefaultOptions
35
+ } from './BizMonthDayPicker.helper';
36
+ import { computed, toRefs } from 'vue';
37
+ import { IFilterMonthDayPicker } from '../../types';
38
+
39
+ const props = defineProps<{
40
+ config: IFilterMonthDayPicker
41
+ tempFilteredValue: Record<string, string>
42
+ }>()
43
+ const { config, tempFilteredValue } = toRefs(props)
44
+
45
+ const emit = defineEmits<{
46
+ (e: 'update:tempFilteredValue', key: string, value: string): void
47
+ }>()
48
+
49
+ const formatDate = (date: string) => {
50
+ if (date) {
51
+ return date
52
+ .split('-')
53
+ // 01 -> 1
54
+ .map(
55
+ (v) => String(Number(v))
56
+ )
57
+ }
58
+
59
+ return []
60
+ }
61
+
62
+ const startDate = computed(() => {
63
+ const { prop } = config.value;
64
+ return formatDate(tempFilteredValue.value[prop[0]]);
65
+ })
66
+
67
+ const endDate = computed(() => {
68
+ const { prop } = config.value;
69
+ return formatDate(tempFilteredValue.value[prop[1]]);
70
+ })
71
+
72
+ // 开始日期范围限制
73
+ const startDateOptions = computed(
74
+ () => {
75
+ if (endDate.value.length === 0) {
76
+ return getMonthDayPickerDefaultOptions();
77
+ }
78
+
79
+ return disableOutOfRangeOptions({
80
+ date: endDate.value,
81
+ isStartDate: false,
82
+ digits: config.value.limit
83
+ });
84
+ }
85
+ );
86
+
87
+ // 结束日期范围限制
88
+ const endDateOptions = computed(
89
+ () => {
90
+ if (startDate.value.length === 0) {
91
+ return getMonthDayPickerDefaultOptions();
92
+ }
93
+
94
+ return disableOutOfRangeOptions({
95
+ date: startDate.value,
96
+ isStartDate: true,
97
+ digits: config.value.limit
98
+ });
99
+ }
100
+ );
101
+
102
+ /**
103
+ * 选择时间更改统一回调
104
+ */
105
+ const handleDateChange = (key: string, value: string[]) => {
106
+ const currentValue = value.length === 0
107
+ ? ''
108
+ : formatMonthDayPickerValue(value)
109
+ emit('update:tempFilteredValue', key, currentValue);
110
+ }
111
+ </script>
112
+
113
+ <style scoped lang="less">
114
+
115
+ </style>