Files
Sub-Router/dist/assets/Topup-CS3pbNbp.js
T
abingyydsandClaude Sonnet 4.6 b27fa4df53 fix: 修复官方等价对比 pattern 无法匹配后端 model_name 的问题
- Pattern 改为匹配后端实际格式(如 claude-opus-4-5 而非 claude-4.5-opus)
- 确保更具体的 pattern 排在前面,避免 Opus 4.5 误匹配到 Opus 4 的 $15 官方价
- 补充更多模型:GPT-4.1 Mini/Nano、Gemini Flash Lite、DeepSeek R1/V3 等

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 17:41:01 +09:00

2 lines
15 KiB
JavaScript

import{u as qe,a as $e,r as n,g as Te,n as Oe,j as e,Q as te,d as Me,z as d,o as Ee,p as Le,q as Ue,t as He,v as Re,w as De,x as Fe}from"./index-D8eKls75.js";import{C as L}from"./CountUp-BixuEoA6.js";import{u as ze}from"./useTranslation-D_OVvIX9.js";function Ve(){var Z;const{t:s}=ze(),{user:i,refreshUser:U}=qe(),{site:r}=$e(),[m,se]=n.useState(null),[l,ae]=n.useState(null),[le,H]=n.useState(!0),[T,R]=n.useState(""),[D,F]=n.useState(!1),[h,O]=n.useState(""),[ne,M]=n.useState(null),[z,B]=n.useState(null),[re,W]=n.useState(!1),[b,y]=n.useState(!1),[E,f]=n.useState(""),[C,S]=n.useState(null),[ce,j]=n.useState(!1),[p,Q]=n.useState(""),[k,oe]=n.useState("usdt"),[N,de]=n.useState(null),[P,ie]=n.useState(!1),[J,me]=n.useState([]),[pe,V]=n.useState(!1);r!=null&&r.enable_topup,r==null||r.topup_config;const A=n.useCallback(async()=>{var t;H(!0);try{const[a,c]=await Promise.all([Te(),r!=null&&r.enable_topup?Oe().catch(()=>null):Promise.resolve(null)]);a.data.success&&se(a.data.data),(t=c==null?void 0:c.data)!=null&&t.data&&ae(c.data.data)}catch{}H(!1)},[r==null?void 0:r.enable_topup]);n.useEffect(()=>{A()},[A]);const G=(m==null?void 0:m.quota)??(i==null?void 0:i.quota)??0,ue=(m==null?void 0:m.used_quota)??(i==null?void 0:i.used_quota)??0,xe=(m==null?void 0:m.request_count)??(i==null?void 0:i.request_count)??0,ge=G/te,he=async t=>{if(t.preventDefault(),!!T.trim()){F(!0);try{(await Me(T.trim())).data.success&&(d.success(s("topup.redeemSuccess")),R(""),await Promise.all([A(),U()]))}catch{}F(!1)}},K=async t=>{if(!t||t<=0){B(null);return}W(!0);try{const a=await Ee({amount:parseInt(t)});a.data.message==="success"&&B(a.data.data)}catch{}W(!1)},be=t=>{M(t),O(t),K(t)},ye=t=>["stripe","alipay","wxpay"].includes(t)&&!t.startsWith("epay_"),fe=async t=>{var c;const a=parseInt(h);if(!a||a<=0){d.error(s("topup.enterAmount"));return}y(!0),f(t);try{const u=window.location.origin+"/topup",_={amount:a,payment_method:t,return_url:u};if(ye(t)){const o=await Le(_);if(o.data.message==="success"&&((c=o.data.data)!=null&&c.pay_link))window.open(o.data.data.pay_link,"_blank");else if(o.data.message!=="success"){const x=typeof o.data.data=="string"?o.data.data:o.data.message;d.error(x||s("common.requestFailed"))}}else{const o=await Ue(_);if(o.data.message==="success"){const x=o.data.data,I=o.data.url;if(I&&x){const g=document.createElement("form");g.action=I,g.method="POST",navigator.userAgent.indexOf("Safari")>-1&&navigator.userAgent.indexOf("Chrome")<1||(g.target="_blank");for(const ee in x){const $=document.createElement("input");$.type="hidden",$.name=ee,$.value=x[ee],g.appendChild($)}document.body.appendChild(g),g.submit(),document.body.removeChild(g)}}else{const x=typeof o.data.data=="string"?o.data.data:o.data.message;d.error(x||s("common.requestFailed"))}}}catch{}y(!1),f("")},je=async t=>{var a;y(!0),f("creem");try{const c=await He({product_id:t.productId,payment_method:"creem"});if(c.data.message==="success"&&((a=c.data.data)!=null&&a.checkout_url))window.open(c.data.data.checkout_url,"_blank");else if(c.data.message!=="success"){const u=typeof c.data.data=="string"?c.data.data:c.data.message;d.error(u||s("common.requestFailed"))}}catch{}y(!1),f("")},Ne=async()=>{const t=parseInt(h);if(!t||t<=0){d.error(s("topup.enterAmount"));return}if(!p){d.error(s("topup.selectChain"));return}if(!k){d.error(s("topup.selectToken"));return}y(!0),f("crypto");try{const a=await Re({amount:t,chain:p,token:k});if(a.data.message==="success"&&a.data.data)S(a.data.data),ve(a.data.data.trade_no);else if(a.data.message!=="success"){const c=typeof a.data.data=="string"?a.data.data:a.data.message;d.error(c||s("common.requestFailed"))}}catch{}y(!1),f("")},ve=t=>{j(!0);const a=setInterval(async()=>{var u,_;try{const o=await De(t);((u=o.data.data)==null?void 0:u.status)==="success"?(clearInterval(a),j(!1),S(null),d.success(s("topup.paymentSuccess")),await Promise.all([A(),U()])):((_=o.data.data)==null?void 0:_.status)==="expired"&&(clearInterval(a),j(!1),d.error(s("topup.orderExpired")))}catch{clearInterval(a),j(!1)}},5e3),c=((l==null?void 0:l.crypto_expiry_minutes)||30)*60*1e3;setTimeout(()=>{clearInterval(a),j(!1)},c)},v=(l==null?void 0:l.crypto_wallets)||{},w=n.useMemo(()=>{const t=[];return v.tron&&t.push({key:"tron",label:"TRON (TRC20)"}),v.eth&&t.push({key:"eth",label:"Ethereum (ERC20)"}),v.bsc&&t.push({key:"bsc",label:"BSC (BEP20)"}),t},[v.tron,v.eth,v.bsc]);n.useEffect(()=>{w.length>0&&!p&&Q(w[0].key)},[w,p]);const X=n.useMemo(()=>{if(!(l!=null&&l.creem_products))return[];try{const t=typeof l.creem_products=="string"?JSON.parse(l.creem_products):l.creem_products;return Array.isArray(t)?t:[]}catch{return[]}},[l==null?void 0:l.creem_products]),we=async()=>{var t;V(!0);try{const a=await Fe({page:1,page_size:20});(t=a.data.data)!=null&&t.items&&me(a.data.data.items)}catch{}V(!1)},Ce=(l==null?void 0:l.amount_options)||[1,5,10,20,50,100],q=(l==null?void 0:l.min_topup)||1,_e=(l==null?void 0:l.pay_methods)||[],Se=l==null?void 0:l.enable_online_topup,ke=l==null?void 0:l.enable_stripe_topup,Pe=l==null?void 0:l.enable_creem_topup,Ae=l==null?void 0:l.enable_crypto_topup,Y=_e.filter(t=>t.type!=="creem"&&t.type!=="crypto");return le?e.jsx("div",{className:"flex items-center justify-center min-h-[60vh]",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-4xl mx-auto px-6 py-10",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-2xl font-heading font-bold text-page mb-1",children:s("topup.title")}),e.jsx("p",{className:"text-sm text-page-secondary",children:s("topup.subtitle")})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-10",children:[e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.balance")}),e.jsxs("div",{className:"text-3xl font-bold text-page",children:["$",e.jsx(L,{from:0,to:ge,duration:1.5})]}),e.jsx("p",{className:"text-xs text-page-muted mt-1",children:s("dashboard.quotaUnits",{count:G.toLocaleString()})})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.used")}),e.jsxs("div",{className:"text-3xl font-bold text-page",children:["$",e.jsx(L,{from:0,to:ue/te,duration:1.5})]})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:s("dashboard.totalRequests")}),e.jsx("div",{className:"text-3xl font-bold text-page",children:e.jsx(L,{from:0,to:xe,duration:1.5})})]})]}),(r==null?void 0:r.enable_topup)&&(Se||ke)&&Y.length>0&&e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page",children:s("topup.onlineTopup")}),e.jsx("button",{onClick:()=>{ie(!P),P||we()},className:"text-sm text-page-secondary hover:text-page transition-colors",children:s(P?"topup.hideHistory":"topup.viewHistory")})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-3",children:s("topup.selectAmount")}),e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2",children:Ce.map(t=>e.jsxs("button",{onClick:()=>be(t),className:`py-2.5 px-3 rounded-xl text-sm font-medium transition-all ${ne===t?"bg-brand-500 text-white shadow-lg shadow-brand-500/25":"glass-sm text-page-label hover:text-page hover:bg-page-surface-hover"}`,children:["$",t]},t))})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.customAmount")}),e.jsx("div",{className:"flex gap-3",children:e.jsx("input",{type:"number",value:h,onChange:t=>{O(t.target.value),M(null)},onBlur:t=>K(t.target.value),min:q,placeholder:s("topup.amountPlaceholder",{min:q}),className:"input flex-1"})}),re?e.jsx("p",{className:"text-xs text-page-muted mt-2",children:s("topup.calculating")}):z?e.jsxs("p",{className:"text-xs text-page-secondary mt-2",children:[s("topup.payAmountLabel"),": ",e.jsxs("span",{className:"text-page-success font-medium",children:["¥",z]})]}):null]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-3",children:s("topup.paymentMethod")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Y.map(t=>{const a=b&&E===t.type;return e.jsx("button",{onClick:()=>fe(t.type),disabled:b||!h,className:"px-4 py-2.5 rounded-xl text-sm font-medium glass-sm text-page-label hover:text-page hover:bg-page-surface-hover disabled:opacity-40 disabled:cursor-not-allowed transition-all",children:a?s("topup.processing"):t.name},t.type)})})]})]}),(r==null?void 0:r.enable_topup)&&Pe&&X.length>0&&e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("topup.creemPayment")||"Creem Payment"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:X.map(t=>e.jsxs("div",{className:`glass-sm rounded-xl p-4 cursor-pointer transition-all ${(N==null?void 0:N.productId)===t.productId?"ring-2 ring-brand-500 bg-brand-500/10":"hover:bg-page-surface"}`,onClick:()=>de(t),children:[e.jsx("h3",{className:"text-sm font-semibold text-page mb-1",children:t.name}),e.jsxs("p",{className:"text-xl font-bold text-page-success mb-1",children:["$",t.price," ",e.jsx("span",{className:"text-xs text-page-muted font-normal",children:t.currency||"USD"})]}),t.quota&&e.jsx("p",{className:"text-xs text-page-secondary",children:s("topup.quotaIncluded")||`${t.quota} quota`})]},t.productId))}),N&&e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx("button",{onClick:()=>je(N),disabled:b,className:"btn-primary px-6",children:b&&E==="creem"?s("topup.processing"):`${s("topup.payNow")||"Pay"} $${N.price}`})})]}),(r==null?void 0:r.enable_topup)&&Ae&&w.length>0&&e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("topup.cryptoPayment")}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.amount")}),e.jsx("input",{type:"number",value:h,onChange:t=>{O(t.target.value),M(null)},min:q,placeholder:s("topup.amountPlaceholder",{min:q}),className:"input w-full"})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.chain")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:w.map(t=>e.jsx("button",{onClick:()=>Q(t.key),className:`px-4 py-2 rounded-xl text-sm font-medium transition-all ${p===t.key?"bg-brand-500 text-white shadow-lg shadow-brand-500/25":"glass-sm text-page-label hover:text-page hover:bg-page-surface-hover"}`,children:t.label},t.key))})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-page-label mb-2",children:s("topup.token")||"Token"}),e.jsx("div",{className:"flex gap-2",children:["usdt","usdc"].map(t=>e.jsx("button",{onClick:()=>oe(t),className:`px-4 py-2 rounded-xl text-sm font-medium transition-all ${k===t?"bg-brand-500 text-white shadow-lg shadow-brand-500/25":"glass-sm text-page-label hover:text-page hover:bg-page-surface-hover"}`,children:t.toUpperCase()},t))})]}),e.jsx("button",{onClick:Ne,disabled:b||!h,className:"btn-primary w-full",children:b&&E==="crypto"?s("topup.processing"):`${s("topup.payWith")||"Pay with"} ${k.toUpperCase()} (${((Z=w.find(t=>t.key===p))==null?void 0:Z.label)||p})`})]}),C&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>S(null),children:e.jsxs("div",{className:"glass rounded-2xl p-6 max-w-md w-full mx-4",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{className:"text-lg font-semibold text-page mb-4",children:s("topup.cryptoPayment")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"glass-sm rounded-xl p-4",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.walletAddress")}),e.jsx("p",{className:"text-sm text-page font-mono break-all",children:C.wallet})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"glass-sm rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.amount")}),e.jsxs("p",{className:"text-sm text-page font-medium",children:[C.amount," ",C.token]})]}),e.jsxs("div",{className:"glass-sm rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-page-secondary mb-1",children:s("topup.chain")}),e.jsx("p",{className:"text-sm text-page font-medium",children:C.chain})]})]}),ce&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-page-secondary",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"}),s("topup.waitingPayment")]}),e.jsx("button",{onClick:()=>{S(null),j(!1)},className:"w-full py-2 rounded-xl text-sm glass-sm text-page-secondary hover:text-page transition-colors",children:s("topup.close")})]})]})}),P&&e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("topup.history")}),pe?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"w-6 h-6 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"})}):J.length===0?e.jsx("p",{className:"text-sm text-page-muted text-center py-8",children:s("topup.noHistory")}):e.jsx("div",{className:"space-y-2",children:J.map((t,a)=>e.jsxs("div",{className:"flex items-center justify-between glass-sm rounded-xl px-4 py-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-page",children:["$",t.amount]}),e.jsxs("p",{className:"text-xs text-page-muted",children:[new Date(t.create_time*1e3).toLocaleString()," · ",t.payment_method||s("topup.redeemCode")]})]}),e.jsx("span",{className:`text-xs px-2 py-1 rounded-full ${t.status==="success"?"bg-green-500/10 text-page-success":t.status==="pending"?"bg-yellow-500/10 text-page-warning":"bg-red-500/10 text-page-danger"}`,children:t.status==="success"?s("topup.statusSuccess"):t.status==="pending"?s("topup.statusPending"):s("topup.statusFailed")})]},a))})]}),e.jsxs("div",{className:"glass rounded-2xl p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:s("topup.redeemTitle")}),e.jsxs("form",{onSubmit:he,className:"flex gap-3",children:[e.jsx("input",{type:"text",value:T,onChange:t=>R(t.target.value),className:"input flex-1",placeholder:s("topup.enterRedeemCode")}),e.jsx("button",{type:"submit",disabled:D,className:"btn-primary whitespace-nowrap",children:s(D?"topup.redeeming":"topup.redeem")})]})]})]})}export{Ve as default};