feat: validate snmp oid table rows
This commit is contained in:
@@ -489,6 +489,40 @@ const switchSnmpOidEditMode = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const validateSnmpOidConfigBeforeSubmit = () => {
|
||||||
|
if (snmpOidEditMode.value === 'table') {
|
||||||
|
const rows = normalizeSnmpOidRows(snmpOidRows.value)
|
||||||
|
const invalidIndex = rows.findIndex((row) => !row.oid || !row.metric_name)
|
||||||
|
if (invalidIndex >= 0) {
|
||||||
|
Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
formData.snmp_oids = rows.length ? JSON.stringify(rows, null, 2) : ''
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!formData.snmp_oids?.trim()) {
|
||||||
|
snmpOidRows.value = []
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const rows = parseSnmpOidRows(formData.snmp_oids)
|
||||||
|
const normalizedRows = normalizeSnmpOidRows(rows)
|
||||||
|
const invalidIndex = normalizedRows.findIndex((row) => !row.oid || !row.metric_name)
|
||||||
|
if (invalidIndex >= 0) {
|
||||||
|
Message.warning(`SNMP OID 第 ${invalidIndex + 1} 行请填写 OID 和指标名称`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
snmpOidRows.value = normalizedRows
|
||||||
|
formData.snmp_oids = normalizedRows.length ? JSON.stringify(normalizedRows, null, 2) : ''
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
Message.warning('SNMP OID 配置必须是合法 JSON 数组')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
try {
|
try {
|
||||||
await formRef.value?.validate()
|
await formRef.value?.validate()
|
||||||
@@ -518,13 +552,8 @@ const handleOk = async () => {
|
|||||||
Message.warning('SNMP v2c 模式下请填写 community')
|
Message.warning('SNMP v2c 模式下请填写 community')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (formData.snmp_oids?.trim()) {
|
if (!validateSnmpOidConfigBeforeSubmit()) {
|
||||||
try {
|
return
|
||||||
JSON.parse(formData.snmp_oids)
|
|
||||||
} catch {
|
|
||||||
Message.warning('SNMP OID 配置必须是合法 JSON')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user