vuux
Version:
Vue3 Nuxt3 Nuxt4 组件库
51 lines (50 loc) • 1.48 kB
JavaScript
import o from "../day/index.mjs";
import { getMonthDate as y } from "../date.mjs";
import { ref as N, reactive as S, computed as m, onMounted as x } from "vue";
const j = (r, l) => {
const v = o().year(), f = o().month() + 1, c = N(y()), t = S({
year: v,
month: f
}), a = () => {
c.value = y(t.year, t.month);
}, d = (e = "") => {
t.year = o(e || void 0).year(), t.month = o(e || void 0).month() + 1, a();
}, D = () => {
t.month > 1 ? t.month -= 1 : (t.year -= 1, t.month = 12), a();
}, $ = () => {
t.month < 12 ? t.month += 1 : (t.year += 1, t.month = 1), a();
}, i = () => {
t.year -= 1, a();
}, u = () => {
t.year += 1, a();
}, M = (e) => {
const s = `${e.year}-${e.month}-${e.showDate}`, n = o(s).format("YYYY-MM-DD");
r.value = n, l("change", n);
}, Y = m(() => (e) => o().isSame(o(`${e.year}-${e.month}-${e.date}`), "day")), p = m(() => (e) => {
const s = e.date === e.showDate;
let n = !1;
if (e.date > 0 && e.date <= e.showDate) {
const w = `${t.year}-${t.month}-${e.showDate}`;
n = o(w).isSame(o(r.value));
}
let h = "";
return s && (h += " is-e"), n && (h += " is-selected"), h;
});
return x(() => {
d(r.value);
}), {
dateData: c,
dateState: t,
dateItemClassNames: p,
checkToday: Y,
init: d,
handlePrveYear: i,
handlePrveMonth: D,
handleNextMonth: $,
handleNextYear: u,
handleSelectDateFn: M
};
};
export {
j as useDate
};