UNPKG

birdpaper-ui

Version:

一个通用的 vue3 UI组件库。A common vue3 UI component library.

88 lines (87 loc) 2.66 kB
"use strict"; const vue = require("vue"); const util = require("../../../utils/util.js"); const vueVirtualScroller = require("vue-virtual-scroller"); require("vue-virtual-scroller/dist/vue-virtual-scroller.css"); const dayjs = require("dayjs"); const types = require("../types.js"); const _sfc_main = vue.defineComponent({ name: "TimeTable", components: { RecycleScroller: vueVirtualScroller.RecycleScroller }, props: { visible: { type: Boolean, default: false } }, setup(props) { const name = "bp-time-table"; const ctx = vue.ref(); const defaultValue = "00"; const hourList = util.generateArray(24); const minuteList = util.generateArray(60); const secondList = util.generateArray(60); ctx.value = vue.inject(types.timeInjectionKey); const globalValue = vue.ref(["", "", ""]); const confirmDisabled = vue.computed(() => globalValue.value.filter((item) => item === "").length > 0); const typeRefs = vue.ref([]); const handleClick = (index, item) => { globalValue.value[index] = item; scrollTo(index, item); setDefault(); }; const setDefault = () => { for (let i = 0; i < globalValue.value.length; i++) { const element = globalValue.value[i]; if (!element) { globalValue.value[i] = defaultValue; scrollTo(i); } } }; const setNow = () => { const now = dayjs().format("HH:mm:ss"); globalValue.value = now.split(":"); for (let i = 0; i < globalValue.value.length; i++) { const item = globalValue.value[i]; scrollTo(i, item); } handleSelect(); }; const scrollTo = (i, item = defaultValue) => typeRefs.value[i].scrollToItem(item); const handleSelect = () => { ctx.value.onSelect(globalValue.value.join(":")); }; vue.watch( () => props.visible, () => { if (props.visible) { if (!ctx.value.modelValue) return; globalValue.value = ["", "", ""]; const arr = ctx.value.modelValue.split(":"); for (let i = 0; i < arr.length; i++) { const element = arr[i]; globalValue.value.push(Number(element).toString().padStart(2, "0")); } vue.nextTick(() => { globalValue.value.map((item, index) => { scrollTo(index, item); }); }); } } ); return { ctx, name, typeRefs, hourList, minuteList, secondList, globalValue, confirmDisabled, setNow, handleClick, handleSelect }; } }); module.exports = _sfc_main;