From 9b6931d1ad6ef3d6542b4eda589377ee83286cc9 Mon Sep 17 00:00:00 2001 From: JenniferW <1627055433@qq.com> Date: Wed, 21 Jan 2026 11:07:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=A1=E7=89=87=E6=98=BE=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/order/intention/search.vue | 65 +++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/src/views/order/intention/search.vue b/src/views/order/intention/search.vue index 8f56fab..37a477e 100644 --- a/src/views/order/intention/search.vue +++ b/src/views/order/intention/search.vue @@ -720,7 +720,7 @@ const updateParameterDifferenceFlags = (entries) => { parameterDifferences.value = differences; }; -const getCompareFieldEntries = () => { +const getCompareFieldEntries = (fallbackFieldList = []) => { const dictList = display_field?.value ?? []; if (dictList.length > 0) { return dictList @@ -731,6 +731,22 @@ const getCompareFieldEntries = () => { })); } + // 如果字典还没加载完成,尝试从接口返回的数据中提取字段信息 + if (fallbackFieldList.length > 0) { + const fieldMap = new Map(); + fallbackFieldList.forEach((item) => { + const key = item.fieldKey || item.key || item.param; + const label = item.fieldName || item.label || item.param || key; + if (key && !fieldMap.has(key)) { + fieldMap.set(key, { key, label }); + } + }); + if (fieldMap.size > 0) { + return Array.from(fieldMap.values()); + } + } + + // 最后回退到 allFields return allFields.value.map((field) => ({ key: field.key, label: field.label || field.key, @@ -2334,7 +2350,52 @@ const fetchCompareTable = async () => { .filter(Boolean); diffFieldKeys.value = new Set(responseKeys); - const fieldEntries = getCompareFieldEntries(); + // 等待字典加载完成,最多等待2秒 + let dictLoaded = false; + const dictList = display_field?.value ?? []; + if (dictList.length > 0) { + dictLoaded = true; + } else { + // 如果字典还没加载完成,等待一段时间 + await new Promise((resolve) => { + let attempts = 0; + const maxAttempts = 20; // 最多尝试20次,每次100ms,总共2秒 + const checkDict = () => { + const currentDictList = display_field?.value ?? []; + if (currentDictList.length > 0) { + dictLoaded = true; + resolve(); + } else if (attempts < maxAttempts) { + attempts++; + setTimeout(checkDict, 100); + } else { + resolve(); // 超时后继续执行,使用fallback数据 + } + }; + checkDict(); + }); + } + + // 使用字典数据或接口返回的数据构建字段列表 + const fieldEntries = getCompareFieldEntries(fieldList); + + // 如果字段列表为空,说明数据有问题,尝试从产品数据中提取字段 + if (fieldEntries.length === 0 && sortedCompareList.value.length > 0) { + // 从第一个产品中提取所有字段 + const firstProduct = sortedCompareList.value[0]; + const extractedFields = Object.keys(firstProduct) + .filter((key) => { + // 排除一些非字段属性 + return !['selected', 'isLatest'].includes(key); + }) + .map((key) => ({ + key, + label: getFieldLabelByKey(key), + })); + if (extractedFields.length > 0) { + fieldEntries.push(...extractedFields); + } + } const rows = fieldEntries.map((entry) => { const row = { param: entry.label };