From c65aabe2b148e54b7dae514eeda6520f83ca0fda Mon Sep 17 00:00:00 2001 From: Diyar-IT <136627746+Diyar-IT@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:32:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 179 ++++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 88 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index 3f33599f..4013f808 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -329,18 +329,18 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ //请求参数的自定义格式 options.request = $.extend({ - pageName: 'page' - ,limitName: 'limit' + pageName: 'page', + limitName: 'limit' }, options.request) // 响应数据的自定义格式 options.response = $.extend({ - statusName: 'code' //规定数据状态的字段名称 - ,statusCode: 0 //规定成功的状态码 - ,msgName: 'msg' //规定状态信息的字段名称 - ,dataName: 'data' //规定数据总数的字段名称 - ,totalRowName: 'totalRow' //规定数据统计的字段名称 - ,countName: 'count' + statusName: 'code', //规定数据状态的字段名称 + statusCode: 0, //规定成功的状态码 + msgName: 'msg', //规定状态信息的字段名称 + dataName: 'data', //规定数据总数的字段名称 + totalRowName: 'totalRow', //规定数据统计的字段名称 + countName: 'count' }, options.response); //如果 page 传入 laypage 对象 @@ -386,11 +386,11 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } //开始插入替代元素 - var othis = options.elem - ,hasRender = othis.next('.' + ELEM_VIEW) + var othis = options.elem; + var hasRender = othis.next('.' + ELEM_VIEW); //主容器 - ,reElem = that.elem = $('
'); + var reElem = that.elem = $('
'); reElem.addClass(function(){ var arr = [ @@ -402,9 +402,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ if(options.className) arr.push(options.className); return arr.join(' '); }()).attr({ - 'lay-filter': 'LAY-TABLE-FORM-DF-'+ that.index - ,'lay-id': options.id - ,'style': function(){ + 'lay-filter': 'LAY-TABLE-FORM-DF-'+ that.index, + 'lay-id': options.id, + 'style': function(){ var arr = []; if(options.width) arr.push('width:'+ options.width + 'px;'); // if(options.height) arr.push('height:'+ options.height + 'px;'); @@ -414,8 +414,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ open: '{{', // 标签符前缀 close: '}}' // 标签符后缀 }).render({ - data: options - ,index: that.index //索引 + data: options, + index: that.index //索引 })); //生成替代元素 @@ -450,12 +450,12 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ //根据列类型,定制化参数 Class.prototype.initOpts = function(item){ var that = this - ,options = that.config - ,initWidth = { - checkbox: 50 - ,radio: 50 - ,space: 30 - ,numbers: 60 + var options = that.config; + var initWidth = { + checkbox: 50, + radio: 50, + space: 30, + numbers: 60 }; //让 type 参数兼容旧版本 @@ -471,8 +471,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ //初始化一些参数 Class.prototype.setInit = function(type){ - var that = this - ,options = that.config; + var that = this; + var options = that.config; options.clientWidth = options.width || function(){ //获取容器宽度 //如果父元素宽度为0(一般为隐藏元素),则继续查找上层元素,直到找到真实宽度为止 @@ -926,6 +926,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ options.HAS_SET_COLS_PATCH = true; var request = options.request; var response = options.response; + var res; var sort = function(){ if(typeof options.initSort === 'object'){ that.sort({ @@ -951,7 +952,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ that.startTime = new Date().getTime(); // 渲染开始时间 if (opts.renderData) { // 将 cache 信息重新渲染 - var res = {}; + res = {}; res[response.dataName] = table.cache[that.key]; res[response.countName] = options.url ? (layui.type(options.page) === 'object' ? options.page.count : res[response.dataName].length) : options.data.length; @@ -1021,7 +1022,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } }); } else if(layui.type(options.data) === 'array'){ //已知数据 - var res = {}; + res = {}; var startLimit = curr*options.limit - options.limit; var newData = options.data.concat(); @@ -1074,8 +1075,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ curr = curr || 1 layui.each(data, function(i1, item1){ - var tds = [], tds_fixed = [], tds_fixed_r = [] - ,numbers = i1 + options.limit*(curr - 1) + 1; // 序号 + var tds = []; + var tds_fixed = []; + var tds_fixed_r = []; + var numbers = i1 + options.limit*(curr - 1) + 1; // 序号 // 数组值是否为 object,如果不是,则自动转为 object if(typeof item1 !== 'object'){ @@ -1159,7 +1162,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ return arr.join(' '); }() +' lay-type="layTableCheckbox">'; - break; + //break; case 'radio': // 单选 return ''; - break; + //break; case 'numbers': return numbers; - break; + //break; }; //解析工具列模板 @@ -1309,15 +1312,15 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ //同步分页状态 if(options.page){ options.page = $.extend({ - elem: 'layui-table-page' + options.index - ,count: count - ,limit: options.limit - ,limits: options.limits || [10,20,30,40,50,60,70,80,90] - ,groups: 3 - ,layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'] - ,prev: '' - ,next: '' - ,jump: function(obj, first){ + elem: 'layui-table-page' + options.index, + count: count, + limit: options.limit, + limits: options.limits || [10,20,30,40,50,60,70,80,90], + groups: 3, + layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'], + prev: '', + next: '', + jump: function(obj, first){ if(!first){ //分页本身并非需要做以下更新,下面参数的同步,主要是因为其它处理统一用到了它们 //而并非用的是 options.page 中的参数(以确保分页未开启的情况仍能正常使用) @@ -1394,9 +1397,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ // 获取自动计算的合并内容 var getContent = item3.totalRow ? (parseTempData.call(that, { - item3: item3 - ,content: thisTotalNum - ,tplData: tplData + item3: item3, + content: thisTotalNum, + tplData: tplData }) || text) : text; // 如果直接传入了合计行数据,则不输出自动计算的结果 @@ -1421,8 +1424,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ if(item3.hide) classNames.push(HIDE); // 插入隐藏列样式 if(!item3.field) classNames.push(ELEM_COL_SPECIAL); // 插入特殊列样式 return classNames.join(' '); - }() +'">' - ,'
', + '
' - ,'' - ,'
'].join('')); + that.layInit = $(['
', + '', + '
'].join('')); that.layBox.append(that.layInit); } } @@ -1674,10 +1677,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ //让表格铺满 Class.prototype.fullSize = function(){ - var that = this - ,options = that.config - ,height = options.height - ,bodyHeight; + var that = this; + var options = that.config; + var height = options.height; + var bodyHeight; if(that.fullHeightGap){ height = _WIN.height() - that.fullHeightGap; @@ -1898,8 +1901,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ '
  • 导出 csv 格式文件
  • ', '
  • 导出 xls 格式文件
  • ' ].join('') - }() - ,done: function(panel, list){ + }(), + done: function(panel, list){ list.on('click', function(){ var type = $(this).data('type') table.exportFile.call(that, options.id, null, type); @@ -1944,8 +1947,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } layui.event.call(this, MOD_NAME, 'toolbar('+ filter +')', $.extend({ - event: events - ,config: options + event: events, + config: options },{})); }); @@ -1970,16 +1973,16 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ var events = othis.attr('lay-event'); layui.event.call(this, MOD_NAME, 'pagebar('+ filter +')', $.extend({ - event: events - ,config: options + event: events, + config: options },{})); }); // 拖拽调整宽度 th.on('mousemove', function(e){ - var othis = $(this) - ,oLeft = othis.offset().left - ,pLeft = e.clientX - oLeft; + var othis = $(this); + var oLeft = othis.offset().left; + var pLeft = e.clientX - oLeft; if(othis.data('unresize') || thisTable.eventMoveElem){ return; } @@ -2095,9 +2098,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ fromEvent: true }); }).find(ELEM_SORT+' .layui-edge ').on('click', function(e){ - var othis = $(this) - ,index = othis.index() - ,field = othis.parents('th').eq(0).data('field') + var othis = $(this); + var index = othis.index(); + var field = othis.parents('th').eq(0).data('field'); layui.stope(e); if(index === 0){ that.sort({ @@ -2652,8 +2655,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ // 遍历表头 table.eachCols = function(id, callback, cols){ - var config = thisTable.config[id] || {} - ,arrs = [], index = 0; + var config = thisTable.config[id] || {}; + var arrs = [], index = 0; cols = $.extend(true, [], cols || config.cols); @@ -2713,12 +2716,12 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ // 获取表格当前页的所有行数据 table.getData = function(id){ - var arr = [] - ,data = table.cache[id] || []; + var arr = []; + var data = table.cache[id] || []; layui.each(data, function(i, item){ if(layui.type(item) === 'array'){ return; - }; + } arr.push(table.clearCacheKey(item)); }); return arr; @@ -2753,8 +2756,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ var thatTable = thisTable.that[id]; var config = thisTable.config[id] || {}; var textType = ({ - csv: 'text/csv' - ,xls: 'application/vnd.ms-excel' + csv: 'text/csv', + xls: 'application/vnd.ms-excel' })[type]; var alink = document.createElement("a"); @@ -2792,11 +2795,11 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ // 解析内容 content = parseTempData.call(thatTable, { - item3: item3 - ,content: content - ,tplData: item1 - ,text: 'text' - ,obj: { + item3: item3, + content: content, + tplData: item1, + text: 'text', + obj: { td: function(field){ var td = thatTable.layBody.find('tr[data-index="'+ i1 +'"]>td'); return td.filter('[data-field="'+ field +'"]');