Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DatePicker): 修复输入框有值时面板切换失效问题 #1293

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent, watchEffect, computed } from '@vue/composition-api';
import { defineComponent, watch, computed } from '@vue/composition-api';
import dayjs from 'dayjs';
import { CalendarIcon } from 'tdesign-icons-vue';
import { usePrefixClass } from '../hooks/useConfig';
Expand Down Expand Up @@ -42,9 +42,9 @@ export default defineComponent({
enableTimePicker: props.enableTimePicker,
}));

watchEffect(() => {
watch(popupVisible, (visible) => {
// 面板展开重置数据
if (popupVisible.value) {
if (visible) {
year.value = parseToDayjs(value.value || new Date(), formatRef.value.format).year();
month.value = parseToDayjs(value.value || new Date(), formatRef.value.format).month();
time.value = formatTime(value.value || new Date(), formatRef.value.timeFormat);
Expand Down
10 changes: 5 additions & 5 deletions src/date-picker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
defineComponent, watchEffect, computed, ref,
defineComponent, watch, computed, ref,
} from '@vue/composition-api';
import dayjs from 'dayjs';
import { CalendarIcon } from 'tdesign-icons-vue';
Expand Down Expand Up @@ -49,9 +49,9 @@ export default defineComponent({
// 记录面板是否选中过
const isSelected = ref(false);

watchEffect(() => {
watch(popupVisible, (visible) => {
// 面板展开重置数据
if (popupVisible.value) {
if (visible) {
isSelected.value = false;
isFirstValueSelected.value = false;
cacheValue.value = formatDate(value.value || [], {
Expand Down Expand Up @@ -113,8 +113,8 @@ export default defineComponent({
// 不开启时间选择时 结束时间默认重置为 23:59:59
if (activeIndex.value && !props.enableTimePicker) date.setHours(23, 59, 59);

props.onPick?.(date, { e, partial });
emit('pick', date, { e, partial });
props.onPick?.(date, { e, partial: activeIndex.value ? 'end' : 'start' });
emit('pick', date, { e, partial: activeIndex.value ? 'end' : 'start' });

isHoverCell.value = false;
isSelected.value = true;
Expand Down
4 changes: 2 additions & 2 deletions src/date-picker/panel/RangePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default defineComponent({
key="startPanel"
{...{
props: {
partial: this.activeIndex ? 'end' : 'start',
partial: 'start',
year: this.year[0],
month: this.month[0],
time: this.time[0],
Expand All @@ -186,7 +186,7 @@ export default defineComponent({
key="endPanel"
{...{
props: {
partial: this.activeIndex ? 'end' : 'start',
partial: 'end',
year: this.year[1],
month: this.month[1],
time: this.time[1],
Expand Down