From d49ad48c2bcdcd1b2cd9585ee9819096760d2958 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Thu, 6 Jul 2023 00:19:33 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=20treeTable=20=E6=A0=91?= =?UTF-8?q?=E5=BD=A2=E8=BD=AC=E5=B9=B3=E9=93=BA=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E8=8A=82=E7=82=B9=E7=9A=84=20`children`=20?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/treeTable.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index 22b529cb..317512b5 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -321,7 +321,6 @@ layui.define(['table'], function (exports) { layui.each(tableData, function (i1, item1) { var dataIndex = (parentIndex ? parentIndex + '-' : '') + i1; var dataNew = $.extend({}, item1); - dataNew[childrenKey] = null; dataNew[pIdKey] = item1[pIdKey] || parentId; flat.push(dataNew); flat = flat.concat(that.treeToFlat(item1[childrenKey], item1[customName.id], dataIndex)); From 37ab1fb585d70fbbb91c8a4a6b4c674e2c446382 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Mon, 17 Jul 2023 22:42:02 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20table=20=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20`init`=20=E8=BD=AC=E6=8D=A2=E7=9A=84=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E5=A4=B4=E9=83=A8=E7=9A=84=20`colspan`=20=E5=92=8C=20?= =?UTF-8?q?`rowspan`=20=E7=9A=84=E9=BB=98=E8=AE=A4=E5=80=BC=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index 059f29c1..440aa5a9 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -2559,8 +2559,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ var row = $.extend({ title: th.text() - ,colspan: parseInt(th.attr('colspan')) || 0 //列单元格 - ,rowspan: parseInt(th.attr('rowspan')) || 0 //行单元格 + ,colspan: parseInt(th.attr('colspan')) || 1 //列单元格 + ,rowspan: parseInt(th.attr('rowspan')) || 1 //行单元格 }, itemData); options.cols[i].push(row); From 108221ad7946c2e8e2384b778d515cdc41b706b9 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Wed, 26 Jul 2023 22:28:27 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=20treeTable=20`reload`?= =?UTF-8?q?=20=E7=94=B1=E9=BB=98=E8=AE=A4=E6=B7=B1=E6=8B=B7=E8=B4=9D?= =?UTF-8?q?=E6=8D=A2=E6=88=90=E9=BB=98=E8=AE=A4=E6=B5=85=E6=8B=B7=E8=B4=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/treeTable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index 30ac17a4..eb761b7a 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -1854,7 +1854,7 @@ layui.define(['table'], function (exports) { // 重载 treeTable.reload = function (id, options, deep, type) { - deep = deep !== false; // 默认采用深拷贝 + // deep = deep !== false; // 默认采用深拷贝 var that = getThisTable(id); if (!that) return; that.reload(options, deep, type); From 24c5b5b06a5b4d4c9813afbad9af1464f66c794b Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Wed, 26 Jul 2023 22:31:10 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20treeTable=20`check.cas?= =?UTF-8?q?cade`=20=E5=A4=8D=E9=80=89=E7=9A=84=E7=BA=A7=E8=81=94=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/treeTable.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index eb761b7a..6bb60a4a 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -203,6 +203,10 @@ layui.define(['table'], function (exports) { Class.prototype.init = function () { var that = this; var options = that.config; + var cascade = options.tree.check.cascade; + if (cascade !== 'parent' || cascade !== 'children') { + options.tree.check.cascade = 'all'; // 超出范围的都重置为全联动 + } // 先初始一个空的表格以便拿到对应的表格实例信息 var tableIns = table.render($.extend({}, options, { @@ -257,6 +261,9 @@ layui.define(['table'], function (exports) { callback: { beforeExpand: null, // 展开前的回调 return false 可以阻止展开的动作 onExpand: null // 展开之后的回调 + }, + check: { + cascade: 'all' // 级联方式 默认全部级联:all 可选 级联父 parent 级联子 children } }, }; @@ -1084,7 +1091,7 @@ layui.define(['table'], function (exports) { return treeTable.reload.apply(null, args); }; - var updateStatus = function (data, statusObj, childrenKey) { + var updateStatus = function (data, statusObj, childrenKey, notCascade) { var dataUpdated = []; layui.each(data, function (i1, item1) { if (layui.type(statusObj) === 'function') { @@ -1093,18 +1100,18 @@ layui.define(['table'], function (exports) { $.extend(item1, statusObj); } dataUpdated.push($.extend({}, item1)); - dataUpdated = dataUpdated.concat(updateStatus(item1[childrenKey], statusObj, childrenKey)); + notCascade || (dataUpdated = dataUpdated.concat(updateStatus(item1[childrenKey], statusObj, childrenKey, notCascade))); }); return dataUpdated; } - Class.prototype.updateStatus = function (data, statusObj) { + Class.prototype.updateStatus = function (data, statusObj, notCascade) { var that = this; var options = that.getOptions(); var treeOptions = options.tree; data = data || table.cache[options.id]; - return updateStatus(data, statusObj, treeOptions.customName.children); + return updateStatus(data, statusObj, treeOptions.customName.children, notCascade); } Class.prototype.getTableData = function () { @@ -1386,6 +1393,8 @@ layui.define(['table'], function (exports) { treeTable.checkStatus = function (id, includeHalfCheck) { var that = getThisTable(id); if (!that) return; + var options = that.getOptions(); + var treeOptions = options.tree; var checkName = table.config.checkName; // 需要区分单双选 @@ -1395,7 +1404,7 @@ layui.define(['table'], function (exports) { }); var isAll = true; - layui.each(table.cache[id], function (i1, item1) { + layui.each(treeOptions.check.cascade === 'all' ? table.cache[id] : treeTable.getData(id, true), function (i1, item1) { if (!item1[checkName]) { isAll = false; return true; @@ -1507,8 +1516,11 @@ layui.define(['table'], function (exports) { var checkName = table.config.checkName; + var cascade = treeOptions.check.cascade; + var isCascadeParent = cascade === 'all' || cascade === 'parent'; + // 如有必要更新父节点们的状态 - if (dataP) { + if (isCascadeParent && dataP) { var trsP = that.updateParentCheckStatus(dataP, layui.type(checked) === 'boolean' ? checked : null); layui.each(trsP, function (indexP, itemP) { var checkboxElem = tableView.find('tr[lay-data-index="' + itemP[LAY_DATA_INDEX] + '"] input[name="layTableCheckbox"]:not(:disabled)'); @@ -1528,13 +1540,16 @@ layui.define(['table'], function (exports) { // 更新全选的状态 var isAll = true; var isIndeterminate = false; - layui.each(table.cache[tableId], function (i1, item1) { + layui.each(treeOptions.check.cascade === 'all' ? table.cache[tableId] : treeTable.getData(tableId, true), function (i1, item1) { if (item1[checkName] || item1[LAY_CHECKBOX_HALF]) { isIndeterminate = true; } if (!item1[checkName]) { isAll = false; } + if (isIndeterminate && !isAll) { + return true; + } }) isIndeterminate = isIndeterminate && !isAll; form.render(tableView.find('input[name="layTableCheckbox"][lay-filter="layTableAllChoose"]').prop({ @@ -1600,6 +1615,7 @@ layui.define(['table'], function (exports) { var checkNode = function (trElem, checked, callbackFlag) { var that = this; var options = that.getOptions(); + var treeOptions = options.tree; var tableId = options.id; var tableView = options.elem.next(); var inputElem = (trElem.length ? trElem : tableView).find('.laytable-cell-radio, .laytable-cell-checkbox').children('input').last(); @@ -1657,11 +1673,9 @@ layui.define(['table'], function (exports) { trElem.siblings().removeClass(ELEM_CHECKED); // 取消其他行背景色 form.render(trElem.find('input[type="radio"][lay-type="layTableRadio"]').prop('checked', checked)); } else { - var isParentKey = options.tree.customName.isParent; // 切换只能用到单条,全选到这一步的时候应该是一个确定的状态 checked = layui.type(checked) === 'boolean' ? checked : !trData[checkName]; // 状态切换,如果遇到不可操作的节点待处理 todo // 全选或者是一个父节点,将子节点的状态同步为当前节点的状态 - // if (!trData || trData[isParentKey]) { // 处理不可操作的信息 var checkedStatusFn = function (d) { if (!d[table.config.disabledName]) { // 节点不可操作的不处理 @@ -1670,13 +1684,12 @@ layui.define(['table'], function (exports) { } } - var trs = that.updateStatus(trData ? [trData] : table.cache[tableId], checkedStatusFn); + var trs = that.updateStatus(trData ? [trData] : table.cache[tableId], checkedStatusFn, trData && treeOptions.check.cascade === 'parent'); var checkboxElem = tableView.find(trs.map(function (value) { return 'tr[lay-data-index="' + value[LAY_DATA_INDEX] + '"] input[name="layTableCheckbox"]:not(:disabled)'; }).join(',')); checkboxElem.closest('tr')[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED); // 标记当前选中行背景色 form.render(checkboxElem.prop({checked: checked, indeterminate: false})); - // } var trDataP; // 更新父节点以及更上层节点的状态 if (trData && trData[LAY_PARENT_INDEX]) {