From 21f89d1d9554337109ee7b2e210ed31da7173b42 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Fri, 6 Jan 2023 17:32:10 +0800 Subject: [PATCH 1/5] =?UTF-8?q?table=E4=BF=AE=E5=A4=8D=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E4=B9=8B=E5=90=8EreloadData=E8=AE=BE=E7=BD=AE=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E6=BB=9A=E5=8A=A8=E6=9D=A1=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E8=BF=98=E6=98=AF=E5=8F=91=E7=94=9F=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E6=9D=A1=E5=9B=9E=E9=9B=B6=E7=8E=B0=E8=B1=A1=EF=BC=9B=E6=96=B0?= =?UTF-8?q?=E5=A2=9Etable.refresh=E6=94=AF=E6=8C=81=E5=B0=86cache=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=87=8D=E6=96=B0=E6=B8=B2=E6=9F=93=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 362 ++++++++++++++++++++++--------------------- 1 file changed, 187 insertions(+), 175 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index a780d981..b56460c3 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -1023,6 +1023,177 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } }; + // 渲染视图 + Class.prototype.renderView = function (sort, type) { + var that = this; + var options = that.config; + + var data = table.cache[that.key]; + + var trs = []; + var trs_fixed = []; + var trs_fixed_r = []; + + options.HAS_SET_COLS_PATCH || that.setColsPatch(); + options.HAS_SET_COLS_PATCH = true; + + var thisCheckedRowIndex; + if(!sort && that.sortKey){ + return that.sort(that.sortKey.field, that.sortKey.sort, true); + } + layui.each(data, function(i1, item1){ + var tds = [], tds_fixed = [], tds_fixed_r = [] + ,numbers = i1 + options.limit*(that.page - 1) + 1; // 序号 + + // 数组值是否为 object,如果不是,则自动转为 object + if(typeof item1 !== 'object'){ + data[i1] = item1 = {LAY_KEY: item1}; + try { + table.cache[that.key][i1] = item1; + } catch(e) {} + } + + //若数据项为空数组,则不往下执行(因为删除数据时,会将原有数据设置为 []) + if(layui.type(item1) === 'array' && item1.length === 0) return; + + // 加入序号保留字段 + item1[table.config.numbersName] = numbers; + + // 记录下标索引,用于恢复排序 + if(!sort) item1[table.config.indexName] = i1; + + // 遍历表头 + that.eachCols(function(i3, item3){ + var field = item3.field || i3; + var key = item3.key; + var content = item1[field]; + + if(content === undefined || content === null) content = ''; + if(item3.colGroup) return; + + // td 内容 + var td = ['' + ,'
' + + function(){ + var tplData = $.extend(true, { + LAY_COL: item3 + }, item1); + var checkName = table.config.checkName; + var disabledName = table.config.disabledName; + + //渲染不同风格的列 + switch(item3.type){ + case 'checkbox': // 复选 + return ''; + break; + case 'radio': // 单选 + if(tplData[checkName]){ + thisCheckedRowIndex = i1; + } + return ''; + break; + case 'numbers': + return numbers; + break; + }; + + //解析工具列模板 + if(item3.toolbar){ + return laytpl($(item3.toolbar).html()||'').render(tplData); + } + return parseTempData.call(that, { + item3: item3 + ,content: content + ,tplData: tplData + }); + }() + ,'
'].join(''); + + tds.push(td); + if(item3.fixed && item3.fixed !== 'right') tds_fixed.push(td); + if(item3.fixed === 'right') tds_fixed_r.push(td); + }); + + trs.push(''+ tds.join('') + ''); + trs_fixed.push(''+ tds_fixed.join('') + ''); + trs_fixed_r.push(''+ tds_fixed_r.join('') + ''); + }); + + // 容器的滚动条位置 + if(!(options.scrollPos === 'fixed' && type === 'reloadData')){ + that.layBody.scrollTop(0); + } + if(options.scrollPos === 'reset'){ + that.layBody.scrollLeft(0); + } + + that.layMain.find('.'+ NONE).remove(); + that.layMain.find('tbody').html(trs.join('')); + that.layFixLeft.find('tbody').html(trs_fixed.join('')); + that.layFixRight.find('tbody').html(trs_fixed_r.join('')); + + that.renderForm(); + typeof thisCheckedRowIndex === 'number' && that.setThisRowChecked(thisCheckedRowIndex); + that.syncCheckAll(); + + // 因为 page 参数有可能发生变化 先重新铺满 + that.fullSize(); + + // 滚动条补丁 + that.haveInit ? that.scrollPatch() : setTimeout(function(){ + that.scrollPatch(); + }, 50); + that.haveInit = true; + + layer.close(that.tipsIndex); + + that.renderTotal(data, that.totalRowData); //数据合计 + that.layTotal && that.layTotal.removeClass(HIDE); + } // 数据渲染 Class.prototype.renderData = function(opts){ @@ -1035,172 +1206,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ var sort = opts.sort; var data = res[options.response.dataName] || []; //列表数据 - var totalRowData = res[options.response.totalRowName]; //合计行数据 - var trs = []; - var trs_fixed = []; - var trs_fixed_r = []; - - // 渲染视图 - var render = function(){ // 后续性能提升的重点 - // 同步表头父列的相关值 - options.HAS_SET_COLS_PATCH || that.setColsPatch(); - options.HAS_SET_COLS_PATCH = true; - - var thisCheckedRowIndex; - if(!sort && that.sortKey){ - return that.sort(that.sortKey.field, that.sortKey.sort, true); - } - layui.each(data, function(i1, item1){ - var tds = [], tds_fixed = [], tds_fixed_r = [] - ,numbers = i1 + options.limit*(curr - 1) + 1; // 序号 - - // 数组值是否为 object,如果不是,则自动转为 object - if(typeof item1 !== 'object'){ - data[i1] = item1 = {LAY_KEY: item1}; - try { - table.cache[that.key][i1] = item1; - } catch(e) {} - } - - //若数据项为空数组,则不往下执行(因为删除数据时,会将原有数据设置为 []) - if(layui.type(item1) === 'array' && item1.length === 0) return; - - // 加入序号保留字段 - item1[table.config.numbersName] = numbers; - - // 记录下标索引,用于恢复排序 - if(!sort) item1[table.config.indexName] = i1; - - // 遍历表头 - that.eachCols(function(i3, item3){ - var field = item3.field || i3; - var key = item3.key; - var content = item1[field]; - - if(content === undefined || content === null) content = ''; - if(item3.colGroup) return; - - // td 内容 - var td = ['' - ,'
' - + function(){ - var tplData = $.extend(true, { - LAY_COL: item3 - }, item1); - var checkName = table.config.checkName; - var disabledName = table.config.disabledName; - - //渲染不同风格的列 - switch(item3.type){ - case 'checkbox': // 复选 - return ''; - break; - case 'radio': // 单选 - if(tplData[checkName]){ - thisCheckedRowIndex = i1; - } - return ''; - break; - case 'numbers': - return numbers; - break; - }; - - //解析工具列模板 - if(item3.toolbar){ - return laytpl($(item3.toolbar).html()||'').render(tplData); - } - return parseTempData.call(that, { - item3: item3 - ,content: content - ,tplData: tplData - }); - }() - ,'
'].join(''); - - tds.push(td); - if(item3.fixed && item3.fixed !== 'right') tds_fixed.push(td); - if(item3.fixed === 'right') tds_fixed_r.push(td); - }); - - trs.push(''+ tds.join('') + ''); - trs_fixed.push(''+ tds_fixed.join('') + ''); - trs_fixed_r.push(''+ tds_fixed_r.join('') + ''); - }); - - // 容器的滚动条位置 - if(!(options.scrollPos === 'fixed' && opts.type === 'reloadData')){ - that.layBody.scrollTop(0); - } - if(options.scrollPos === 'reset'){ - that.layBody.scrollLeft(0); - } - - that.layMain.find('.'+ NONE).remove(); - that.layMain.find('tbody').html(trs.join('')); - that.layFixLeft.find('tbody').html(trs_fixed.join('')); - that.layFixRight.find('tbody').html(trs_fixed_r.join('')); - - that.renderForm(); - typeof thisCheckedRowIndex === 'number' && that.setThisRowChecked(thisCheckedRowIndex); - that.syncCheckAll(); - - // 因为 page 参数有可能发生变化 先重新铺满 - that.fullSize(); - - // 滚动条补丁 - that.haveInit ? that.scrollPatch() : setTimeout(function(){ - that.scrollPatch(); - }, 50); - that.haveInit = true; - - layer.close(that.tipsIndex); - }; - + that.totalRowData = res[options.response.totalRowName]; //合计行数据 table.cache[that.key] = data; //记录数据 //显示隐藏合计栏 @@ -1222,15 +1228,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ that.layFixLeft.removeClass(HIDE); } - //如果执行初始排序 - if(sort){ - return render(); + that.renderView(sort, opts.type); //渲染数据 + if (sort) { + return; } - - //正常初始化数据渲染 - render(); //渲染数据 - that.renderTotal(data, totalRowData); //数据合计 - that.layTotal && that.layTotal.removeClass(HIDE); //同步分页状态 if(options.page){ @@ -1447,7 +1448,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ res: res, curr: that.page, count: that.count, - sort: true + sort: true, + type: formEvent ? '' : 'reloadData' // 通过按钮触发排序会默认回滚到顶部否则根据情况处理 }); if(formEvent){ @@ -2653,6 +2655,16 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ // 重新适配尺寸 that.resize(); } + + // 重新渲染视图 + table.refresh = function (id) { + var that = getThisTable(id); + if (!that) { + return; + } + + that.renderView(null, 'reloadData'); + } // 自动完成渲染 $(function(){ From 618c62a68b3bbd372b55d1b6954fc62bbeee9b9c Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Tue, 10 Jan 2023 09:38:06 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=9A=84=E4=BF=AE=E6=94=B9=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E4=B9=8B=E5=90=8E=E7=82=B9=E5=87=BB=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E5=88=87=E6=8D=A2=E9=A1=B5=E6=95=B0=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E6=BB=9A=E5=8A=A8=E6=9D=A1=E6=B2=A1=E6=9C=89=E5=9B=9E?= =?UTF-8?q?=E9=9B=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index b56460c3..2ec36063 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -1039,7 +1039,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ var thisCheckedRowIndex; if(!sort && that.sortKey){ - return that.sort(that.sortKey.field, that.sortKey.sort, true); + return that.sort(that.sortKey.field, that.sortKey.sort, true, null, type); } layui.each(data, function(i1, item1){ var tds = [], tds_fixed = [], tds_fixed_r = [] @@ -1382,7 +1382,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ }; //数据排序 - Class.prototype.sort = function(th, type, pull, formEvent){ + Class.prototype.sort = function(th, type, pull, formEvent, reloadType){ var that = this ,field ,res = {} @@ -1449,7 +1449,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ curr: that.page, count: that.count, sort: true, - type: formEvent ? '' : 'reloadData' // 通过按钮触发排序会默认回滚到顶部否则根据情况处理 + type: formEvent ? '' : reloadType // 通过按钮触发排序会默认回滚到顶部否则根据情况处理 }); if(formEvent){ From 676a3df8782d975735d97db365d3e57016a5da1d Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Thu, 12 Jan 2023 15:24:10 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E5=92=8C=E4=B8=8B=E6=8B=89=E8=8F=9C=E5=8D=95=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=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/dropdown.js | 2 +- src/modules/table.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index 47460f56..c0ae6148 100644 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -10,7 +10,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){ ,laytpl = layui.laytpl ,hint = layui.hint() ,device = layui.device() - ,clickOrMousedown = (device.mobile ? 'click' : 'mousedown') + ,clickOrMousedown = (device.mobile ? 'touchstart' : 'mousedown') //模块名 ,MOD_NAME = 'dropdown' diff --git a/src/modules/table.js b/src/modules/table.js index 2ec36063..4d1422cd 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -1957,12 +1957,13 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } ,update: function(fields, related){ //修改行数据 fields = fields || {}; + var trThat = this; layui.each(fields, function(key, value){ var td = tr.children('td[data-field="'+ key +'"]'); var cell = td.children(ELEM_CELL); //获取当前修改的列 // 更新缓存中的数据 - if(key in data) data[key] = value; + if(key in data) trThat.data[key] = data[key] = value; // 更新相应列视图 that.eachCols(function(i, item3){ From f267138550430001a48ec7d3834b117b8e748f55 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Mon, 30 Jan 2023 17:58:48 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E5=92=8C=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9=E7=9A=84=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/form.js | 3 ++- src/modules/laydate.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/form.js b/src/modules/form.js index 9fa7e87f..9f97afca 100644 --- a/src/modules/form.js +++ b/src/modules/form.js @@ -651,7 +651,8 @@ layui.define(['lay', 'layer', 'util'], function(exports){ checks.each(function(index, check){ var othis = $(this); - var skin = othis.attr('lay-skin') || 'primary'; + var skin = othis.attr('lay-skin') || ''; + check.title || (check.title = othis.attr('lay-text') || ''); // 向下兼容将以前设置在lay-text的值赋给title var title = (check.title.replace(/\s/g, '') || '').split('|'); var disabled = this.disabled; diff --git a/src/modules/laydate.js b/src/modules/laydate.js index 991751e1..4a65cad8 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -967,6 +967,11 @@ minutes: that.endDate.minutes, seconds: that.endDate.seconds, } + // 如果是年月范围,将对应的日期统一成当月的1日进行比较,避免出现同一个月但是开始日期大于结束日期的情况 + if (options.type === 'month') { + options.dateTime.date = 1; + that.endDate.date = 1; + } } // 初始值不在最大最小范围内 From d3f112160cac52b49f42b97e144a2f8c3c72a115 Mon Sep 17 00:00:00 2001 From: sunxb <470459819@qq.com> Date: Tue, 31 Jan 2023 10:55:18 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=A4=8D=E9=80=89?= =?UTF-8?q?=E6=A1=86=E9=BB=98=E8=AE=A4=E6=95=88=E6=9E=9C=E8=B7=9F2.8.0-rc.?= =?UTF-8?q?6=E4=B8=80=E8=87=B4=EF=BC=8C=E5=BE=AE=E8=B0=83=E5=A4=8D?= =?UTF-8?q?=E9=80=89skin=E7=9A=84=E5=80=BC=E7=9A=84=E7=BB=86=E8=8A=82?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/form.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/form.js b/src/modules/form.js index 9f97afca..f7df7b8a 100644 --- a/src/modules/form.js +++ b/src/modules/form.js @@ -651,12 +651,16 @@ layui.define(['lay', 'layer', 'util'], function(exports){ checks.each(function(index, check){ var othis = $(this); - var skin = othis.attr('lay-skin') || ''; + var skin = othis.attr('lay-skin') || 'primary'; check.title || (check.title = othis.attr('lay-text') || ''); // 向下兼容将以前设置在lay-text的值赋给title var title = (check.title.replace(/\s/g, '') || '').split('|'); var disabled = this.disabled; - if(skin === 'switch') skin = '_'+ skin; + if(skin === 'switch') { + skin = '_'+ skin; + } else if (skin !== 'tag') { + skin = 'primary'; + } var RE_CLASS = CLASS[skin] || CLASS.checkbox; if(typeof othis.attr('lay-ignore') === 'string') return othis.show();