From c9d3e6e00eebc4509f235a4f22e07b6e968760f5 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Thu, 10 Nov 2022 15:54:22 +0800 Subject: [PATCH 01/13] =?UTF-8?q?laydate=E4=BF=AE=E5=A4=8D=E5=87=A0?= =?UTF-8?q?=E4=B8=AA=E5=B0=8F=E9=97=AE=E9=A2=98=E4=BB=A5=E5=8F=8A=E6=96=B0?= =?UTF-8?q?=E5=A2=9EcalendarLinkage=E9=85=8D=E7=BD=AE=E8=AE=A9=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=80=89=E6=8B=A9=E6=97=A5=E5=8E=86=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/modules/laydate.css | 4 +- src/modules/laydate.js | 223 +++++++++++++++++++++++++++++++----- 2 files changed, 196 insertions(+), 31 deletions(-) diff --git a/src/css/modules/laydate.css b/src/css/modules/laydate.css index caa7840e..aa5624ca 100644 --- a/src/css/modules/laydate.css +++ b/src/css/modules/laydate.css @@ -98,9 +98,11 @@ html #layuicss-laydate{display: none; position: absolute; width: 1989px;} /* 双日历 */ .layui-laydate-range{width: 546px;} -.layui-laydate-range .layui-laydate-main{display: inline-block; vertical-align: middle;width:50%;} +.layui-laydate-range .layui-laydate-main{display: inline-block; vertical-align: middle;max-width: 50%;} .layui-laydate-range .laydate-main-list-1 .layui-laydate-header, .layui-laydate-range .laydate-main-list-1 .layui-laydate-content{border-left: 1px solid #e2e2e2;} +.layui-laydate-range.layui-laydate-linkage .laydate-main-list-0 .laydate-next-m, .layui-laydate-range.layui-laydate-linkage .laydate-main-list-0 .laydate-next-y, +.layui-laydate-range.layui-laydate-linkage .laydate-main-list-1 .laydate-prev-m, .layui-laydate-range.layui-laydate-linkage .laydate-main-list-1 .laydate-prev-y{display: none;} /* 默认简约主题 */ diff --git a/src/modules/laydate.js b/src/modules/laydate.js index 3cac3a65..074cd7e2 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -245,6 +245,9 @@ that.rangeStr = options.range ? ( typeof options.range === 'string' ? options.range : '-' ) : ''; + + //日期范围的日历面板是否联动 + that.calendarLinkage = !!(options.range && options.calendarLinkage && (options.type === 'date' || options.type === 'datetime')) //若 range 参数为数组,则表示为开始日期和结束日期的 input 对象 if(layui.type(options.range) === 'array'){ @@ -394,6 +397,7 @@ ,"class": [ 'layui-laydate' ,options.range ? ' layui-laydate-range' : '' + ,that.calendarLinkage ? ' layui-laydate-linkage' : '' ,isStatic ? (' '+ ELEM_STATIC) : '' ,options.fullPanel ? ' laydate-theme-fullpanel' : '' // 全面版 // ,options.theme && options.theme !== 'default' && !/^#/.test(options.theme) ? (' laydate-theme-' + options.theme) : '' @@ -559,7 +563,7 @@ lay.extend(dateTime, that.systemDate(layui.type(item) === 'date' ? item : new Date(item))) } - if (type === 'time') { + if (type === 'time' || type === 'datetime') { that[['startTime', 'endTime'][i]] = { hours: dateTime.hours, minutes: dateTime.minutes, @@ -568,10 +572,19 @@ } if (type === 'year' || type === 'month' || type === 'time') { that.listYM[i] = [dateTime.year, dateTime.month + 1]; - that.checkDate('limit').calendar(null,i); + that.checkDate('limit').calendar(null, i); that.list(type, i); } else { - that.checkDate('limit').calendar(null,i); + if (that.calendarLinkage) { + if (i === 0) { // 第一个值作为startDate + that.startDate = lay.extend({}, dateTime); + } else { + that.endState = !!(that.startDate && that.endDate); + that.checkDate('limit').calendar(null, null, 'init'); + } + } else { + that.checkDate('limit').calendar(null, i); + } that.closeList(); } }); @@ -670,7 +683,11 @@ that.checkDate(function(){ elem.remove(); //delete options.dateTime; - //delete that.endDate; + delete that.startDate; + delete that.endDate; + delete that.endState; + delete that.startTime; + delete that.endTime; delete laydate.thisId; typeof options.close === 'function' && options.close(that); }); @@ -815,7 +832,15 @@ checkValid(dateTime); }; - if(fn === 'limit') return checkValid(dateTime), that; + if(fn === 'limit') { + if (options.range) { + checkValid(that.calendarLinkage ? that.startDate : dateTime); // 校验开始时间 + checkValid(that.endDate); // 校验结束时间 + } else { + checkValid(dateTime); + } + return that; + } value = value || options.value; if(typeof value === 'string'){ @@ -857,6 +882,7 @@ lay.each([options.dateTime, that.endDate], function(i, item){ initDate(item, value[i], i); }); + that.startDate = lay.extend({}, options.dateTime); } else { initDate(dateTime, value); } @@ -896,6 +922,9 @@ //校验日期有效数字 checkValid(dateTime); if(options.range) checkValid(that.endDate); + if(that.calendarLinkage) { + that.endState = !!(that.startDate && that.endDate); // 初始化选中范围状态 + } //如果初始值格式错误,则纠正初始值 if(error && value){ @@ -991,10 +1020,9 @@ var timestrap = {} var dateTime = opts.index > (opts.time ? 0 : 41) ? that.endDate : options.dateTime; var isOut; - var thisDateTime = lay.extend({}, dateTime, opts.date || {}); - + lay.each({ - now: thisDateTime + now: lay.extend({}, dateTime, opts.date || {}) ,min: options.min ,max: options.max }, function(key, item){ @@ -1063,7 +1091,9 @@ YMD = that.getAsYM(dateTime.year, dateTime.month, 'sub'); } else if(index_ >= startWeek && index_ < thisMaxDate + startWeek){ st = index_ - startWeek; - st + 1 === dateTime.date && item.addClass(THIS); + if (!that.calendarLinkage) { + st + 1 === dateTime.date && item.addClass(THIS); + } } else { st = index_ - thisMaxDate - startWeek; item.addClass('laydate-day-next'); @@ -1098,9 +1128,18 @@ //初始默认选择器 if(isAlone){ //年、月等独立选择器 if(options.range){ + if (that.calendarLinkage) { + value ? that.endDate = (that.endDate || { + year: dateTime.year + (options.type === 'year' ? 1 : 0) + ,month: dateTime.month + (options.type === 'month' ? 0 : -1) + }) : (that.startDate = that.startDate || { + year: dateTime.year + ,month: dateTime.month + }); + } if(value){ that.listYM = [ - [options.dateTime.year, options.dateTime.month + 1] + [(that.startDate || options.dateTime).year, (that.startDate || options.dateTime).month + 1] ,[that.endDate.year, that.endDate.month + 1] ]; that.list(options.type, 0).list(options.type, 1); @@ -1118,9 +1157,17 @@ } //初始赋值双日历 - if(options.range && type === 'init' && !value){ + if(options.range && type === 'init'){ //执行渲染第二个日历 - that.calendar(that.endDate, 1); + if (that.calendarLinkage) { + var EYM = that.getAsYM(dateTime.year, dateTime.month, index ? 'sub' : null) + that.calendar(lay.extend({}, dateTime, { + year: EYM[0] + ,month: EYM[1] + }), 1 - index); // 渲染另外一个 + } else { + that.calendar(that.endDate, 1); + } } // 通过检测当前有效日期,来设定底部按钮状态 @@ -1147,7 +1194,10 @@ // 重置快捷栏选中状态 lay(that.shortcut).find('li.' + THIS).removeClass(THIS); - + + //标记选择范围 + if(that.calendarLinkage && type !== 'init') that.stampRange(); + return that; }; @@ -1334,7 +1384,17 @@ index: 0 }); } else { //范围选择 - that.endDate[type] = ym; + if(isAlone){ //非date/datetime类型 + that.endDate[type] = ym; + } else { + var YM = type === 'year' + ? that.getAsYM(ym, listYM[1] - 1, 'sub') + : that.getAsYM(listYM[0], ym, 'sub'); + lay.extend(dateTime, { + year: YM[0] + ,month: YM[1] + }); + } } //当为年选择器或者年月选择器 @@ -1350,7 +1410,11 @@ that.list('month', index); } } else { - that.checkDate('limit').calendar(null, index); + if (that.calendarLinkage) { + that.checkDate('limit').calendar(null, 0, 'init'); + } else { + that.checkDate('limit').calendar(null, index); + } that.closeList(); } @@ -1451,6 +1515,9 @@ start = start || options.dateTime; end = end || that.endDate; isOut = that.newDate(start).getTime() > that.newDate(end).getTime(); + if(that.calendarLinkage) { + isOut = !that.endState; + } //如果不在有效日期内,直接禁用按钮,否则比较开始和结束日期 (that.limit({ @@ -1476,7 +1543,7 @@ ? lay.extend({}, that.endDate, that.endTime) : ( options.range - ? lay.extend({}, options.dateTime, that.startTime) + ? lay.extend({}, that.calendarLinkage ? that.startDate : options.dateTime, that.startTime) : options.dateTime) ) ,format = laydate.parse(dateTime, that.format, 1); @@ -1549,7 +1616,7 @@ if(!options.isPreview) return; var elemPreview = lay(that.elem).find('.'+ ELEM_PREVIEW) - ,value = options.range ? (that.endDate ? that.parse() : '') : that.parse(); + ,value = options.range ? ((that.calendarLinkage ? that.endState : that.endDate) ? that.parse() : '') : that.parse(); //显示预览 elemPreview.html(value).css({ @@ -1573,6 +1640,51 @@ } }; + //标记范围内的日期 + Class.prototype.stampRange = function(){ + var that = this + ,options = that.config + ,startTime, endTime + ,tds = lay(that.elem).find('td'); + + if(options.range && !that.endState) lay(that.footer).find(ELEM_CONFIRM).addClass(DISABLED); + // if(!that.endState) return; + + startTime = that.startDate && that.newDate({ + year: that.startDate.year + ,month: that.startDate.month + ,date: that.startDate.date + }).getTime(); + + endTime = that.endState && that.endDate && that.newDate({ + year: that.endDate.year + ,month: that.endDate.month + ,date: that.endDate.date + }).getTime(); + + // if(startTime > endTime) return that.hint(TIPS_OUT); + + lay.each(tds, function(i, item){ + var ymd = lay(item).attr('lay-ymd').split('-') + ,thisTime = that.newDate({ + year: ymd[0] + ,month: ymd[1] - 1 + ,date: ymd[2] + }).getTime(); + lay(item).removeClass(ELEM_SELECTED + ' ' + THIS); + if(thisTime === startTime || thisTime === endTime){ + lay(item).addClass( + lay(item).hasClass(ELEM_PREV) || lay(item).hasClass(ELEM_NEXT) + ? ELEM_SELECTED + : THIS + ); + } + if(thisTime > startTime && thisTime < endTime){ + lay(item).addClass(ELEM_SELECTED); + } + }); + }; + //执行 done/change 回调 Class.prototype.done = function(param, type){ var that = this @@ -1599,8 +1711,20 @@ //选择日期 Class.prototype.choose = function(td, index){ var that = this - ,options = that.config - ,dateTime = that.thisDateTime(index) + ,options = that.config; + + if (that.calendarLinkage) { + if (that.endState || !that.startDate) { + // 重新选择或者第一次选择 + index = 0; + that.endState = false; + } else { + index = 1; + that.endState = true; + } + } + + var dateTime = that.thisDateTime(index) ,tds = lay(that.elem).find('td') ,YMD = td.attr('lay-ymd').split('-'); @@ -1643,7 +1767,22 @@ } } }); - that.calendar(null, index).done(null, 'change'); + if (that.calendarLinkage) { + if (!index) { + that.startDate = lay.extend({}, dateTime); + } + if (that.endState && that.newDate(that.startDate) > that.newDate(that.endDate)) { + // 判断是否反选 + var startDate = that.startDate; + that.startDate = that.endDate; + options.dateTime = lay.extend({}, that.startDate); + that.endDate = startDate; + startDate = that.startTime; + that.startTime = that.endTime; + that.endTime = startDate; + } + } + that.calendar(null, that.calendarLinkage ? null : index, that.calendarLinkage ? 'init' : null).done(null, 'change'); } else if(options.position === 'static'){ //直接嵌套的选中 that.calendar().done().done(null, 'change'); //同时执行 done 和 change 回调 } else if(options.type === 'date'){ @@ -1773,33 +1912,57 @@ return { prevYear: function(){ if(addSubYeay('sub')) return; - dateTime.year--; - that.checkDate('limit').calendar(null, index); - that.done(null, 'change'); + if (that.calendarLinkage) { + options.dateTime.year--; + that.checkDate('limit').calendar(null, null, 'init'); + } else { + dateTime.year--; + that.checkDate('limit').calendar(null, index); + that.done(null, 'change'); + } } ,prevMonth: function(){ + if (that.calendarLinkage) { + dateTime = options.dateTime; + } var YM = that.getAsYM(dateTime.year, dateTime.month, 'sub'); lay.extend(dateTime, { year: YM[0] ,month: YM[1] }); - that.checkDate('limit').calendar(null, index); - that.done(null, 'change'); + if (that.calendarLinkage) { + that.checkDate('limit').calendar(null, null, 'init'); + } else { + that.checkDate('limit').calendar(null, index); + that.done(null, 'change'); + } } ,nextMonth: function(){ + if (that.calendarLinkage) { + dateTime = options.dateTime; + } var YM = that.getAsYM(dateTime.year, dateTime.month); lay.extend(dateTime, { year: YM[0] ,month: YM[1] }); - that.checkDate('limit').calendar(null, index); - that.done(null, 'change'); + if (that.calendarLinkage) { + that.checkDate('limit').calendar(null, null, 'init'); + } else { + that.checkDate('limit').calendar(null, index); + that.done(null, 'change'); + } } ,nextYear: function(){ if(addSubYeay()) return; - dateTime.year++ - that.checkDate('limit').calendar(null, index); - that.done(null, 'change'); + if (that.calendarLinkage) { + options.dateTime.year++; + that.checkDate('limit').calendar(null, 0, 'init'); + } else { + dateTime.year++; + that.checkDate('limit').calendar(null, index); + that.done(null, 'change'); + } } }; }; From 2aaea403fa0c568c48b3418ed52afb8abceeffa4 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Fri, 11 Nov 2022 17:38:09 +0800 Subject: [PATCH 02/13] =?UTF-8?q?laydate=E6=8B=93=E5=B1=95calendarLinkage?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E7=9A=84=E9=85=8D=E7=BD=AE=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/laydate.js | 79 +++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/src/modules/laydate.js b/src/modules/laydate.js index 074cd7e2..d1750399 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -248,7 +248,18 @@ //日期范围的日历面板是否联动 that.calendarLinkage = !!(options.range && options.calendarLinkage && (options.type === 'date' || options.type === 'datetime')) - + + //切换日历联动方式 + that.autoCalendarModel = function () { + var state = that.calendarLinkage; + that.calendarLinkage = that.startDate && that.endDate && that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month; + lay(that.elem)[that.calendarLinkage ? 'addClass' : 'removeClass']('layui-laydate-linkage'); + return that.calendarLinkage !== state; // 返回发生了变化 + }; + + //是否自动切换 + that.autoCalendarModel.auto = that.calendarLinkage && options.calendarLinkage === 'auto'; + //若 range 参数为数组,则表示为开始日期和结束日期的 input 对象 if(layui.type(options.range) === 'array'){ that.rangeElem = [ @@ -883,6 +894,10 @@ initDate(item, value[i], i); }); that.startDate = lay.extend({}, options.dateTime); + if (that.autoCalendarModel.auto) { // 自动日历模式 + // 判断联动与否 + that.autoCalendarModel() + } } else { initDate(dateTime, value); } @@ -922,10 +937,8 @@ //校验日期有效数字 checkValid(dateTime); if(options.range) checkValid(that.endDate); - if(that.calendarLinkage) { - that.endState = !!(that.startDate && that.endDate); // 初始化选中范围状态 - } - + that.endState = !that.calendarLinkage || !!(that.startDate && that.endDate); // 初始化选中范围状态 + //如果初始值格式错误,则纠正初始值 if(error && value){ that.setValue( @@ -1166,7 +1179,7 @@ ,month: EYM[1] }), 1 - index); // 渲染另外一个 } else { - that.calendar(that.endDate, 1); + that.calendar(null, 1 - index); } } @@ -1196,7 +1209,7 @@ lay(that.shortcut).find('li.' + THIS).removeClass(THIS); //标记选择范围 - if(that.calendarLinkage && type !== 'init') that.stampRange(); + if(options.range && !isAlone && type !== 'init') that.stampRange(); return that; }; @@ -1644,16 +1657,16 @@ Class.prototype.stampRange = function(){ var that = this ,options = that.config - ,startTime, endTime + ,startTime = that.calendarLinkage ? that.startDate : options.dateTime, endTime ,tds = lay(that.elem).find('td'); if(options.range && !that.endState) lay(that.footer).find(ELEM_CONFIRM).addClass(DISABLED); // if(!that.endState) return; - startTime = that.startDate && that.newDate({ - year: that.startDate.year - ,month: that.startDate.month - ,date: that.startDate.date + startTime = startTime && that.newDate({ + year: startTime.year + ,month: startTime.month + ,date: startTime.date }).getTime(); endTime = that.endState && that.endDate && that.newDate({ @@ -1671,8 +1684,9 @@ ,month: ymd[1] - 1 ,date: ymd[2] }).getTime(); - lay(item).removeClass(ELEM_SELECTED + ' ' + THIS); + that.calendarLinkage && lay(item).removeClass(ELEM_SELECTED + ' ' + THIS); if(thisTime === startTime || thisTime === endTime){ + (that.calendarLinkage || (!that.calendarLinkage && (i < 42 ? thisTime === startTime : thisTime === endTime))) && lay(item).addClass( lay(item).hasClass(ELEM_PREV) || lay(item).hasClass(ELEM_NEXT) ? ELEM_SELECTED @@ -1767,22 +1781,27 @@ } } }); - if (that.calendarLinkage) { - if (!index) { - that.startDate = lay.extend({}, dateTime); - } - if (that.endState && that.newDate(that.startDate) > that.newDate(that.endDate)) { - // 判断是否反选 - var startDate = that.startDate; - that.startDate = that.endDate; - options.dateTime = lay.extend({}, that.startDate); - that.endDate = startDate; - startDate = that.startTime; - that.startTime = that.endTime; - that.endTime = startDate; - } + if (!index) { + that.startDate = lay.extend({}, dateTime); // 同步startDate } - that.calendar(null, that.calendarLinkage ? null : index, that.calendarLinkage ? 'init' : null).done(null, 'change'); + // 根据选择之后判断是否需要切换模式 + var isChange; + if (that.endState && that.autoCalendarModel.auto) { + isChange = that.autoCalendarModel(); + } + if (that.endState && that.newDate(that.startDate) > that.newDate(that.endDate)) { + // 判断是否反选 + var startDate = that.startDate; + that.startDate = lay.extend({}, that.endDate, that.startTime); + options.dateTime = lay.extend({}, that.startDate); + that.endDate = lay.extend({}, startDate, that.endTime); + // startDate = that.startTime; + // that.startTime = that.endTime; + // that.endTime = startDate; + } + isChange && (options.dateTime = lay.extend({}, that.startDate)); + that.calendar(null, that.calendarLinkage ? null : index, isChange || that.calendarLinkage ? 'init' : null).done(null, 'change'); + // that.calendar(null, null, 'init').done(null, 'change'); } else if(options.position === 'static'){ //直接嵌套的选中 that.calendar().done().done(null, 'change'); //同时执行 done 和 change 回调 } else if(options.type === 'date'){ @@ -1918,6 +1937,7 @@ } else { dateTime.year--; that.checkDate('limit').calendar(null, index); + that.choose(lay(elemCont).find('td.layui-this'), index); that.done(null, 'change'); } } @@ -1934,6 +1954,7 @@ that.checkDate('limit').calendar(null, null, 'init'); } else { that.checkDate('limit').calendar(null, index); + that.choose(lay(elemCont).find('td.layui-this'), index); that.done(null, 'change'); } } @@ -1950,6 +1971,7 @@ that.checkDate('limit').calendar(null, null, 'init'); } else { that.checkDate('limit').calendar(null, index); + that.choose(lay(elemCont).find('td.layui-this'), index); that.done(null, 'change'); } } @@ -1961,6 +1983,7 @@ } else { dateTime.year++; that.checkDate('limit').calendar(null, index); + that.choose(lay(elemCont).find('td.layui-this'), index); that.done(null, 'change'); } } From c96b6fb86f033ab0733759ee5eee048dc4cd2989 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Fri, 11 Nov 2022 19:30:00 +0800 Subject: [PATCH 03/13] =?UTF-8?q?laydate=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/laydate.js | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/modules/laydate.js b/src/modules/laydate.js index d1750399..aeeea6b7 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -252,7 +252,7 @@ //切换日历联动方式 that.autoCalendarModel = function () { var state = that.calendarLinkage; - that.calendarLinkage = that.startDate && that.endDate && that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month; + that.calendarLinkage = (options.range && (options.type === 'date' || options.type === 'datetime')) && that.startDate && that.endDate && that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month; lay(that.elem)[that.calendarLinkage ? 'addClass' : 'removeClass']('layui-laydate-linkage'); return that.calendarLinkage !== state; // 返回发生了变化 }; @@ -583,22 +583,15 @@ } if (type === 'year' || type === 'month' || type === 'time') { that.listYM[i] = [dateTime.year, dateTime.month + 1]; - that.checkDate('limit').calendar(null, i); - that.list(type, i); } else { - if (that.calendarLinkage) { - if (i === 0) { // 第一个值作为startDate - that.startDate = lay.extend({}, dateTime); - } else { - that.endState = !!(that.startDate && that.endDate); - that.checkDate('limit').calendar(null, null, 'init'); - } + if (i === 0) { // 第一个值作为startDate + that.startDate = lay.extend({}, dateTime); } else { - that.checkDate('limit').calendar(null, i); + that.autoCalendarModel.auto && that.autoCalendarModel(); } - that.closeList(); } }); + that.checkDate('limit').calendar(null, null, 'init'); var timeBtn = lay(that.footer).find('.'+ ELEM_TIME_BTN).removeClass(DISABLED); timeBtn && timeBtn.attr('lay-type') === 'date' && timeBtn[0].click(); @@ -847,6 +840,7 @@ if (options.range) { checkValid(that.calendarLinkage ? that.startDate : dateTime); // 校验开始时间 checkValid(that.endDate); // 校验结束时间 + that.endState = !that.calendarLinkage || !!(that.startDate && that.endDate); } else { checkValid(dateTime); } @@ -1141,16 +1135,16 @@ //初始默认选择器 if(isAlone){ //年、月等独立选择器 if(options.range){ - if (that.calendarLinkage) { - value ? that.endDate = (that.endDate || { - year: dateTime.year + (options.type === 'year' ? 1 : 0) - ,month: dateTime.month + (options.type === 'month' ? 0 : -1) - }) : (that.startDate = that.startDate || { - year: dateTime.year - ,month: dateTime.month - }); - } - if(value){ + // if (that.calendarLinkage) { + // value ? that.endDate = (that.endDate || { + // year: dateTime.year + (options.type === 'year' ? 1 : 0) + // ,month: dateTime.month + (options.type === 'month' ? 0 : -1) + // }) : (that.startDate = that.startDate || { + // year: dateTime.year + // ,month: dateTime.month + // }); + // } + if(value || type !== 'init'){ // 判断是否需要显示年月时间列表 that.listYM = [ [(that.startDate || options.dateTime).year, (that.startDate || options.dateTime).month + 1] ,[that.endDate.year, that.endDate.month + 1] From 84f92c0a7e92327d5b05974e4f29d5333e72930d Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Mon, 14 Nov 2022 17:09:48 +0800 Subject: [PATCH 04/13] =?UTF-8?q?laydate=E4=BF=AE=E5=A4=8D=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/laydate.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/modules/laydate.js b/src/modules/laydate.js index aeeea6b7..a848ff65 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -254,7 +254,7 @@ var state = that.calendarLinkage; that.calendarLinkage = (options.range && (options.type === 'date' || options.type === 'datetime')) && that.startDate && that.endDate && that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month; lay(that.elem)[that.calendarLinkage ? 'addClass' : 'removeClass']('layui-laydate-linkage'); - return that.calendarLinkage !== state; // 返回发生了变化 + return that.calendarLinkage != state; // 返回发生了变化 }; //是否自动切换 @@ -887,11 +887,6 @@ lay.each([options.dateTime, that.endDate], function(i, item){ initDate(item, value[i], i); }); - that.startDate = lay.extend({}, options.dateTime); - if (that.autoCalendarModel.auto) { // 自动日历模式 - // 判断联动与否 - that.autoCalendarModel() - } } else { initDate(dateTime, value); } @@ -931,7 +926,6 @@ //校验日期有效数字 checkValid(dateTime); if(options.range) checkValid(that.endDate); - that.endState = !that.calendarLinkage || !!(that.startDate && that.endDate); // 初始化选中范围状态 //如果初始值格式错误,则纠正初始值 if(error && value){ @@ -976,6 +970,10 @@ that.hint('value ' + lang.invalidDate + lang.formatError[1]); } + that.startDate = that.startDate || lay.extend({}, options.dateTime); + that.endState = !that.calendarLinkage || !!(that.startDate && that.endDate); // 初始化选中范围状态 + that.autoCalendarModel.auto && that.autoCalendarModel(); + fn && fn(); return that; }; @@ -1522,10 +1520,7 @@ start = start || options.dateTime; end = end || that.endDate; isOut = that.newDate(start).getTime() > that.newDate(end).getTime(); - if(that.calendarLinkage) { - isOut = !that.endState; - } - + //如果不在有效日期内,直接禁用按钮,否则比较开始和结束日期 (that.limit({ date: start @@ -1783,15 +1778,18 @@ if (that.endState && that.autoCalendarModel.auto) { isChange = that.autoCalendarModel(); } - if (that.endState && that.newDate(that.startDate) > that.newDate(that.endDate)) { + var isSameDate = that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month && that.startDate.date === that.endDate.date; + if (that.calendarLinkage && that.endState && that.newDate(that.startDate) > that.newDate(that.endDate)) { // 判断是否反选 var startDate = that.startDate; - that.startDate = lay.extend({}, that.endDate, that.startTime); + that.startDate = lay.extend({}, that.endDate, isSameDate ? {} : that.startTime); options.dateTime = lay.extend({}, that.startDate); - that.endDate = lay.extend({}, startDate, that.endTime); - // startDate = that.startTime; - // that.startTime = that.endTime; - // that.endTime = startDate; + that.endDate = lay.extend({}, startDate, isSameDate ? {} : that.endTime); + isSameDate && ( // 如果是同一天并且出现了反选证明是时分秒出现开始时间大于结束时间的现象 + startDate = that.startTime, + that.startTime = that.endTime, + that.endTime = startDate + ) } isChange && (options.dateTime = lay.extend({}, that.startDate)); that.calendar(null, that.calendarLinkage ? null : index, isChange || that.calendarLinkage ? 'init' : null).done(null, 'change'); From 37eb2c6a4f7adfaca9a04dc878eb2fef25736cd8 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Tue, 15 Nov 2022 17:40:41 +0800 Subject: [PATCH 05/13] =?UTF-8?q?laydate=E4=BF=AE=E5=A4=8D=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/laydate.js | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/modules/laydate.js b/src/modules/laydate.js index a848ff65..3393e972 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -1210,7 +1210,7 @@ Class.prototype.list = function(type, index){ var that = this ,options = that.config - ,dateTime = options.dateTime + ,dateTime = that.calendarLinkage ? options.dateTime : [options.dateTime, that.endDate][index] ,lang = that.lang() ,isAlone = options.range && options.type !== 'date' && options.type !== 'datetime' //独立范围选择器 @@ -1382,24 +1382,13 @@ lay(ul).find('li').on('click', function(){ var ym = lay(this).attr('lay-ym') | 0; if(lay(this).hasClass(DISABLED)) return; - if(index === 0){ - dateTime[type] = ym; - that.limit({ - elem: lay(that.footer).find(ELEM_CONFIRM), - index: 0 + if (that.calendarLinkage) { + lay.extend(dateTime, { + year: type === 'year' ? ym : listYM[0] + ,month: type === 'year' ? listYM[1] - 1 : ym }); - } else { //范围选择 - if(isAlone){ //非date/datetime类型 - that.endDate[type] = ym; - } else { - var YM = type === 'year' - ? that.getAsYM(ym, listYM[1] - 1, 'sub') - : that.getAsYM(listYM[0], ym, 'sub'); - lay.extend(dateTime, { - year: YM[0] - ,month: YM[1] - }); - } + } else { + dateTime[type] = ym; } //当为年选择器或者年月选择器 @@ -1415,11 +1404,8 @@ that.list('month', index); } } else { - if (that.calendarLinkage) { - that.checkDate('limit').calendar(null, 0, 'init'); - } else { - that.checkDate('limit').calendar(null, index); - } + that.checkDate('limit').calendar(dateTime, index, 'init'); // 重新渲染一下两个面板 + that.calendarLinkage || that.choose(lay(elemCont).find('td.layui-this'), index); that.closeList(); } @@ -1517,7 +1503,7 @@ ,lang = that.lang() ,isOut, elemBtn = lay(that.footer).find(ELEM_CONFIRM); if(options.range && options.type !== 'time'){ - start = start || options.dateTime; + start = start || that.startDate || options.dateTime; end = end || that.endDate; isOut = that.newDate(start).getTime() > that.newDate(end).getTime(); @@ -1673,7 +1659,7 @@ ,month: ymd[1] - 1 ,date: ymd[2] }).getTime(); - that.calendarLinkage && lay(item).removeClass(ELEM_SELECTED + ' ' + THIS); + lay(item).removeClass(ELEM_SELECTED + ' ' + THIS); if(thisTime === startTime || thisTime === endTime){ (that.calendarLinkage || (!that.calendarLinkage && (i < 42 ? thisTime === startTime : thisTime === endTime))) && lay(item).addClass( From 1d9056bd0ca59f20a15c6f0792f43fbd32cb62c6 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Wed, 16 Nov 2022 11:04:06 +0800 Subject: [PATCH 06/13] =?UTF-8?q?laydate=E4=BF=AE=E5=A4=8D=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=97=AE=E9=A2=98=EF=BC=9B=E4=BF=AE=E5=A4=8Dgulp?= =?UTF-8?q?=E6=89=93=E5=8C=85=E7=8B=AC=E7=AB=8B=E7=BB=84=E4=BB=B6laydate?= =?UTF-8?q?=E7=9A=84=E5=91=BD=E4=BB=A4=E8=AF=AD=E5=8F=A5=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=88=B0=E6=9C=80=E6=96=B0=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E5=AF=BC=E8=87=B4=E6=89=93=E5=8C=85=E5=87=BA=E6=9D=A5?= =?UTF-8?q?=E7=9A=84laydate=E7=8B=AC=E7=AB=8B=E7=BB=84=E4=BB=B6=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=BD=BF=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gulpfile.js | 6 ++++-- src/modules/lay.js | 2 +- src/modules/laydate.js | 12 ++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 77f64418..7e33e880 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -136,9 +136,11 @@ exports.laydate = () => { // gulp laydate // js return gulp.src(['./src/layui.js', './src/modules/{lay,laydate}.js']) .pipe(replace('win.layui =', 'var layui =')) // 将 layui 替换为局部变量 - .pipe(replace('})(window); //gulp build: layui-footer', '')) // 替换 layui.js 的落脚 - .pipe(replace('(function(window){ //gulp build: lay-header', '')) // 替换 lay.js 的头部 + .pipe(replace('}(window); //gulp build: layui-footer', '')) // 替换 layui.js 的落脚 + .pipe(replace(';!function(window){ //gulp build: lay-header', '')) // 替换 lay.js 的头部 + .pipe(replace('}(window, window.document); //gulp build: lay-footer', '')) // 替换 lay.js 的落脚 .pipe(concat('laydate.js', {newLine: ''})) + .pipe(replace(';!function(window, document){ //gulp build: laydate-header', '')) // 替换 laydate.js 的头部 .pipe(header.apply(null, comment)) //追加头部 .pipe(gulp.dest(dest + 'src')); }; diff --git a/src/modules/lay.js b/src/modules/lay.js index 427c9359..fceff512 100644 --- a/src/modules/lay.js +++ b/src/modules/lay.js @@ -428,4 +428,4 @@ }); } -}(window, window.document); \ No newline at end of file +}(window, window.document); //gulp build: lay-footer \ No newline at end of file diff --git a/src/modules/laydate.js b/src/modules/laydate.js index 3393e972..102339a8 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -1,6 +1,6 @@ /** layDate 日期与时间控件 | MIT Licensed */ -;!function(window, document){ +;!function(window, document){ //gulp build: laydate-header "use strict"; var isLayui = window.layui && layui.define, ready = { @@ -42,7 +42,7 @@ ,ready: function(callback){ var cssname = 'laydate'; var ver = '' - var path = (isLayui ? 'modules/' : 'css/') + 'laydate.css?v='+ laydate.v + ver; + var path = (isLayui ? 'modules/' : '') + 'laydate.css?v='+ laydate.v + ver; isLayui ? ( layui['layui.all'] @@ -1503,7 +1503,7 @@ ,lang = that.lang() ,isOut, elemBtn = lay(that.footer).find(ELEM_CONFIRM); if(options.range && options.type !== 'time'){ - start = start || that.startDate || options.dateTime; + start = start || (that.calendarLinkage ? that.startDate : options.dateTime); end = end || that.endDate; isOut = that.newDate(start).getTime() > that.newDate(end).getTime(); @@ -1699,6 +1699,8 @@ //选择日期 Class.prototype.choose = function(td, index){ + if(td.hasClass(DISABLED)) return; + var that = this ,options = that.config; @@ -1723,9 +1725,7 @@ ,month: (YMD[1] | 0) - 1 ,date: YMD[2] | 0 }; - - if(td.hasClass(DISABLED)) return; - + lay.extend(dateTime, YMD); //同步 dateTime //范围选择 From d1b8932ca64353d91c0589906cf9340b395a9b4e Mon Sep 17 00:00:00 2001 From: mek <573883887@qq.com> Date: Thu, 17 Nov 2022 16:18:24 +0800 Subject: [PATCH 07/13] =?UTF-8?q?input=E7=9A=84type=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/transfer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/transfer.js b/src/modules/transfer.js index b1aecb9e..8c85dce4 100644 --- a/src/modules/transfer.js +++ b/src/modules/transfer.js @@ -73,7 +73,7 @@ layui.define(['laytpl', 'form'], function(exports){ ,'{{# if(d.data.showSearch){ }}' ,'' ,'{{# } }}' ,'' From 469f1d9f0161436070fd8f4ec3f9143f8d8031b8 Mon Sep 17 00:00:00 2001 From: mek <573883887@qq.com> Date: Fri, 18 Nov 2022 08:58:25 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=88=86=E5=8F=B7?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6=E9=87=8C?= =?UTF-8?q?=EF=BC=8C=E7=BC=96=E7=A0=81=E9=A3=8E=E6=A0=BC=E5=BB=BA=E8=AE=AE?= =?UTF-8?q?=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layui.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/layui.js b/src/layui.js index d370be40..8c9bb507 100644 --- a/src/layui.js +++ b/src/layui.js @@ -149,7 +149,7 @@ (function poll() { if(++timeout > config.timeout * 1000 / 4){ return error(item + ' is not a valid module', 'error'); - }; + } config.status[item] ? onCallback() : setTimeout(poll, 4); }()); } @@ -222,7 +222,7 @@ (function poll() { if(++timeout > config.timeout * 1000 / 4){ return error(item + ' is not a valid module', 'error'); - }; + } (typeof config.modules[item] === 'string' && config.status[item]) ? onCallback() : setTimeout(poll, 4); @@ -286,7 +286,7 @@ //如果轮询超过指定秒数,则视为请求文件失败或 css 文件不符合规范 if(++timeout > config.timeout * 1000 / delay){ return error(href + ' timeout'); - }; + } //css 加载就绪 if(parseInt(that.getStyle(getLinkElem, 'width')) === 1989){ @@ -672,7 +672,7 @@ } else { //数字 vs 数字 return v1 - v2; } - }; + } /** * 字典序排序 From f61a3850ff098ef074b231e3a3ac77d69dfe2d9c Mon Sep 17 00:00:00 2001 From: mek <573883887@qq.com> Date: Fri, 18 Nov 2022 10:41:46 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9Aif..esle=E5=88=A4=E6=96=AD=E5=86=97=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/rate.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/modules/rate.js b/src/modules/rate.js index 9c07ae5b..c0a77d44 100644 --- a/src/modules/rate.js +++ b/src/modules/rate.js @@ -87,16 +87,8 @@ layui.define('jquery',function(exports){ + (i>Math.floor(options.value)?ICON_RATE:ICON_RATE_SOLID) + '" '+ style +'>'; - if(options.half){ - if(parseInt(options.value) !== options.value){ - if(i == Math.ceil(options.value)){ - temp = temp + '
  • '; - }else{ - temp = temp + item - } - }else{ - temp = temp + item - } + if(options.half&&parseInt(options.value) !== options.value&&i == Math.ceil(options.value)){ + temp = temp + '
  • '; }else{ temp = temp +item; } From 93f8f6a48e1f9492e21de853f2aac28fd2af78b5 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Fri, 18 Nov 2022 16:42:47 +0800 Subject: [PATCH 10/13] =?UTF-8?q?laydate=E4=BF=AE=E5=A4=8D=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E8=81=94=E5=8A=A8=E7=9A=84=E4=B8=80=E4=BA=9B=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/modules/laydate.css | 8 ++--- src/modules/laydate.js | 61 +++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/css/modules/laydate.css b/src/css/modules/laydate.css index aa5624ca..580c5820 100644 --- a/src/css/modules/laydate.css +++ b/src/css/modules/laydate.css @@ -113,8 +113,8 @@ html #layuicss-laydate{display: none; position: absolute; width: 1989px;} .layui-laydate-content{border-top: none 0; border-bottom: none 0;} .layui-laydate-content th{color: #333;} .layui-laydate-content td{color: #666;} -.layui-laydate-content td.laydate-selected{background-color: #B5FFF8;} -.laydate-selected:hover{background-color: #00F7DE !important;} +.layui-laydate-content td.laydate-selected>div{background-color: #00F7DE;} +.laydate-selected:hover>div{background-color: #00F7DE !important;} .layui-laydate-content td>div:hover, .layui-laydate-list li:hover, .layui-laydate-shortcut>li:hover{background-color: #eee; color: #333;} @@ -123,8 +123,8 @@ html #layuicss-laydate{display: none; position: absolute; width: 1989px;} .laydate-time-list>li:hover{background: none;} .layui-laydate-content .laydate-day-prev, .layui-laydate-content .laydate-day-next{color: #d2d2d2;} -.laydate-selected.laydate-day-prev, -.laydate-selected.laydate-day-next{background-color: #f8f8f8 !important;} +.laydate-selected.laydate-day-prev>div, +.laydate-selected.laydate-day-next>div{background-color: #f8f8f8 !important;} .layui-laydate-footer{border-top: 1px solid #e2e2e2;} .layui-laydate-hint{color: #FF5722;} .laydate-day-mark::after{background-color: #5FB878;} diff --git a/src/modules/laydate.js b/src/modules/laydate.js index 102339a8..631d6365 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -252,7 +252,8 @@ //切换日历联动方式 that.autoCalendarModel = function () { var state = that.calendarLinkage; - that.calendarLinkage = (options.range && (options.type === 'date' || options.type === 'datetime')) && that.startDate && that.endDate && that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month; + that.calendarLinkage = (options.range && (options.type === 'date' || options.type === 'datetime')) + && that.startDate && that.endDate && that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month; lay(that.elem)[that.calendarLinkage ? 'addClass' : 'removeClass']('layui-laydate-linkage'); return that.calendarLinkage != state; // 返回发生了变化 }; @@ -839,8 +840,7 @@ if(fn === 'limit') { if (options.range) { checkValid(that.calendarLinkage ? that.startDate : dateTime); // 校验开始时间 - checkValid(that.endDate); // 校验结束时间 - that.endState = !that.calendarLinkage || !!(that.startDate && that.endDate); + that.endDate && checkValid(that.endDate); // 校验结束时间 } else { checkValid(dateTime); } @@ -1709,6 +1709,7 @@ // 重新选择或者第一次选择 index = 0; that.endState = false; + that.endDate = {}; } else { index = 1; that.endState = true; @@ -1759,27 +1760,29 @@ if (!index) { that.startDate = lay.extend({}, dateTime); // 同步startDate } - // 根据选择之后判断是否需要切换模式 - var isChange; - if (that.endState && that.autoCalendarModel.auto) { - isChange = that.autoCalendarModel(); + // 校验另外一个日期是否在有效的范围内 + if (that.endState && !that.limit({date: that.thisDateTime(1 - index)})) { + // 根据选择之后判断是否需要切换模式 + var isChange; + if (that.endState && that.autoCalendarModel.auto) { + isChange = that.autoCalendarModel(); + } + var isSameDate = that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month && that.startDate.date === that.endDate.date; + if (that.calendarLinkage && that.endState && that.newDate(that.startDate) > that.newDate(that.endDate)) { + // 判断是否反选 + var startDate = that.startDate; + that.startDate = lay.extend({}, that.endDate, isSameDate ? {} : that.startTime); + options.dateTime = lay.extend({}, that.startDate); + that.endDate = lay.extend({}, startDate, isSameDate ? {} : that.endTime); + isSameDate && ( // 如果是同一天并且出现了反选证明是时分秒出现开始时间大于结束时间的现象 + startDate = that.startTime, + that.startTime = that.endTime, + that.endTime = startDate + ) + } + isChange && (options.dateTime = lay.extend({}, that.startDate)); } - var isSameDate = that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month && that.startDate.date === that.endDate.date; - if (that.calendarLinkage && that.endState && that.newDate(that.startDate) > that.newDate(that.endDate)) { - // 判断是否反选 - var startDate = that.startDate; - that.startDate = lay.extend({}, that.endDate, isSameDate ? {} : that.startTime); - options.dateTime = lay.extend({}, that.startDate); - that.endDate = lay.extend({}, startDate, isSameDate ? {} : that.endTime); - isSameDate && ( // 如果是同一天并且出现了反选证明是时分秒出现开始时间大于结束时间的现象 - startDate = that.startTime, - that.startTime = that.endTime, - that.endTime = startDate - ) - } - isChange && (options.dateTime = lay.extend({}, that.startDate)); that.calendar(null, that.calendarLinkage ? null : index, isChange || that.calendarLinkage ? 'init' : null).done(null, 'change'); - // that.calendar(null, null, 'init').done(null, 'change'); } else if(options.position === 'static'){ //直接嵌套的选中 that.calendar().done().done(null, 'change'); //同时执行 done 和 change 回调 } else if(options.type === 'date'){ @@ -1928,10 +1931,9 @@ year: YM[0] ,month: YM[1] }); - if (that.calendarLinkage) { - that.checkDate('limit').calendar(null, null, 'init'); - } else { - that.checkDate('limit').calendar(null, index); + + that.checkDate('limit').calendar(null, null, 'init'); + if (!that.calendarLinkage) { that.choose(lay(elemCont).find('td.layui-this'), index); that.done(null, 'change'); } @@ -1945,10 +1947,9 @@ year: YM[0] ,month: YM[1] }); - if (that.calendarLinkage) { - that.checkDate('limit').calendar(null, null, 'init'); - } else { - that.checkDate('limit').calendar(null, index); + + that.checkDate('limit').calendar(null, null, 'init'); + if (!that.calendarLinkage) { that.choose(lay(elemCont).find('td.layui-this'), index); that.done(null, 'change'); } From af0b38385c0650a429f90019d30533284423a2d7 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Mon, 28 Nov 2022 14:09:50 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtable=E6=9C=89=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E5=88=97=E7=9A=84=E5=A4=8D=E6=9D=82=E8=A1=A8=E5=A4=B4?= =?UTF-8?q?=EF=BC=8C=E7=AD=9B=E9=80=89=E5=88=97=E4=B9=8B=E5=90=8E=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E7=9A=84=E5=9B=BA=E5=AE=9A=E5=88=97=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E8=B7=9F=E6=9C=AC=E4=BD=93=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9Btable=E5=AD=97=E6=AE=B5=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=B0=E5=A2=9EfieldTitle=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=AD=9B=E9=80=89=E5=88=97=E5=92=8C=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index fcb87d77..9e407a1b 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -438,18 +438,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ // 让表格平铺 that.fullSize(); - // 如果多级表头,则填补表头高度 - if(options.cols.length > 1){ - // 补全高度 - var th = that.layFixed.find(ELEM_HEADER).find('th'); - // 固定列表头同步跟本体 th 一致高度 - var headerMain = that.layHeader.first(); - layui.each(th, function (thIndex, thElem) { - thElem = $(thElem); - thElem.height(headerMain.find('th[data-key="' + thElem.attr('data-key') + '"]').height() + 'px'); - }) - } - that.pullData(that.page); //请求数据 that.events(); //事件 }; @@ -1593,6 +1581,18 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } else { that.layMain.outerHeight(bodyHeight); } + + // 如果多级表头,则填补表头高度 + if(options.cols.length > 1){ + // 补全高度 + var th = that.layFixed.find(ELEM_HEADER).find('th'); + // 固定列表头同步跟本体 th 一致高度 + var headerMain = that.layHeader.first(); + layui.each(th, function (thIndex, thElem) { + thElem = $(thElem); + thElem.height(headerMain.find('th[data-key="' + thElem.attr('data-key') + '"]').height() + 'px'); + }) + } }; //获取滚动条宽度 @@ -1702,7 +1702,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ var lis = []; that.eachCols(function(i, item){ if(item.field && item.type == 'normal'){ - lis.push('
  • '); + lis.push('
  • '); } }); return lis.join(''); @@ -2503,7 +2503,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ if(content === undefined || content === null) content = ''; - i1 == 0 && dataTitle.push(item3.title || ''); + i1 == 0 && dataTitle.push(item3.fieldTitle || item3.title || item3.field || ''); vals.push('"'+ parseTempData.call(thatTable, { item3: item3 ,content: content From 751c5cbe7b7169f414896e0a70673b950aeffabf Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Mon, 28 Nov 2022 14:47:51 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtable=E6=9C=89=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E5=88=97=E7=9A=84=E5=A4=8D=E6=9D=82=E8=A1=A8=E5=A4=B4?= =?UTF-8?q?=EF=BC=8C=E7=AD=9B=E9=80=89=E5=88=97=E4=B9=8B=E5=90=8E=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E7=9A=84=E5=9B=BA=E5=AE=9A=E5=88=97=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E8=B7=9F=E6=9C=AC=E4=BD=93=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9Btable=E5=AD=97=E6=AE=B5=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=B0=E5=A2=9EfieldTitle=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=AD=9B=E9=80=89=E5=88=97=E5=92=8C=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index 9e407a1b..a36b2880 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -629,10 +629,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ hide ? parentColspan-- : parentColspan++; parentTh.attr('colspan', parentColspan); - parentTh[parentColspan < 1 ? 'addClass' : 'removeClass'](HIDE); - + parentTh[parentColspan >= 1 || !hide ? 'removeClass' : 'addClass'](HIDE); // 如果子列显示,父列必然需要显示 + getThisCol.colspan = parentColspan; //同步 colspan 参数 - getThisCol.hide = parentColspan < 1; //同步 hide 参数 + getThisCol.hide = parentColspan >= 1 || !hide; //同步 hide 参数 //递归,继续往上查询是否有父列 var nextParentKey = parentTh.data('parentkey'); @@ -1550,6 +1550,19 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ if (height < 135) height = 135; that.elem.css("height", height); } + + // debugger; + // 如果多级表头,则填补表头高度 + if(options.cols.length > 1){ + // 补全高度 + var th = that.layFixed.find(ELEM_HEADER).find('th'); + // 固定列表头同步跟本体 th 一致高度 + var headerMain = that.layHeader.first(); + layui.each(th, function (thIndex, thElem) { + thElem = $(thElem); + thElem.height(headerMain.find('th[data-key="' + thElem.attr('data-key') + '"]').height() + 'px'); + }) + } if(!height) return; @@ -1581,18 +1594,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } else { that.layMain.outerHeight(bodyHeight); } - - // 如果多级表头,则填补表头高度 - if(options.cols.length > 1){ - // 补全高度 - var th = that.layFixed.find(ELEM_HEADER).find('th'); - // 固定列表头同步跟本体 th 一致高度 - var headerMain = that.layHeader.first(); - layui.each(th, function (thIndex, thElem) { - thElem = $(thElem); - thElem.height(headerMain.find('th[data-key="' + thElem.attr('data-key') + '"]').height() + 'px'); - }) - } }; //获取滚动条宽度 @@ -1725,6 +1726,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ ](HIDE); // 根据列的显示隐藏,同步多级表头的父级相关属性值 + debugger; if(hide != col.hide){ that.setParentCol(!checked, parentKey); } From f317a8ffc54255d212576f4c52fd340911a5e4dc Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Mon, 28 Nov 2022 14:48:31 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtable=E6=9C=89=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E5=88=97=E7=9A=84=E5=A4=8D=E6=9D=82=E8=A1=A8=E5=A4=B4?= =?UTF-8?q?=EF=BC=8C=E7=AD=9B=E9=80=89=E5=88=97=E4=B9=8B=E5=90=8E=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E7=9A=84=E5=9B=BA=E5=AE=9A=E5=88=97=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E8=B7=9F=E6=9C=AC=E4=BD=93=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9Btable=E5=AD=97=E6=AE=B5=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=B0=E5=A2=9EfieldTitle=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=AD=9B=E9=80=89=E5=88=97=E5=92=8C=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index a36b2880..a780d981 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -1551,7 +1551,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ that.elem.css("height", height); } - // debugger; // 如果多级表头,则填补表头高度 if(options.cols.length > 1){ // 补全高度 @@ -1726,7 +1725,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ ](HIDE); // 根据列的显示隐藏,同步多级表头的父级相关属性值 - debugger; if(hide != col.hide){ that.setParentCol(!checked, parentKey); }