优化数据置标选择框的勾选方式

master
guoxin 1 year ago
parent 9e4edadfc4
commit 0b74f2da21
  1. 35
      shandan-common/src/main/resources/static/js/common/layui/extend/datalabel.js
  2. 6
      shandan-common/src/main/resources/static/js/common/layui/extend/globalTree.js

@ -170,7 +170,7 @@ layui.define(['globalTree'], function (exports) {
all: true, all: true,
cache: true, cache: true,
checkbar: true, checkbar: true,
checkbarType: multiple ? 'no-all' : 'only', checkbarType: multiple ? 'self' : 'only',
scroll: '#label-tree', scroll: '#label-tree',
done: function () { done: function () {
let _chooseIds = []; let _chooseIds = [];
@ -198,24 +198,39 @@ layui.define(['globalTree'], function (exports) {
}) })
}, },
checkbarFun: { checkbarFun: {
activeNode: null,
chooseBefore: function ($i, node) {
this.activeNode = node;
this.activeNode['checked'] = !$i.hasClass('dtree-theme-choose');
return true;
},
chooseDone: function (nodes) { chooseDone: function (nodes) {
if (disableIds.length > 0) { if (disableIds.length > 0) {
treeObj.chooseDataInit(disableIds.join(',')); treeObj.chooseDataInit(disableIds.join(','));
} }
const chooseNodes = treeObj.chooseNodes;
if (!multiple) { if (!multiple) {
treeObj.chooseNodes = nodes; treeObj.chooseNodes = nodes;
} else { } else {
const nodeMap = new Map(); const {id, parentId, checked} = this.activeNode;
const choosePids = nodes.map(n => n.id); if (checked) {
// 如果包含选中节点中包含上下级关系,则在选中节点中去掉上级节点 // 判断父级节点,如果是选中状态,则模拟复选框单击事件,取消选中
for(const node of nodes){ if (isChecked(parentId)) {
if(nodeMap.has(node.parentId)){ treeObj.dtreeObj.clickNodeCheckbar(parentId);
nodeMap.delete(node.parentId); }
// 获取下级节点集合,并遍历集合,如果是选中状态,则模拟复选框单击事件,取消选中
const children = layui.globalTree.getChildParam(treeObj, id);
for (const child of children) {
if (isChecked(child.id)) {
treeObj.dtreeObj.clickNodeCheckbar(child.id);
}
} }
nodeMap.set(node.id, node)
} }
treeObj.chooseNodes = [...nodeMap.values()];
treeObj.chooseNodes = layui.globalTree.getCheckbarNodesParam("label-tree");
}
function isChecked(id) {
return $(`.dtree-nav-checkbox-div[data-id="${id}"] i`).hasClass('dtree-theme-choose')
} }
} }
} }

@ -74,8 +74,8 @@ layui.define(['jquery', 'layer', 'dtree'], function (exports) {
_this.elem = `#${_this.id}`; _this.elem = `#${_this.id}`;
dtreeObj = dtree.render(_this); this.dtreeObj = dtree.render(_this);
return dtreeObj; return this.dtreeObj;
} }
/** /**
@ -107,7 +107,7 @@ layui.define(['jquery', 'layer', 'dtree'], function (exports) {
} }
GlobalTree.prototype.getParentParam2 = function (id) { GlobalTree.prototype.getParentParam2 = function (id) {
dtree.getParentParam(this.id, id); dtree.getParentParam(this.dtreeObj, id);
}; };
GlobalTree.prototype.initNoAllCheck2 = function () { GlobalTree.prototype.initNoAllCheck2 = function () {