@antmjs/vantui
Version:
一套适用于Taro3及React的vantui组件库
54 lines (53 loc) • 2.88 kB
JavaScript
;
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatMonthTitle = formatMonthTitle;
exports.getDayStyle = getDayStyle;
exports.getMark = getMark;
exports.getMonthStyle = getMonthStyle;
var utils = _interopRequireWildcard(require("../../utils"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function getMark(date) {
return new Date(date).getMonth() + 1;
}
var ROW_HEIGHT = 64;
function getDayStyle(type, index, date, rowHeight, color, firstDayOfWeek) {
var style = [];
var current = new Date(date).getDay() || 7;
var offset = current < firstDayOfWeek ? 7 - firstDayOfWeek + current : current === 7 && firstDayOfWeek === 0 ? 0 : current - firstDayOfWeek;
if (index === 0) {
style.push(['margin-left', 100 * offset / 7 + '%']);
}
if (rowHeight !== ROW_HEIGHT) {
style.push(['height', rowHeight + 'px']);
}
if (color) {
if (type === 'start' || type === 'end' || type === 'start-end' || type === 'multiple-selected' || type === 'multiple-middle') {
style.push(['background', color]);
} else if (type === 'middle') {
style.push(['color', color]);
}
}
return style.map(function (item) {
return item.join(':');
}).join(';');
}
function formatMonthTitle(date) {
date = new Date(date);
return date.getFullYear() + '年' + (date.getMonth() + 1) + '月';
}
function getMonthStyle(visible, date, rowHeight) {
if (!visible) {
date = new Date(date);
var totalDay = utils.getMonthEndDay(date.getFullYear(), date.getMonth() + 1);
var offset = new Date(date).getDay();
var padding = Math.ceil((totalDay + offset) / 7) * rowHeight;
return {
paddingBottom: "".concat(padding, "px")
};
}
return {};
}