UNPKG

birdpaper-ui

Version:

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

49 lines (48 loc) 1.5 kB
import { defineComponent, inject, ref } from "vue"; import dayjs from "dayjs"; import { dateInjectionKey, PanelType } from "../types.js"; import { useDayJs } from "../core.js"; import { IconArrowLeftDoubleFill, IconArrowRightDoubleFill } from "birdpaper-icon"; const _sfc_main = defineComponent({ name: "MonthTable", components: { IconArrowLeftDoubleFill, IconArrowRightDoubleFill }, emits: ["change-picker"], setup(props, { emit }) { const name = "bp-month-table"; let ctx = null; ctx = inject(dateInjectionKey); const { toDay, current, currentYear, monthCell, setMonthCell, changeYear } = useDayJs(ctx.langs, ctx.modelValue.value); const currentVal = ref(current.value && current.value.format(ctx.valueFormat)); setMonthCell(ctx.valueFormat); const handleChange = (type, step = 1) => { let val = currentYear.value; val = type === "next" ? val + step : val - step; changeYear(val); setMonthCell(ctx.valueFormat); }; const handleSelect = (date) => { currentVal.value = date.value; ctx.onSelect(currentVal.value, {}, false); emit("change-picker", "date"); }; const handleChangePicker = (typeName, val) => { emit("change-picker", typeName, val); }; return { name, ctx, toDay, currentVal, currentYear, monthCell, handleSelect, handleChange, handleChangePicker, PanelType, dayjs }; } }); export { _sfc_main as default };