20 lines
45 KiB
JavaScript
20 lines
45 KiB
JavaScript
import{a as d,j as e,b as H}from"./react-vendor-Bf9ELcll.js";import{r as O,c as M,b as ie}from"./chat-metadata-CxFNzZmJ.js";import{c as ce}from"./contract-COFcZjyb.js";import{L as W,u as de,P as G,T as se,X as K,$ as pe,W as J,a0 as xe,e as ne,a1 as me,a2 as re,a3 as le,a4 as he,V as ue,a5 as be,_ as ye,o as ge,s as fe,a6 as je}from"./icons-vendor-eB2mgMyz.js";import"./vendor-BE-_xUHH.js";const _e=a=>{let s=a.api_config;if(typeof s=="string"&&s.trim())try{s=JSON.parse(s)}catch{s=void 0}return s&&typeof s=="object"&&s.timeout_seconds===void 0&&s.timeout!==void 0&&(s.timeout_seconds=Number(s.timeout)||10),s&&typeof s=="object"&&!s.content_type&&(s.content_type="application/json"),{...a,api_config:s||void 0}},U=a=>{if(a&&typeof a=="object"&&!Array.isArray(a))return a;if(typeof a!="string"||!a.trim())return;const s=JSON.parse(a);if(!s||typeof s!="object"||Array.isArray(s))throw new Error("请求头和请求参数必须是 JSON 对象");return s},X=a=>({name:a.name,type:a.type,api_config:typeof a.api_config=="string"?a.api_config:a.api_config?{...a.api_config,headers:U(a.api_config.headers),params:U(a.api_config.params),body:U(a.api_config.body),content_type:a.api_config.content_type||"application/json"}:void 0,text_content:a.text_content,data_content:a.data_content,image_url:a.image_url,description:a.description,enabled:a.enabled,delay_seconds:a.delay_seconds,is_multi_spec:a.is_multi_spec,spec_name:a.spec_name,spec_value:a.spec_value}),Ne=async a=>{const s=await O(u=>M.GET("/api/v1/cards",{signal:u}),a);return ce(s,["cards","data","items"]).map(_e)},ve=async a=>O(s=>M.POST("/api/v1/cards",{body:X(a),signal:s})),Q=async(a,s)=>O(n=>M.PUT("/api/v1/cards/{card_id}",{params:{path:{card_id:String(a)}},body:X(s),signal:n})),we=async a=>O(s=>M.DELETE("/api/v1/cards/{card_id}",{params:{path:{card_id:String(a)}},signal:s})),Ce=async(a,s)=>{const n=new FormData;return n.append("file",a),O(u=>M.POST("/api/v1/cards/batch",{body:ie(n),signal:u}),s)},ke=async(a,s,n)=>O(u=>M.POST("/api/v1/cards/{card_id}/append-data",{params:{path:{card_id:String(a)}},body:{content:s},signal:u}),n),Z=async a=>O(s=>M.POST("/api/v1/cards/test-api",{body:{api_config:X({name:"",type:"api",api_config:a}).api_config},signal:s})),Se=(a,s,n)=>{const u=n.trim().toLocaleLowerCase();return a.filter(b=>(!s||b.type===s)&&(!u||b.name.toLocaleLowerCase().includes(u)))},oe=a=>a.split(`
|
||
`).map(s=>s.trim()).filter(Boolean),Te=(a,s,n)=>!!(a&&oe(s).length>0&&!n),L=(a,s,n,u)=>a===s&&n===u,ee=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:"",api_content_type:"application/json",api_body:"",api_response_path:"",api_retry_enabled:!1}),z=(a,s)=>a instanceof Error?a.message:s,Ae=({cards:a,loadCards:s})=>{const[n,u]=d.useState(!1),[b,_]=d.useState(!1),[j,N]=d.useState(null),[o,v]=d.useState({}),[p,x]=d.useState(ee),[h,f]=d.useState(""),[l,y]=d.useState(""),r=d.useMemo(()=>a.filter(c=>c.type==="data"),[a]),i=d.useMemo(()=>Se(a,h,l),[a,l,h]),I=d.useCallback(c=>{var t,m,w,S,k,g;N(c),v({id:c.id,name:c.name||"",type:c.type||"text",api_url:((t=c.api_config)==null?void 0:t.url)||"",api_method:((m=c.api_config)==null?void 0:m.method)||"GET",api_timeout:((w=c.api_config)==null?void 0:w.timeout_seconds)||10,api_headers:"",api_params:"",api_content_type:((S=c.api_config)==null?void 0:S.content_type)||"application/json",api_body:"",api_response_path:((k=c.api_config)==null?void 0:k.response_path)||"",api_retry_enabled:((g=c.api_config)==null?void 0:g.retry_enabled)||!1,api_headers_action:"retain",api_params_action:"retain",text_content:c.text_content||"",data_content:c.data_content||"",image_url:c.image_url||"",delay_seconds:c.delay_seconds||0,description:c.description||"",enabled:c.enabled}),u(!0)},[]),D=d.useCallback(async()=>{var c,t,m,w,S,k,g,A,P,T,B,Y;if(j){if(!((c=o.name)!=null&&c.trim())){alert("请输入卡密名称");return}if(!o.type){alert("请选择卡密类型");return}try{const R={name:o.name.trim(),type:o.type,description:(t=o.description)==null?void 0:t.trim(),delay_seconds:o.delay_seconds||0,enabled:o.enabled??!0};o.type==="api"?R.api_config={url:((m=o.api_url)==null?void 0:m.trim())||"",method:o.api_method||"GET",timeout_seconds:o.api_timeout||10,headers:o.api_headers_action==="clear"?void 0:o.api_headers_action==="replace"&&!((w=o.api_headers)!=null&&w.trim())?{}:((S=o.api_headers)==null?void 0:S.trim())||void 0,params:o.api_params_action==="clear"?void 0:o.api_params_action==="replace"&&!((k=o.api_params)!=null&&k.trim())?{}:((g=o.api_params)==null?void 0:g.trim())||void 0,content_type:o.api_content_type||"application/json",body:((A=o.api_body)==null?void 0:A.trim())||void 0,headers_action:o.api_headers_action||"retain",params_action:o.api_params_action||"retain",response_path:((P=o.api_response_path)==null?void 0:P.trim())||void 0,retry_enabled:o.api_retry_enabled||!1}:o.type==="text"?R.text_content=((T=o.text_content)==null?void 0:T.trim())||"":o.type==="data"?R.data_content=((B=o.data_content)==null?void 0:B.trim())||"":o.type==="image"&&(R.image_url=((Y=o.image_url)==null?void 0:Y.trim())||""),await Q(j.id,R),u(!1),await s()}catch(R){console.error("更新卡密失败:",R),alert(z(R,"更新失败,请重试"))}}},[o,s,j]),F=d.useCallback(async c=>{if(confirm("确认删除该卡密吗?"))try{await we(c),await s()}catch(t){console.error("删除卡密失败:",t),alert(z(t,"删除失败,请重试"))}},[s]),C=d.useCallback(async()=>{if(!p.name.trim()){alert("请输入卡密名称");return}if(!p.content.trim()){alert(p.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const c={name:p.name.trim(),type:p.type,description:p.description.trim(),enabled:p.enabled,delay_seconds:p.delay_seconds};p.type==="text"&&(c.text_content=p.content.trim()),p.type==="data"&&(c.data_content=p.content.trim()),p.type==="image"&&(c.image_url=p.content.trim()),p.type==="api"&&(c.api_config={url:p.content.trim(),method:p.api_method,timeout_seconds:p.api_timeout,headers:p.api_headers.trim()||void 0,params:p.api_params.trim()||void 0,content_type:p.api_content_type,body:p.api_body.trim()||void 0,response_path:p.api_response_path.trim()||void 0,retry_enabled:p.api_retry_enabled}),await ve(c),_(!1),x(ee()),await s()}catch(c){console.error("添加卡密失败:",c),alert(z(c,"添加失败,请重试"))}},[p,s]),E=d.useCallback(async c=>{try{await Q(c.id,{...c,enabled:!c.enabled}),await s()}catch(t){console.error("切换状态失败:",t)}},[s]),$=d.useCallback(async c=>{try{await navigator.clipboard.writeText(String(c)),alert(`已复制卡密组ID:${c}`)}catch{prompt("复制卡密组ID",String(c))}},[]),V=d.useCallback(()=>{const m=[["名称","类型","内容","描述","启用","延迟秒","多规格","规格名","规格值"],...[["VIP月卡","data",`VIP-MONTH-001
|
||
VIP-MONTH-002
|
||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(g=>g.map(A=>`"${String(A).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),w=new Blob(["\uFEFF"+m],{type:"text/csv;charset=utf-8"}),S=URL.createObjectURL(w),k=document.createElement("a");k.href=S,k.download="卡密组批量导入模板.csv",document.body.appendChild(k),k.click(),k.remove(),URL.revokeObjectURL(S)},[]);return{dataCards:r,filteredCards:i,typeFilter:h,setTypeFilter:f,nameSearch:l,setNameSearch:y,showEditModal:n,setShowEditModal:u,showAddModal:b,setShowAddModal:_,selectedCard:j,editForm:o,setEditForm:v,addForm:p,setAddForm:x,handleEdit:I,handleSaveEdit:D,handleDelete:F,handleAddCard:C,toggleCardStatus:E,copyCardID:$,downloadCardTemplate:V}},Ee=[{value:"application/json",label:"JSON(application/json)"},{value:"application/x-www-form-urlencoded",label:"表单键值(x-www-form-urlencoded)"},{value:"text/plain",label:"纯文本(text/plain)"},{value:"application/xml",label:"XML(application/xml)"}],Pe=a=>a.toLowerCase().includes("json"),te=a=>{if(!a.trim())return[{key:"",value:""}];try{const s=JSON.parse(a);if(!s||typeof s!="object"||Array.isArray(s))return[{key:"",value:""}];const n=Object.entries(s);return n.length===0?[{key:"",value:""}]:n.map(u=>{const[b,_]=u;return{key:b,value:typeof _=="string"?_:JSON.stringify(_)}})}catch{return[{key:"",value:a.trim()}]}},Be=a=>{const s=a.reduce((n,u)=>{const b=u.key.trim();return b&&(n[b]=u.value),n},{});return JSON.stringify(s)},q=({label:a,value:s,placeholder:n,onChange:u})=>{const[b,_]=d.useState(()=>te(s)),j=d.useRef(s);d.useEffect(()=>{s!==j.current&&(_(te(s)),j.current=s)},[s]);const N=x=>{const h=Be(x);_(x),j.current=h,u(h)},o=(x,h,f)=>{const l=b.map((y,r)=>r===x?{...y,[h]:f}:y);N(l)},v=()=>N([...b,{key:"",value:""}]),p=x=>N(b.filter((h,f)=>f!==x));return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("label",{className:"text-sm font-bold text-gray-800",children:a}),e.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-bold text-blue-600 transition-colors hover:bg-blue-50",title:`添加${a}字段`,children:[e.jsx(G,{className:"h-3.5 w-3.5"}),"添加字段"]})]}),e.jsxs("div",{className:"overflow-hidden rounded-xl border border-gray-200 bg-white",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,0.8fr)_minmax(0,1.2fr)_40px] gap-2 border-b border-gray-100 bg-gray-50 px-3 py-2 text-[11px] font-bold uppercase tracking-wide text-gray-400",children:[e.jsx("span",{children:"KEY"}),e.jsx("span",{children:"VALUE"}),e.jsx("span",{"aria-hidden":"true"})]}),e.jsx("div",{className:"divide-y divide-gray-100",children:b.map((x,h)=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,0.8fr)_minmax(0,1.2fr)_40px] items-center gap-2 px-3 py-2",children:[e.jsx("input",{"aria-label":`${a}第${h+1}行键名`,value:x.key,onChange:(f=>o(h,"key",f.target.value)),placeholder:h===0?n:"键名",className:"min-w-0 border-0 bg-transparent px-1 py-2 font-mono text-sm text-gray-800 outline-none ring-0 placeholder:text-gray-300"}),e.jsx("input",{"aria-label":`${a}第${h+1}行值`,value:x.value,onChange:(f=>o(h,"value",f.target.value)),placeholder:h===0?"输入值或动态变量,例如 {order_id}":"值",className:"min-w-0 border-0 bg-transparent px-1 py-2 font-mono text-sm text-gray-800 outline-none ring-0 placeholder:text-gray-300"}),e.jsx("button",{type:"button",onClick:(()=>p(h)),className:"inline-flex h-8 w-8 items-center justify-center rounded-lg text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",title:`删除${a}第${h+1}行`,"aria-label":`删除${a}第${h+1}行`,children:e.jsx(se,{className:"h-4 w-4"})})]},`${a}-${h}`))})]})]})},ae=({url:a,method:s,timeout:n,headers:u,params:b,contentType:_,body:j,responsePath:N,retryEnabled:o,headersAction:v,paramsAction:p,onChange:x,onTest:h})=>{const f=Pe(_),[l,y]=d.useState({loading:!1}),r=async()=>{if(h){y({loading:!0});try{y({loading:!1,result:await h()})}catch(i){y({loading:!1,error:i instanceof Error?i.message:"API 测试请求失败"})}}};return e.jsxs("div",{className:"space-y-5 rounded-2xl border border-blue-100 bg-blue-50/40 p-4 sm:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 请求配置"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:"按 Postman 的请求结构填写,敏感模板只会加密保存在服务端。"})]}),e.jsx("span",{className:"rounded-full bg-white px-2.5 py-1 text-[11px] font-bold text-blue-600 shadow-sm",children:"API"})]}),h&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:r,disabled:l.loading,className:"inline-flex items-center gap-2 rounded-xl bg-gray-900 px-4 py-2.5 text-sm font-bold text-white transition-colors hover:bg-gray-700 disabled:cursor-wait disabled:opacity-60",children:[l.loading?e.jsx(W,{className:"h-4 w-4 animate-spin"}):e.jsx(de,{className:"h-4 w-4"}),"测试请求"]}),l.error&&e.jsx("span",{className:"text-sm font-semibold text-red-600",children:l.error}),l.result&&e.jsxs("div",{className:`w-full rounded-xl border p-3 text-sm ${l.result.status==="success"?"border-green-200 bg-green-50":"border-red-200 bg-red-50"}`,children:[e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-1 font-semibold",children:[e.jsx("span",{children:l.result.status==="success"?"测试成功":"测试失败"}),e.jsxs("span",{children:["HTTP 状态:",l.result.status_code||"网络错误"]}),e.jsxs("span",{children:["响应类型:",l.result.response_content_type||"未知"]})]}),e.jsxs("div",{className:"mt-2 grid gap-1 text-gray-700",children:[e.jsxs("span",{children:["响应字段:",l.result.response_fields.length?l.result.response_fields.join("、"):"未识别 JSON 字段"]}),e.jsxs("span",{children:["提取结果:",l.result.extracted_value||"未提取到内容"]})]}),l.result.response_preview&&e.jsx("pre",{className:"mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded-lg bg-white/70 p-2 text-xs text-gray-600",children:l.result.response_preview})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-[minmax(0,1fr)_130px_130px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"API 地址"}),e.jsx("input",{type:"url",value:a,onChange:(i=>x("url",i.target.value)),className:"w-full ios-input rounded-xl px-4 py-3 font-mono text-sm",placeholder:"https://api.example.com/get-code"})]}),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,onChange:(i=>x("method",i.target.value)),className:"w-full ios-input rounded-xl px-3 py-3",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:n,onChange:(i=>x("timeout",Number(i.target.value)||10)),className:"w-full ios-input rounded-xl px-3 py-3"})]})]}),e.jsxs("div",{className:"space-y-5 border-t border-blue-100 pt-5",children:[e.jsx(q,{label:"Headers / 请求头",value:u,onChange:(i=>x("headers",i)),placeholder:"Authorization"}),v&&e.jsxs("select",{"aria-label":"请求头处理方式",value:v,onChange:(i=>x("headersAction",i.target.value)),className:"w-full ios-input rounded-xl px-3 py-2 text-sm sm:w-auto",children:[e.jsx("option",{value:"retain",children:"保留已保存请求头"}),e.jsx("option",{value:"replace",children:"替换为上方字段"}),e.jsx("option",{value:"clear",children:"清除已保存请求头"})]}),e.jsx(q,{label:"Params / 查询参数",value:b,onChange:(i=>x("params",i)),placeholder:"order_id"}),p&&e.jsxs("select",{"aria-label":"查询参数处理方式",value:p,onChange:(i=>x("paramsAction",i.target.value)),className:"w-full ios-input rounded-xl px-3 py-2 text-sm sm:w-auto",children:[e.jsx("option",{value:"retain",children:"保留已保存查询参数"}),e.jsx("option",{value:"replace",children:"替换为上方字段"}),e.jsx("option",{value:"clear",children:"清除已保存查询参数"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("label",{className:"text-sm font-bold text-gray-800",children:"Body / 请求正文"}),e.jsx("select",{"aria-label":"请求正文 Content-Type",value:_,onChange:(i=>x("contentType",i.target.value)),className:"ios-input rounded-xl px-3 py-2 text-sm sm:w-[290px]",children:Ee.map(i=>e.jsx("option",{value:i.value,children:i.label},i.value))})]}),f?e.jsx("textarea",{"aria-label":"JSON 请求正文",value:j,onChange:(i=>x("body",i.target.value)),className:"h-36 w-full resize-y ios-input rounded-xl px-4 py-3 font-mono text-sm",placeholder:`{
|
||
"order_id": "{order_id}"
|
||
}`}):e.jsx(q,{label:"Body 字段",value:j,onChange:(i=>x("body",i)),placeholder:"field"}),e.jsx("p",{className:"text-xs text-gray-500",children:"GET 请求通常只使用 Params;POST 请求会按所选 Content-Type 发送 Body。"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 border-t border-blue-100 pt-5 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]",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:N,onChange:(i=>x("responsePath",i.target.value)),className:"w-full ios-input rounded-xl px-4 py-3 font-mono text-sm",placeholder:"data.cards[0].code"})]}),e.jsxs("label",{className:"flex items-center gap-2 self-end pb-3 text-sm font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:(i=>x("retryEnabled",i.target.checked))}),"启用幂等重试(需配置 ","{idempotency_key}",")"]})]})]})},Re=({dataCards:a,downloadCardTemplate:s,...n})=>{var y;const u=r=>{var i;n.setBatchFile(((i=r.target.files)==null?void 0:i[0])||null)},b=r=>{n.setAppendContent(r.target.value)},_=r=>{n.setAppendTargetId(r.target.value)},j=()=>n.closeBatchModal(),N=()=>n.setBatchTab("create"),o=()=>n.setBatchTab("append"),v=()=>void n.handleRetryBatchCreate(),p=()=>void n.handleRetryBatchAppend(),x=n.batchResult&&"rows"in n.batchResult?n.batchResult:null,h=r=>e.jsxs("option",{value:String(r.id),children:[r.name,"(ID: ",r.id,")"]},r.id),f=()=>void n.handleBatchCreate(),l=()=>void n.handleBatchAppend();return n.showBatchModal?H.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(K,{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:N,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${n.batchTab==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(pe,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:o,className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${n.batchTab==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(J,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),n.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:s,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(xe,{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(J,{className:"w-4 h-4"}),n.batchFile?n.batchFile.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:u})]})]}),((y=n.batchResult)==null?void 0:y.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:n.batchResult.error}),e.jsx("button",{type:"button",onClick:v,disabled:!n.batchFile||n.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),x&&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:["共 ",x.total," 行 · 成功 ",x.created," · 失败 ",x.failed]}),x.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:x.rows.filter(r=>!r.success).map(r=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",r.row_no," 行「",r.name,"」:",r.error]},r.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:a.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:n.appendTargetId,onChange:_,className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:a.map(h)})]}),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:n.appendContent,onChange:b,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:["预览:",n.appendPreview.length," 个有效卡密,空行自动忽略。"]})]}),n.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:n.appendError}),e.jsx("button",{type:"button",onClick:p,disabled:n.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),n.appendResult&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",n.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:"关闭"}),n.batchTab==="create"?e.jsxs("button",{onClick:f,disabled:!n.batchFile||n.batchBusy,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[n.batchBusy?e.jsx(W,{className:"w-4 h-4 animate-spin"}):e.jsx(J,{className:"w-4 h-4"}),n.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:l,disabled:!n.appendTargetId||n.appendPreview.length===0||n.batchBusy||a.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[n.batchBusy?e.jsx(W,{className:"w-4 h-4 animate-spin"}):e.jsx(G,{className:"w-4 h-4"}),n.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},Ie=({type:a})=>{switch(a){case"text":return e.jsx(le,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(re,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(me,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(ne,{className:"w-5 h-5 text-gray-500"})}},Fe=()=>{const[a,s]=d.useState([]),[n,u]=d.useState(!0),b=d.useRef(0),_=d.useRef(null),j=d.useCallback(async()=>{var v;const N=++b.current;(v=_.current)==null||v.abort();const o=new AbortController;_.current=o,u(!0);try{const p=await Ne({signal:o.signal});if(N!==b.current)return;s(p)}catch(p){N===b.current&&!o.signal.aborted&&console.error("加载卡密库存失败:",p)}finally{N===b.current&&u(!1)}},[]);return d.useEffect(()=>(j(),()=>{var o;b.current+=1,(o=_.current)==null||o.abort()}),[j]),{cards:a,setCards:s,loading:n,loadCards:j}},$e=a=>{const s=a.dataCards,n=a.loadCards,[u,b]=d.useState(!1),[_,j]=d.useState("create"),[N,o]=d.useState(null),[v,p]=d.useState(null),[x,h]=d.useState(!1),[f,l]=d.useState(""),[y,r]=d.useState(""),[i,I]=d.useState(null),[D,F]=d.useState(""),C=d.useRef(0),E=d.useRef(null),$=d.useRef("");d.useEffect(()=>(()=>{var g;C.current+=1,(g=E.current)==null||g.abort()}),[]);const V=d.useMemo(()=>oe(y),[y]),c=d.useCallback(()=>{var g;j("create"),o(null),p(null),l((g=s[0])!=null&&g.id?String(s[0].id):""),r(""),I(null),F(""),b(!0)},[s]),t=d.useCallback(()=>{var g;C.current+=1,(g=E.current)==null||g.abort(),h(!1),b(!1)},[]),m=d.useCallback(async()=>{var P;if(!N||x)return;const g=++C.current;(P=E.current)==null||P.abort();const A=new AbortController;E.current=A,h(!0),p(null);try{const T=await Ce(N,{signal:A.signal});if(!L(g,C.current,"",""))return;p(T),T.created>0&&await n()}catch(T){if(!L(g,C.current,"",""))return;p({error:(T==null?void 0:T.message)||"上传失败"})}finally{L(g,C.current,"","")&&h(!1)}},[x,N,n]),w=d.useCallback(async()=>{var T;if(!Te(f,y,x))return;const g=f,A=++C.current;$.current=g,(T=E.current)==null||T.abort();const P=new AbortController;E.current=P,h(!0),I(null),F("");try{const B=await ke(g,y,{signal:P.signal});if(!L(A,C.current,g,f))return;I({added:B.added}),r(""),await n()}catch(B){if(!L(A,C.current,g,f))return;F((B==null?void 0:B.message)||"追加失败")}finally{L(A,C.current,g,f)&&h(!1)}},[y,f,x,n]),S=d.useCallback(async()=>{await m()},[m]),k=d.useCallback(async()=>{$.current&&f!==$.current||await w()},[f,w]);return{showBatchModal:u,setShowBatchModal:b,batchTab:_,setBatchTab:j,batchFile:N,setBatchFile:o,batchResult:v,batchBusy:x,appendTargetId:f,setAppendTargetId:l,appendContent:y,setAppendContent:r,appendResult:i,appendError:D,appendPreview:V,openBatchModal:c,closeBatchModal:t,handleBatchCreate:m,handleBatchAppend:w,handleRetryBatchCreate:S,handleRetryBatchAppend:k}},Je=()=>{const{cards:a,loadCards:s}=Fe(),n=Ae({cards:a,loadCards:s}),{dataCards:u,filteredCards:b,typeFilter:_,setTypeFilter:j,nameSearch:N,setNameSearch:o,showEditModal:v,setShowEditModal:p,showAddModal:x,setShowAddModal:h,selectedCard:f,editForm:l,setEditForm:y,addForm:r,setAddForm:i,handleEdit:I,handleSaveEdit:D,handleDelete:F,handleAddCard:C,toggleCardStatus:E,copyCardID:$,downloadCardTemplate:V}=n,c=$e({dataCards:u,loadCards:s});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:c.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(J,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:(()=>h(!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(G,{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(he,{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(ue,{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:N,onChange:(t=>o(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:["显示 ",b.length," / ",a.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:b.map(t=>{let m="";return t.type==="data"&&t.data_content?m=`库存: ${t.data_content.split(`
|
||
`).filter(S=>S.trim()).length} 条`:t.type==="text"&&t.text_content?m=t.text_content:t.type==="api"&&t.api_config?m=t.api_config.url:t.type==="image"&&t.image_url&&(m="图片链接"),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(Ie,{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:(()=>$(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(be,{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:m,children:m})}),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:(()=>E(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:(()=>I(t)),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(ye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>F(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(se,{className:"h-4 w-4"})})]})})]},t.id)})})]})}),b.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ge,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:a.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),v&&f&&H.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:(()=>p(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(K,{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=>y({...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=>y({...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:"data",children:"批量库存"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"image",children:"图片"}),e.jsx("option",{value:"api",children:"API 接口"})]})]})]}),l.type==="api"&&e.jsx(e.Fragment,{children:e.jsx(ae,{url:l.api_url||"",method:l.api_method||"GET",timeout:l.api_timeout||10,headers:l.api_headers||"",params:l.api_params||"",contentType:l.api_content_type||"application/json",body:l.api_body||"",responsePath:l.api_response_path||"",retryEnabled:l.api_retry_enabled||!1,headersAction:l.api_headers_action||"retain",paramsAction:l.api_params_action||"retain",onTest:(()=>Z({url:l.api_url||"",method:l.api_method||"GET",timeout_seconds:l.api_timeout||10,headers:l.api_headers||void 0,params:l.api_params||void 0,content_type:l.api_content_type||"application/json",body:l.api_body||void 0,response_path:l.api_response_path||void 0,retry_enabled:l.api_retry_enabled||!1})),onChange:((t,m)=>y(w=>({...w,...t==="url"?{api_url:String(m)}:{},...t==="method"?{api_method:m}:{},...t==="timeout"?{api_timeout:Number(m)}:{},...t==="headers"?{api_headers:String(m)}:{},...t==="params"?{api_params:String(m)}:{},...t==="contentType"?{api_content_type:String(m)}:{},...t==="body"?{api_body:String(m)}:{},...t==="responsePath"?{api_response_path:String(m)}:{},...t==="retryEnabled"?{api_retry_enabled:!!m}:{},...t==="headersAction"?{api_headers_action:m}:{},...t==="paramsAction"?{api_params_action:m}:{}})))})}),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=>y({...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=>y({...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=>y({...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=>y({...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=>y({...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:(()=>y({...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:(()=>p(!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:D,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),x&&H.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:(()=>h(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(K,{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:r.name,onChange:(t=>i({...r,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-4 gap-2",children:[e.jsxs("button",{type:"button",onClick:(()=>i({...r,type:"data",content:""})),className:`p-3 rounded-xl font-bold transition-all ${r.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(ne,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:(()=>i({...r,type:"text",content:""})),className:`p-3 rounded-xl font-bold transition-all ${r.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(le,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:(()=>i({...r,type:"image",content:""})),className:`p-3 rounded-xl font-bold transition-all ${r.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(re,{className:"w-5 h-5 mx-auto mb-1"}),"图片"]}),e.jsxs("button",{type:"button",onClick:(()=>i({...r,type:"api",content:""})),className:`p-3 rounded-xl font-bold transition-all ${r.type==="api"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(je,{className:"w-5 h-5 mx-auto mb-1"}),"API 接口"]})]})]}),r.type!=="api"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:r.type==="data"?"库存内容(一行一个)":r.type==="text"?"固定回复内容":"图片 URL"}),r.type==="image"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{type:"url",value:r.content,onChange:(t=>i({...r,content:t.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"https://example.com/card.png"}),e.jsx("p",{className:"text-xs text-gray-500",children:"仅保存图片 URL;发货时会临时下载并上传到闲鱼"})]}):e.jsx("textarea",{value:r.content,onChange:(t=>i({...r,content:t.target.value})),className:`w-full ios-input px-4 py-3 rounded-xl resize-none text-sm ${r.type==="data"?"h-48 font-mono":"h-32"}`,placeholder:r.type==="data"?`CODE-123456
|
||
CODE-789012
|
||
...`:"请输入每次发货时发送的固定文字"}),r.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:r.content.split(`
|
||
`).filter(t=>t.trim()).length})," 条"]})]}),r.type==="api"&&e.jsx(e.Fragment,{children:e.jsx(ae,{url:r.content,method:r.api_method,timeout:r.api_timeout,headers:r.api_headers,params:r.api_params,contentType:r.api_content_type,body:r.api_body,responsePath:r.api_response_path,retryEnabled:r.api_retry_enabled,onTest:(()=>Z({url:r.content,method:r.api_method,timeout_seconds:r.api_timeout,headers:r.api_headers||void 0,params:r.api_params||void 0,content_type:r.api_content_type,body:r.api_body||void 0,response_path:r.api_response_path||void 0,retry_enabled:r.api_retry_enabled})),onChange:((t,m)=>i(w=>({...w,...t==="url"?{content:String(m)}:{},...t==="method"?{api_method:m}:{},...t==="timeout"?{api_timeout:Number(m)}:{},...t==="headers"?{api_headers:String(m)}:{},...t==="params"?{api_params:String(m)}:{},...t==="contentType"?{api_content_type:String(m)}:{},...t==="body"?{api_body:String(m)}:{},...t==="responsePath"?{api_response_path:String(m)}:{},...t==="retryEnabled"?{api_retry_enabled:!!m}:{}})))})}),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:r.description,onChange:(t=>i({...r,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:r.delay_seconds,onChange:(t=>i({...r,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:(()=>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:C,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(G,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),e.jsx(Re,{dataCards:u,downloadCardTemplate:V,...c})]})};export{Je as default};
|