Merge remote-tracking branch 'github/2.x' into 2.x

pull/1345/head
贤心 2023-08-23 22:03:50 +08:00
commit 1b4c612373
4 changed files with 50 additions and 37 deletions

View File

@ -249,11 +249,12 @@ shortcuts: [
- 若为 `string` 类型,必须和 `format` 设置的格式对应; - 若为 `string` 类型,必须和 `format` 设置的格式对应;
- 若为 `date` 对象类型,则可通过操作 `new Date()` 来对选项值进行相应的返回计算; - 若为 `date` 对象类型,则可通过操作 `new Date()` 来对选项值进行相应的返回计算;
- 若为 `array` 类型,则数组成员可填写开始日期和结束日期。 - 若为 `array` 类型,则数组成员可填写开始日期和结束日期。
- 若为 `function` 类型,返回值同上。<sup>2.8.16+</sup>
详细用法可参考: [#示例](#demo-shortcut) 详细用法可参考: [#示例](#demo-shortcut)
</td> </td>
<td>string<br>date<br>array</td> <td>string<br>date<br>array<br>function</td>
<td>-</td> <td>-</td>
</tr> </tr>
<tr> <tr>

View File

@ -90,16 +90,21 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setDate(now.getDate() - 1); now.setDate(now.getDate() - 1);
return now; return now;
}() }
},
{
text: "今天",
value: function(){
return Date.now();
}
}, },
{ text: "今天", value: Date.now() },
{ {
text: "明天", text: "明天",
value: function(){ value: function(){
var now = new Date(); var now = new Date();
now.setDate(now.getDate() + 1); now.setDate(now.getDate() + 1);
return now; return now;
}() }
}, },
{ {
text: "上个月", text: "上个月",
@ -108,7 +113,7 @@ layui.use(function(){
// now.setDate(now.getDate() - 1); // now.setDate(now.getDate() - 1);
now.setMonth(now.getMonth() - 1); now.setMonth(now.getMonth() - 1);
return [now]; return [now];
}() }
}, },
{ {
text: "上个月的前一天", text: "上个月的前一天",
@ -117,7 +122,7 @@ layui.use(function(){
now.setMonth(now.getMonth() - 1); now.setMonth(now.getMonth() - 1);
now.setDate(now.getDate() - 1); now.setDate(now.getDate() - 1);
return [now]; return [now];
}() }
}, },
{ {
text: "某一天", text: "某一天",
@ -137,7 +142,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setFullYear(now.getFullYear() - 1); now.setFullYear(now.getFullYear() - 1);
return now; return now;
}() }
}, },
{ {
text: "明年", text: "明年",
@ -145,7 +150,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setFullYear(now.getFullYear() + 1); now.setFullYear(now.getFullYear() + 1);
return now; return now;
}() }
} }
] ]
}); });
@ -161,7 +166,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setMonth(now.getMonth() - 1); now.setMonth(now.getMonth() - 1);
return now; return now;
}() }
}, },
{ {
text: "下个月", text: "下个月",
@ -169,7 +174,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setMonth(now.getMonth() + 1); now.setMonth(now.getMonth() + 1);
return now; return now;
}() }
}, },
{ {
text: "去年12月", text: "去年12月",
@ -178,7 +183,7 @@ layui.use(function(){
now.setMonth(11); now.setMonth(11);
now.setFullYear(now.getFullYear() - 1); now.setFullYear(now.getFullYear() - 1);
return now; return now;
}() }
} }
] ]
}); });
@ -214,16 +219,21 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setDate(now.getDate() - 1); now.setDate(now.getDate() - 1);
return now; return now;
}() }
},
{
text: "今天",
value: function(){
return Date.now();
}
}, },
{ text: "今天", value: Date.now() },
{ {
text: "明天", text: "明天",
value: function(){ value: function(){
var now = new Date(); var now = new Date();
now.setDate(now.getDate() + 1); now.setDate(now.getDate() + 1);
return now; return now;
}() }
}, },
{ {
text: "上个月", text: "上个月",
@ -232,7 +242,7 @@ layui.use(function(){
// now.setDate(now.getDate() - 1); // now.setDate(now.getDate() - 1);
now.setMonth(now.getMonth() - 1); now.setMonth(now.getMonth() - 1);
return [now]; return [now];
}() }
}, },
{ {
text: "上个月的前一天", text: "上个月的前一天",
@ -241,7 +251,7 @@ layui.use(function(){
now.setMonth(now.getMonth() - 1); now.setMonth(now.getMonth() - 1);
now.setDate(now.getDate() - 1); now.setDate(now.getDate() - 1);
return [now]; return [now];
}() }
}, },
{ {
text: "某一天", text: "某一天",
@ -263,7 +273,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setDate(now.getDate() - 1); now.setDate(now.getDate() - 1);
return now; return now;
}() }
}, },
{ text: "今天", value: Date.now() }, { text: "今天", value: Date.now() },
{ {
@ -272,7 +282,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setDate(now.getDate() + 1); now.setDate(now.getDate() + 1);
return now; return now;
}() }
}, },
{ {
text: "上个月", text: "上个月",
@ -281,7 +291,7 @@ layui.use(function(){
// now.setDate(now.getDate() - 1); // now.setDate(now.getDate() - 1);
now.setMonth(now.getMonth() - 1); now.setMonth(now.getMonth() - 1);
return [now]; return [now];
}() }
}, },
{ {
text: "上个月的前一天", text: "上个月的前一天",
@ -290,7 +300,7 @@ layui.use(function(){
now.setMonth(now.getMonth() - 1); now.setMonth(now.getMonth() - 1);
now.setDate(now.getDate() - 1); now.setDate(now.getDate() - 1);
return [now]; return [now];
}() }
}, },
{ {
text: "某一天", text: "某一天",
@ -323,7 +333,7 @@ layui.use(function(){
value.push(new Date(date2)); value.push(new Date(date2));
return value; return value;
}() }
}, },
{ {
text: "这个月", text: "这个月",
@ -344,7 +354,7 @@ layui.use(function(){
value.push(new Date(date2)); value.push(new Date(date2));
return value; return value;
}() }
}, },
{ {
text: "下个月", text: "下个月",
@ -365,7 +375,7 @@ layui.use(function(){
value.push(new Date(date2)); value.push(new Date(date2));
return value; return value;
}() }
} }
] ]
}); });
@ -383,7 +393,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setFullYear(now.getFullYear() - 1); now.setFullYear(now.getFullYear() - 1);
return [now, new Date()]; return [now, new Date()];
}() }
}, },
{ {
text: "未来一年", text: "未来一年",
@ -391,7 +401,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setFullYear(now.getFullYear() + 1); now.setFullYear(now.getFullYear() + 1);
return [new Date(), now]; return [new Date(), now];
}() }
}, },
{ {
text: "近三年", text: "近三年",
@ -399,7 +409,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setFullYear(now.getFullYear() - 3); now.setFullYear(now.getFullYear() - 3);
return [now, new Date()]; return [now, new Date()];
}() }
} }
] ]
}); });
@ -420,7 +430,7 @@ layui.use(function(){
date2.setMonth(0, 1); date2.setMonth(0, 1);
date2.setHours(0, 0, 0, 0); date2.setHours(0, 0, 0, 0);
return [date1, date2.getTime() - 1]; return [date1, date2.getTime() - 1];
}() }
}, },
{ {
text: "明年", text: "明年",
@ -428,7 +438,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setFullYear(now.getFullYear() + 1); now.setFullYear(now.getFullYear() + 1);
return [now, now]; return [now, now];
}() }
}, },
{ {
text: "近三年", text: "近三年",
@ -436,7 +446,7 @@ layui.use(function(){
var now = new Date(); var now = new Date();
now.setFullYear(now.getFullYear() - 3); now.setFullYear(now.getFullYear() - 3);
return [now, new Date()]; return [now, new Date()];
}() }
} }
] ]
}); });
@ -457,7 +467,7 @@ layui.use(function(){
date2.setHours(11, 30, 0, 0); date2.setHours(11, 30, 0, 0);
return [date1, date2]; return [date1, date2];
})() })
}, },
{ {
text: '13:00 <p style="text-align: center;"></p> 15:00', text: '13:00 <p style="text-align: center;"></p> 15:00',
@ -469,7 +479,7 @@ layui.use(function(){
date2.setHours(15, 0, 0, 0); date2.setHours(15, 0, 0, 0);
return [date1, date2]; return [date1, date2];
})() })
} }
] ]
}); });
@ -498,7 +508,7 @@ layui.use(function(){
value.push(new Date(date2)); value.push(new Date(date2));
return value; return value;
}() }
}, },
{ {
text: "这个月", text: "这个月",
@ -519,7 +529,7 @@ layui.use(function(){
value.push(new Date(date2)); value.push(new Date(date2));
return value; return value;
}() }
}, },
{ {
text: "下个月", text: "下个月",
@ -540,7 +550,7 @@ layui.use(function(){
value.push(new Date(date2)); value.push(new Date(date2));
return value; return value;
}() }
} }
] ]
}); });

