Skip to content

Commit

Permalink
fix(DatePicker): 修复输入框有值时面板切换失效问题 (#1293)
Browse files Browse the repository at this point in the history
* fix: 修复有值时面板切换失效问题

* fix: 修复有值时面板切换失效问题
  • Loading branch information
honkinglin authored Aug 15, 2022
1 parent 790d4a0 commit 5d95280
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
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

0 comments on commit 5d95280

Please sign in to comment.