dk-plus
Version:
59 lines (58 loc) • 2.13 kB
JavaScript
import { defineComponent as m, reactive as v, computed as o, watch as w } from "vue";
import { dkDatePickerPanelProps as g } from "./index3.js";
import { datePickerPanelEmits as f } from "./index4.js";
import { buildWeekdays as M, buildMonthCells as P, parseDate as k, addMonths as s, formatDate as y } from "./index5.js";
const E = m({
name: "DkDatePickerPanel",
props: g,
emits: f,
setup(n, { emit: i }) {
const t = v({
viewDate: new Date(),
selected: null
}), l = o(() => {
var a;
const e = (a = n.firstDayOfWeek) != null ? a : 0;
return Math.min(6, Math.max(0, e));
}), r = o(() => M(l.value)), c = o(() => {
const e = t.viewDate.getFullYear(), a = t.viewDate.getMonth() + 1;
return `${e} \u5E74 ${a} \u6708`;
}), d = o(() => {
const e = t.viewDate.getFullYear(), a = t.viewDate.getMonth();
return P(e, a, t.selected, l.value, n.disabled, n.disabledDate);
}), u = o(() => {
const e = d.value;
return [e.slice(0, 7), e.slice(7, 14), e.slice(14, 21), e.slice(21, 28), e.slice(28, 35), e.slice(35, 42)];
}), D = o(() => ({ width: n.width })), h = (e) => {
const a = k(e);
t.selected = a, a && (t.viewDate = new Date(a.getFullYear(), a.getMonth(), 1));
};
return w(
() => n.modelValue,
(e) => h(e || ""),
{ immediate: !0 }
), {
state: t,
rootStyle: D,
weekdays: r,
headerText: c,
rows: u,
toPrevMonth: () => {
n.disabled || (t.viewDate = s(t.viewDate, -1), i("panel-change", { year: t.viewDate.getFullYear(), month: t.viewDate.getMonth() + 1 }));
},
toNextMonth: () => {
n.disabled || (t.viewDate = s(t.viewDate, 1), i("panel-change", { year: t.viewDate.getFullYear(), month: t.viewDate.getMonth() + 1 }));
},
onPick: (e) => {
if (n.disabled || e.isDisabled)
return;
t.selected = new Date(e.date.getFullYear(), e.date.getMonth(), e.date.getDate());
const a = y(t.selected);
i("update:modelValue", a), i("change", a);
}
};
}
});
export {
E as default
};