import{d as Ee,o as Ae,L as xe,a as o,c as u,b as Ue,B as De,e as a,F as W,r as Y,t as l,w as $e,G as ze,f as h,N as ie,n as Ge,g as v,h as L,i as x,E as c,V as Ke,W as Me,X as Be,U as ce,Y as Le,Z as He,$ as qe,a0 as je,a1 as Ve,a2 as Oe,a3 as Je,_ as Xe,q as Qe,s as We}from"./pywebview-DNfEzGOK.js";import{e as Ye}from"./brand-D4E3c93-.js";import{c as Ze}from"./categorized-timers-JPA-olTr.js";const es={class:"page-shell module-page"},ss={class:"main-content"},ts={class:"left-panel"},as={class:"upload-zone"},ns={class:"selected-files"},ls={key:0},rs={class:"prompt-card"},os={class:"run-row"},us=["disabled"],is=["disabled"],cs={key:0,class:"parse-card"},ds={key:1,class:"queue-payload"},fs={class:"right-panel"},ps={class:"task-list-wrap"},vs={class:"clean-result-summary"},gs={class:"summary-card"},ys={class:"summary-card"},hs={class:"summary-card"},_s={class:"summary-card"},ks={class:"result-list-wrap"},ws={key:0,class:"empty-tasks"},Is={key:1,class:"task-list clean-result-list"},ms={class:"left"},Cs={class:"id"},Ps={class:"files"},Ss={class:"files"},bs={key:0,class:"files result-hint"},Fs={key:1,class:"file-progress"},Ts={class:"file-progress-meta"},Ns={class:"file-progress-track"},Rs={class:"file-progress-count"},Es={class:"task-right"},As={class:"status running"},xs=["onClick"],Us={class:"result-list-wrap"},Ds={key:0,class:"empty-tasks"},$s={key:1,class:"task-list clean-result-list"},zs={class:"left"},Gs={class:"id"},Ks={class:"files"},Ms={key:0,class:"files"},Bs={key:1,class:"files result-hint"},Ls={key:2,class:"file-progress"},Hs={class:"file-progress-meta"},qs={class:"file-progress-track"},js={class:"file-progress-count"},Vs={key:3,class:"files"},Os={class:"task-right"},Js=["onClick"],Xs=["onClick"],de=`请帮我排查以下亚马逊商品在英国及欧洲地区是否存在知识产权侵权风险。 请直接给出明确结论(有侵权风险 或 未发现明显侵权风险),并严格按照以下三个维度提供精简的排查理由: 外观维度: 评估产品外形、图案设计是否与欧洲/英国常见外观专利雷同。 专利维度: 评估产品的核心技术或物理结构是否存在侵权可能。 标题维度: 排查标题中是否包含大牌商标、敏感词或版权保护词汇。 结论:XX`,Qs=3e3,Ws=Ee({__name:"BrandAppearancePatentTab",setup(Zs){const U=v([]),b=v([]),w=v(null),F=v(null),H=v(""),D=v(!1),$=v(!1),I=v(""),d=v([]),i=v([]),y=v(null),q=v(!1);let T=null,Z=0,N=!1;const R=Ze("appearance-patent"),E=v({pendingTaskCount:0,processedTaskCount:0,successTaskCount:0,failedTaskCount:0}),g=v([]),P=L(()=>w.value||F.value),j=L(()=>{const e=w.value;return!e?.taskId||g.value.some(t=>t.taskId===e.taskId)?null:{taskId:e.taskId,sourceFilename:e.sourceFilename,rowCount:e.acceptedRows,taskStatus:"PENDING",success:!1}}),ee=L(()=>{const e=new Set([...d.value,...i.value]),s=g.value.filter(n=>{const r=C(n);return n.taskId!=null&&(e.has(n.taskId)||r==="RUNNING"||r==="PENDING")});return j.value?s.some(n=>n.taskId===j.value?.taskId)?s:[j.value,...s]:s}),se=L(()=>g.value.filter(e=>{const s=C(e);return s!=="RUNNING"&&s!=="PENDING"}));function te(){return H.value.trim()||de}function z(){return Oe("appearance-patent").trim()}function fe(){return typeof window<"u"&&window.localStorage.getItem("uid")||"0"}function V(){return`appearance-patent:tasks:${fe()}`}function pe(e){return{taskId:e.taskId,totalRows:e.totalRows,acceptedRows:e.acceptedRows,groupCount:e.groupCount,droppedRows:e.droppedRows}}function m(){if(typeof window>"u")return;const e=Array.from(new Set([...d.value,...i.value]));e.length?window.localStorage.setItem(V(),JSON.stringify(e)):window.localStorage.removeItem(V())}function ve(){if(!(typeof window>"u"))try{const e=window.localStorage.getItem(V()),s=e?JSON.parse(e):[];d.value=Array.isArray(s)?s.filter(t=>typeof t=="number"&&t>0):[]}catch{d.value=[]}}async function ae(e){const s=x();if(!s?.upload_file_to_java)throw new Error("当前桌面端未提供文件上传能力");const t=[];for(const n of e){const r=typeof n=="string"?n:n.absolutePath,f=typeof n=="string"?void 0:n.relativePath,p=await s.upload_file_to_java(r,f);if(!p?.success||!p.data)throw new Error(p?.error||p?.message||`上传失败:${r}`);t.push(p.data)}return t}async function ge(){const e=x();if(!e?.select_brand_xlsx_files||!e.upload_file_to_java){c.warning("当前环境不支持文件选择或上传");return}const s=await e.select_brand_xlsx_files();if(!s?.length)return;const t=await ae(s);b.value=t,U.value=t.map(n=>n.relativePath||n.originalFilename||n.fileKey),w.value=null,F.value=null,I.value=""}async function ye(){const e=x();if(!e?.select_brand_folder){c.warning("当前环境不支持文件夹选择,请在本地客户端中打开");return}try{const s=await e.select_brand_folder();if(!s)return;const t=await Ye(s);if(!t.success||!t.items?.length){c.warning(t.error||"该文件夹下没有可用的 xlsx 文件");return}const n=await ae(t.items);b.value=n,U.value=t.items.map(r=>r.relativePath||r.absolutePath),w.value=null,F.value=null,I.value="",c.success(`已选择文件夹内 ${t.items.length} 个 Excel 文件`)}catch(s){c.error(s instanceof Error?s.message:"选择失败")}}async function he(){if(!b.value.length){c.warning("请先选择 Excel");return}if(!z()){c.warning("请先在左上角设置中填写外观专利密钥");return}D.value=!0;try{const e=b.value.map(t=>({fileKey:t.fileKey,originalFilename:t.originalFilename,relativePath:t.relativePath})),s=await Ke(e,te(),z());w.value=s,F.value=null,I.value="",c.success(`解析完成,共 ${s.groupCount||0} 组 / ${s.acceptedRows} 条`)}catch(e){c.error(e instanceof Error?e.message:"解析失败")}finally{D.value=!1}}async function _e(){const e=x(),s=w.value,t=s?.taskId;if(!t){c.warning("请先解析文件");return}if(!e?.enqueue_json){c.error("当前环境未启用 pywebview enqueue_json");return}if(!z()){c.warning("请先在左上角设置中填写外观专利密钥");return}$.value=!0;try{const n=await Me(t),r=n.groups||[],f={type:"appearance-patent-run",ts:Date.now(),data:{taskId:t,prompt:n.aiPrompt||s.aiPrompt||te(),api_key:z(),sourceFileCount:s.sourceFileCount||0,totalRows:s.totalRows||0,acceptedRows:s.acceptedRows||0,groupCount:s.groupCount||0,groups:r.map(_=>({sourceFileKey:_.sourceFileKey||"",sourceFilename:_.sourceFilename||"",groupKey:_.groupKey||"",baseId:_.baseId||"",displayId:_.displayId||"",items:(_.items||[]).map(k=>({sourceFileKey:k.sourceFileKey||"",sourceFilename:k.sourceFilename||"",rowToken:k.rowToken||"",groupKey:k.groupKey||"",id:k.displayId,asin:k.asin,country:k.country,url:k.url||"",title:k.title||""}))}))}};I.value=`任务 ${t} 已准备推送,共 ${r.length} 组`,await Be(t);const p=await e.enqueue_json(f);if(!p?.success){c.error(p?.error||"推送失败");return}F.value=pe(s),we(t),ke(),await G(),await K({force:!0}),c.success("已推送到 Python 队列")}finally{$.value=!1}}function ke(){w.value=null,I.value=""}function we(e){d.value.includes(e)||(d.value=[...d.value,e],m()),S()}function O(e){d.value=d.value.filter(s=>s!==e),m()}function Ie(e){i.value.includes(e)||(i.value=[...i.value,e],m()),S()}function J(e){i.value=i.value.filter(s=>s!==e),m()}function S(){N||y.value==null&&me(!0)}function ne(){y.value!=null&&(R.clearTimer("task-poll",y.value),y.value=null)}function me(e=!1){if(N)return;if(y.value!=null){if(!e)return;R.clearTimer("task-poll",y.value),y.value=null}const s=async()=>{y.value=null,!N&&(!d.value.length&&!i.value.length||(await Ce(),!N&&y.value==null&&(d.value.length||i.value.length)&&(y.value=R.setTimeout("task-poll",s,ce()))))};e?s():y.value=R.setTimeout("task-poll",s,ce())}async function Ce(){if(q.value||!d.value.length&&!i.value.length){!d.value.length&&!i.value.length&&ne();return}q.value=!0;try{let e=!1,s=!1;const t=Array.from(new Set([...d.value,...i.value]));if(t.length){const n=await Je(t,{force:i.value.length>0});for(const r of n.items||[]){const f=r.task;if(!f?.id)continue;const p=r.items?.[0];if(p&&Pe(p),(f.status==="SUCCESS"||f.status==="FAILED")&&(O(f.id),e=!0,f.status==="SUCCESS"?Ie(f.id):J(f.id)),p&&f.status==="SUCCESS"&&i.value.includes(f.id)){const _=(p.fileStatus||"").toUpperCase();(p.fileReady||_==="SUCCESS"||_==="FAILED")&&(J(f.id),e=!0,s=!0)}}n.missingTaskIds?.length&&(n.missingTaskIds.forEach(r=>{O(r),J(r)}),s=!0,e=!0)}e&&await G(),s&&await K(),Se()}finally{q.value=!1}}function Pe(e){if(!e.taskId&&!e.resultId)return;const s=g.value.findIndex(t=>e.resultId!=null&&t.resultId===e.resultId||e.taskId!=null&&t.taskId===e.taskId);s>=0?g.value[s]={...g.value[s],...e}:g.value=[e,...g.value]}function Se(){if(!i.value.length)return;const e=[];for(const s of i.value){const t=g.value.find(f=>f.taskId===s);if(!t){e.push(s);continue}const n=(t.taskStatus||"").toUpperCase(),r=(t.fileStatus||"").toUpperCase();n==="FAILED"||t.fileReady||r==="SUCCESS"||r==="FAILED"||n==="SUCCESS"&&e.push(s)}i.value=e,m(),i.value.length&&S()}function be(){const e=g.value.filter(s=>s.taskId!=null&&A(s)).map(s=>s.taskId);i.value=Array.from(new Set(e)),m(),i.value.length&&S()}function Fe(){const e=g.value.filter(s=>s.taskId!=null&&C(s)==="RUNNING").map(s=>s.taskId);e.length&&(d.value=Array.from(new Set([...d.value,...e])),m(),S())}async function G(){E.value=await Le()}async function K(e={}){const s=Date.now();if(!(!e.force&&g.value.length&&s-Z{g.value=t.items||[],Z=Date.now()}).finally(()=>{T=null}),T)}function le(e){const s=C(e);return s==="RUNNING"?"执行中":s==="PENDING"?"已解析待推送":A(e)?"结果生成中":X(e)?"结果生成失败":s==="SUCCESS"||e.success?"已完成":s==="FAILED"?"失败":"等待中"}function Te(e){const s=C(e);return s==="RUNNING"||A(e)?"running":X(e)||s==="FAILED"?"failed":s==="SUCCESS"||e.success?"success":"pending"}function A(e){const s=C(e),t=(e.fileStatus||"").toUpperCase();return!(s!=="SUCCESS"||re(e)||t==="FAILED"||t==="SUCCESS")}function C(e){return(e.taskStatus||"").toUpperCase()}function X(e){return(e.fileStatus||"").toUpperCase()==="FAILED"}function M(e){if(X(e))return e.fileError||"结果文件生成失败,请稍后重试或检查后端日志";if(Q(e)||!A(e))return"";const s=(e.fileStatus||"").toUpperCase();return s==="RUNNING"?"任务已完成,正在等待 Coze 回流并组装结果文件,下载按钮稍后出现":s==="PENDING"?"任务已完成,结果文件已入队,正在等待后端开始处理":"任务已完成,正在生成结果文件,下载按钮稍后出现"}function re(e){return!!(e.resultId&&(e.fileReady||e.downloadUrl))}function B(e){const s=Number(e.fileProgressPercent||0);return Number.isFinite(s)?Math.max(0,Math.min(100,Math.round(s))):0}function oe(e,s){const t=(e.fileProgressMessage||"").trim();return t?Ne(t):s}function Ne(e){const s=e.match(/^Coze submitted (\d+) batches, completed (\d+), waiting for results$/);if(s)return`已提交 Coze ${s[1]} 批,已完成 ${s[2]} 批,等待结果回流`;const t=e.match(/^Coze completed (\d+) batches, waiting for remaining Python data$/);return t?`Coze 已完成 ${t[1]} 批,等待 Python 继续回传数据`:{"Receiving Python data, waiting for 50 rows before Coze":"正在接收 Python 数据,累计 50 条后提交 Coze","Submitting Coze":"正在提交 Coze","Coze submitted, waiting for result":"Coze 已提交,等待结果回流","Waiting for Python upload":"等待 Python 继续回传数据","Coze results ready, assembling xlsx":"Coze 结果已回流,正在组装 xlsx","Assembling xlsx":"正在组装 xlsx","Uploading result file":"正在上传结果文件","Result file generated":"结果文件已生成"}[e]||e}function Q(e){return(C(e)==="RUNNING"||A(e))&&(e.fileProgressTotal||0)>0}async function Re(e){if(!e.resultId)return;const s=x();if(!s?.save_file_from_url_new){c.error("当前客户端未提供下载能力");return}const t=e.downloadUrl||qe(e.resultId),n=e.resultFilename||`${e.sourceFilename||"appearance-patent"}.xlsx`,r=await s.save_file_from_url_new(t,n);r.success?c.success(`已保存: ${r.path||n}`):r.error&&r.error!=="用户取消"&&c.error(r.error)}async function ue(e){try{e.taskStatus==="RUNNING"&&e.taskId?(await je(e.taskId),O(e.taskId)):e.resultId&&await Ve(e.resultId),await G(),await K({force:!0}),c.success("已删除")}catch(s){c.error(s instanceof Error?s.message:"删除失败")}}return Ae(async()=>{ve(),await Promise.all([G().catch(()=>{}),K().catch(()=>{})]),Fe(),be(),(d.value.length||i.value.length)&&S()}),xe(()=>{N=!0,ne(),R.clearScope()}),(e,s)=>(o(),u("div",es,[Ue(De,{active:"appearance-patent"}),a("div",ss,[a("aside",ts,[s[4]||(s[4]=a("div",{class:"section-title"},"上传文件",-1)),a("div",as,[s[1]||(s[1]=a("div",{class:"hint"},"选择 Excel 后点击解析,后端会提取 id、ASIN、国家,并保留整数 id 与子数据的第一条。",-1)),a("div",{class:"btns"},[a("button",{type:"button",class:"opt-btn",onClick:ge},"选择 Excel"),a("button",{type:"button",class:"opt-btn",onClick:ye},"选择文件夹")]),a("div",ns,[U.value.length?(o(!0),u(W,{key:1},Y(U.value,t=>(o(),u("span",{key:t},l(t),1))),128)):(o(),u("span",ls,"暂未选择文件"))])]),a("div",rs,[s[2]||(s[2]=a("div",{class:"section-title"},"AI 提示词",-1)),$e(a("textarea",{"onUpdate:modelValue":s[0]||(s[0]=t=>H.value=t),class:"prompt-input",rows:"8",placeholder:"可选,留空时使用下方默认提示词"},null,512),[[ze,H.value]]),s[3]||(s[3]=a("div",{class:"prompt-default-label"},"留空时默认使用以下提示词",-1)),a("div",{class:"prompt-preview"},l(de))]),a("div",os,[a("button",{type:"button",class:"btn-run",disabled:D.value||!b.value.length,onClick:he},l(D.value?"解析中...":"解析并创建任务"),9,us),a("button",{type:"button",class:"btn-run btn-queue",disabled:$.value||!w.value?.taskId,onClick:_e},l($.value?"推送中...":"推送到 Python 队列"),9,is)]),s[5]||(s[5]=a("p",{class:"loading-msg"},"Python 回传字段按 asin、国家、url、标题提交;后端接收分片后累计 50 条调用 Coze,当前任务区展示 Coze 回流和结果组装进度。",-1)),P.value?(o(),u("div",cs,[a("div",null,"任务 ID:"+l(P.value.taskId),1),a("div",null,"总行数:"+l(P.value.totalRows)+",有效:"+l(P.value.acceptedRows)+",分组:"+l(P.value.groupCount||0)+",过滤:"+l(P.value.droppedRows),1)])):h("",!0),I.value?(o(),u("pre",ds,l(I.value),1)):h("",!0)]),a("section",fs,[s[13]||(s[13]=a("div",{class:"panel-header"},"外观专利检测",-1)),a("div",ps,[a("div",vs,[a("div",gs,[s[6]||(s[6]=a("span",{class:"summary-label"},"运行中任务",-1)),a("strong",null,l(E.value.pendingTaskCount),1)]),a("div",ys,[s[7]||(s[7]=a("span",{class:"summary-label"},"已结束任务",-1)),a("strong",null,l(E.value.processedTaskCount),1)]),a("div",hs,[s[8]||(s[8]=a("span",{class:"summary-label"},"成功任务",-1)),a("strong",null,l(E.value.successTaskCount),1)]),a("div",_s,[s[9]||(s[9]=a("span",{class:"summary-label"},"失败任务",-1)),a("strong",null,l(E.value.failedTaskCount),1)])]),s[12]||(s[12]=a("div",{class:"subsection-title"},"匹配任务",-1)),a("div",ks,[s[10]||(s[10]=a("div",{class:"result-list-header"},[a("span",null,"当前任务")],-1)),ee.value.length?(o(),u("ul",Is,[(o(!0),u(W,null,Y(ee.value,t=>(o(),u("li",{key:`cur-${t.taskId}`,class:"task-item"},[a("div",ms,[a("span",Cs,l(t.sourceFilename||"外观专利检测"),1),a("div",Ps,"任务 ID:"+l(t.taskId),1),a("div",Ss,"行数:"+l(t.rowCount??"-"),1),M(t)?(o(),u("div",bs,l(M(t)),1)):h("",!0),Q(t)?(o(),u("div",Fs,[a("div",Ts,[a("span",null,l(oe(t,"处理中")),1),a("span",null,l(B(t))+"%",1)]),a("div",Ns,[a("div",{class:"file-progress-bar",style:ie({width:`${B(t)}%`})},null,4)]),a("div",Rs,l(t.fileProgressCurrent||0)+"/"+l(t.fileProgressTotal||0),1)])):h("",!0)]),a("div",Es,[a("span",As,l(le(t)),1),a("button",{type:"button",class:"btn-delete",onClick:n=>ue(t)},"删除",8,xs)])]))),128))])):(o(),u("div",ws,"暂无当前任务"))]),a("div",Us,[s[11]||(s[11]=a("div",{class:"result-list-header"},[a("span",null,"历史记录")],-1)),se.value.length?(o(),u("ul",$s,[(o(!0),u(W,null,Y(se.value,t=>(o(),u("li",{key:`his-${t.resultId}-${t.taskId}`,class:"task-item"},[a("div",zs,[a("span",Gs,l(t.sourceFilename||"外观专利检测"),1),a("div",Ks,"任务 ID:"+l(t.taskId??"-"),1),t.resultFilename?(o(),u("div",Ms,l(t.resultFilename||"下载结果"),1)):h("",!0),M(t)?(o(),u("div",Bs,l(M(t)),1)):h("",!0),Q(t)?(o(),u("div",Ls,[a("div",Hs,[a("span",null,l(oe(t,"结果生成中")),1),a("span",null,l(B(t))+"%",1)]),a("div",qs,[a("div",{class:"file-progress-bar",style:ie({width:`${B(t)}%`})},null,4)]),a("div",js,l(t.fileProgressCurrent||0)+"/"+l(t.fileProgressTotal||0),1)])):h("",!0),t.error?(o(),u("div",Vs,"错误:"+l(t.error),1)):h("",!0)]),a("div",Os,[a("span",{class:Ge(["status",Te(t)])},l(le(t)),3),re(t)?(o(),u("button",{key:0,type:"button",class:"download",onClick:n=>Re(t)},"下载",8,Js)):h("",!0),t.resultId?(o(),u("button",{key:1,type:"button",class:"btn-delete",onClick:n=>ue(t)},"删除",8,Xs)):h("",!0)])]))),128))])):(o(),u("div",Ds,"暂无历史记录"))])])])])]))}}),Ys=Xe(Ws,[["__scopeId","data-v-fe2c20af"]]);Qe(Ys).use(We).mount("#app");