UNPKG

@layui/layui-vue

Version:

a component library for Vue 3 base on layui-vue

30 lines (29 loc) 2.41 kB
import { defineComponent as V, inject as _, ref as k, computed as C, watch as b, openBlock as d, createElementBlock as m, createElementVNode as o, renderSlot as Y, createVNode as D, unref as n, toDisplayString as x, Fragment as j, renderList as F, normalizeClass as L } from "vue"; import s from "dayjs"; import P from "../../../icon/index.js"; import { DATE_PICKER_CONTEXT as M } from "../../interface.js"; import { getYears as N } from "../../util.js"; const B = { class: "layui-laydate-main" }, S = { class: "layui-laydate-header" }, $ = { class: "laydate-set-ym" }, q = { class: "laydate-time-text" }, z = { class: "layui-laydate-content", style: { height: "220px", "overflow-y": "auto" } }, A = { class: "layui-laydate-list laydate-year-list" }, I = ["onClick", "onMouseenter"], H = V({ name: "YearPanel", __name: "Year", props: { modelValue: {}, showDate: {}, dateType: {}, classes: { type: Function } }, emits: ["pick", "hover-cell"], setup(w, { emit: E }) { const p = w, v = E, a = _(M), u = k(), r = k(s()), y = C(() => N(r.value.year(), a.yearPage)), f = C(() => [y.value.at(0), y.value.at(-1)]); function c(e) { return a.disabledDate ? a.disabledDate(r.value.year(e).toDate()) : !!(a.min && e < s(a.min).year()) || !!(a.max && e > s(a.max).year()); } function h(e) { r.value = r.value.year(r.value.year() + e); } return b([() => p.modelValue, () => p.showDate], ([e, i]) => { u.value = e ? e.year() : null, r.value = e || i; }, { immediate: !0 }), (e, i) => (d(), m("div", B, [o("div", S, [Y(e.$slots, "header", { yearList: f.value }, () => [D(n(P), { type: "layui-icon-prev", onClick: i[0] || (i[0] = (l) => h(-n(a).yearPage)) }), o("div", $, [o("span", q, x(f.value.join(" - ")), 1)]), D(n(P), { type: "layui-icon-next", onClick: i[1] || (i[1] = (l) => h(n(a).yearPage)) })])]), o("div", z, [o("ul", A, [(d(!0), m(j, null, F(y.value, (l) => { var g; return d(), m("li", { key: l, class: L({ "layui-this": u.value === l, "layui-laydate-current": l === n(s)().year(), "layui-disabled": c(l), ...(g = e.classes) == null ? void 0 : g.call(e, n(s)().year(l)) }), onClick: (T) => function(t) { if (c(t)) return !0; u.value = t, v("pick", a.range ? s().year(t) : t); }(l), onMouseenter: (T) => function(t) { !c(t) && a.range && v("hover-cell", s().year(t)); }(l) }, x(l), 43, I); }), 128))])])])); } }); export { H as default };