From 3c276d13c4991e06d3dbafe508f0ebc2dc1b6a3a Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Tue, 17 Jun 2025 21:05:24 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(GroupRatioSettings):=20enhance?= =?UTF-8?q?=20JSON=20validation=20for=20group=20ratios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Setting/Operation/GroupRatioSettings.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/web/src/pages/Setting/Operation/GroupRatioSettings.js b/web/src/pages/Setting/Operation/GroupRatioSettings.js index c0e1ed24..4a51a98c 100644 --- a/web/src/pages/Setting/Operation/GroupRatioSettings.js +++ b/web/src/pages/Setting/Operation/GroupRatioSettings.js @@ -180,8 +180,27 @@ export default function GroupRatioSettings(props) { stopValidateWithError rules={[ { - validator: (rule, value) => verifyJSON(value), - message: t('不是合法的 JSON 字符串'), + validator: (rule, value) => { + if (!value || value.trim() === '') { + return true; // Allow empty values + } + + // First check if it's valid JSON + try { + const parsed = JSON.parse(value); + + // Check if it's an array + if (!Array.isArray(parsed)) { + return false; + } + + // Check if every element is a string + return parsed.every(item => typeof item === 'string'); + } catch (error) { + return false; + } + }, + message: t('必须是有效的 JSON 字符串数组,例如:["g1","g2"]'), }, ]} onChange={(value) =>