From b5b9ea3e03b03a22fb43a695e807aa733878977e Mon Sep 17 00:00:00 2001 From: zhang1106 <849185023@qq.com> Date: Fri, 6 Feb 2026 16:03:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(devices):=20=E6=94=B9=E8=BF=9BCSV=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=97=B6=E7=9A=84=E5=AD=97=E6=AE=B5=E5=90=8D=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E9=80=BB=E8=BE=91=E5=B9=B6=E7=A7=BB=E9=99=A4=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除不必要的调试日志输出 优化字段名提取正则表达式以更好处理带格式说明的字段 --- backend/routes/devices.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/routes/devices.js b/backend/routes/devices.js index 33566c6..d13ed42 100644 --- a/backend/routes/devices.js +++ b/backend/routes/devices.js @@ -508,9 +508,13 @@ router.post('/import', async (req, res) => { const row = results[i]; const rowNum = i + 2; // CSV行号(第一行是标题) - // 辅助函数:从带格式说明的字段名中提取原始字段名(如从"设备类型(server/switch/router/storage)"提取"设备类型") + // 辅助函数:从带格式说明的字段名中提取原始字段名 + // 例如:"设备类型(server/switch/router/storage)" -> "设备类型" + // "位置(U)(必填)" -> "位置(U)" const extractFieldName = (fieldNameWithFormat) => { - const match = fieldNameWithFormat.match(/^([^\(]+)/); + // 匹配规则:提取到 "(必填)"、"(可选)"、"(YYYY-MM-DD)" 或类似格式说明之前的内容 + // 但保留字段名本身的括号,如 "位置(U)" + const match = fieldNameWithFormat.match(/^(.+?)(\(必填\)|\(可选\)|\([a-zA-Z0-9\-\/]+\))$/); return match ? match[1].trim() : fieldNameWithFormat; }; @@ -535,14 +539,12 @@ router.post('/import', async (req, res) => { const missingFields = []; for (const fieldName of trulyRequiredFields) { const value = fieldValueMap[fieldName]; - console.log(`验证字段: ${fieldName}, 值:`, value); if (!value || (typeof value === 'string' && value.trim() === '')) { missingFields.push(fieldName); } } if (missingFields.length > 0) { - console.log('fieldValueMap:', fieldValueMap); throw new Error(`缺少必填字段:${missingFields.join('、')}`); }