View File

@ -209,12 +209,12 @@ layui.define(['lay', 'util', 'element', 'form'], function(exports){
elemToolbar.on('click', '>i', function(){ elemToolbar.on('click', '>i', function(){
var oi = $(this); var oi = $(this);
var type = oi.data('type'); var type = oi.data('type');
typeof tools[type].event === 'function' && tools[type].event(oi, type); tools[type] && typeof tools[type].event === 'function' && tools[type].event(oi, type);
typeof options.toolsEvent === 'function' && options.toolsEvent(oi, type); typeof options.toolsEvent === 'function' && options.toolsEvent(oi, type);
}); });
layui.each(options.tools, function(i, v){ layui.each(options.tools, function(i, v){
var className = (tools[v] && tools[v].className) || v; var className = (tools[v] && tools[v].className) || v;
var title = tools[v].title || ['']; var title = (tools[v] && tools[v].title) || [''];
elemToolbar.append( elemToolbar.append(
'<i class="layui-icon layui-icon-'+ className +'" data-type="'+ v +'" title="'+ title[0] +'"></i>' '<i class="layui-icon layui-icon-'+ className +'" data-type="'+ v +'" title="'+ title[0] +'"></i>'
); );

View File

@ -591,7 +591,9 @@
return shortcutBtns.join(''); return shortcutBtns.join('');
}()).find('li').on('click', function (event) { }()).find('li').on('click', function (event) {
var btnSetting = options.shortcuts[this.dataset['index']] || {}; 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)) { if (!layui.isArray(value)) {
value = [value]; value = [value];
} }