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 63262c4..c67a6dd 100644 --- a/src/views/ops/pages/dc/device-collect/components/FormDialog.vue +++ b/src/views/ops/pages/dc/device-collect/components/FormDialog.vue @@ -324,6 +324,19 @@ const normalizeSnmpOidRows = (rows: SnmpOidRow[]) => })) .filter((row) => row.oid || row.metric_name || row.metric_unit || row.type) +const findIncompleteSnmpOidRowIndex = (rows: SnmpOidRow[]) => + rows.findIndex((row) => { + const normalizedRow = { + oid: row.oid.trim(), + metric_name: row.metric_name.trim(), + metric_unit: row.metric_unit.trim(), + type: row.type.trim(), + } + const hasAnyValue = + normalizedRow.oid || normalizedRow.metric_name || normalizedRow.metric_unit || normalizedRow.type + return Boolean(hasAnyValue && (!normalizedRow.oid || !normalizedRow.metric_name)) + }) + const stringifySnmpOidRows = (rows: SnmpOidRow[]) => { const normalizedRows = normalizeSnmpOidRows(rows) return normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : '' @@ -491,12 +504,12 @@ const switchSnmpOidEditMode = () => { const validateSnmpOidConfigBeforeSubmit = () => { if (snmpOidEditMode.value === 'table') { - const rows = normalizeSnmpOidRows(snmpOidRows.value) - const invalidIndex = rows.findIndex((row) => !row.oid || !row.metric_name) + const invalidIndex = findIncompleteSnmpOidRowIndex(snmpOidRows.value) if (invalidIndex >= 0) { Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`) return false } + const rows = normalizeSnmpOidRows(snmpOidRows.value) formData.snmp_oids = rows.length ? JSON.stringify(rows, null, 2) : '' return true } @@ -509,12 +522,12 @@ const validateSnmpOidConfigBeforeSubmit = () => { try { const rows = parseSnmpOidRows(formData.snmp_oids) - const normalizedRows = normalizeSnmpOidRows(rows) - const invalidIndex = normalizedRows.findIndex((row) => !row.oid || !row.metric_name) + const invalidIndex = findIncompleteSnmpOidRowIndex(rows) if (invalidIndex >= 0) { Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`) return false } + const normalizedRows = normalizeSnmpOidRows(rows) snmpOidRows.value = normalizedRows formData.snmp_oids = normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : '' return true