From 1b31ba87fc35e58fb7712c5dd73b4c9aa240118a Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Wed, 24 May 2023 14:52:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20treeTable=20=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E6=8E=92=E5=BA=8F=E5=92=8C=E8=A7=86=E5=9B=BE=E5=86=85?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E5=88=9D=E5=A7=8B=E5=8C=96=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/treeTable.js | 51 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index f0b21c79..0484b448 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -10,7 +10,6 @@ layui.define(['table'], function (exports) { var form = layui.form; var table = layui.table; var hint = layui.hint(); - var timer = {}; // 记录定时器 index // api var treeTable = { @@ -427,7 +426,9 @@ layui.define(['table'], function (exports) { var debounceFn = (function () { var fn = {}; return function (tableId, func, wait) { - fn[tableId] = fn[tableId] || layui.debounce(func, wait); + if (!fn[tableId]) { + fn[tableId] = layui.debounce(func, wait); + } return fn[tableId]; } })() @@ -667,13 +668,15 @@ layui.define(['table'], function (exports) { }).join(',')).addClass(HIDE); } } - debounceFn(tableId, function () { + + + debounceFn('resize-' + tableId, function () { treeTable.resize(tableId); - }, 25)(); + }, 0)(); if (callbackFlag && trData[LAY_ASYNC_STATUS] !== 'loading') { var onExpand = treeOptions.callback.onExpand; - layui.type(onExpand) === 'function' && onExpand(tableId, trData, expandFlag); + layui.type(onExpand) === 'function' && onExpand(tableId, trData, trExpand); } return retValue; @@ -908,14 +911,18 @@ layui.define(['table'], function (exports) { }); // 当前层的数据看看是否需要展开 - sonSign !== false && layui.each(dataExpand, function (index, item) { - var trDefaultExpand = tableViewElem.find('tr[lay-data-index="' + index + '"]'); - trDefaultExpand.find('.layui-table-tree-flexIcon').html(treeOptionsView.flexIconOpen); - expandNode({trElem: trDefaultExpand.first()}, true); - }); - - options.hasNumberCol && that.formatNumber(tableId); - form.render(null, tableFilterId); + if (sonSign !== false && dataExpand) { + layui.each(dataExpand, function (index, item) { + var trDefaultExpand = tableViewElem.find('tr[lay-data-index="' + index + '"]'); + trDefaultExpand.find('.layui-table-tree-flexIcon').html(treeOptionsView.flexIconOpen); + expandNode({trElem: trDefaultExpand.first()}, true); + }); + } else { + debounceFn('renderTreeTable-' + tableId, function () { + options.hasNumberCol && formatNumber(that); + form.render(null, tableFilterId); + }, 0)(); + } } var formatNumber = function (that) { @@ -923,24 +930,18 @@ layui.define(['table'], function (exports) { var tableViewElem = options.elem.next(); var num = 0; + var trMain = tableViewElem.find('.layui-table-main tbody tr'); + var trFixedL = tableViewElem.find('.layui-table-fixed-l tbody tr'); + var trFixedR = tableViewElem.find('.layui-table-fixed-r tbody tr'); layui.each(that.treeToFlat(table.cache[options.id]), function (i1, item1) { - if (layui.isArray(item1)) { - return; - } var itemData = that.getNodeDataByIndex(item1[LAY_DATA_INDEX]); itemData['LAY_NUM'] = ++num; - tableViewElem.find('tr[lay-data-index="' + item1[LAY_DATA_INDEX] + '"] .laytable-cell-numbers').html(itemData['LAY_NUM']); + trMain.eq(i1).find('.laytable-cell-numbers').html(num); + trFixedL.eq(i1).find('.laytable-cell-numbers').html(num); + trFixedR.eq(i1).find('.laytable-cell-numbers').html(num); }) } - Class.prototype.formatNumber = function (id) { - var that = this; - clearTimeout(id); - timer[id] = setTimeout(function () { - formatNumber(that); - }, 10) - } - // 树表渲染 Class.prototype.render = function (type) { var that = this;