之前只用了单次周期的 quota 计算等价,导致每日重置套餐(如 $1/天 × 30天) 只显示 $45 等价,实际应该是 $30 总额度 × 45倍 = $1359 等价 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 lines
8.5 KiB
JavaScript
2 lines
8.5 KiB
JavaScript
import{u as $,b as A,r,l as Q,f as R,m as k,j as e,Q as x,L as W,s as z,z as y}from"./index-B9rrPGAP.js";import{c as I,R as T}from"./RotatingEquiv-DU2TNmsW.js";import{u as U}from"./useTranslation-BJL0XL8_.js";const w={never:"packages.resetNever",daily:"packages.resetDaily",weekly:"packages.resetWeekly",monthly:"packages.resetMonthly"};function S(a){return a?new Date(a*1e3).toLocaleDateString():""}function H(){const{t:a}=U(),{user:o,refreshUser:_}=$(),L=A(),[q,M]=r.useState([]),[h,P]=r.useState([]),[C,F]=r.useState(!0),[m,f]=r.useState(null),[b,j]=r.useState([]),[l,u]=r.useState(null),g=s=>a(w[s]||w.never);r.useEffect(()=>{Promise.all([Q().then(s=>{s.data.success&&M(s.data.data||[])}).catch(()=>{}),R().then(s=>{s.data.success&&P(s.data.data||[])}).catch(()=>{})]).finally(()=>F(!1))},[]),r.useEffect(()=>{o&&k().then(s=>{s.data.success&&j(s.data.data||[])}).catch(()=>{})},[o]);const D=async s=>{if(!o){L("/register");return}u(s)},E=async()=>{if(!l)return;const s=l.id;f(s);try{const n=await z(s);n.data.success?(y.success(a("packages.subscribedSuccess")),u(null),await _(),k().then(t=>{t.data.success&&j(t.data.data||[])}).catch(()=>{})):y.error(n.data.message||a("common.requestFailed"))}catch{}f(null)},B=r.useMemo(()=>h.filter(s=>s.enabled!==!1),[h]);if(C)return 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"})});const N=q.filter(s=>s.enabled);return e.jsxs("div",{className:"max-w-7xl mx-auto px-6 py-10",children:[e.jsxs("div",{className:"text-center mb-12",children:[e.jsx("h1",{className:"text-3xl font-heading font-bold text-page mb-3",children:a("packages.title")}),e.jsx("p",{className:"text-page-secondary max-w-xl mx-auto",children:a("packages.subtitle")})]}),b.length>0&&e.jsxs("div",{className:"max-w-3xl mx-auto mb-10",children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-4",children:a("packages.mySubscriptions")}),e.jsx("div",{className:"space-y-3",children:b.map(s=>{const n=s.amount_total||0,t=s.amount_used||0,i=Math.max(0,n-t),d=n>0?Math.min(100,t/n*100):0;return e.jsxs("div",{className:"glass rounded-xl p-4 border border-page-divider",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-page",children:a("packages.subscriptionId",{id:s.id})}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-green-500/10 text-page-success border border-green-500/20",children:a("packages.active")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-page-secondary mb-3",children:[e.jsxs("span",{children:[a("packages.expires"),": ",S(s.end_time)]}),s.next_reset_time>0&&e.jsxs("span",{children:[a("packages.nextReset"),": ",S(s.next_reset_time)]})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("div",{className:"flex-1 h-2 bg-page-surface rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-gradient-to-r from-brand-500 to-purple-500 transition-all",style:{width:`${d}%`}})}),e.jsxs("span",{className:"text-xs text-page-secondary whitespace-nowrap",children:["$",(i/x).toFixed(2)," / $",(n/x).toFixed(2)]})]})]},s.id)})})]}),N.length===0?e.jsxs("div",{className:"text-center py-12 text-page-secondary",children:[e.jsx("p",{children:a("packages.noPackages")}),e.jsxs(W,{to:"/pricing",className:"text-page-link hover:text-page-link transition-colors mt-2 inline-block",children:[a("packages.checkPricing")," →"]})]}):e.jsx("div",{className:"grid md:grid-cols-2 lg:grid-cols-3 gap-6 max-w-5xl mx-auto",children:N.map((s,n)=>{const t=s.quota_reset_period||"never",i=t!=="never",d=s.quota_amount>0?s.quota_amount/x:0;let p=d;if(i&&s.duration>0&&d>0){let c=1;t==="daily"?c=s.duration:t==="weekly"?c=Math.floor(s.duration/7):t==="monthly"&&(c=Math.floor(s.duration/30)),c<1&&(c=1),p=d*c}const v=I(B,p);return e.jsx("div",{className:"glass rounded-2xl flex flex-col",children:e.jsxs("div",{className:"p-6 flex-1 flex flex-col",children:[e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-xl font-semibold text-page",children:s.name}),i&&e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-purple-500/10 text-page-info border border-purple-500/20",children:g(t)})]}),s.description&&e.jsx("p",{className:"text-sm text-page-secondary mt-1",children:s.description})]}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-4xl font-bold text-page",children:["$",Number(s.price).toFixed(2)]}),s.original_price>0&&s.original_price>s.price&&e.jsxs("span",{className:"text-lg text-page-muted line-through",children:["$",Number(s.original_price).toFixed(2)]})]}),s.duration>0&&e.jsx("p",{className:"text-sm text-page-muted mt-1",children:a("packages.daysAccess",{count:s.duration})})]}),v.length>0&&e.jsx("div",{className:"bg-gradient-to-r from-amber-500/10 to-orange-500/10 border border-amber-500/20 rounded-xl p-3 mb-4",children:e.jsxs("p",{className:"text-xs text-page-warning font-medium",children:["🔥 ",e.jsx(T,{items:v,text:c=>a("packages.officialEquiv",{model:c.label,amount:c.equivDollars})})]})}),e.jsxs("ul",{className:"space-y-2 mb-6 flex-1",children:[s.quota_amount>0&&e.jsxs("li",{className:"flex items-center gap-2 text-sm text-page-label",children:[e.jsx("svg",{className:"w-4 h-4 text-page-success flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),i?a("packages.periodicQuota",{amount:(s.quota_amount/x).toFixed(2),period:g(t)}):a("packages.creditIncluded",{amount:(s.quota_amount/x).toFixed(2)})]}),i&&e.jsxs("li",{className:"flex items-center gap-2 text-sm text-page-label",children:[e.jsx("svg",{className:"w-4 h-4 text-page-warning flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),a("packages.unusedQuotaExpires")]}),e.jsxs("li",{className:"flex items-center gap-2 text-sm text-page-label",children:[e.jsx("svg",{className:"w-4 h-4 text-page-success flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),a("packages.allModels")]}),e.jsxs("li",{className:"flex items-center gap-2 text-sm text-page-label",children:[e.jsx("svg",{className:"w-4 h-4 text-page-success flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),a("packages.openaiApi")]})]}),e.jsx("button",{onClick:()=>D(s),disabled:m===s.id,className:"btn-primary w-full text-center",children:m===s.id?a("packages.processing"):a(o?"packages.subscribeNow":"packages.signUpToSubscribe")})]})},s.id)})}),l&&(()=>{const s=((o==null?void 0:o.quota)||0)/x,n=Number(l.price),t=s<n,i=l.quota_reset_period||"never",d=i!=="never";return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>!m&&u(null),children:e.jsxs("div",{className:"glass rounded-2xl p-6 w-full max-w-sm",onClick:p=>p.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold text-page mb-3",children:a("packages.confirmTitle")}),e.jsx("p",{className:"text-sm text-page-secondary mb-2",children:a("packages.confirmDesc",{name:l.name,price:n.toFixed(2)})}),d&&e.jsx("div",{className:"bg-purple-500/10 border border-purple-500/20 rounded-xl p-3 mb-3",children:e.jsx("p",{className:"text-xs text-page-info",children:a("packages.subscriptionInfo",{period:g(i),days:l.duration||30,amount:(l.quota_amount/x).toFixed(2)})})}),e.jsxs("p",{className:"text-sm text-page-secondary mb-4",children:[a("packages.yourBalance")," ",e.jsxs("span",{className:`font-medium ${t?"text-page-danger":"text-page-success"}`,children:["$",s.toFixed(2)]})]}),t&&e.jsx("div",{className:"bg-red-500/10 border border-red-500/20 rounded-xl p-3 mb-4",children:e.jsx("p",{className:"text-sm text-page-danger",children:a("packages.insufficientBalance")})}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>u(null),disabled:m,className:"btn-secondary",children:a("tokens.cancel")}),e.jsx("button",{onClick:E,disabled:t||m,className:"btn-primary",children:a(m?"packages.processing":"packages.confirm")})]})]})})})()]})}export{H as default};
|