117159322aca8db58a28b8ff1e714796d763fe6b34ed188837ca1a572de7a1673176ed72b2f3b2a81be919b178ba739bad5b147b5b1a6bf18b62ab737d4622 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var utils = require('../utils.js');
  5. var constants = require('../../../time-picker/src/constants.js');
  6. var index = require('../../../../hooks/use-locale/index.js');
  7. const usePanelDateRange = (props, emit, leftDate, rightDate) => {
  8. const leftCurrentView = vue.ref("date");
  9. const leftCurrentViewRef = vue.ref();
  10. const rightCurrentView = vue.ref("date");
  11. const rightCurrentViewRef = vue.ref();
  12. const pickerBase = vue.inject(constants.PICKER_BASE_INJECTION_KEY);
  13. const { disabledDate } = pickerBase.props;
  14. const { t, lang } = index.useLocale();
  15. const leftYear = vue.computed(() => {
  16. return leftDate.value.year();
  17. });
  18. const leftMonth = vue.computed(() => {
  19. return leftDate.value.month();
  20. });
  21. const rightYear = vue.computed(() => {
  22. return rightDate.value.year();
  23. });
  24. const rightMonth = vue.computed(() => {
  25. return rightDate.value.month();
  26. });
  27. function computedYearLabel(currentView, yearValue) {
  28. const yearTranslation = t("el.datepicker.year");
  29. if (currentView.value === "year") {
  30. const startYear = Math.floor(yearValue.value / 10) * 10;
  31. return yearTranslation ? `${startYear} ${yearTranslation} - ${startYear + 9} ${yearTranslation}` : `${startYear} - ${startYear + 9}`;
  32. }
  33. return `${yearValue.value} ${yearTranslation}`;
  34. }
  35. function focusPicker(currentViewRef) {
  36. currentViewRef == null ? void 0 : currentViewRef.focus();
  37. }
  38. async function showPicker(pickerType, view) {
  39. if (props.disabled)
  40. return;
  41. const currentView = pickerType === "left" ? leftCurrentView : rightCurrentView;
  42. const currentViewRef = pickerType === "left" ? leftCurrentViewRef : rightCurrentViewRef;
  43. currentView.value = view;
  44. await vue.nextTick();
  45. focusPicker(currentViewRef.value);
  46. }
  47. async function handlePick(mode, pickerType, value) {
  48. if (props.disabled)
  49. return;
  50. const isLeftPicker = pickerType === "left";
  51. const startDate = isLeftPicker ? leftDate : rightDate;
  52. const endDate = isLeftPicker ? rightDate : leftDate;
  53. const currentView = isLeftPicker ? leftCurrentView : rightCurrentView;
  54. const currentViewRef = isLeftPicker ? leftCurrentViewRef : rightCurrentViewRef;
  55. if (mode === "year") {
  56. const data = startDate.value.year(value);
  57. startDate.value = utils.getValidDateOfYear(data, lang.value, disabledDate);
  58. }
  59. if (mode === "month") {
  60. startDate.value = utils.getValidDateOfMonth(startDate.value, startDate.value.year(), value, lang.value, disabledDate);
  61. }
  62. if (!props.unlinkPanels) {
  63. endDate.value = pickerType === "left" ? startDate.value.add(1, "month") : startDate.value.subtract(1, "month");
  64. }
  65. currentView.value = mode === "year" ? "month" : "date";
  66. await vue.nextTick();
  67. focusPicker(currentViewRef.value);
  68. handlePanelChange(mode);
  69. }
  70. function handlePanelChange(mode) {
  71. emit("panel-change", [leftDate.value.toDate(), rightDate.value.toDate()], mode);
  72. }
  73. function adjustDateByView(currentView, date, forward) {
  74. const action = forward ? "add" : "subtract";
  75. return currentView === "year" ? date[action](10, "year") : date[action](1, "year");
  76. }
  77. return {
  78. leftCurrentView,
  79. rightCurrentView,
  80. leftCurrentViewRef,
  81. rightCurrentViewRef,
  82. leftYear,
  83. rightYear,
  84. leftMonth,
  85. rightMonth,
  86. leftYearLabel: vue.computed(() => computedYearLabel(leftCurrentView, leftYear)),
  87. rightYearLabel: vue.computed(() => computedYearLabel(rightCurrentView, rightYear)),
  88. showLeftPicker: (view) => showPicker("left", view),
  89. showRightPicker: (view) => showPicker("right", view),
  90. handleLeftYearPick: (year) => handlePick("year", "left", year),
  91. handleRightYearPick: (year) => handlePick("year", "right", year),
  92. handleLeftMonthPick: (month) => handlePick("month", "left", month),
  93. handleRightMonthPick: (month) => handlePick("month", "right", month),
  94. handlePanelChange,
  95. adjustDateByView
  96. };
  97. };
  98. exports.usePanelDateRange = usePanelDateRange;
  99. //# sourceMappingURL=use-panel-date-range.js.map