9ca2f70b528be41561b70061b3712af731a5f6adb8851774af8ac53a964458ea14fe8b0577dad28f573ef638aa486eaba6322a8459006da9c102e1bd5a8671 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { defineComponent, ref, computed, openBlock, createBlock, unref, withCtx, normalizeClass, resolveDynamicComponent, createCommentVNode, createElementBlock, Fragment, renderList } from 'vue';
  2. import dayjs from 'dayjs';
  3. import customParseFormat from 'dayjs/plugin/customParseFormat.js';
  4. import { ElSelect } from '../../select/index.mjs';
  5. import { ElIcon } from '../../icon/index.mjs';
  6. import { timeSelectProps } from './time-select.mjs';
  7. import { parseTime, formatTime, compareTime, nextTime } from './utils.mjs';
  8. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  9. import { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '../../../constants/event.mjs';
  10. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  11. import { useFormDisabled } from '../../form/src/hooks/use-form-common-props.mjs';
  12. import { useLocale } from '../../../hooks/use-locale/index.mjs';
  13. const __default__ = defineComponent({
  14. name: "ElTimeSelect"
  15. });
  16. const _sfc_main = /* @__PURE__ */ defineComponent({
  17. ...__default__,
  18. props: timeSelectProps,
  19. emits: [CHANGE_EVENT, "blur", "focus", "clear", UPDATE_MODEL_EVENT],
  20. setup(__props, { expose }) {
  21. const props = __props;
  22. dayjs.extend(customParseFormat);
  23. const { Option: ElOption } = ElSelect;
  24. const nsInput = useNamespace("input");
  25. const select = ref();
  26. const _disabled = useFormDisabled();
  27. const { lang } = useLocale();
  28. const value = computed(() => props.modelValue);
  29. const start = computed(() => {
  30. const time = parseTime(props.start);
  31. return time ? formatTime(time) : null;
  32. });
  33. const end = computed(() => {
  34. const time = parseTime(props.end);
  35. return time ? formatTime(time) : null;
  36. });
  37. const step = computed(() => {
  38. const time = parseTime(props.step);
  39. return time ? formatTime(time) : null;
  40. });
  41. const minTime = computed(() => {
  42. const time = parseTime(props.minTime || "");
  43. return time ? formatTime(time) : null;
  44. });
  45. const maxTime = computed(() => {
  46. const time = parseTime(props.maxTime || "");
  47. return time ? formatTime(time) : null;
  48. });
  49. const items = computed(() => {
  50. var _a;
  51. const result = [];
  52. const push = (formattedValue, rawValue) => {
  53. result.push({
  54. value: formattedValue,
  55. disabled: compareTime(rawValue, minTime.value || "-1:-1") <= 0 || compareTime(rawValue, maxTime.value || "100:100") >= 0
  56. });
  57. };
  58. if (props.start && props.end && props.step) {
  59. let current = start.value;
  60. let currentTime;
  61. while (current && end.value && compareTime(current, end.value) <= 0) {
  62. currentTime = dayjs(current, "HH:mm").locale(lang.value).format(props.format);
  63. push(currentTime, current);
  64. current = nextTime(current, step.value);
  65. }
  66. if (props.includeEndTime && end.value && ((_a = result[result.length - 1]) == null ? void 0 : _a.value) !== end.value) {
  67. const formattedValue = dayjs(end.value, "HH:mm").locale(lang.value).format(props.format);
  68. push(formattedValue, end.value);
  69. }
  70. }
  71. return result;
  72. });
  73. const blur = () => {
  74. var _a, _b;
  75. (_b = (_a = select.value) == null ? void 0 : _a.blur) == null ? void 0 : _b.call(_a);
  76. };
  77. const focus = () => {
  78. var _a, _b;
  79. (_b = (_a = select.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a);
  80. };
  81. expose({
  82. blur,
  83. focus
  84. });
  85. return (_ctx, _cache) => {
  86. return openBlock(), createBlock(unref(ElSelect), {
  87. ref_key: "select",
  88. ref: select,
  89. "model-value": unref(value),
  90. disabled: unref(_disabled),
  91. clearable: _ctx.clearable,
  92. "clear-icon": _ctx.clearIcon,
  93. size: _ctx.size,
  94. effect: _ctx.effect,
  95. placeholder: _ctx.placeholder,
  96. "default-first-option": "",
  97. filterable: _ctx.editable,
  98. "empty-values": _ctx.emptyValues,
  99. "value-on-clear": _ctx.valueOnClear,
  100. "onUpdate:modelValue": (event) => _ctx.$emit(unref(UPDATE_MODEL_EVENT), event),
  101. onChange: (event) => _ctx.$emit(unref(CHANGE_EVENT), event),
  102. onBlur: (event) => _ctx.$emit("blur", event),
  103. onFocus: (event) => _ctx.$emit("focus", event),
  104. onClear: () => _ctx.$emit("clear")
  105. }, {
  106. prefix: withCtx(() => [
  107. _ctx.prefixIcon ? (openBlock(), createBlock(unref(ElIcon), {
  108. key: 0,
  109. class: normalizeClass(unref(nsInput).e("prefix-icon"))
  110. }, {
  111. default: withCtx(() => [
  112. (openBlock(), createBlock(resolveDynamicComponent(_ctx.prefixIcon)))
  113. ]),
  114. _: 1
  115. }, 8, ["class"])) : createCommentVNode("v-if", true)
  116. ]),
  117. default: withCtx(() => [
  118. (openBlock(true), createElementBlock(Fragment, null, renderList(unref(items), (item) => {
  119. return openBlock(), createBlock(unref(ElOption), {
  120. key: item.value,
  121. label: item.value,
  122. value: item.value,
  123. disabled: item.disabled
  124. }, null, 8, ["label", "value", "disabled"]);
  125. }), 128))
  126. ]),
  127. _: 1
  128. }, 8, ["model-value", "disabled", "clearable", "clear-icon", "size", "effect", "placeholder", "filterable", "empty-values", "value-on-clear", "onUpdate:modelValue", "onChange", "onBlur", "onFocus", "onClear"]);
  129. };
  130. }
  131. });
  132. var TimeSelect = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "time-select.vue"]]);
  133. export { TimeSelect as default };
  134. //# sourceMappingURL=time-select2.mjs.map