From 59381dac00b127b233e2ea66a4c037c7cf150d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9A=93=E6=9C=88=E5=BD=92=E5=B0=98?= Date: Tue, 22 Apr 2025 03:42:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20HTS=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 useIndex 和 exportToExcel 函数中,改进了对 HTS 数据的处理方式 - 通过遍历结果层级,生成格式化的描述字符串,替代了之前的条件判断逻辑 - 新的实现方式提高了代码的可读性和可维护性,同时支持更多层级的 HTS 数据 --- src/views/codes/index/utils/hook.tsx | 159 +++++++++++++++++---- src/views/codes/log/components/details.vue | 141 ++++++++++++++---- 2 files changed, 244 insertions(+), 56 deletions(-) diff --git a/src/views/codes/index/utils/hook.tsx b/src/views/codes/index/utils/hook.tsx index 82a6bb5..de36ab0 100644 --- a/src/views/codes/index/utils/hook.tsx +++ b/src/views/codes/index/utils/hook.tsx @@ -452,39 +452,136 @@ export const useIndex = (tableRef: Ref) => { response.result_text[0]["description"] ); if (response.result_text[0]["hts_data"]) { - 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" - ] - ); + let description = ""; + if (response.result_text[0]["hts_data"]["oneResult"]) { + description = + description + + `${ + response.result_text[0]["hts_data"]["oneResult"]["htsno"] + ? response.result_text[0]["hts_data"]["oneResult"][ + "htsno" + ] + .replace(/(\d{2})/g, "$1.") + .slice(0, -1) + : "" + }:${ + response.result_text[0]["hts_data"]["oneResult"][ + "description" + ] + }\n`; } 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 { row.push(""); } diff --git a/src/views/codes/log/components/details.vue b/src/views/codes/log/components/details.vue index d569035..2533099 100644 --- a/src/views/codes/log/components/details.vue +++ b/src/views/codes/log/components/details.vue @@ -512,33 +512,124 @@ const exportToExcel = (dataList: QueryCodeLogInfo[], filename: string) => { response.result_text[0]["description"] ); if (response.result_text[0]["hts_data"]) { - 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"] - ); + let description = ""; + if (response.result_text[0]["hts_data"]["oneResult"]) { + description = + description + + `${ + response.result_text[0]["hts_data"]["oneResult"]["htsno"] + ? response.result_text[0]["hts_data"]["oneResult"]["htsno"] + .replace(/(\d{2})/g, "$1.") + .slice(0, -1) + : "" + }:${ + response.result_text[0]["hts_data"]["oneResult"][ + "description" + ] + }\n`; } 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 { row.push(""); }