From 232fc178d1c00fcac5610ec9dd1840da6315b8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 5 May 2024 11:41:14 +0800 Subject: [PATCH] =?UTF-8?q?docs(laydate):=20=E4=BC=98=E5=8C=96=E5=86=9C?= =?UTF-8?q?=E5=8E=86=E9=A2=84=E8=A7=88=E6=98=BE=E7=A4=BA=20(#1855)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/laydate/examples/cell.md | 55 ++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/docs/laydate/examples/cell.md b/docs/laydate/examples/cell.md index c2415648..d7625e54 100644 --- a/docs/laydate/examples/cell.md +++ b/docs/laydate/examples/cell.md @@ -93,13 +93,20 @@ btns: ['now'], theme: 'lunar', autoConfirm: false, - ready: function () { + ready: function (date) { if (!this._previewEl) { var key = this.elem.attr('lay-key'); var panelEl = $('#layui-laydate' + key); this._previewEl = panelEl.find('.layui-laydate-preview'); + this.cellRender(date); } }, + change: function(value, date) { + this.cellRender(date); + }, + onNow: function(value, date) { + this.cellRender(date); + }, cellRender: function (ymd, render, info) { var that = this; var y = ymd.year; @@ -112,6 +119,30 @@ var displayHoliday = holiday && holiday.getTarget() === holiday.getDay() ? holiday.getName() : undefined; var displayHolidayBadge = holiday && holiday.getTarget() ? (holiday.isWork() ? '班' : '休') : undefined; var isHoliday = holiday && holiday.getTarget() && !holiday.isWork(); + // 在预览区显示自定义农历相关信息 + if (that._previewEl && (!info || (info && info.type === "date"))) { + var holidayBadgeStyle = [ + 'color:#fff', + 'background-color:' + (isHoliday ? '#eb3333' : '#333'), + 'display:' + (displayHolidayBadge ? 'inline-block' : 'none') + ].join(';') + var festivalBadgeStyle = [ + 'color:#fff', + 'background-color:#1e9fff', + 'display:' + (displayHoliday || jieQi ? 'inline-block' : 'none') + ].join(';') + var tipsText = [ + '
', + '
农历' + lunarDate.getMonthInChinese() + '月' + lunarDate.getDayInChinese() + '
', + '
' + lunarDate.getYearInGanZhi() + lunarDate.getYearShengXiao() + '年
', + '
' + lunarDate.getMonthInGanZhi() + '月 ' + lunarDate.getDayInGanZhi() + '日
', + '
' + displayHolidayBadge + '
', + '
' + (displayHoliday || jieQi) + '
', + '
' + ].join(''); + that._previewEl.html(tipsText); + }; + if (!render) return; // 面板类型 if (info.type === 'date') { var clazz = [ @@ -136,28 +167,6 @@ zIndex: 999999999, }); }); - contentEl.on('click', function () { - var holidayBadgeStyle = [ - 'color:#fff', - 'background-color:' + (isHoliday ? '#eb3333' : '#333'), - 'display:' + (displayHolidayBadge ? 'inline-block' : 'none') - ].join(';') - var festivalBadgeStyle = [ - 'color:#fff', - 'background-color:#1e9fff', - 'display:' + (displayHoliday || jieQi ? 'inline-block' : 'none') - ].join(';') - var tipsText = [ - '
', - '
农历' + lunarDate.getMonthInChinese() + '月' + lunarDate.getDayInChinese() + '
', - '
' + lunarDate.getYearInGanZhi() + lunarDate.getYearShengXiao() + '年
', - '
' + lunarDate.getMonthInGanZhi() + '月 ' + lunarDate.getDayInGanZhi() + '日
', - '
' + displayHolidayBadge + '
', - '
' + (displayHoliday || jieQi) + '
', - '
' - ].join(''); - that._previewEl.html(tipsText); - }); render(contentEl); } else if (info.type === 'year') { var lunarDate = Lunar.fromDate(new Date(y + 1, 0));