修复WBS编码: 分支1→分支1.1层级正确(prefix空字符串处理)

This commit is contained in:
2026-08-06 11:42:52 +08:00
parent 67755c7847
commit 8f0f725e26
2 changed files with 15 additions and 16 deletions

View File

@ -108,19 +108,19 @@ export default {
},
branchLabelMap() {
const map = {};
if (!this.product || !this.product.task_tree) return map;
const traverse = (tasks, prefix) => {
if (!tasks) return;
tasks.forEach((t, i) => {
map[t.id] = prefix ? `分支 ${prefix}${i + 1}` : '分支 1';
traverse(t.child_tasks, prefix ? `${prefix}${i + 1}.` : `${i + 1}.`);
const num = prefix ? `${prefix}.${i + 1}` : `${i + 1}`;
map[t.id] = `分支 ${num}`;
traverse(t.child_tasks, num);
});
};
if (this.product && this.product.task_tree) {
this.product.task_tree.forEach((t, i) => {
map[t.id] = '主分支';
traverse(t.child_tasks, `${i + 1}.`);
});
}
this.product.task_tree.forEach((t, i) => {
map[t.id] = '主分支';
traverse(t.child_tasks, '');
});
return map;
},
canvasWidth() { if (!this.treeNodes.length) return 400; return Math.max(800, Math.max(...this.treeNodes.map(n => n.x)) + 300); },

View File

@ -143,16 +143,15 @@ export default {
const traverse = (tasks, prefix) => {
if (!tasks) return;
tasks.forEach((t, i) => {
if (prefix === '') {
map[t.id] = '主分支';
} else {
map[t.id] = `分支 ${prefix}${i + 1}`;
}
const nextPrefix = prefix === '' ? `${i + 1}.` : `${prefix}${i + 1}.`;
traverse(t.child_tasks, nextPrefix);
const num = prefix ? `${prefix}.${i + 1}` : `${i + 1}`;
map[t.id] = `分支 ${num}`;
traverse(t.child_tasks, num);
});
};
traverse(this.product.task_tree, '');
this.product.task_tree.forEach((t, i) => {
map[t.id] = '主分支';
traverse(t.child_tasks, '');
});
return map;
},
},