"use client"; import { useState } from "react"; import { Truck } from "@phosphor-icons/react"; import { InputField } from "@/components/ui/input-field"; import { PrimaryButton } from "@/components/ui/primary-button"; import { ErrorBanner } from "@/components/ui/error-banner"; import { Card } from "@/components/ui/card"; import { embedDemoLogin, embedDemoLoginWithKey, type EmbedDemoLoginType, type EmbedDemoSession, } from "@/lib/frontend/api-client"; interface EmbedDemoLoginProps { onSuccess: (session: EmbedDemoSession) => void; } const LOGIN_TABS: Array<{ id: EmbedDemoLoginType; label: string }> = [ { id: "password", label: "账号密码登录" }, { id: "api_key", label: "API Key 登录" }, ]; export function EmbedDemoLogin({ onSuccess }: EmbedDemoLoginProps) { const [loginType, setLoginType] = useState("password"); const [customerId, setCustomerId] = useState(""); const [password, setPassword] = useState(""); const [apiKey, setApiKey] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (loading) return; setLoading(true); setError(null); const res = loginType === "api_key" ? await embedDemoLoginWithKey("", apiKey.trim()) : await embedDemoLogin("", customerId.trim(), password); setLoading(false); if (res.code !== 0) { setError( res.message || (loginType === "api_key" ? "API Key 无效" : "客户编号或密码错误"), ); return; } onSuccess(res.data); }; return (
宿主嵌入演示

客户登录

{loginType === "api_key" ? "使用管理员分配的 API Key 登录(每次进入须重新填写)" : "使用客户编号与管理员分配的密码登录(每次进入须重新填写)"}

{LOGIN_TABS.map((tab) => ( ))}
{error && (
{error}
)}
void handleSubmit(e)} className="space-y-4" autoComplete="off" > {loginType === "api_key" ? ( setApiKey(e.target.value)} /> ) : ( <> setCustomerId(e.target.value)} /> setPassword(e.target.value)} /> )} 进入演示
); }