UNPKG

birdpaper-ui

Version:

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

43 lines (42 loc) 1.31 kB
import { defineComponent, inject, ref } from "vue"; import { dateInjectionKey } from "../types.js"; import dayjs from "dayjs"; import { useDayJs } from "../core.js"; import { IconArrowLeftDoubleFill, IconArrowRightDoubleFill } from "birdpaper-icon"; const _sfc_main = defineComponent({ name: "YearTable", components: { IconArrowLeftDoubleFill, IconArrowRightDoubleFill }, emits: ["change-picker"], setup(props, { emit }) { const name = "bp-year-table"; let ctx = null; ctx = inject(dateInjectionKey); const { toDay, current, firstYear, yearCell, setYearCell } = useDayJs(ctx.langs, ctx.modelValue.value); const currentVal = ref(current.value && current.value.format(ctx.valueFormat)); setYearCell(ctx.valueFormat); const handleChange = (type, step = 12) => { let val = firstYear.value; firstYear.value = type === "next" ? val + step : val - step; setYearCell(ctx.valueFormat); }; const handleSelect = (date) => { currentVal.value = date.value; ctx.onSelect(currentVal.value, {}, false); emit("change-picker", "month"); }; return { name, ctx, toDay, handleChange, currentVal, yearCell, firstYear, handleSelect, dayjs }; } }); export { _sfc_main as default };