From 0dc95b4ee96bc263c254b2d544bc88e9db253ecb Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Sat, 19 Aug 2023 07:02:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20laydate=20=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E9=80=89=E6=8B=A9=20`shortcuts.value=20`=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E5=87=BD=E6=95=B0=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/laydate.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/laydate.js b/src/modules/laydate.js index 3da065fe..36973a07 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -591,7 +591,9 @@ return shortcutBtns.join(''); }()).find('li').on('click', function (event) { var btnSetting = options.shortcuts[this.dataset['index']] || {}; - var value = btnSetting.value || []; + var value = (typeof btnSetting.value === 'function' + ? btnSetting.value() + : btnSetting.value) || []; if (!layui.isArray(value)) { value = [value]; } From d1bc0468a566d22f45ff542b20a5389d9366c111 Mon Sep 17 00:00:00 2001 From: sight <1453017105@qq.com> Date: Sat, 19 Aug 2023 07:44:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20laydate=20=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/laydate/detail/options.md | 3 +- docs/laydate/examples/shortcut.md | 76 +++++++++++++++++-------------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/docs/laydate/detail/options.md b/docs/laydate/detail/options.md index 564e0ca7..1be45c1a 100644 --- a/docs/laydate/detail/options.md +++ b/docs/laydate/detail/options.md @@ -249,11 +249,12 @@ shortcuts: [ - 若为 `string` 类型,必须和 `format` 设置的格式对应; - 若为 `date` 对象类型,则可通过操作 `new Date()` 来对选项值进行相应的返回计算; - 若为 `array` 类型,则数组成员可填写开始日期和结束日期。 +- 若为 `function` 类型,返回值同上。2.8.16+ 详细用法可参考: [#示例](#demo-shortcut) -string
date
array +string
date
array
function - diff --git a/docs/laydate/examples/shortcut.md b/docs/laydate/examples/shortcut.md index a1d31207..86676922 100644 --- a/docs/laydate/examples/shortcut.md +++ b/docs/laydate/examples/shortcut.md @@ -90,16 +90,21 @@ layui.use(function(){ var now = new Date(); now.setDate(now.getDate() - 1); return now; - }() + } + }, + { + text: "今天", + value: function(){ + return Date.now(); + } }, - { text: "今天", value: Date.now() }, { text: "明天", value: function(){ var now = new Date(); now.setDate(now.getDate() + 1); return now; - }() + } }, { text: "上个月", @@ -108,7 +113,7 @@ layui.use(function(){ // now.setDate(now.getDate() - 1); now.setMonth(now.getMonth() - 1); return [now]; - }() + } }, { text: "上个月的前一天", @@ -117,7 +122,7 @@ layui.use(function(){ now.setMonth(now.getMonth() - 1); now.setDate(now.getDate() - 1); return [now]; - }() + } }, { text: "某一天", @@ -137,7 +142,7 @@ layui.use(function(){ var now = new Date(); now.setFullYear(now.getFullYear() - 1); return now; - }() + } }, { text: "明年", @@ -145,7 +150,7 @@ layui.use(function(){ var now = new Date(); now.setFullYear(now.getFullYear() + 1); return now; - }() + } } ] }); @@ -161,7 +166,7 @@ layui.use(function(){ var now = new Date(); now.setMonth(now.getMonth() - 1); return now; - }() + } }, { text: "下个月", @@ -169,7 +174,7 @@ layui.use(function(){ var now = new Date(); now.setMonth(now.getMonth() + 1); return now; - }() + } }, { text: "去年12月", @@ -178,7 +183,7 @@ layui.use(function(){ now.setMonth(11); now.setFullYear(now.getFullYear() - 1); return now; - }() + } } ] }); @@ -214,16 +219,21 @@ layui.use(function(){ var now = new Date(); now.setDate(now.getDate() - 1); return now; - }() + } + }, + { + text: "今天", + value: function(){ + return Date.now(); + } }, - { text: "今天", value: Date.now() }, { text: "明天", value: function(){ var now = new Date(); now.setDate(now.getDate() + 1); return now; - }() + } }, { text: "上个月", @@ -232,7 +242,7 @@ layui.use(function(){ // now.setDate(now.getDate() - 1); now.setMonth(now.getMonth() - 1); return [now]; - }() + } }, { text: "上个月的前一天", @@ -241,7 +251,7 @@ layui.use(function(){ now.setMonth(now.getMonth() - 1); now.setDate(now.getDate() - 1); return [now]; - }() + } }, { text: "某一天", @@ -263,7 +273,7 @@ layui.use(function(){ var now = new Date(); now.setDate(now.getDate() - 1); return now; - }() + } }, { text: "今天", value: Date.now() }, { @@ -272,7 +282,7 @@ layui.use(function(){ var now = new Date(); now.setDate(now.getDate() + 1); return now; - }() + } }, { text: "上个月", @@ -281,7 +291,7 @@ layui.use(function(){ // now.setDate(now.getDate() - 1); now.setMonth(now.getMonth() - 1); return [now]; - }() + } }, { text: "上个月的前一天", @@ -290,7 +300,7 @@ layui.use(function(){ now.setMonth(now.getMonth() - 1); now.setDate(now.getDate() - 1); return [now]; - }() + } }, { text: "某一天", @@ -323,7 +333,7 @@ layui.use(function(){ value.push(new Date(date2)); return value; - }() + } }, { text: "这个月", @@ -344,7 +354,7 @@ layui.use(function(){ value.push(new Date(date2)); return value; - }() + } }, { text: "下个月", @@ -365,7 +375,7 @@ layui.use(function(){ value.push(new Date(date2)); return value; - }() + } } ] }); @@ -383,7 +393,7 @@ layui.use(function(){ var now = new Date(); now.setFullYear(now.getFullYear() - 1); return [now, new Date()]; - }() + } }, { text: "未来一年", @@ -391,7 +401,7 @@ layui.use(function(){ var now = new Date(); now.setFullYear(now.getFullYear() + 1); return [new Date(), now]; - }() + } }, { text: "近三年", @@ -399,7 +409,7 @@ layui.use(function(){ var now = new Date(); now.setFullYear(now.getFullYear() - 3); return [now, new Date()]; - }() + } } ] }); @@ -420,7 +430,7 @@ layui.use(function(){ date2.setMonth(0, 1); date2.setHours(0, 0, 0, 0); return [date1, date2.getTime() - 1]; - }() + } }, { text: "明年", @@ -428,7 +438,7 @@ layui.use(function(){ var now = new Date(); now.setFullYear(now.getFullYear() + 1); return [now, now]; - }() + } }, { text: "近三年", @@ -436,7 +446,7 @@ layui.use(function(){ var now = new Date(); now.setFullYear(now.getFullYear() - 3); return [now, new Date()]; - }() + } } ] }); @@ -457,7 +467,7 @@ layui.use(function(){ date2.setHours(11, 30, 0, 0); return [date1, date2]; - })() + }) }, { text: '13:00

15:00', @@ -469,7 +479,7 @@ layui.use(function(){ date2.setHours(15, 0, 0, 0); return [date1, date2]; - })() + }) } ] }); @@ -498,7 +508,7 @@ layui.use(function(){ value.push(new Date(date2)); return value; - }() + } }, { text: "这个月", @@ -519,7 +529,7 @@ layui.use(function(){ value.push(new Date(date2)); return value; - }() + } }, { text: "下个月", @@ -540,7 +550,7 @@ layui.use(function(){ value.push(new Date(date2)); return value; - }() + } } ] });