From 2a56a0d8893f2c068692a85a797cd57dec2b8aec Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 10 Nov 2025 15:42:36 +0800 Subject: [PATCH] style(usage-script): unify form input styles with shadcn/ui components Replace native HTML input elements with shadcn/ui Input and FormLabel components to ensure consistent styling across the application. Changes: - Import Input, FormLabel, Eye, and EyeOff components - Replace all credential input fields with Input component - Add show/hide toggle buttons for password fields (API Key, Access Token) - Replace label/span elements with FormLabel component - Update timeout and auto-query interval inputs to use Input component - Improve spacing consistency (space-y-4 for credential config) - Add proper id attributes for accessibility - Use muted-foreground for hint text The form now matches the styling of provider configuration forms throughout the application. --- src/components/UsageScriptModal.tsx | 173 +++++++++++++++++----------- 1 file changed, 104 insertions(+), 69 deletions(-) diff --git a/src/components/UsageScriptModal.tsx b/src/components/UsageScriptModal.tsx index ce4ed5b..899b5ba 100644 --- a/src/components/UsageScriptModal.tsx +++ b/src/components/UsageScriptModal.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { Play, Wand2 } from "lucide-react"; +import { Play, Wand2, Eye, EyeOff } from "lucide-react"; import { toast } from "sonner"; import { useTranslation } from "react-i18next"; import { Provider, UsageScript } from "@/types"; @@ -16,6 +16,8 @@ import { DialogFooter, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { FormLabel } from "@/components/ui/form"; interface UsageScriptModalProps { provider: Provider; @@ -140,6 +142,10 @@ const UsageScriptModal: React.FC = ({ }, ); + // 控制 API Key 的显示/隐藏 + const [showApiKey, setShowApiKey] = useState(false); + const [showAccessToken, setShowAccessToken] = useState(false); + const handleSave = () => { // 验证脚本格式 if (script.enabled && !script.code.trim()) { @@ -292,9 +298,9 @@ const UsageScriptModal: React.FC = ({ <> {/* 预设模板选择 */}
- +
{Object.keys(PRESET_TEMPLATES).map((name) => { const isSelected = selectedTemplate === name; @@ -317,93 +323,122 @@ const UsageScriptModal: React.FC = ({ {/* 凭证配置区域:通用和 NewAPI 模板显示 */} {shouldShowCredentialsConfig && ( -
-

+
+

{t("usageScript.credentialsConfig")}

{/* 通用模板:显示 apiKey + baseUrl */} {selectedTemplate === TEMPLATE_KEYS.GENERAL && ( <> -
@@ -411,9 +446,9 @@ const UsageScriptModal: React.FC = ({ {/* 脚本编辑器 */}
- + setScript({ ...script, code })} @@ -430,14 +465,15 @@ const UsageScriptModal: React.FC = ({ {/* 配置选项 */}
-
{/* 脚本说明 */}