18 lines
33 KiB
JavaScript
18 lines
33 KiB
JavaScript
import{b as D,j as e,r as n}from"./react-vendor-C_od1ZSF.js";import{K as X,L as Y,M as Q,N as G,O as Z,P as ee}from"./index-BmJe6Y8O.js";import{X as z,W as te,J as L,Y as ae,f as U,N as V,C as q,_ as se,$ as H,a0 as W,a1 as le,I as ne,a2 as re,V as oe,F as ie,P as de,r as ce}from"./icons-vendor-ThcsWkZG.js";const xe=({dataCards:i,downloadCardTemplate:c,...l})=>{var v;const h=d=>{var A;l.setBatchFile(((A=d.target.files)==null?void 0:A[0])||null)},u=d=>{l.setAppendContent(d.target.value)},j=d=>{l.setAppendTargetId(d.target.value)},b=()=>l.closeBatchModal(),g=()=>l.setBatchTab("create"),a=()=>l.setBatchTab("append"),x=()=>void l.handleRetryBatchCreate(),s=()=>void l.handleRetryBatchAppend(),r=l.batchResult&&"rows"in l.batchResult?l.batchResult:null,N=d=>e.jsxs("option",{value:String(d.id),children:[d.name,"(ID: ",d.id,")"]},d.id),y=()=>void l.handleBatchCreate(),B=()=>void l.handleBatchAppend();return l.showBatchModal?D.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:b,className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(z,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:g,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${l.batchTab==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(te,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:a,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${l.batchTab==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(L,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),l.batchTab==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),"。 类型填 text/data/image;data 类型的“内容”按行存卡密(CSV 单元格内换行需用引号包裹)。"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:c,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transition-colors",children:[e.jsx(ae,{className:"w-4 h-4"}),"下载模板"]}),e.jsxs("label",{className:"flex-1 px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm cursor-pointer transition-colors",children:[e.jsx(L,{className:"w-4 h-4"}),l.batchFile?l.batchFile.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:h})]})]}),((v=l.batchResult)==null?void 0:v.error)&&e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 p-4 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:l.batchResult.error}),e.jsx("button",{type:"button",onClick:x,disabled:!l.batchFile||l.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),r&&e.jsxs("div",{className:"rounded-xl border border-gray-200 p-4 space-y-2",children:[e.jsxs("div",{className:"text-sm font-bold text-gray-900",children:["共 ",r.total," 行 · 成功 ",r.created," · 失败 ",r.failed]}),r.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:r.rows.filter(d=>!d.success).map(d=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",d.row_no," 行「",d.name,"」:",d.error]},d.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:i.length===0?e.jsx("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 text-sm text-amber-800",children:"暂无 data(批量卡密)类型的卡密组,请先创建一个再充卡密。"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"选择卡密组"}),e.jsx("select",{value:l.appendTargetId,onChange:j,className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:i.map(N)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"卡密号(每行一个)"}),e.jsx("textarea",{value:l.appendContent,onChange:u,placeholder:`VIP-001
|
||
VIP-002
|
||
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["预览:",l.appendPreview.length," 个有效卡密,空行自动忽略。"]})]}),l.appendError&&e.jsxs("div",{className:"rounded-xl bg-red-50 border border-red-200 p-3 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:l.appendError}),e.jsx("button",{type:"button",onClick:s,disabled:l.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),l.appendResult&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",l.appendResult.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:b,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),l.batchTab==="create"?e.jsxs("button",{onClick:y,disabled:!l.batchFile||l.batchBusy,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[l.batchBusy?e.jsx(U,{className:"w-4 h-4 animate-spin"}):e.jsx(L,{className:"w-4 h-4"}),l.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:B,disabled:!l.appendTargetId||l.appendPreview.length===0||l.batchBusy||i.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[l.batchBusy?e.jsx(U,{className:"w-4 h-4 animate-spin"}):e.jsx(V,{className:"w-4 h-4"}),l.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},pe=({type:i})=>{switch(i){case"text":return e.jsx(W,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(H,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(se,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(q,{className:"w-5 h-5 text-gray-500"})}},me=(i,c,l)=>{const h=l.trim().toLocaleLowerCase();return i.filter(u=>(!c||u.type===c)&&(!h||u.name.toLocaleLowerCase().includes(h)))},K=i=>i.split(`
|
||
`).map(c=>c.trim()).filter(Boolean),he=(i,c,l)=>!!(i&&K(c).length>0&&!l),I=(i,c,l,h)=>i===c&&l===h,ue=()=>{const[i,c]=n.useState([]),[l,h]=n.useState(!0),u=n.useRef(0),j=n.useRef(null),b=n.useCallback(async()=>{var x;const g=++u.current;(x=j.current)==null||x.abort();const a=new AbortController;j.current=a,h(!0);try{const s=await X({signal:a.signal});if(g!==u.current)return;c(s)}catch(s){g===u.current&&!a.signal.aborted&&console.error("加载卡密库存失败:",s)}finally{g===u.current&&h(!1)}},[]);return n.useEffect(()=>(b(),()=>{var a;u.current+=1,(a=j.current)==null||a.abort()}),[b]),{cards:i,setCards:c,loading:l,loadCards:b}},be=i=>{const c=i.dataCards,l=i.loadCards,[h,u]=n.useState(!1),[j,b]=n.useState("create"),[g,a]=n.useState(null),[x,s]=n.useState(null),[r,N]=n.useState(!1),[y,B]=n.useState(""),[v,d]=n.useState(""),[A,R]=n.useState(null),[O,P]=n.useState(""),w=n.useRef(0),T=n.useRef(null),E=n.useRef(""),F=n.useMemo(()=>K(v),[v]),$=n.useCallback(()=>{var o;b("create"),a(null),s(null),B((o=c[0])!=null&&o.id?String(c[0].id):""),d(""),R(null),P(""),u(!0)},[c]),t=n.useCallback(()=>{var o;w.current+=1,(o=T.current)==null||o.abort(),N(!1),u(!1)},[]),p=n.useCallback(async()=>{var S;if(!g||r)return;const o=++w.current;(S=T.current)==null||S.abort();const _=new AbortController;T.current=_,N(!0),s(null);try{const m=await Y(g,{signal:_.signal});if(!I(o,w.current,"",""))return;s(m),m.created>0&&await l()}catch(m){if(!I(o,w.current,"",""))return;s({error:(m==null?void 0:m.message)||"上传失败"})}finally{I(o,w.current,"","")&&N(!1)}},[r,g,l]),f=n.useCallback(async()=>{var m;if(!he(y,v,r))return;const o=y,_=++w.current;E.current=o,(m=T.current)==null||m.abort();const S=new AbortController;T.current=S,N(!0),R(null),P("");try{const M=await Q(o,v,{signal:S.signal});if(!I(_,w.current,o,y))return;R({added:M.added}),d(""),await l()}catch(M){if(!I(_,w.current,o,y))return;P((M==null?void 0:M.message)||"追加失败")}finally{I(_,w.current,o,y)&&N(!1)}},[v,y,r,l]),C=n.useCallback(async()=>{await p()},[p]),k=n.useCallback(async()=>{E.current&&y!==E.current||await f()},[y,f]);return{showBatchModal:h,setShowBatchModal:u,batchTab:j,setBatchTab:b,batchFile:g,setBatchFile:a,batchResult:x,batchBusy:r,appendTargetId:y,setAppendTargetId:B,appendContent:v,setAppendContent:d,appendResult:A,appendError:O,appendPreview:F,openBatchModal:$,closeBatchModal:t,handleBatchCreate:p,handleBatchAppend:f,handleRetryBatchCreate:C,handleRetryBatchAppend:k}},J=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),fe=()=>{const{cards:i,loadCards:c}=ue(),[l,h]=n.useState(!1),[u,j]=n.useState(!1),[b,g]=n.useState(null),[a,x]=n.useState({}),[s,r]=n.useState(J),[N,y]=n.useState(""),[B,v]=n.useState(""),d=n.useMemo(()=>i.filter(t=>t.type==="data"),[i]),A=be({dataCards:d,loadCards:c}),R=t=>{var p,f,C,k,o;g(t),x({id:t.id,name:t.name||"",type:t.type||"text",api_url:((p=t.api_config)==null?void 0:p.url)||"",api_method:((f=t.api_config)==null?void 0:f.method)||"GET",api_timeout:((C=t.api_config)==null?void 0:C.timeout)||10,api_headers:((k=t.api_config)==null?void 0:k.headers)||"",api_params:((o=t.api_config)==null?void 0:o.params)||"",text_content:t.text_content||"",data_content:t.data_content||"",image_url:t.image_url||"",delay_seconds:t.delay_seconds||0,description:t.description||"",enabled:t.enabled}),h(!0)},O=async()=>{var t,p,f,C,k,o,_,S;if(b){if(!((t=a.name)!=null&&t.trim())){alert("请输入卡密名称");return}if(!a.type){alert("请选择卡密类型");return}try{const m={name:a.name.trim(),type:a.type,description:(p=a.description)==null?void 0:p.trim(),delay_seconds:a.delay_seconds||0,enabled:a.enabled??!0};a.type==="api"?m.api_config={url:((f=a.api_url)==null?void 0:f.trim())||"",method:a.api_method,timeout:a.api_timeout||10,headers:((C=a.api_headers)==null?void 0:C.trim())||void 0,params:((k=a.api_params)==null?void 0:k.trim())||void 0}:a.type==="text"?m.text_content=((o=a.text_content)==null?void 0:o.trim())||"":a.type==="data"?m.data_content=((_=a.data_content)==null?void 0:_.trim())||"":a.type==="image"&&(m.image_url=((S=a.image_url)==null?void 0:S.trim())||""),await G(b.id,m),h(!1),await c()}catch(m){console.error("更新卡密失败:",m),alert("更新失败,请重试")}}},P=async t=>{if(confirm("确认删除该卡密吗?"))try{await Z(t),await c()}catch(p){console.error("删除卡密失败:",p),alert("删除失败,请重试")}},w=async()=>{if(!s.name.trim()){alert("请输入卡密名称");return}if(!s.content.trim()){alert(s.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const t={name:s.name.trim(),type:s.type,description:s.description.trim(),enabled:s.enabled,delay_seconds:s.delay_seconds};s.type==="text"&&(t.text_content=s.content.trim()),s.type==="data"&&(t.data_content=s.content.trim()),s.type==="image"&&(t.image_url=s.content.trim()),s.type==="api"&&(t.api_config={url:s.content.trim(),method:s.api_method,timeout:s.api_timeout,headers:s.api_headers.trim()||void 0,params:s.api_params.trim()||void 0}),await ee(t),j(!1),r(J()),await c()}catch(t){console.error("添加卡密失败:",t),alert("添加失败,请重试")}},T=async t=>{try{await G(t.id,{...t,enabled:!t.enabled}),await c()}catch(p){console.error("切换状态失败:",p)}},E=async t=>{try{await navigator.clipboard.writeText(String(t)),alert(`已复制卡密组ID:${t}`)}catch{prompt("复制卡密组ID",String(t))}},F=n.useMemo(()=>me(i,N,B),[i,B,N]),$=()=>{const f=[["名称","类型","内容","描述","启用","延迟秒","多规格","规格名","规格值"],...[["VIP月卡","data",`VIP-MONTH-001
|
||
VIP-MONTH-002
|
||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(_=>_.map(S=>`"${String(S).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),C=new Blob(["\uFEFF"+f],{type:"text/csv;charset=utf-8"}),k=URL.createObjectURL(C),o=document.createElement("a");o.href=k,o.download="卡密组批量导入模板.csv",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(k)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:A.openBatchModal,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(L,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:(()=>j(!0)),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(V,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(le,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:N,onChange:(t=>y(t.target.value)),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(ne,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:B,onChange:(t=>v(t.target.value)),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",F.length," / ",i.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:F.map(t=>{let p="";return t.type==="data"&&t.data_content?p=`库存: ${t.data_content.split(`
|
||
`).filter(C=>C.trim()).length} 条`:t.type==="text"&&t.text_content?p=t.text_content:t.type==="api"&&t.api_config?p=t.api_config.url:t.type==="image"&&t.image_url&&(p="图片链接"),e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(pe,{type:t.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:t.name,children:t.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:(()=>E(t.id)),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:t.id}),e.jsx(re,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${t.type==="text"?"bg-blue-50 text-blue-600":t.type==="data"?"bg-purple-50 text-purple-600":t.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:t.type==="text"?"文本":t.type==="data"?"批量":t.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:p,children:p})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:t.description||"-",children:t.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:(()=>T(t)),className:`w-12 h-8 rounded-full relative transition-colors ${t.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${t.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:(()=>R(t)),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>P(t.id)),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(ie,{className:"h-4 w-4"})})]})})]},t.id)})})]})}),F.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(de,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:i.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),l&&b&&D.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:(()=>h(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(z,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:a.name||"",onChange:(t=>x({...a,name:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:a.type||"text",onChange:(t=>x({...a,type:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(b==null?void 0:b.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),a.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:a.api_url||"",onChange:(t=>x({...a,api_url:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"请求方法"}),e.jsxs("select",{value:a.api_method||"GET",onChange:(t=>x({...a,api_method:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"超时时间(秒)"}),e.jsx("input",{type:"number",value:a.api_timeout||10,onChange:(t=>x({...a,api_timeout:parseInt(t.target.value)||10})),className:"w-full ios-input px-4 py-3 rounded-xl",min:"1",max:"60"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"请求头(JSON 格式)"}),e.jsx("textarea",{value:a.api_headers||"",onChange:(t=>x({...a,api_headers:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-20 resize-none font-mono text-sm",placeholder:'{"Authorization": "Bearer token"}'})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"请求参数(JSON 格式)"}),e.jsx("textarea",{value:a.api_params||"",onChange:(t=>x({...a,api_params:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-20 resize-none font-mono text-sm",placeholder:'{"type": "card", "count": 1}'})]})]}),a.type==="text"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"固定文字配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"文字内容"}),e.jsx("textarea",{value:a.text_content||"",onChange:(t=>x({...a,text_content:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none",placeholder:"请输入要发送的固定文字内容..."})]})]}),a.type==="data"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"批量数据配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"数据内容(一行一个)"}),e.jsx("textarea",{value:a.data_content||"",onChange:(t=>x({...a,data_content:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-80 resize-none font-mono text-sm",placeholder:`请输入数据,每行一个:
|
||
卡号1:密码1
|
||
卡号2:密码2
|
||
或者
|
||
兑换码1
|
||
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:a.data_content?a.data_content.split(`
|
||
`).filter(t=>t.trim()).length:0})," 条"]})]})]}),a.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:a.image_url||"",onChange:(t=>x({...a,image_url:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),a.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:a.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:(t=>{t.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:a.delay_seconds||0,onChange:(t=>x({...a,delay_seconds:parseInt(t.target.value)||0})),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:a.description||"",onChange:(t=>x({...a,description:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:(()=>x({...a,enabled:!a.enabled})),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${a.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${a.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:(()=>h(!1)),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:O,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(ce,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),u&&D.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:(()=>j(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(z,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:s.name,onChange:(t=>r({...s,name:t.target.value})),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:(()=>r({...s,type:"data",content:""})),className:`p-3 rounded-xl font-bold transition-all ${s.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(q,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:(()=>r({...s,type:"text",content:""})),className:`p-3 rounded-xl font-bold transition-all ${s.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(W,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:(()=>r({...s,type:"image",content:""})),className:`p-3 rounded-xl font-bold transition-all ${s.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(H,{className:"w-5 h-5 mx-auto mb-1"}),"图片"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:s.type==="data"?"库存内容(一行一个)":s.type==="text"?"固定回复内容":s.type==="image"?"图片 URL":"API 地址"}),s.type==="api"?e.jsx("input",{type:"url",value:s.content,onChange:(t=>r({...s,content:t.target.value})),placeholder:"https://api.example.com/get-code",className:"w-full ios-input px-4 py-3 rounded-xl"}):s.type==="image"?e.jsx("input",{type:"url",value:s.content,onChange:(t=>r({...s,content:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"https://example.com/card.png"}):e.jsx("textarea",{value:s.content,onChange:(t=>r({...s,content:t.target.value})),className:`w-full ios-input px-4 py-3 rounded-xl resize-none text-sm ${s.type==="data"?"h-48 font-mono":"h-32"}`,placeholder:s.type==="data"?`CODE-123456
|
||
CODE-789012
|
||
...`:"请输入每次发货时发送的固定文字"}),s.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:s.content.split(`
|
||
`).filter(t=>t.trim()).length})," 条"]})]}),s.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:s.api_method,onChange:(t=>r({...s,api_method:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:s.api_timeout,onChange:(t=>r({...s,api_timeout:parseInt(t.target.value)||10})),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:s.api_headers,onChange:(t=>r({...s,api_headers:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:s.api_params,onChange:(t=>r({...s,api_params:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:s.description,onChange:(t=>r({...s,description:t.target.value})),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:s.delay_seconds,onChange:(t=>r({...s,delay_seconds:parseInt(t.target.value)||0})),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:(()=>j(!1)),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:w,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),e.jsx(xe,{dataCards:d,downloadCardTemplate:$,...A})]})};export{fe as default};
|