UNPKG

birdpaper-ui

Version:

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

79 lines (78 loc) 2.48 kB
import { defineComponent, inject, ref } from "vue"; import { IconArrowLeftSLine, IconArrowRightSLine, IconArrowLeftDoubleFill, IconArrowRightDoubleFill } from "birdpaper-icon"; import { dateInjectionKey, PanelType } from "../types.js"; import { useDayJs } from "../core.js"; import _sfc_main$1 from "./time-table.vue.js"; const _sfc_main = defineComponent({ name: "DateTable", components: { timeTable: _sfc_main$1, IconArrowLeftSLine, IconArrowRightSLine, IconArrowLeftDoubleFill, IconArrowRightDoubleFill }, emits: ["change-picker"], setup(props, { emit }) { const name = "bp-date-table"; let ctx = null; ctx = inject(dateInjectionKey); const { toDay, current, currentMonth, currentYear, dates, setDates, changeMonth, changeYear, weeks, months } = useDayJs( ctx.langs, ctx.modelValue.value ); const currentVal = ref(current.value && current.value.format("YYYY-MM-DD")); const currentTimeVal = ref(""); setDates("YYYY-MM-DD"); const timeTableRef = ref(); const handleSelect = (date) => { currentVal.value = date.value; if (ctx.showTime) { const time = timeTableRef.value.getTime(); currentTimeVal.value = time; return; } ctx.onSelect(currentVal.value, {}, true); }; const onTimeSelect = (time) => { currentTimeVal.value = time; }; const handleChange = (mode, type, step = 1) => { let v = mode === "month" ? currentMonth.value : currentYear.value; v = type === "next" ? v + step : v - step; mode === "month" ? changeMonth(v) : changeYear(v); setDates(ctx.valueFormat); }; const handleChangePicker = (typeName, val) => { emit("change-picker", typeName, val); }; const getValue = () => { const val = `${currentVal.value} ${currentTimeVal.value}`; ctx.onSelect(val, {}, true); return val; }; const setNow = () => { currentVal.value = current.value && current.value.format("YYYY-MM-DD"); timeTableRef.value.setNow(); currentTimeVal.value = timeTableRef.value.getTime(); }; return { ctx, toDay, current, currentVal, currentTimeVal, name, weeks, months, dates, currentYear, currentMonth, handleChange, handleSelect, handleChangePicker, PanelType, timeTableRef, onTimeSelect, getValue, setNow }; } }); export { _sfc_main as default };