2025-10-17 14:31:34 +08:00
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
|
import ApiKeyInput from "../ApiKeyInput";
|
|
|
|
|
|
import type { ProviderCategory } from "@/types";
|
|
|
|
|
|
|
|
|
|
|
|
interface ApiKeySectionProps {
|
|
|
|
|
|
id?: string;
|
|
|
|
|
|
label?: string;
|
|
|
|
|
|
value: string;
|
|
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
|
|
category?: ProviderCategory;
|
|
|
|
|
|
shouldShowLink: boolean;
|
|
|
|
|
|
websiteUrl: string;
|
|
|
|
|
|
placeholder?: {
|
|
|
|
|
|
official: string;
|
|
|
|
|
|
thirdParty: string;
|
|
|
|
|
|
};
|
|
|
|
|
|
disabled?: boolean;
|
2025-11-06 15:22:38 +08:00
|
|
|
|
isPartner?: boolean;
|
|
|
|
|
|
partnerPromotionKey?: string;
|
2025-10-17 14:31:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function ApiKeySection({
|
|
|
|
|
|
id,
|
|
|
|
|
|
label,
|
|
|
|
|
|
value,
|
|
|
|
|
|
onChange,
|
|
|
|
|
|
category,
|
|
|
|
|
|
shouldShowLink,
|
|
|
|
|
|
websiteUrl,
|
|
|
|
|
|
placeholder,
|
|
|
|
|
|
disabled,
|
2025-11-06 15:22:38 +08:00
|
|
|
|
isPartner,
|
|
|
|
|
|
partnerPromotionKey,
|
2025-10-17 14:31:34 +08:00
|
|
|
|
}: ApiKeySectionProps) {
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
|
|
const defaultPlaceholder = {
|
|
|
|
|
|
official: t("providerForm.officialNoApiKey", {
|
|
|
|
|
|
defaultValue: "官方供应商无需 API Key",
|
|
|
|
|
|
}),
|
|
|
|
|
|
thirdParty: t("providerForm.apiKeyAutoFill", {
|
|
|
|
|
|
defaultValue: "输入 API Key,将自动填充到配置",
|
|
|
|
|
|
}),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const finalPlaceholder = placeholder || defaultPlaceholder;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
|
<ApiKeyInput
|
|
|
|
|
|
id={id}
|
|
|
|
|
|
label={label}
|
|
|
|
|
|
value={value}
|
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
|
placeholder={
|
|
|
|
|
|
category === "official"
|
|
|
|
|
|
? finalPlaceholder.official
|
|
|
|
|
|
: finalPlaceholder.thirdParty
|
|
|
|
|
|
}
|
|
|
|
|
|
disabled={disabled ?? category === "official"}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{/* API Key 获取链接 */}
|
|
|
|
|
|
{shouldShowLink && websiteUrl && (
|
2025-11-06 15:22:38 +08:00
|
|
|
|
<div className="space-y-2 -mt-1 pl-1">
|
2025-10-17 14:31:34 +08:00
|
|
|
|
<a
|
|
|
|
|
|
href={websiteUrl}
|
|
|
|
|
|
target="_blank"
|
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
|
className="text-xs text-blue-400 dark:text-blue-500 hover:text-blue-500 dark:hover:text-blue-400 transition-colors"
|
|
|
|
|
|
>
|
|
|
|
|
|
{t("providerForm.getApiKey", {
|
|
|
|
|
|
defaultValue: "获取 API Key",
|
|
|
|
|
|
})}
|
|
|
|
|
|
</a>
|
2025-11-06 15:22:38 +08:00
|
|
|
|
|
|
|
|
|
|
{/* 合作伙伴促销信息 */}
|
|
|
|
|
|
{isPartner && partnerPromotionKey && (
|
|
|
|
|
|
<div className="rounded-md bg-blue-50 dark:bg-blue-950/30 p-2.5 border border-blue-200 dark:border-blue-800">
|
|
|
|
|
|
<p className="text-xs leading-relaxed text-blue-700 dark:text-blue-300">
|
|
|
|
|
|
💡{" "}
|
|
|
|
|
|
{t(`providerForm.partnerPromotion.${partnerPromotionKey}`, {
|
|
|
|
|
|
defaultValue: "",
|
|
|
|
|
|
})}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2025-10-17 14:31:34 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|