gantt.attachEvent(“onBeforeTaskDisplay”, function (id, task) {
if (task.parent > 0) {
// 判断是否为子任务
setTimeout(function () {
let taskBar = gantt.getTaskNode(id);
if (taskBar !== null) {
// 确保任务条存在
taskBar.style.display = “none”; // 隐藏子任务的日期条
// taskBar.parentNode.removeChild(taskBar);
} else {
console.log(“任务条不存在!”, id); // 输出调试信息
}
}, 120); // 延迟 0 毫秒,确保任务条已渲染
setTimeout(function () {
let taskRow = gantt.getTaskRowNode(id);
if (taskRow !== null) {
let elements = taskRow.querySelectorAll(‘[data-column-index=“1”]’);
// 遍历所有匹配的元素并隐藏它们
elements.forEach(function (element) {
// 隐藏当前元素
element.style.display = “none”;
// element.parentNode.removeChild(element);
});
let elements1 = taskRow.querySelectorAll(‘[data-column-index=“2”]’);
// 遍历所有匹配的元素并隐藏它们
elements1.forEach(function (element) {
// 隐藏当前元素
element.style.display = “none”;
// element.parentNode.removeChild(element);
});
// let elements3 = taskRow.querySelectorAll(‘[data-column-index=“5”]’);
// // 遍历所有匹配的元素并隐藏它们
// elements3.forEach(function (element) {
// // 删除
// element.style.display = ‘none’;
// // element.parentNode.removeChild(element);
//
// });
let elements4 = taskRow.querySelectorAll(‘[data-column-index=“0”]’);
// 遍历所有匹配的元素并隐藏它们
elements4.forEach(function (element) {
// 任务名称宽度拉长
element.style.width = “450px”;
});
}
}, 120); // 延迟 0 毫秒,确保任务条已渲染
}
else {
setTimeout(function () {
let taskRow = gantt.getTaskRowNode(id);
if (taskRow !== null) {
let elements1 = taskRow.querySelectorAll(‘[data-column-index=“3”]’);
elements1.forEach(function (element) {
if (element.getAttribute(“aria-label”) === “进行中”) {
element.style.background = “#FFC107”;
} else if (element.getAttribute(“aria-label”) === “未开始”) {
element.style.background = “#808080”;
} else if (element.getAttribute(“aria-label”) === “延期”) {
element.style.background = “#FF9800”;
} else if (element.getAttribute(“aria-label”) === “已完成”) {
element.style.background = “#4CAF50”;
} else if (element.getAttribute(“aria-label”) === “暂停”) {
element.style.background = “#2196F3”;
} else if (element.getAttribute(“aria-label”) === “暂缓”) {
element.style.background = “#9C27B0”;
}
});
}
}, 120);
}
return true;
});这是代码,要咋修改,求助