- 页面顶部添加限时特惠横幅,提示当前为特价 - 每个套餐卡片增加"特惠价"徽章 - 价格区域增加折扣百分比标签和涨价提示 - 中英文 i18n 键补全 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
74 lines
17 KiB
JavaScript
74 lines
17 KiB
JavaScript
import{r as o,e as E,f as I,j as e,z as C,h as P,i as W,k as U}from"./index-DFuC01Yj.js";import{u as K}from"./useTranslation-BEbHB0KC.js";const F=()=>{var D;const{t:s}=K(),[j,_]=o.useState([]),[i,L]=o.useState(null),[S,m]=o.useState([]),[l,v]=o.useState(""),[x,A]=o.useState("claudecode"),[H,$]=o.useState(!0),[k,M]=o.useState(!1),[u,p]=o.useState(""),[h,y]=o.useState(!1),T=o.useRef(null),d=window.location.origin,w=[{id:"claudecode",name:"Claude Code",path:"~/.claude/settings.json"},{id:"openclaw",name:"OpenClaw",path:"~/.openclaw/openclaw.json"},{id:"opencode",name:"OpenCode",path:"~/.config/opencode/opencode.json"},{id:"cursor",name:"Cursor",path:"Settings → Models → OpenAI API Key"},{id:"curl",name:"cURL",path:"Terminal"},{id:"python",name:"Python SDK",path:"main.py"},{id:"anthropic",name:"Anthropic SDK",path:"main.py"}];o.useEffect(()=>{a()},[]),o.useEffect(()=>{i&&f(i)},[i]),o.useEffect(()=>{const t=n=>{T.current&&!T.current.contains(n.target)&&y(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[]);const a=async()=>{$(!0);try{const t=await E();if(t.data.success){const n=t.data.data||[];_(n),n.length>0&&L(n[0])}}catch{}$(!1)},f=async t=>{try{if(t.model_limits_enabled&&t.model_limits){const r=t.model_limits.split(",").filter(g=>g.trim());m(r),r.length>0&&v(r[0]);return}const n=await I();if(n.data.success&&n.data.data){const g=(Array.isArray(n.data.data)?n.data.data:n.data.data.items||[]).map(b=>b.model_name||b.id||b);m(g),g.length>0&&v(g[0])}}catch{}},c=t=>{const n=t.toLowerCase();return n.includes("claude")?{provider:"anthropic",api:"anthropic-messages"}:n.includes("gpt")||n.includes("o1")||n.includes("o3")?{provider:"openai",api:"openai-chat"}:n.includes("gemini")?{provider:"google",api:"google-chat"}:{provider:"openai",api:"openai-chat"}},N=()=>{if(!i||!l)return"";const t="sk-"+i.key;switch(x){case"claudecode":return`{
|
|
"env": {
|
|
"ANTHROPIC_API_KEY": "${t}",
|
|
"ANTHROPIC_BASE_URL": "${d}/",
|
|
"ANTHROPIC_MODEL": "${l}"
|
|
}
|
|
}`;case"openclaw":{const n=c(l);return`{
|
|
"provider": "${n.provider}",
|
|
"base_url": "${d}/",
|
|
"api": "${n.api}",
|
|
"api_key": "${t}",
|
|
"model": {
|
|
"id": "${l}",
|
|
"name": "${l}"
|
|
}
|
|
}`}case"opencode":return`{
|
|
"provider": {
|
|
"openai": {
|
|
"options": {
|
|
"baseURL": "${d}/v1",
|
|
"apiKey": "${t}"
|
|
},
|
|
"models": {
|
|
"${l}": {
|
|
"name": "${l}",
|
|
"options": {
|
|
"store": false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"$schema": "https://opencode.ai/config.json"
|
|
}`;case"cursor":return`API Key: ${t}
|
|
Base URL: ${d}/v1
|
|
Model: ${l}`;case"curl":return`curl ${d}/v1/chat/completions \\
|
|
-H "Content-Type: application/json" \\
|
|
-H "Authorization: Bearer ${t}" \\
|
|
-d '{
|
|
"model": "${l}",
|
|
"messages": [
|
|
{"role": "user", "content": "Hello!"}
|
|
]
|
|
}'`;case"python":return`from openai import OpenAI
|
|
|
|
client = OpenAI(
|
|
api_key="${t}",
|
|
base_url="${d}/v1"
|
|
)
|
|
|
|
response = client.chat.completions.create(
|
|
model="${l}",
|
|
messages=[
|
|
{"role": "user", "content": "Hello!"}
|
|
]
|
|
)
|
|
|
|
print(response.choices[0].message.content)`;case"anthropic":return`import anthropic
|
|
|
|
client = anthropic.Anthropic(
|
|
api_key="${t}",
|
|
base_url="${d}/"
|
|
)
|
|
|
|
message = client.messages.create(
|
|
model="${l}",
|
|
max_tokens=1024,
|
|
messages=[
|
|
{"role": "user", "content": "Hello!"}
|
|
]
|
|
)
|
|
|
|
print(message.content[0].text)`;default:return""}},z=()=>{var t;switch(x){case"curl":return"api-call.sh";case"python":return"main.py";case"anthropic":return"main.py";case"cursor":return"cursor-config.txt";default:return((t=w.find(n=>n.id===x))==null?void 0:t.path.split("/").pop())||"config.json"}},O=async()=>{const t=N();try{await navigator.clipboard.writeText(t)}catch{const r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.opacity="0",document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r)}M(!0),C.success(s("config.copied")),setTimeout(()=>M(!1),2e3)},R=()=>{const t=N(),n=z(),r=new Blob([t],{type:"text/plain"}),g=URL.createObjectURL(r),b=document.createElement("a");b.href=g,b.download=n,b.click(),URL.revokeObjectURL(g),C.success(s("config.downloaded"))};if(H)return e.jsxs("div",{className:"glass rounded-2xl p-6 text-center",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-page-secondary",children:s("config.loading")})]});if(j.length===0)return e.jsxs("div",{className:"glass rounded-2xl p-6 text-center",children:[e.jsx("svg",{className:"w-8 h-8 mx-auto mb-3 text-page-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})}),e.jsx("p",{className:"text-sm text-page-secondary mb-1",children:s("config.loginPrompt")}),e.jsx("p",{className:"text-xs text-page-muted",children:s("config.loginDesc")})]});const B=N();return e.jsxs("div",{className:"glass rounded-2xl overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-white/5",children:[e.jsxs("h4",{className:"font-semibold text-sm text-page flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 text-brand-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),s("config.title")]}),e.jsx("p",{className:"text-xs text-page-muted mt-1",children:s("config.subtitle")})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-page-label mb-2",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})}),s("config.selectKey")]}),e.jsx("select",{value:(i==null?void 0:i.id)||"",onChange:t=>{const n=j.find(r=>r.id===parseInt(t.target.value));L(n)},className:"input",children:j.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (sk-",t.key.substring(0,16),"...)"]},t.id))})]}),S.length>0&&e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-medium text-page-label mb-2",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})}),s("config.selectModel")]}),e.jsxs("div",{className:"relative",ref:T,children:[e.jsx("input",{type:"text",value:h?u:l,onChange:t=>{p(t.target.value),y(!0)},onFocus:()=>{p(""),y(!0)},className:"input pr-8",placeholder:s("config.searchModel")}),e.jsx("svg",{className:"w-3.5 h-3.5 absolute right-3 top-1/2 -translate-y-1/2 text-page-muted pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),h&&e.jsxs("div",{className:"absolute z-50 mt-1 w-full max-h-60 overflow-y-auto rounded-lg border border-white/10 bg-neutral-900 shadow-xl",children:[S.filter(t=>t.toLowerCase().includes(u.toLowerCase())).map(t=>e.jsx("button",{onClick:()=>{v(t),y(!1),p("")},className:`w-full text-left px-3 py-2 text-sm transition-colors hover:bg-white/10 ${t===l?"text-brand-400 bg-brand-500/10":"text-page-secondary"}`,children:t},t)),S.filter(t=>t.toLowerCase().includes(u.toLowerCase())).length===0&&e.jsx("p",{className:"px-3 py-3 text-xs text-page-muted text-center",children:s("config.noModelMatch")})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-page-label mb-2 block",children:s("config.selectTool")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:w.map(t=>e.jsx("button",{onClick:()=>A(t.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-all ${x===t.id?"bg-brand-500 text-white shadow-sm":"bg-white/5 text-page-secondary hover:bg-white/10"}`,children:t.name},t.id))})]})]}),e.jsxs("div",{className:"border-t border-white/5",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 bg-black/20",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-red-400"}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-yellow-400"}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-400"})]}),e.jsx("span",{className:"text-xs text-page-muted ml-1",children:(D=w.find(t=>t.id===x))==null?void 0:D.path})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:O,className:"p-1.5 rounded-md hover:bg-white/10 transition-colors text-page-muted hover:text-page",title:s("config.copy"),children:k?e.jsx("svg",{className:"w-3.5 h-3.5 text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),e.jsx("button",{onClick:R,className:"p-1.5 rounded-md hover:bg-white/10 transition-colors text-page-muted hover:text-page",title:s("config.download"),children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})})]})]}),e.jsx("pre",{className:"p-4 text-xs leading-relaxed overflow-x-auto max-h-64 font-mono text-green-400",children:e.jsx("code",{children:B})})]})]})};function Y(){const{t:s}=K(),[j,_]=o.useState([]),[i,L]=o.useState(!0),[S,m]=o.useState(!1),[l,v]=o.useState(""),[x,A]=o.useState(!1),[H,$]=o.useState(null),[k,M]=o.useState(null),[u,p]=o.useState(null),h=o.useCallback(async()=>{L(!0);try{const a=await E();a.data.success&&_(a.data.data||[])}catch{}L(!1)},[]);o.useEffect(()=>{h()},[h]);const y=async a=>{var f;if(a.preventDefault(),!l.trim()){C.error(s("tokens.enterName"));return}A(!0);try{const c=await P({name:l.trim()});if(c.data.success){v(""),m(!1);const N=(f=c.data.data)==null?void 0:f.key;N&&M(N),await h()}}catch{}A(!1)},T=async a=>{try{(await W(a.id,{status:a.status===1?2:1})).data.success&&(C.success(a.status===1?s("tokens.tokenDisabled"):s("tokens.tokenEnabled")),await h())}catch{}},d=async()=>{if(u)try{(await U(u.id)).data.success&&(C.success(s("tokens.tokenDeleted")),p(null),await h())}catch{}},w=async a=>{try{await navigator.clipboard.writeText(a)}catch{const c=document.createElement("textarea");c.value=a,c.style.position="fixed",c.style.opacity="0",document.body.appendChild(c),c.select(),document.execCommand("copy"),document.body.removeChild(c)}$(a),C.success(s("tokens.copiedToClipboard")),setTimeout(()=>$(null),2e3)};return i?e.jsx("div",{className:"flex items-center justify-center min-h-[50vh]",children:e.jsx("div",{className:"w-8 h-8 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"max-w-5xl mx-auto px-6 py-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-heading font-bold text-page",children:s("tokens.title")}),e.jsx("p",{className:"text-sm text-page-secondary mt-1",children:s("tokens.subtitle")})]}),e.jsx("button",{onClick:()=>m(!0),className:"btn-primary",children:s("tokens.newKey")})]}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>m(!1),children:e.jsxs("div",{className:"glass rounded-2xl p-6 w-full max-w-md",onClick:a=>a.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("tokens.createApiKey")}),e.jsxs("form",{onSubmit:y,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-1.5",children:s("tokens.name")}),e.jsx("input",{type:"text",value:l,onChange:a=>v(a.target.value),className:"input",placeholder:s("tokens.namePlaceholder"),autoFocus:!0,required:!0})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>m(!1),className:"btn-secondary",children:s("tokens.cancel")}),e.jsx("button",{type:"submit",disabled:x,className:"btn-primary",children:s(x?"tokens.creating":"tokens.create")})]})]})]})}),k&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"glass rounded-2xl p-6 w-full max-w-lg",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-2",children:s("tokens.newApiKey")}),e.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/20 rounded-xl p-3 mb-4",children:e.jsx("p",{className:"text-sm text-yellow-300",children:s("tokens.keyWarning")})}),e.jsxs("div",{className:"bg-black/40 rounded-xl p-4 flex items-center gap-3",children:[e.jsx("code",{className:"text-sm font-mono text-green-400 flex-1 break-all select-all",children:k}),e.jsx("button",{onClick:()=>w(k),className:"btn-primary !px-4 !py-1.5 flex-shrink-0",children:s(H===k?"tokens.copied":"tokens.copy")})]}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx("button",{onClick:()=>M(null),className:"btn-secondary",children:s("tokens.savedKey")})})]})}),u&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>p(null),children:e.jsxs("div",{className:"glass rounded-2xl p-6 w-full max-w-sm",onClick:a=>a.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-3",children:s("tokens.deleteToken")}),e.jsx("p",{className:"text-sm text-page-secondary mb-4",children:s("tokens.deleteConfirm",{name:u.name})}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>p(null),className:"btn-secondary",children:s("tokens.cancel")}),e.jsx("button",{onClick:d,className:"px-6 py-2.5 rounded-xl bg-red-600 text-white text-sm font-medium hover:bg-red-500 transition-colors",children:s("tokens.delete")})]})]})}),j.length===0?e.jsxs("div",{className:"glass rounded-2xl p-12 text-center",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-2xl bg-neutral-800/50 flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-neutral-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})})}),e.jsx("p",{className:"text-page-secondary mb-4",children:s("tokens.noKeys")}),e.jsx("button",{onClick:()=>m(!0),className:"btn-primary",children:s("tokens.createFirst")})]}):e.jsx("div",{className:"space-y-3",children:j.map(a=>e.jsxs("div",{className:"glass-sm rounded-xl p-5",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${a.status===1?"bg-green-500":"bg-neutral-600"}`}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm font-medium text-page",children:a.name})}),e.jsx("span",{className:"text-xs text-page-muted hidden md:block",children:a.created_time?new Date(a.created_time*1e3).toLocaleDateString():""}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>T(a),className:`px-3 py-1 text-xs rounded-lg border transition-colors ${a.status===1?"border-green-500/30 text-green-400 hover:bg-green-500/10":"border-neutral-600 text-page-secondary hover:bg-neutral-800"}`,children:a.status===1?s("tokens.enabled"):s("tokens.disabled")}),e.jsx("button",{onClick:()=>p(a),className:"px-3 py-1 text-xs rounded-lg border border-red-500/20 text-red-400 hover:bg-red-500/10 transition-colors",children:s("tokens.delete")})]})]}),a.key&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 bg-black/30 rounded-lg px-3 py-2",children:[e.jsxs("code",{className:"text-xs font-mono text-page-muted flex-1 break-all select-all",children:["sk-",a.key]}),e.jsx("button",{onClick:()=>w("sk-"+a.key),className:"flex-shrink-0 px-2.5 py-1 text-xs rounded-md bg-white/10 text-page-secondary hover:bg-white/20 hover:text-page transition-colors",children:H==="sk-"+a.key?s("tokens.copied"):s("tokens.copy")})]})]},a.id))}),e.jsx("div",{className:"mt-8",children:e.jsx(F,{})})]})}export{Y as default};
|