18 lines
34 KiB
JavaScript
18 lines
34 KiB
JavaScript
import{b as z,j as e,r}from"./react-vendor-C_od1ZSF.js";import{X as G,W as Y,J as $,Y as Q,f as U,N as V,C as H,_ as Z,$ as W,a0 as K,a1 as ee,I as te,a2 as ae,V as se,F as le,P as ne,r as re}from"./icons-vendor-ThcsWkZG.js";import{K as oe,L as ie,M as de,N as J,O as ce,P as xe}from"./index-DK02p8DH.js";const pe=({dataCards:c,downloadCardTemplate:d,...s})=>{var x;const u=a=>{var m;s.setBatchFile(((m=a.target.files)==null?void 0:m[0])||null)},p=a=>{s.setAppendContent(a.target.value)},_=a=>{s.setAppendTargetId(a.target.value)},j=()=>s.closeBatchModal(),f=()=>s.setBatchTab("create"),i=()=>s.setBatchTab("append"),A=()=>void s.handleRetryBatchCreate(),o=()=>void s.handleRetryBatchAppend(),y=s.batchResult&&"rows"in s.batchResult?s.batchResult:null,N=a=>e.jsxs("option",{value:String(a.id),children:[a.name,"(ID: ",a.id,")"]},a.id),b=()=>void s.handleBatchCreate(),l=()=>void s.handleBatchAppend();return s.showBatchModal?z.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:j,className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(G,{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:f,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${s.batchTab==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Y,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:i,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${s.batchTab==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx($,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),s.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:d,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(Q,{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($,{className:"w-4 h-4"}),s.batchFile?s.batchFile.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:u})]})]}),((x=s.batchResult)==null?void 0:x.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:s.batchResult.error}),e.jsx("button",{type:"button",onClick:A,disabled:!s.batchFile||s.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),y&&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:["共 ",y.total," 行 · 成功 ",y.created," · 失败 ",y.failed]}),y.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:y.rows.filter(a=>!a.success).map(a=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",a.row_no," 行「",a.name,"」:",a.error]},a.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:c.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:s.appendTargetId,onChange:_,className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:c.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:s.appendContent,onChange:p,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:["预览:",s.appendPreview.length," 个有效卡密,空行自动忽略。"]})]}),s.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:s.appendError}),e.jsx("button",{type:"button",onClick:o,disabled:s.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),s.appendResult&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",s.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:j,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),s.batchTab==="create"?e.jsxs("button",{onClick:b,disabled:!s.batchFile||s.batchBusy,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[s.batchBusy?e.jsx(U,{className:"w-4 h-4 animate-spin"}):e.jsx($,{className:"w-4 h-4"}),s.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:l,disabled:!s.appendTargetId||s.appendPreview.length===0||s.batchBusy||c.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[s.batchBusy?e.jsx(U,{className:"w-4 h-4 animate-spin"}):e.jsx(V,{className:"w-4 h-4"}),s.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},me=({type:c})=>{switch(c){case"text":return e.jsx(K,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(W,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(Z,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(H,{className:"w-5 h-5 text-gray-500"})}},he=(c,d,s)=>{const u=s.trim().toLocaleLowerCase();return c.filter(p=>(!d||p.type===d)&&(!u||p.name.toLocaleLowerCase().includes(u)))},X=c=>c.split(`
|
||
`).map(d=>d.trim()).filter(Boolean),ue=(c,d,s)=>!!(c&&X(d).length>0&&!s),F=(c,d,s,u)=>c===d&&s===u,be=()=>{const[c,d]=r.useState([]),[s,u]=r.useState(!0),p=r.useRef(0),_=r.useRef(null),j=r.useCallback(async()=>{var A;const f=++p.current;(A=_.current)==null||A.abort();const i=new AbortController;_.current=i,u(!0);try{const o=await oe({signal:i.signal});if(f!==p.current)return;d(o)}catch(o){f===p.current&&!i.signal.aborted&&console.error("加载卡密库存失败:",o)}finally{f===p.current&&u(!1)}},[]);return r.useEffect(()=>(j(),()=>{var i;p.current+=1,(i=_.current)==null||i.abort()}),[j]),{cards:c,setCards:d,loading:s,loadCards:j}},ge=c=>{const d=c.dataCards,s=c.loadCards,[u,p]=r.useState(!1),[_,j]=r.useState("create"),[f,i]=r.useState(null),[A,o]=r.useState(null),[y,N]=r.useState(!1),[b,l]=r.useState(""),[x,a]=r.useState(""),[m,E]=r.useState(null),[M,R]=r.useState(""),w=r.useRef(0),T=r.useRef(null),P=r.useRef(""),L=r.useMemo(()=>X(x),[x]),n=r.useCallback(()=>{var h;j("create"),i(null),o(null),l((h=d[0])!=null&&h.id?String(d[0].id):""),a(""),E(null),R(""),p(!0)},[d]),t=r.useCallback(()=>{var h;w.current+=1,(h=T.current)==null||h.abort(),N(!1),p(!1)},[]),g=r.useCallback(async()=>{var v;if(!f||y)return;const h=++w.current;(v=T.current)==null||v.abort();const B=new AbortController;T.current=B,N(!0),o(null);try{const I=await ie(f,{signal:B.signal});if(!F(h,w.current,"",""))return;o(I),I.created>0&&await s()}catch(I){if(!F(h,w.current,"",""))return;o({error:(I==null?void 0:I.message)||"上传失败"})}finally{F(h,w.current,"","")&&N(!1)}},[y,f,s]),k=r.useCallback(async()=>{var I;if(!ue(b,x,y))return;const h=b,B=++w.current;P.current=h,(I=T.current)==null||I.abort();const v=new AbortController;T.current=v,N(!0),E(null),R("");try{const O=await de(h,x,{signal:v.signal});if(!F(B,w.current,h,b))return;E({added:O.added}),a(""),await s()}catch(O){if(!F(B,w.current,h,b))return;R((O==null?void 0:O.message)||"追加失败")}finally{F(B,w.current,h,b)&&N(!1)}},[x,b,y,s]),S=r.useCallback(async()=>{await g()},[g]),C=r.useCallback(async()=>{P.current&&b!==P.current||await k()},[b,k]);return{showBatchModal:u,setShowBatchModal:p,batchTab:_,setBatchTab:j,batchFile:f,setBatchFile:i,batchResult:A,batchBusy:y,appendTargetId:b,setAppendTargetId:l,appendContent:x,setAppendContent:a,appendResult:m,appendError:M,appendPreview:L,openBatchModal:n,closeBatchModal:t,handleBatchCreate:g,handleBatchAppend:k,handleRetryBatchCreate:S,handleRetryBatchAppend:C}},q=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),D=(c,d)=>c instanceof Error?c.message:d,ye=({cards:c,loadCards:d})=>{const[s,u]=r.useState(!1),[p,_]=r.useState(!1),[j,f]=r.useState(null),[i,A]=r.useState({}),[o,y]=r.useState(q),[N,b]=r.useState(""),[l,x]=r.useState(""),a=r.useMemo(()=>c.filter(n=>n.type==="data"),[c]),m=r.useMemo(()=>he(c,N,l),[c,l,N]),E=r.useCallback(n=>{var t,g,k,S,C;f(n),A({id:n.id,name:n.name||"",type:n.type||"text",api_url:((t=n.api_config)==null?void 0:t.url)||"",api_method:((g=n.api_config)==null?void 0:g.method)||"GET",api_timeout:((k=n.api_config)==null?void 0:k.timeout)||10,api_headers:((S=n.api_config)==null?void 0:S.headers)||"",api_params:((C=n.api_config)==null?void 0:C.params)||"",text_content:n.text_content||"",data_content:n.data_content||"",image_url:n.image_url||"",delay_seconds:n.delay_seconds||0,description:n.description||"",enabled:n.enabled}),u(!0)},[]),M=r.useCallback(async()=>{var n,t,g,k,S,C,h,B;if(j){if(!((n=i.name)!=null&&n.trim())){alert("请输入卡密名称");return}if(!i.type){alert("请选择卡密类型");return}try{const v={name:i.name.trim(),type:i.type,description:(t=i.description)==null?void 0:t.trim(),delay_seconds:i.delay_seconds||0,enabled:i.enabled??!0};i.type==="api"?v.api_config={url:((g=i.api_url)==null?void 0:g.trim())||"",method:i.api_method||"GET",timeout:i.api_timeout||10,headers:((k=i.api_headers)==null?void 0:k.trim())||void 0,params:((S=i.api_params)==null?void 0:S.trim())||void 0}:i.type==="text"?v.text_content=((C=i.text_content)==null?void 0:C.trim())||"":i.type==="data"?v.data_content=((h=i.data_content)==null?void 0:h.trim())||"":i.type==="image"&&(v.image_url=((B=i.image_url)==null?void 0:B.trim())||""),await J(j.id,v),u(!1),await d()}catch(v){console.error("更新卡密失败:",v),alert(D(v,"更新失败,请重试"))}}},[i,d,j]),R=r.useCallback(async n=>{if(confirm("确认删除该卡密吗?"))try{await ce(n),await d()}catch(t){console.error("删除卡密失败:",t),alert(D(t,"删除失败,请重试"))}},[d]),w=r.useCallback(async()=>{if(!o.name.trim()){alert("请输入卡密名称");return}if(!o.content.trim()){alert(o.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const n={name:o.name.trim(),type:o.type,description:o.description.trim(),enabled:o.enabled,delay_seconds:o.delay_seconds};o.type==="text"&&(n.text_content=o.content.trim()),o.type==="data"&&(n.data_content=o.content.trim()),o.type==="image"&&(n.image_url=o.content.trim()),o.type==="api"&&(n.api_config={url:o.content.trim(),method:o.api_method,timeout:o.api_timeout,headers:o.api_headers.trim()||void 0,params:o.api_params.trim()||void 0}),await xe(n),_(!1),y(q()),await d()}catch(n){console.error("添加卡密失败:",n),alert(D(n,"添加失败,请重试"))}},[o,d]),T=r.useCallback(async n=>{try{await J(n.id,{...n,enabled:!n.enabled}),await d()}catch(t){console.error("切换状态失败:",t)}},[d]),P=r.useCallback(async n=>{try{await navigator.clipboard.writeText(String(n)),alert(`已复制卡密组ID:${n}`)}catch{prompt("复制卡密组ID",String(n))}},[]),L=r.useCallback(()=>{const g=[["名称","类型","内容","描述","启用","延迟秒","多规格","规格名","规格值"],...[["VIP月卡","data",`VIP-MONTH-001
|
||
VIP-MONTH-002
|
||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(h=>h.map(B=>`"${String(B).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),k=new Blob(["\uFEFF"+g],{type:"text/csv;charset=utf-8"}),S=URL.createObjectURL(k),C=document.createElement("a");C.href=S,C.download="卡密组批量导入模板.csv",document.body.appendChild(C),C.click(),C.remove(),URL.revokeObjectURL(S)},[]);return{dataCards:a,filteredCards:m,typeFilter:N,setTypeFilter:b,nameSearch:l,setNameSearch:x,showEditModal:s,setShowEditModal:u,showAddModal:p,setShowAddModal:_,selectedCard:j,editForm:i,setEditForm:A,addForm:o,setAddForm:y,handleEdit:E,handleSaveEdit:M,handleDelete:R,handleAddCard:w,toggleCardStatus:T,copyCardID:P,downloadCardTemplate:L}},ve=()=>{const{cards:c,loadCards:d}=be(),s=ye({cards:c,loadCards:d}),{dataCards:u,filteredCards:p,typeFilter:_,setTypeFilter:j,nameSearch:f,setNameSearch:i,showEditModal:A,setShowEditModal:o,showAddModal:y,setShowAddModal:N,selectedCard:b,editForm:l,setEditForm:x,addForm:a,setAddForm:m,handleEdit:E,handleSaveEdit:M,handleDelete:R,handleAddCard:w,toggleCardStatus:T,copyCardID:P,downloadCardTemplate:L}=s,n=ge({dataCards:u,loadCards:d});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:n.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($,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:(()=>N(!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(ee,{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:_,onChange:(t=>j(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(te,{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:f,onChange:(t=>i(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:["显示 ",p.length," / ",c.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:p.map(t=>{let g="";return t.type==="data"&&t.data_content?g=`库存: ${t.data_content.split(`
|
||
`).filter(S=>S.trim()).length} 条`:t.type==="text"&&t.text_content?g=t.text_content:t.type==="api"&&t.api_config?g=t.api_config.url:t.type==="image"&&t.image_url&&(g="图片链接"),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(me,{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:(()=>P(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(ae,{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:g,children:g})}),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)),"aria-label":`切换卡密 ${t.name} 状态`,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:(()=>E(t)),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(se,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>R(t.id)),"aria-label":`删除卡密 ${t.name}`,className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(le,{className:"h-4 w-4"})})]})})]},t.id)})})]})}),p.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ne,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:c.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),A&&b&&z.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:(()=>o(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(G,{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:l.name||"",onChange:(t=>x({...l,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:l.type||"text",onChange:(t=>x({...l,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:"图片"})]})]})]}),l.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:l.api_url||"",onChange:(t=>x({...l,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:l.api_method||"GET",onChange:(t=>x({...l,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:l.api_timeout||10,onChange:(t=>x({...l,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:l.api_headers||"",onChange:(t=>x({...l,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:l.api_params||"",onChange:(t=>x({...l,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}'})]})]}),l.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:l.text_content||"",onChange:(t=>x({...l,text_content:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none",placeholder:"请输入要发送的固定文字内容..."})]})]}),l.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:l.data_content||"",onChange:(t=>x({...l,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:l.data_content?l.data_content.split(`
|
||
`).filter(t=>t.trim()).length:0})," 条"]})]})]}),l.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:l.image_url||"",onChange:(t=>x({...l,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 地址"})]}),l.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:l.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:l.delay_seconds||0,onChange:(t=>x({...l,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:l.description||"",onChange:(t=>x({...l,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({...l,enabled:!l.enabled})),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${l.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 ${l.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:(()=>o(!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:M,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),y&&z.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:(()=>N(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(G,{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:a.name,onChange:(t=>m({...a,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:(()=>m({...a,type:"data",content:""})),className:`p-3 rounded-xl font-bold transition-all ${a.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(H,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:(()=>m({...a,type:"text",content:""})),className:`p-3 rounded-xl font-bold transition-all ${a.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(K,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:(()=>m({...a,type:"image",content:""})),className:`p-3 rounded-xl font-bold transition-all ${a.type==="image"?"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("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:a.type==="data"?"库存内容(一行一个)":a.type==="text"?"固定回复内容":a.type==="image"?"图片 URL":"API 地址"}),a.type==="api"?e.jsx("input",{type:"url",value:a.content,onChange:(t=>m({...a,content:t.target.value})),placeholder:"https://api.example.com/get-code",className:"w-full ios-input px-4 py-3 rounded-xl"}):a.type==="image"?e.jsx("input",{type:"url",value:a.content,onChange:(t=>m({...a,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:a.content,onChange:(t=>m({...a,content:t.target.value})),className:`w-full ios-input px-4 py-3 rounded-xl resize-none text-sm ${a.type==="data"?"h-48 font-mono":"h-32"}`,placeholder:a.type==="data"?`CODE-123456
|
||
CODE-789012
|
||
...`:"请输入每次发货时发送的固定文字"}),a.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:a.content.split(`
|
||
`).filter(t=>t.trim()).length})," 条"]})]}),a.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:a.api_method,onChange:(t=>m({...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",{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:a.api_timeout,onChange:(t=>m({...a,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:a.api_headers,onChange:(t=>m({...a,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:a.api_params,onChange:(t=>m({...a,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:a.description,onChange:(t=>m({...a,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:a.delay_seconds,onChange:(t=>m({...a,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:(()=>N(!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(pe,{dataCards:u,downloadCardTemplate:L,...n})]})};export{ve as default};
|