105 lines
3.4 KiB
JavaScript
105 lines
3.4 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const _sfc_main = {
|
|
__name: "calendar",
|
|
setup(__props) {
|
|
const now = /* @__PURE__ */ new Date();
|
|
const year = common_vendor.ref(now.getFullYear());
|
|
const month = common_vendor.ref(now.getMonth());
|
|
const selectedKey = common_vendor.ref(null);
|
|
const weekdays = ["一", "二", "三", "四", "五", "六", "日"];
|
|
const firstWeekdayOfMonth = (y, m) => {
|
|
const d = new Date(y, m, 1).getDay();
|
|
return (d + 6) % 7;
|
|
};
|
|
const cells = common_vendor.computed(() => {
|
|
const list = [];
|
|
const prevMonthDate = new Date(year.value, month.value, 0);
|
|
const prevYear = prevMonthDate.getFullYear();
|
|
const prevMonth2 = prevMonthDate.getMonth();
|
|
const prevTotal = prevMonthDate.getDate();
|
|
const startOffset = firstWeekdayOfMonth(year.value, month.value);
|
|
for (let i = 0; i < startOffset; i++) {
|
|
const day = prevTotal - startOffset + i + 1;
|
|
const lunar = common_vendor.solarlunar.solar2lunar(prevYear, prevMonth2 + 1, day);
|
|
list.push({
|
|
key: `prev-${prevYear}-${prevMonth2 + 1}-${day}`,
|
|
dateText: day,
|
|
lunarText: lunar.dayCn,
|
|
prev: true,
|
|
next: false
|
|
});
|
|
}
|
|
const totalDays = new Date(year.value, month.value + 1, 0).getDate();
|
|
for (let d = 1; d <= totalDays; d++) {
|
|
const lunar = common_vendor.solarlunar.solar2lunar(year.value, month.value + 1, d);
|
|
list.push({
|
|
key: `${year.value}-${month.value + 1}-${d}`,
|
|
dateText: d,
|
|
lunarText: lunar.dayCn,
|
|
prev: false,
|
|
next: false
|
|
});
|
|
}
|
|
return list;
|
|
});
|
|
function isSelected(key) {
|
|
return selectedKey.value === key;
|
|
}
|
|
function selectDate(cell) {
|
|
if (cell.prev) {
|
|
return;
|
|
}
|
|
selectedKey.value = cell.key;
|
|
common_vendor.index.__f__("log", "at component/public/calendar.vue:91", "Selected date:", cell.key);
|
|
}
|
|
function prevMonth() {
|
|
if (month.value === 0) {
|
|
year.value--;
|
|
month.value = 11;
|
|
} else {
|
|
month.value--;
|
|
}
|
|
}
|
|
function nextMonth() {
|
|
if (month.value === 11) {
|
|
year.value++;
|
|
month.value = 0;
|
|
} else {
|
|
month.value++;
|
|
}
|
|
}
|
|
return (_ctx, _cache) => {
|
|
return {
|
|
a: common_vendor.t(year.value),
|
|
b: common_vendor.t(month.value + 1),
|
|
c: common_vendor.o(prevMonth),
|
|
d: common_vendor.o(nextMonth),
|
|
e: common_vendor.f(weekdays, (day, idx, i0) => {
|
|
return {
|
|
a: common_vendor.t(day),
|
|
b: idx
|
|
};
|
|
}),
|
|
f: common_vendor.f(cells.value, (cell, k0, i0) => {
|
|
return common_vendor.e({
|
|
a: common_vendor.t(cell.dateText),
|
|
b: cell.lunarText
|
|
}, cell.lunarText ? {
|
|
c: common_vendor.t(cell.lunarText)
|
|
} : {}, {
|
|
d: cell.key,
|
|
e: cell.prev ? 1 : "",
|
|
f: cell.next ? 1 : "",
|
|
g: isSelected(cell.key) ? 1 : "",
|
|
h: common_vendor.o(($event) => selectDate(cell), cell.key)
|
|
});
|
|
})
|
|
};
|
|
};
|
|
}
|
|
};
|
|
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-41c06644"]]);
|
|
wx.createComponent(Component);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/component/public/calendar.js.map
|