From e0ff3b6f28c451a4dd9517982645b0462684c490 Mon Sep 17 00:00:00 2001 From: "Apple\\Apple" Date: Sun, 8 Jun 2025 12:38:03 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(token):=20auto-generate=20defa?= =?UTF-8?q?ult=20token=20names=20when=20user=20input=20is=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When creating tokens, if the user doesn't provide a token name (empty or whitespace-only), the system will now automatically generate a name using the format "default-xxxxxx" where "xxxxxx" is a 6-character random alphanumeric string. This enhancement ensures that all created tokens have meaningful names and improves the user experience by removing the requirement to manually input token names for quick token creation scenarios. Changes: - Modified token creation logic to detect empty token names - Added automatic fallback to "default" base name when user input is missing - Maintained existing behavior for multiple token creation with random suffixes - Ensured consistent naming pattern across single and batch token creation --- web/src/pages/Token/EditToken.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/src/pages/Token/EditToken.js b/web/src/pages/Token/EditToken.js index 946164da..71f611bd 100644 --- a/web/src/pages/Token/EditToken.js +++ b/web/src/pages/Token/EditToken.js @@ -219,9 +219,15 @@ const EditToken = (props) => { let successCount = 0; // 记录成功创建的令牌数量 for (let i = 0; i < tokenCount; i++) { let localInputs = { ...inputs }; - if (i !== 0) { - // 如果用户想要创建多个令牌,则给每个令牌一个序号后缀 - localInputs.name = `${inputs.name}-${generateRandomSuffix()}`; + + // 检查用户是否填写了令牌名称 + const baseName = inputs.name.trim() === '' ? 'default' : inputs.name; + + if (i !== 0 || inputs.name.trim() === '') { + // 如果创建多个令牌(i !== 0)或者用户没有填写名称,则添加随机后缀 + localInputs.name = `${baseName}-${generateRandomSuffix()}`; + } else { + localInputs.name = baseName; } localInputs.remain_quota = parseInt(localInputs.remain_quota);