From 7a203295941c83fb7c8a1b9ef5f468eff1a91d15 Mon Sep 17 00:00:00 2001 From: zxr <271055687@qq.com> Date: Sun, 5 Jul 2026 18:35:01 +0800 Subject: [PATCH] fix: validate advanced snmp oid json rows --- .../device-collect/components/FormDialog.vue | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/views/ops/pages/dc/device-collect/components/FormDialog.vue b/src/views/ops/pages/dc/device-collect/components/FormDialog.vue index 2a947b1..dae7be5 100644 --- a/src/views/ops/pages/dc/device-collect/components/FormDialog.vue +++ b/src/views/ops/pages/dc/device-collect/components/FormDialog.vue @@ -355,12 +355,21 @@ const hasSnmpOidTableUnsupportedFields = (raw: string) => { const rows = parseSnmpOidJsonArray(raw) return rows.some((item) => { if (!item || typeof item !== 'object' || Array.isArray(item)) { - return Boolean(item) + return true } return Object.keys(item).some((key) => !snmpOidTableFields.includes(key)) }) } +const findInvalidSnmpOidJsonRowIndex = (rows: unknown[]) => + rows.findIndex((item) => { + if (!item || typeof item !== 'object' || Array.isArray(item)) { + return true + } + const row = item as Record + return !String(row.oid ?? '').trim() || !String(row.metric_name ?? '').trim() + }) + const stringifySnmpOidRows = (rows: SnmpOidRow[]) => { const normalizedRows = normalizeSnmpOidRows(rows) return normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : '' @@ -552,12 +561,12 @@ const validateSnmpOidConfigBeforeSubmit = () => { try { const parsedRows = parseSnmpOidJsonArray(formData.snmp_oids) - const rows = parseSnmpOidRows(formData.snmp_oids) - const invalidIndex = findIncompleteSnmpOidRowIndex(rows) - if (invalidIndex >= 0) { - Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`) + const invalidJsonIndex = findInvalidSnmpOidJsonRowIndex(parsedRows) + if (invalidJsonIndex >= 0) { + Message.warning(`SNMP OID 第 ${invalidJsonIndex + 1} 行请填写 OID 和指标名称`) return false } + const rows = parseSnmpOidRows(formData.snmp_oids) const normalizedRows = normalizeSnmpOidRows(rows) snmpOidRows.value = normalizedRows formData.snmp_oids = JSON.stringify(parsedRows, null, 2)