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

master
guoxin 1 year ago
parent 9e4edadfc4
commit 0b74f2da21
  1. 37
      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,
cache: true,
checkbar: true,
checkbarType: multiple ? 'no-all' : 'only',
checkbarType: multiple ? 'self' : 'only',
scroll: '#label-tree',
done: function () {
let _chooseIds = [];
@ -198,24 +198,39 @@ layui.define(['globalTree'], function (exports) {
})
},
checkbarFun: {
activeNode: null,
chooseBefore: function ($i, node) {
this.activeNode = node;
this.activeNode['checked'] = !$i.hasClass('dtree-theme-choose');
return true;
},
chooseDone: function (nodes) {
if (disableIds.length > 0) {
treeObj.chooseDataInit(disableIds.join(','));
}
const chooseNodes = treeObj.chooseNodes;
if (!multiple) {
treeObj.chooseNodes = nodes;
} else {
const nodeMap = new Map();
const choosePids = nodes.map(n => n.id);
// 如果包含选中节点中包含上下级关系,则在选中节点中去掉上级节点
for(const node of nodes){
if(nodeMap.has(node.parentId)){
nodeMap.delete(node.parentId);
const {id, parentId, checked} = this.activeNode;
if (checked) {
// 判断父级节点,如果是选中状态,则模拟复选框单击事件,取消选中
if (isChecked(parentId)) {
treeObj.dtreeObj.clickNodeCheckbar(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')
}
}
}
@ -250,7 +265,7 @@ layui.define(['globalTree'], function (exports) {
}
function addOtherLabel(value, readonly) {
let template = `<div class="label-set-component other-label ${readonly?'read-only':''}" th:data-field-title="其他标签"></div>`;
let template = `<div class="label-set-component other-label ${readonly ? 'read-only' : ''}" th:data-field-title="其他标签"></div>`;
$('.other-label-item.layui-input-block').append(template);
let cid = _KEY + _CACHE.size,
component = new Component(cid, $('.label-set-component.other-label:last'));

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