fix(产品需求): 修复需求树的序号展示问题。

This commit is contained in:
dk
2026-05-07 11:02:10 +08:00
parent 67ef8af3fa
commit 991cbb5278

View File

@@ -147,6 +147,17 @@ function getPriorityTagType(priority?: number | null): UI.ThemeColor {
return priorityTagTypeMap[priority] || 'info';
}
function flattenTree(nodes: Api.Product.Requirement[]): Api.Product.Requirement[] {
const result: Api.Product.Requirement[] = [];
for (const node of nodes) {
result.push(node);
if (node.children?.length) {
result.push(...flattenTree(node.children));
}
}
return result;
}
function collectAllRequirementIds(nodes: Api.Product.Requirement[]): string[] {
const ids: string[] = [];
for (const node of nodes) {
@@ -186,11 +197,25 @@ function getRowActions(row: Api.Product.Requirement): Api.Product.RequirementLif
}
const columns = computed(() => [
{ prop: 'index', type: 'index', label: '序号', width: 64 },
{
type: 'index',
label: '序号',
width: 64,
align: 'center',
index: (index: number): number => {
const flatList = flattenTree(treeData.value);
const row = flatList[index];
if (!row || row.parentId !== '0') {
return 0;
}
const parentIndex = treeData.value.findIndex(item => item.id === row.id);
return parentIndex >= 0 ? (pagination.pageNo - 1) * pagination.pageSize + parentIndex + 1 : 0;
}
},
{
prop: 'title',
label: '标题',
minWidth: 220,
minWidth: 200,
formatter: (row: Api.Product.Requirement) => {
const isTerminal = isTerminalStatus(row.statusCode);
const className = 'requirement-title';
@@ -625,13 +650,15 @@ watch(
<ElTable
ref="requirementTableRef"
v-loading="loading"
height="100%"
border
lazy
row-key="id"
:indent="32"
height="100%"
:data="treeData"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
<ElTableColumn v-for="col in columns" :key="String(col.prop)" v-bind="col" />
<ElTableColumn v-for="col in columns" :key="String(col.prop || 'index')" v-bind="col" />
<template #empty>
<ElEmpty description="当前模块下暂无需求" />
@@ -714,4 +741,8 @@ watch(
:deep(.requirement-source-link) {
padding: 0;
}
:deep(.el-table__row[class*='el-table__row--level-']:not(.el-table__row--level-0) td:first-child .cell) {
color: transparent;
}
</style>