time-select2.js 6.0 KB

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