From 44a7d402e058c30b0cc9ba182d49459be8186ab3 Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Tue, 14 Apr 2026 15:07:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BB=B7=E6=A0=BC=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=BA=93=E6=A0=B7=E5=BC=8F=E5=AE=8C=E5=96=84=EF=BC=8C=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E5=BA=8F=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/price/ExcelSearch.vue | 189 ++++++++++++++++++++++++++------ 1 file changed, 156 insertions(+), 33 deletions(-) diff --git a/src/views/price/ExcelSearch.vue b/src/views/price/ExcelSearch.vue index 910f001..71764e4 100644 --- a/src/views/price/ExcelSearch.vue +++ b/src/views/price/ExcelSearch.vue @@ -343,6 +343,39 @@ const escapeRegExp = (string: string) => { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }; +/** + * 获取关键字段(key 包含"名称"、"规格"、"价"、"金额") + * @param item - ExcelRowData 对象 + * @returns 关键字段列表 + */ +const getKeyFields = (item: ExcelRowData) => { + const keyNames = ['名称', '规格', '价', '金额']; + try { + const rowObj = JSON.parse(item.rowData); + const keyword = searchKeyword.value.toLowerCase().trim(); + + const highlightText = (text: string) => { + if (!keyword) return text; + const regex = new RegExp(`(${escapeRegExp(keyword)})`, 'gi'); + return text.replace(regex, '$1'); + }; + + return Object.entries(rowObj) + .filter(([key]) => keyNames.some(k => key.includes(k))) + .map(([key, value]) => { + let displayValue = typeof value === 'object' + ? JSON.stringify(value) + : String(value); + return { + key: highlightText(key), + value: highlightText(displayValue) + }; + }); + } catch { + return []; + } +}; + // ==================== 表格列表相关方法 ==================== /** @@ -694,10 +727,10 @@ loadBatchList();