refactor: 重构 HTS 数据处理逻辑
- 在 useIndex 和 exportToExcel 函数中,改进了对 HTS 数据的处理方式 - 通过遍历结果层级,生成格式化的描述字符串,替代了之前的条件判断逻辑 - 新的实现方式提高了代码的可读性和可维护性,同时支持更多层级的 HTS 数据
This commit is contained in:
parent
ceef159ec4
commit
59381dac00
@ -452,39 +452,136 @@ export const useIndex = (tableRef: Ref) => {
|
|||||||
response.result_text[0]["description"]
|
response.result_text[0]["description"]
|
||||||
);
|
);
|
||||||
if (response.result_text[0]["hts_data"]) {
|
if (response.result_text[0]["hts_data"]) {
|
||||||
if (response.result_text[0]["hts_data"]["fiveResult"]) {
|
let description = "";
|
||||||
row.push(
|
if (response.result_text[0]["hts_data"]["oneResult"]) {
|
||||||
response.result_text[0]["hts_data"]["fiveResult"][
|
description =
|
||||||
"description"
|
description +
|
||||||
]
|
`${
|
||||||
);
|
response.result_text[0]["hts_data"]["oneResult"]["htsno"]
|
||||||
} else if (response.result_text[0]["hts_data"]["fourResult"]) {
|
? response.result_text[0]["hts_data"]["oneResult"][
|
||||||
row.push(
|
"htsno"
|
||||||
response.result_text[0]["hts_data"]["fourResult"][
|
]
|
||||||
"description"
|
.replace(/(\d{2})/g, "$1.")
|
||||||
]
|
.slice(0, -1)
|
||||||
);
|
: ""
|
||||||
} else if (response.result_text[0]["hts_data"]["threeResult"]) {
|
}:${
|
||||||
row.push(
|
response.result_text[0]["hts_data"]["oneResult"][
|
||||||
response.result_text[0]["hts_data"]["threeResult"][
|
"description"
|
||||||
"description"
|
]
|
||||||
]
|
}\n`;
|
||||||
);
|
|
||||||
} else if (response.result_text[0]["hts_data"]["secondResult"]) {
|
|
||||||
row.push(
|
|
||||||
response.result_text[0]["hts_data"]["secondResult"][
|
|
||||||
"description"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
} else if (response.result_text[0]["hts_data"]["oneResult"]) {
|
|
||||||
row.push(
|
|
||||||
response.result_text[0]["hts_data"]["oneResult"][
|
|
||||||
"description"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
row.push("");
|
description = description + "\n";
|
||||||
}
|
}
|
||||||
|
if (response.result_text[0]["hts_data"]["secondResult"]) {
|
||||||
|
description =
|
||||||
|
description +
|
||||||
|
`\t${
|
||||||
|
response.result_text[0]["hts_data"]["secondResult"]["htsno"]
|
||||||
|
? response.result_text[0]["hts_data"]["secondResult"][
|
||||||
|
"htsno"
|
||||||
|
]
|
||||||
|
.replace(/(\d{2})/g, "$1.")
|
||||||
|
.slice(0, -1)
|
||||||
|
: ""
|
||||||
|
}:${
|
||||||
|
response.result_text[0]["hts_data"]["secondResult"][
|
||||||
|
"description"
|
||||||
|
]
|
||||||
|
}\n`;
|
||||||
|
} else {
|
||||||
|
description = description + "\t\n";
|
||||||
|
}
|
||||||
|
if (response.result_text[0]["hts_data"]["threeResult"]) {
|
||||||
|
description =
|
||||||
|
description +
|
||||||
|
`\t\t${
|
||||||
|
response.result_text[0]["hts_data"]["threeResult"]["htsno"]
|
||||||
|
? response.result_text[0]["hts_data"]["threeResult"][
|
||||||
|
"htsno"
|
||||||
|
]
|
||||||
|
.replace(/(\d{2})/g, "$1.")
|
||||||
|
.slice(0, -1)
|
||||||
|
: ""
|
||||||
|
}:${
|
||||||
|
response.result_text[0]["hts_data"]["threeResult"][
|
||||||
|
"description"
|
||||||
|
]
|
||||||
|
}\n`;
|
||||||
|
} else {
|
||||||
|
description = description + "\t\t\n";
|
||||||
|
}
|
||||||
|
if (response.result_text[0]["hts_data"]["fourResult"]) {
|
||||||
|
description =
|
||||||
|
description +
|
||||||
|
`\t\t\t${
|
||||||
|
response.result_text[0]["hts_data"]["fourResult"]["htsno"]
|
||||||
|
? response.result_text[0]["hts_data"]["fourResult"][
|
||||||
|
"htsno"
|
||||||
|
]
|
||||||
|
.replace(/(\d{2})/g, "$1.")
|
||||||
|
.slice(0, -1)
|
||||||
|
: ""
|
||||||
|
}:${
|
||||||
|
response.result_text[0]["hts_data"]["fourResult"][
|
||||||
|
"description"
|
||||||
|
]
|
||||||
|
}\n`;
|
||||||
|
} else {
|
||||||
|
description = description + "\t\t\t\n";
|
||||||
|
}
|
||||||
|
if (response.result_text[0]["hts_data"]["fiveResult"]) {
|
||||||
|
description =
|
||||||
|
description +
|
||||||
|
`\t\t\t\t${
|
||||||
|
response.result_text[0]["hts_data"]["fiveResult"]["htsno"]
|
||||||
|
? response.result_text[0]["hts_data"]["fiveResult"][
|
||||||
|
"htsno"
|
||||||
|
]
|
||||||
|
.replace(/(\d{2})/g, "$1.")
|
||||||
|
.slice(0, -1)
|
||||||
|
: ""
|
||||||
|
}:${
|
||||||
|
response.result_text[0]["hts_data"]["fiveResult"][
|
||||||
|
"description"
|
||||||
|
]
|
||||||
|
}\n`;
|
||||||
|
} else {
|
||||||
|
description = description + "\t\t\t\t\n";
|
||||||
|
}
|
||||||
|
row.push(description);
|
||||||
|
// if (response.result_text[0]["hts_data"]["fiveResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["fiveResult"][
|
||||||
|
// "description"
|
||||||
|
// ]
|
||||||
|
// );
|
||||||
|
// } else if (response.result_text[0]["hts_data"]["fourResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["fourResult"][
|
||||||
|
// "description"
|
||||||
|
// ]
|
||||||
|
// );
|
||||||
|
// } else if (response.result_text[0]["hts_data"]["threeResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["threeResult"][
|
||||||
|
// "description"
|
||||||
|
// ]
|
||||||
|
// );
|
||||||
|
// } else if (response.result_text[0]["hts_data"]["secondResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["secondResult"][
|
||||||
|
// "description"
|
||||||
|
// ]
|
||||||
|
// );
|
||||||
|
// } else if (response.result_text[0]["hts_data"]["oneResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["oneResult"][
|
||||||
|
// "description"
|
||||||
|
// ]
|
||||||
|
// );
|
||||||
|
// } else {
|
||||||
|
// row.push("");
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
row.push("");
|
row.push("");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -512,33 +512,124 @@ const exportToExcel = (dataList: QueryCodeLogInfo[], filename: string) => {
|
|||||||
response.result_text[0]["description"]
|
response.result_text[0]["description"]
|
||||||
);
|
);
|
||||||
if (response.result_text[0]["hts_data"]) {
|
if (response.result_text[0]["hts_data"]) {
|
||||||
if (response.result_text[0]["hts_data"]["fiveResult"]) {
|
let description = "";
|
||||||
row.push(
|
if (response.result_text[0]["hts_data"]["oneResult"]) {
|
||||||
response.result_text[0]["hts_data"]["fiveResult"]["description"]
|
description =
|
||||||
);
|
description +
|
||||||
} else if (response.result_text[0]["hts_data"]["fourResult"]) {
|
`${
|
||||||
row.push(
|
response.result_text[0]["hts_data"]["oneResult"]["htsno"]
|
||||||
response.result_text[0]["hts_data"]["fourResult"]["description"]
|
? response.result_text[0]["hts_data"]["oneResult"]["htsno"]
|
||||||
);
|
.replace(/(\d{2})/g, "$1.")
|
||||||
} else if (response.result_text[0]["hts_data"]["threeResult"]) {
|
.slice(0, -1)
|
||||||
row.push(
|
: ""
|
||||||
response.result_text[0]["hts_data"]["threeResult"][
|
}:${
|
||||||
"description"
|
response.result_text[0]["hts_data"]["oneResult"][
|
||||||
]
|
"description"
|
||||||
);
|
]
|
||||||
} else if (response.result_text[0]["hts_data"]["secondResult"]) {
|
}\n`;
|
||||||
row.push(
|
|
||||||
response.result_text[0]["hts_data"]["secondResult"][
|
|
||||||
"description"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
} else if (response.result_text[0]["hts_data"]["oneResult"]) {
|
|
||||||
row.push(
|
|
||||||
response.result_text[0]["hts_data"]["oneResult"]["description"]
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
row.push("");
|
description = description + "\n";
|
||||||
}
|
}
|
||||||
|
if (response.result_text[0]["hts_data"]["secondResult"]) {
|
||||||
|
description =
|
||||||
|
description +
|
||||||
|
`\t${
|
||||||
|
response.result_text[0]["hts_data"]["secondResult"]["htsno"]
|
||||||
|
? response.result_text[0]["hts_data"]["secondResult"][
|
||||||
|
"htsno"
|
||||||
|
]
|
||||||
|
.replace(/(\d{2})/g, "$1.")
|
||||||
|
.slice(0, -1)
|
||||||
|
: ""
|
||||||
|
}:${
|
||||||
|
response.result_text[0]["hts_data"]["secondResult"][
|
||||||
|
"description"
|
||||||
|
]
|
||||||
|
}\n`;
|
||||||
|
} else {
|
||||||
|
description = description + "\t\n";
|
||||||
|
}
|
||||||
|
if (response.result_text[0]["hts_data"]["threeResult"]) {
|
||||||
|
description =
|
||||||
|
description +
|
||||||
|
`\t\t${
|
||||||
|
response.result_text[0]["hts_data"]["threeResult"]["htsno"]
|
||||||
|
? response.result_text[0]["hts_data"]["threeResult"][
|
||||||
|
"htsno"
|
||||||
|
]
|
||||||
|
.replace(/(\d{2})/g, "$1.")
|
||||||
|
.slice(0, -1)
|
||||||
|
: ""
|
||||||
|
}:${
|
||||||
|
response.result_text[0]["hts_data"]["threeResult"][
|
||||||
|
"description"
|
||||||
|
]
|
||||||
|
}\n`;
|
||||||
|
} else {
|
||||||
|
description = description + "\t\t\n";
|
||||||
|
}
|
||||||
|
if (response.result_text[0]["hts_data"]["fourResult"]) {
|
||||||
|
description =
|
||||||
|
description +
|
||||||
|
`\t\t\t${
|
||||||
|
response.result_text[0]["hts_data"]["fourResult"]["htsno"]
|
||||||
|
? response.result_text[0]["hts_data"]["fourResult"]["htsno"]
|
||||||
|
.replace(/(\d{2})/g, "$1.")
|
||||||
|
.slice(0, -1)
|
||||||
|
: ""
|
||||||
|
}:${
|
||||||
|
response.result_text[0]["hts_data"]["fourResult"][
|
||||||
|
"description"
|
||||||
|
]
|
||||||
|
}\n`;
|
||||||
|
} else {
|
||||||
|
description = description + "\t\t\t\n";
|
||||||
|
}
|
||||||
|
if (response.result_text[0]["hts_data"]["fiveResult"]) {
|
||||||
|
description =
|
||||||
|
description +
|
||||||
|
`\t\t\t\t${
|
||||||
|
response.result_text[0]["hts_data"]["fiveResult"]["htsno"]
|
||||||
|
? response.result_text[0]["hts_data"]["fiveResult"]["htsno"]
|
||||||
|
.replace(/(\d{2})/g, "$1.")
|
||||||
|
.slice(0, -1)
|
||||||
|
: ""
|
||||||
|
}:${
|
||||||
|
response.result_text[0]["hts_data"]["fiveResult"][
|
||||||
|
"description"
|
||||||
|
]
|
||||||
|
}\n`;
|
||||||
|
} else {
|
||||||
|
description = description + "\t\t\t\t\n";
|
||||||
|
}
|
||||||
|
row.push(description);
|
||||||
|
// if (response.result_text[0]["hts_data"]["fiveResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["fiveResult"]["description"]
|
||||||
|
// );
|
||||||
|
// } else if (response.result_text[0]["hts_data"]["fourResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["fourResult"]["description"]
|
||||||
|
// );
|
||||||
|
// } else if (response.result_text[0]["hts_data"]["threeResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["threeResult"][
|
||||||
|
// "description"
|
||||||
|
// ]
|
||||||
|
// );
|
||||||
|
// } else if (response.result_text[0]["hts_data"]["secondResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["secondResult"][
|
||||||
|
// "description"
|
||||||
|
// ]
|
||||||
|
// );
|
||||||
|
// } else if (response.result_text[0]["hts_data"]["oneResult"]) {
|
||||||
|
// row.push(
|
||||||
|
// response.result_text[0]["hts_data"]["oneResult"]["description"]
|
||||||
|
// );
|
||||||
|
// } else {
|
||||||
|
// row.push("");
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
row.push("");
|
row.push("");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user