UNPKG

hongluan-ui

Version:
1 lines 5.82 kB
{"version":3,"file":"time-select2.mjs","sources":["../../../../../../packages/components/time-select/src/time-select.vue"],"sourcesContent":["<template>\n <hl-select\n ref=\"select\"\n :model-value=\"value\"\n :disabled=\"timeDisabled\"\n :clearable=\"clearable\"\n :size=\"timeSize\"\n :effect=\"effect\"\n :fill=\"timeFill\"\n :placeholder=\"placeholder\"\n default-first-option\n :filterable=\"editable\"\n :teleported=\"teleported\"\n :empty-values=\"emptyValues\"\n :value-on-clear=\"valueOnClear\"\n @update:model-value=\"(event) => $emit('update:modelValue', event)\"\n @change=\"(event) => $emit('change', event)\"\n @blur=\"(event) => $emit('blur', event)\"\n @focus=\"(event) => $emit('focus', event)\"\n @clear=\"() => $emit('clear')\"\n >\n <hl-option\n v-for=\"item in items\"\n :key=\"item.value\"\n :label=\"item.value\"\n :value=\"item.value\"\n :disabled=\"item.disabled\"\n />\n <template #prefix>\n <slot name=\"prefix\">\n <hl-icon>\n <system-clock />\n </hl-icon>\n </slot>\n </template>\n </hl-select>\n</template>\n\n<script lang=\"ts\">\nimport { computed, defineComponent, ref } from 'vue'\nimport dayjs from 'dayjs'\nimport customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport { useLocale, useConsistentProp } from '@hongluan-ui/hooks'\nimport HlSelect from '@hongluan-ui/components/select'\nimport HlOption from '@hongluan-ui/components/option'\nimport HlIcon from '@hongluan-ui/components/icon'\nimport { SystemClock } from '@hongluan-ui/components/system-icon'\nimport { timeSelectProps } from './time-select'\nimport { compareTime, formatTime, nextTime, parseTime } from './utils'\n\ndayjs.extend(customParseFormat)\n\nexport default defineComponent({\n name: 'TimeSelect',\n components: { HlSelect, HlOption, HlIcon, SystemClock },\n props: timeSelectProps,\n emits: ['change', 'blur', 'focus', 'clear', 'update:modelValue'],\n setup(props) {\n const { lang } = useLocale()\n // computed\n const select = ref<typeof HlSelect>()\n const value = computed(() => props.modelValue)\n const start = computed(() => {\n const time = parseTime(props.start)\n return time ? formatTime(time) : null\n })\n\n const end = computed(() => {\n const time = parseTime(props.end)\n return time ? formatTime(time) : null\n })\n\n const step = computed(() => {\n const time = parseTime(props.step)\n return time ? formatTime(time) : null\n })\n\n const minTime = computed(() => {\n const time = parseTime(props.minTime || '')\n return time ? formatTime(time) : null\n })\n\n const maxTime = computed(() => {\n const time = parseTime(props.maxTime || '')\n return time ? formatTime(time) : null\n })\n const items = computed(() => {\n const result: { value: string; disabled: boolean; }[] = []\n if (props.start && props.end && props.step) {\n let current = start.value\n let currentTime: string\n while (current && end.value && compareTime(current, end.value) <= 0) {\n currentTime = dayjs(current, 'HH:mm')\n .locale(lang.value)\n .format(props.format)\n\n result.push({\n value: currentTime,\n disabled:\n compareTime(current, minTime.value || '-1:-1') <= 0 ||\n compareTime(current, maxTime.value || '100:100') >= 0,\n })\n current = nextTime(current, step.value!)\n }\n }\n return result\n })\n const popperPaneRef = computed(() => select.value?.popperPaneRef)\n const blur = () => {\n select.value?.blur?.()\n }\n const focus = () => {\n select.value?.focus?.()\n }\n\n const { size: timeSize, disabled: timeDisabled, fill: timeFill } = useConsistentProp()\n\n return {\n select,\n popperPaneRef,\n value,\n items,\n blur,\n focus,\n timeSize,\n timeDisabled,\n timeFill,\n }\n },\n})\n</script>\n"],"names":["_createElementBlock"],"mappings":";;;;;;;;;;;;;;;AAkDA,MAAM,OAAO,iBAAiB;AAE9B,MAAK,YAAa,gBAAa;AAAA,EAC7B,MAAM;AAAA,EACN,YAAY,EAAE,UAAU,UAAU,QAAQ;AAAY,EACtD,OAAO;AAAA,EACP,OAAO,CAAC,UAAU,QAAQ,SAAS,SAAS,mBAAmB;AAAA,EAC/D,MAAM,OAAO;AACX,UAAM,EAAE,SAAS;AAEjB,UAAM,SAAS;AACf,UAAM,QAAQ,SAAS,MAAM,MAAM,UAAU;AAC7C,UAAM,QAAQ,SAAS,MAAM;AAC3B,YAAM,OAAO,UAAU,MAAM,KAAK;AAClC,aAAO,OAAO,WAAW,IAAI,IAAI;AAAA,K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