UNPKG

hyj-ui

Version:

测试文件

59 lines (49 loc) 3.02 kB
import dayjs from 'dayjs'; function renderMonth() { var _this = this; var bindEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var contentHtml = ''; var _this$options = this.options, headClassName = _this$options.headClassName, dateCellRender = _this$options.dateCellRender, dateCellClick = _this$options.dateCellClick, showLunaCalendar = _this$options.showLunaCalendar, showWeekHeader = _this$options.showWeekHeader; var weekDay = this.weekDay; contentHtml = "<div class='calendar-body'>\n<table>\n\n".concat(showWeekHeader ? "<thead class=".concat(headClassName || 'head', ">\n<tr>\n").concat(weekDay.map(function (item) { return "<th>".concat(item, "</th>"); }).join(''), "\n</tr>\n</thead>") : '', "\n\n<tbody>\n").concat(Array(this.getRenderRows(this.firstWeekDay, this.monthDays, this.options.weekStartOrder) // Math.ceil( // this.firstWeekDay === 6 ? this.monthDays / 7 : (this.monthDays + this.firstWeekDay) / 7 // ) ).fill(1).map(function (item, rowIndex) { return "<tr>".concat(Array(7).fill(1).map(function (item, weekIndex) { if (_this.count) { ++_this.count; } if (_this.getRenderStartWeek(rowIndex, weekIndex)) { ++_this.count; } if (_this.count && _this.count < _this.monthDays + 1) { if (dateCellRender) { return "<td>".concat(dateCellRender(dayjs(_this.value, 'YYYY-MM-DD').startOf('month').add(_this.count - 1, 'day').format('YYYY-MM-DD'), _this.count, weekIndex), "</td>"); } if (!_this.mounted) { // 第一次挂载 var currentDay = _this.count; if (bindEvent) { document.querySelectorAll('.date-cell')[currentDay - 1].addEventListener('click', function () { var nowDate = dayjs(_this.value, 'YYYY-MM-DD').startOf('month').add(currentDay - 1, 'day').format('YYYY-MM-DD'); _this.selectedDate = nowDate; dateCellClick && dateCellClick(nowDate, currentDay, weekIndex); }); } } return "<td class=\"date-cell\">".concat(_this.count, "\n ").concat(showLunaCalendar ? "<span> \n ".concat(_this.solarToLunar(dayjs(_this.value).year(), dayjs(_this.value).month() + 1, _this.count).dayCn, "\n </span>") : '', "\n </td>"); } _this.getOtherMonthDays(rowIndex, weekIndex, dayjs(_this.value).month() + 1, _this.firstWeekDay); return "<td class='other-month'>".concat(_this.getOtherMonthDays(rowIndex, weekIndex, dayjs(_this.value).month() + 1, _this.firstWeekDay).nowDay, "\n ").concat(showLunaCalendar ? "<span>\n ".concat(_this.getOtherMonthDays(rowIndex, weekIndex, dayjs(_this.value).month() + 1, _this.firstWeekDay).lunarData.dayCn, "\n </span>") : '', "\n </td>"); }).join(''), "\n </tr>"); }).join(''), "\n</tbody>\n</table>\n</div>"); return contentHtml; } export default renderMonth;