taro-ui-vue3
Version:
Taro UI Rewritten in Vue 3.0
81 lines (80 loc) • 2.38 kB
JavaScript
import dayjs from "dayjs/esm/index";
import _flow from "lodash-es/flow";
import * as constant from "./constant";
import plugins from "./plugins";
const TOTAL = 7 * 6;
function getFullItem(item, options, selectedDate, isShowStatus) {
if (options.marks.find((x) => x.value === item.value)) {
item.marks = [{
value: item.value
}];
}
if (!isShowStatus)
return item;
const bindedPlugins = plugins.map((fn) => fn.bind(null, {
options,
selectedDate
}));
return _flow(bindedPlugins)(item);
}
function generateCalendarGroup(options) {
return function(generateDate, selectedDate, isShowStatus) {
const date = dayjs(generateDate);
const {format} = options;
const firstDate = date.startOf("month");
const lastDate = date.endOf("month");
const preMonthDate = date.subtract(1, "month");
const list = [];
const nowMonthDays = date.daysInMonth();
const preMonthLastDay = preMonthDate.endOf("month").day();
for (let i2 = 1; i2 <= preMonthLastDay + 1; i2++) {
const thisDate = firstDate.subtract(i2, "day").startOf("day");
let item = {
marks: [],
_value: thisDate,
text: thisDate.date(),
type: constant.TYPE_PRE_MONTH,
value: thisDate.format(format)
};
item = getFullItem(item, options, selectedDate, isShowStatus);
list.push(item);
}
list.reverse();
for (let i2 = 0; i2 < nowMonthDays; i2++) {
const thisDate = firstDate.add(i2, "day").startOf("day");
let item = {
marks: [],
_value: thisDate,
text: thisDate.date(),
type: constant.TYPE_NOW_MONTH,
value: thisDate.format(format)
};
item = getFullItem(item, options, selectedDate, isShowStatus);
list.push(item);
}
let i = 1;
while (list.length < TOTAL) {
const thisDate = lastDate.add(i++, "day").startOf("day");
let item = {
marks: [],
_value: thisDate,
text: thisDate.date(),
type: constant.TYPE_NEXT_MONTH,
value: thisDate.format(format)
};
item = getFullItem(item, options, selectedDate, isShowStatus);
list.push(item);
}
return {
list,
value: generateDate
};
};
}
function getGenerateDate(date) {
return dayjs(date).startOf("month");
}
export {
generateCalendarGroup as default,
getGenerateDate
};