Skip to content

Commit

Permalink
feat: support multiple select
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Dec 25, 2024
1 parent 55cc765 commit f7aabfd
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default defineComponent({
}

function processDate(date: Date) {
if (!value.value) return [];
const isSameDate = (value.value as DateMultipleValue).some((val) => isSame(dayjs(val).toDate(), date));
let currentDate: DateMultipleValue;

Expand Down Expand Up @@ -311,6 +312,7 @@ export default defineComponent({
format: formatRef.value.format,
mode: props.mode,
presets: props.presets,
multiple: props.multiple,
time: props.multiple ? false : time.value,
disableDate: props.disableDate,
firstDayOfWeek: props.firstDayOfWeek,
Expand Down
2 changes: 1 addition & 1 deletion src/date-picker/_example/multiple.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<t-space direction="vertical">
<t-date-picker multiple />
<t-date-picker multiple :default-value="[]" />
<t-date-picker mode="week" multiple />
<t-date-picker mode="year" multiple />
</t-space>
Expand Down
10 changes: 6 additions & 4 deletions src/date-picker/hooks/useSingleValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function useSingleValue(props: TdDatePickerProps) {
getDefaultFormat({
mode: props.mode,
format: props.format,
enableTimePicker: props.enableTimePicker,
enableTimePicker: props.multiple ? false : props.enableTimePicker,
}),
);

Expand All @@ -28,9 +28,11 @@ export default function useSingleValue(props: TdDatePickerProps) {
}

const time = ref(formatTime(value.value, formatRef.value.format, formatRef.value.timeFormat, props.defaultTime));
const month = ref<number>(parseToDayjs(value.value, formatRef.value.format).month());
const year = ref<number>(parseToDayjs(value.value, formatRef.value.format).year());
const cacheValue = ref(formatDate(value.value, { format: formatRef.value.format })); // 缓存选中值,panel 点击时更改
const month = ref<number>(
parseToDayjs(props.multiple ? value.value[0] : value.value, formatRef.value.format).month(),
);
const year = ref<number>(parseToDayjs(props.multiple ? value.value[0] : value.value, formatRef.value.format).year());
const cacheValue = ref(formatDate(props.multiple ? value.value[0] : value.value, { format: formatRef.value.format })); // 缓存选中值,panel 点击时更改

// 输入框响应 value 变化
watchEffect(() => {
Expand Down
11 changes: 8 additions & 3 deletions src/date-picker/panel/SinglePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { defineComponent, PropType, computed } from 'vue';
import { useConfig, usePrefixClass } from '../../hooks/useConfig';
import TPanelContent from './PanelContent';
import TExtraContent from './ExtraContent';
import { TdDatePickerProps } from '../type';
import { getDefaultFormat, parseToDayjs } from '../../_common/js/date-picker/format';
import useTableData from '../hooks/useTableData';
import useDisableDate from '../hooks/useDisableDate';

import { TdDatePickerProps } from '../type';

export default defineComponent({
name: 'TSinglePanel',
props: {
Expand All @@ -29,6 +30,7 @@ export default defineComponent({
month: Number,
time: String,
popupVisible: Boolean,
multiple: Boolean,
needConfirm: {
type: Boolean,
default: true,
Expand Down Expand Up @@ -70,8 +72,11 @@ export default defineComponent({
year: props.year,
month: props.month,
mode: props.mode,
start: props.value ? parseToDayjs(props.value, format.value).toDate() : undefined,
start: props.value
? parseToDayjs(props.multiple ? (props.value as any)?.[0] : props.value, format.value).toDate()
: undefined,
firstDayOfWeek: props.firstDayOfWeek || globalConfig.value.firstDayOfWeek,
multiple: props.multiple,
...disableDateOptions.value,
}),
);
Expand All @@ -85,7 +90,7 @@ export default defineComponent({
firstDayOfWeek: props.firstDayOfWeek || globalConfig.value.firstDayOfWeek,
tableData: tableData.value,
popupVisible: props.popupVisible,

multiple: props.multiple,
enableTimePicker: props.enableTimePicker,
timePickerProps: props.timePickerProps,
time: props.time,
Expand Down
1 change: 0 additions & 1 deletion src/date-picker/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ export interface TdDatePickerPanelProps
| 'value'
| 'defaultValue'
| 'disableDate'
| 'disableTime'
| 'enableTimePicker'
| 'firstDayOfWeek'
| 'format'
Expand Down
2 changes: 1 addition & 1 deletion src/tag-input/tag-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default defineComponent({
const onClick: TdInputProps['onClick'] = (ctx) => {
if (isDisabled.value) return;
isFocused.value = true;
tagInputRef.value.focus();
tagInputRef.value?.focus();
props.onClick?.(ctx);
};

Expand Down

0 comments on commit f7aabfd

Please sign in to comment.