@varlet/ui 3.15.1 → 3.15.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.
@@ -3,5 +3,5 @@ import '../../icon/icon.css'
3
3
  import '../../ripple/ripple.css'
4
4
  import '../../popup/popup.css'
5
5
  import '../actionSheet.css'
6
- import '../ActionItemSfc.css'
7
6
  import '../ActionSheetSfc.css'
7
+ import '../ActionItemSfc.css'
@@ -76,9 +76,9 @@ function __render__(_ctx, _cache) {
76
76
  onClick: _cache[0] || (_cache[0] = ($event) => _ctx.clickEl("year"))
77
77
  },
78
78
  [
79
- _renderSlot(_ctx.$slots, "year", { year: _ctx.chooseYear }, () => [
79
+ _renderSlot(_ctx.$slots, "year", { year: _ctx.displayYear }, () => [
80
80
  _createTextVNode(
81
- _toDisplayString(_ctx.chooseYear),
81
+ _toDisplayString(_ctx.displayYear),
82
82
  1
83
83
  /* TEXT */
84
84
  )
@@ -337,6 +337,7 @@ const __sfc__ = defineComponent({
337
337
  previewMonth: previewMonth.value,
338
338
  previewYear: previewYear.value
339
339
  }));
340
+ const displayYear = computed(() => previewYear.value || chooseYear.value || "");
340
341
  const getYearTitle = computed(() => {
341
342
  var _a;
342
343
  const { multiple, range } = props2;
@@ -416,7 +417,7 @@ const __sfc__ = defineComponent({
416
417
  watch(
417
418
  () => props2.modelValue,
418
419
  (value) => {
419
- if (!checkValue() || invalidFormatDate(value)) {
420
+ if (!checkValue()) {
420
421
  return;
421
422
  }
422
423
  if (props2.range) {
@@ -431,7 +432,7 @@ const __sfc__ = defineComponent({
431
432
  }
432
433
  multipleInit(value, props2.type);
433
434
  } else {
434
- dateInit(value);
435
+ dateInit(getSingleDate(value));
435
436
  }
436
437
  },
437
438
  { immediate: true }
@@ -626,28 +627,47 @@ const __sfc__ = defineComponent({
626
627
  }
627
628
  return false;
628
629
  }
630
+ function getFallbackDate() {
631
+ if (props2.fallbackViewDate) {
632
+ const formatDate = dayjs(props2.fallbackViewDate).format("YYYY-MM-D");
633
+ if (formatDate !== "Invalid Date") {
634
+ return props2.fallbackViewDate;
635
+ }
636
+ }
637
+ return dayjs().format("YYYY-MM-D");
638
+ }
639
+ function getSingleDate(value) {
640
+ if (value && !invalidFormatDate(dayjs(value).format("YYYY-MM-D"))) {
641
+ return value;
642
+ }
643
+ return getFallbackDate();
644
+ }
645
+ function getFirstValidDate(value, type) {
646
+ const formatType = type === "year" ? "YYYY" : type === "month" ? "YYYY-MM" : "YYYY-MM-D";
647
+ return value.find((choose) => !invalidFormatDate(dayjs(choose).format(formatType)));
648
+ }
629
649
  function rangeInit(value, type) {
650
+ var _a;
630
651
  const rangeDate = type === "year" ? chooseRangeYear : type === "month" ? chooseRangeMonth : chooseRangeDay;
631
652
  const formatType = type === "year" ? "YYYY" : type === "month" ? "YYYY-MM" : "YYYY-MM-D";
632
- const formatDateList = value.map((choose) => dayjs(choose).format(formatType)).slice(0, 2);
633
- const isValid = rangeDate.value.some((date) => invalidFormatDate(date));
634
- if (isValid) {
635
- return;
636
- }
653
+ const formatDateList = value.map((choose) => dayjs(choose).format(formatType)).filter((date) => !invalidFormatDate(date)).slice(0, 2);
637
654
  rangeDate.value = formatDateList;
638
655
  const isChangeOrder = dayjs(rangeDate.value[0]).isAfter(rangeDate.value[1]);
639
656
  if (rangeDate.value.length === 2 && isChangeOrder) {
640
657
  rangeDate.value = [rangeDate.value[1], rangeDate.value[0]];
641
658
  }
659
+ previewInit((_a = getFirstValidDate(value, type)) != null ? _a : getFallbackDate());
642
660
  }
643
661
  function multipleInit(value, type) {
662
+ var _a;
644
663
  const rangeDate = type === "year" ? chooseYears : type === "month" ? chooseMonths : chooseDays;
645
664
  const formatType = type === "year" ? "YYYY" : type === "month" ? "YYYY-MM" : "YYYY-MM-D";
646
665
  const formatDateList = Array.from(new Set(value.map((choose) => dayjs(choose).format(formatType))));
647
666
  rangeDate.value = formatDateList.filter((date) => date !== "Invalid Date");
667
+ previewInit((_a = getFirstValidDate(value, type)) != null ? _a : getFallbackDate());
648
668
  }
649
669
  function dateInit(value) {
650
- const handleValue = value ? dayjs(value) : dayjs();
670
+ const handleValue = value ? dayjs(value) : dayjs(getFallbackDate());
651
671
  const formatDate = handleValue.format("YYYY-MM-D");
652
672
  if (invalidFormatDate(formatDate)) {
653
673
  return;
@@ -657,6 +677,16 @@ const __sfc__ = defineComponent({
657
677
  chooseMonth.value = monthDes2;
658
678
  chooseYear.value = yearValue;
659
679
  chooseDay.value = dayValue;
680
+ previewInit(formatDate);
681
+ }
682
+ function previewInit(value) {
683
+ const handleValue = value ? dayjs(value) : dayjs(getFallbackDate());
684
+ const formatDate = handleValue.format("YYYY-MM-D");
685
+ if (invalidFormatDate(formatDate)) {
686
+ return;
687
+ }
688
+ const [yearValue, monthValue] = formatDate.split("-");
689
+ const monthDes2 = MONTH_LIST.find((month) => month === monthValue);
660
690
  previewMonth.value = monthDes2;
661
691
  previewYear.value = yearValue;
662
692
  }
@@ -676,6 +706,7 @@ const __sfc__ = defineComponent({
676
706
  chooseYear,
677
707
  chooseDay,
678
708
  previewYear,
709
+ displayYear,
679
710
  isYearPanel,
680
711
  isMonthPanel,
681
712
  getMonthTitle,
@@ -8,6 +8,7 @@ const props = {
8
8
  default: "date"
9
9
  },
10
10
  hint: String,
11
+ fallbackViewDate: String,
11
12
  allowedDates: Function,
12
13
  color: String,
13
14
  titleColor: String,
@@ -283,7 +283,7 @@ import './tooltip/style/index.mjs'
283
283
  import './uploader/style/index.mjs'
284
284
  import './watermark/style/index.mjs'
285
285
 
286
- const version = '3.15.1'
286
+ const version = '3.15.2'
287
287
 
288
288
  function install(app) {
289
289
  ActionSheet.install && app.use(ActionSheet)
package/es/index.mjs CHANGED
@@ -188,7 +188,7 @@ export * from './tooltip/index.mjs'
188
188
  export * from './uploader/index.mjs'
189
189
  export * from './watermark/index.mjs'
190
190
 
191
- const version = '3.15.1'
191
+ const version = '3.15.2'
192
192
 
193
193
  function install(app) {
194
194
  ActionSheet.install && app.use(ActionSheet)