2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
import{d as ts,o as as,J as ls,a as n,c as o,b as ns,B as os,e as a,F as g,r as B,t as r,f as i,K as rs,L as J,n as O,g as v,h as P,i as w,E as u,j as is,M as cs,N as us,O as ds,P as vs,Q as _s,_ as ps,q as fs,s as hs}from"./pywebview-p4QBqp2b.js";const ys={class:"page-shell module-page"},bs={class:"main-content"},ks={class:"left-panel"},gs={class:"upload-zone"},ws={class:"selected-files clean-placeholder split-selected-files"},ms={key:0,class:"more-line"},Is={key:1},$s={class:"run-row"},Cs=["disabled"],xs={class:"loading-msg"},Ps={key:0,class:"queue-debug-card"},Ss={key:0,class:"queue-debug-line"},Rs={key:1,class:"queue-debug-payload"},Fs={class:"right-panel"},Bs={class:"task-list-wrap"},Ds={class:"clean-result-summary"},Es={class:"summary-card"},Ns={class:"summary-card"},Ts={class:"summary-card"},qs={class:"result-list-wrap"},Us={key:0,class:"empty-tasks"},js={key:0,class:"result-subsection"},Ms={class:"task-list clean-result-list"},zs={class:"left split-result-main"},Vs=["title"],As={class:"files"},Ks={class:"files"},Hs={key:0,class:"files"},Js={key:1,class:"files"},Os={key:2,class:"time"},Ls={key:3,class:"delete-brand-progress-block"},Gs={class:"delete-brand-progress-header"},Qs={class:"delete-brand-progress-bar"},Ws={class:"files delete-brand-progress"},Xs={key:4,class:"files split-entry-list delete-brand-preview"},Ys={key:5,class:"files"},Zs={class:"task-right split-result-actions"},se=["onClick"],ee=["onClick"],te=["onClick"],ae={key:1,class:"result-subsection"},le={class:"task-list clean-result-list"},ne={class:"left split-result-main"},oe=["title"],re={class:"files"},ie={class:"files"},ce={key:0,class:"files"},ue={key:1,class:"files"},de={key:2,class:"time"},ve={key:3,class:"delete-brand-progress-block"},_e={class:"delete-brand-progress-header"},pe={class:"delete-brand-progress-bar"},fe={class:"files delete-brand-progress"},he={key:4,class:"files split-entry-list delete-brand-preview"},ye={key:5,class:"files"},be={class:"task-right split-result-actions"},ke=["onClick"],ge=["onClick"],we=["onClick"],me=ts({__name:"BrandDeleteBrandTab",setup($e){const p=v([]),m=v([]),h=v(!1),S=v([]),R=v([]),D=v([]),I=v({total:0,successCount:0,failedCount:0,items:[]}),f=v(""),y=v(""),_=v({}),b=v(null),F=P(()=>p.value.slice(0,10)),$=P(()=>R.value),C=P(()=>D.value.filter(t=>!R.value.some(e=>(e.resultId||e.taskId||e.fileKey||e.sourceFilename)===(t.resultId||t.taskId||t.fileKey||t.sourceFilename)))),L=P(()=>$.value.length>0||C.value.length>0);function E(t){return t.map(e=>e.matched?e:{...e,success:!1,error:e.error||"未匹配到紫鸟店铺",taskId:void 0,openStoreUrl:void 0})}function G(){S.value=[...$.value,...C.value]}function N(){G(),Q(S.value)}function Q(t){I.value={total:t.length,successCount:t.filter(e=>e.success).length,failedCount:t.filter(e=>!e.success).length,items:t}}function W(t){return t.taskId||0}function T(t){if(!t)return"";const e=_.value[t],s=e?.line_progress?.info;if(!e?.line_progress?.has_progress||!s){const c=e?.task?.status;return c?`任务状态:${c}`:""}const l=[];return s.phase&&l.push(`阶段:${s.phase}`),s.file_index&&s.file_total&&l.push(`文件:${s.file_index}/${s.file_total}`),s.file_name&&l.push(`当前文件:${s.file_name}`),s.current_line!==void 0&&s.total_lines!==void 0&&l.push(`进度:${s.current_line}/${s.total_lines}`),s.current_country&&l.push(`国家:${s.current_country}`),s.current_asin&&l.push(`ASIN:${s.current_asin}`),s.finished_files!==void 0&&l.push(`已完成文件:${s.finished_files}`),l.join("|")}function x(t){if(!t)return 0;const e=_.value[t]?.line_progress?.info;return e?e.current_line!==void 0&&e.total_lines&&e.total_lines>0?Math.max(0,Math.min(100,Math.round(e.current_line/e.total_lines*100))):e.finished_files!==void 0&&e.file_total&&e.file_total>0?Math.max(0,Math.min(100,Math.round(e.finished_files/e.file_total*100))):_.value[t]?.task?.status==="SUCCESS"?100:0:0}function X(t){return _.value[t]?.task?.status==="RUNNING"}function q(t){const e=t.taskId;return!e||!t.matched?!1:_.value[e]?.task?.status==="SUCCESS"}async function U(){const t=Array.from(new Set(S.value.map(W).filter(e=>e>0)));for(const e of t)try{const s=await _s(e);_.value[e]=s}catch{}}function Y(){b.value||(b.value=window.setInterval(async()=>{await U(),Object.keys(_.value).some(e=>X(Number(e)))||j()},1500))}function j(){b.value&&(window.clearInterval(b.value),b.value=null)}async function M(t){const e=w();if(!e?.upload_file_to_java)throw new Error("当前桌面端未提供文件上传桥接能力");const s=[];for(const l of t){const c=typeof l=="string"?l:l.absolutePath,d=typeof l=="string"?void 0:l.relativePath,k=await e.upload_file_to_java(c,d);if(!k?.success||!k.data)throw new Error(k?.error||k?.message||`上传失败:${c}`);s.push(k.data)}return s}async function Z(){const t=w();if(!t?.select_brand_xlsx_files){u.warning("当前环境不支持文件选择,请在本机客户端中打开");return}try{const e=await t.select_brand_xlsx_files();if(!e?.length)return;p.value=e,m.value=await M(e),u.success(`已选择 ${e.length} 个删除品牌文件`)}catch(e){u.error(e instanceof Error?e.message:"选择失败")}}async function ss(){const t=w();if(!t?.select_brand_folder){u.warning("当前环境不支持文件夹选择,请在本机客户端中打开");return}try{const e=await t.select_brand_folder();if(!e)return;const s=await is(e);if(!s.success||!s.items?.length){u.warning(s.error||"该文件夹下没有 xlsx 文件");return}p.value=s.items.map(l=>l.relativePath||l.absolutePath),m.value=await M(s.items),u.success(`已选择文件夹内 ${s.items.length} 个 xlsx 文件`)}catch(e){u.error(e instanceof Error?e.message:"选择失败")}}async function es(){if(!m.value.length){u.warning("请先选择待处理文件");return}try{h.value=!0;const t=await cs({files:m.value.map(c=>({fileKey:c.fileKey,originalFilename:c.originalFilename,relativePath:c.relativePath}))}),e=E(t.items||[]);R.value=e,N(),await U(),Y();const s=w(),l=e.some(c=>!c.matched);if(!l&&s?.enqueue_json){const c={type:"delete-brand-run",ts:Date.now(),data:{...t,items:e}};y.value=JSON.stringify(c,null,2);const d=await s.enqueue_json(c);d?.success?f.value=`已推送到 Python 队列,当前队列长度:${d.queue_size??"-"}`:f.value=`推送到 Python 队列失败:${d?.error||"未知错误"}`}else f.value=l?"存在未匹配到紫鸟店铺的文件,已跳过推送到 Python 队列":"当前环境未启用 pywebview enqueue_json(浏览器环境不会推送)",y.value="";l?u.error("存在未匹配到紫鸟店铺的文件,已标记为失败"):u.success("删除品牌解析完成")}catch(t){u.error(t instanceof Error?t.message:"执行失败")}finally{h.value=!1}}async function z(t){const e=t.taskId;if(!e){u.warning("未找到任务ID");return}const s=w(),l=us(e),c=t.outputFilename||t.sourceFilename||`delete-brand_${e}.xlsx`;if(s?.save_file_from_url){const d=await s.save_file_from_url(l,c);d.success?u.success(`已保存:${d.path||c}`):d.error&&d.error!=="用户取消"&&u.error(d.error);return}window.open(l,"_blank")}async function V(){try{const t=await ds();D.value=E(t.items||[]),N()}catch{}}async function A(t){try{await vs(t),await V(),u.success("已删除")}catch(e){u.error(e instanceof Error?e.message:"删除失败")}}function K(t){const e=t.slice(0,5).map(l=>`${l.country}:${l.asin}${l.status?`(${l.status})`:""}`);return t.length-e.length>0?`${e.join("、")} 等 ${t.length} 条`:e.join("、")}function H(t){window.open(t,"_blank")}return as(()=>{V().catch(()=>{})}),ls(()=>{j()}),(t,e)=>(n(),o("div",ys,[ns(os,{active:"delete-brand"}),a("div",bs,[a("aside",ks,[e[2]||(e[2]=a("div",{class:"section-title"},"选择文件",-1)),a("div",gs,[e[0]||(e[0]=a("div",{class:"hint"},"上传删除品牌 Excel;无论是直接上传文件还是上传文件夹批量导入,都会按每个 Excel 文件名作为店铺名。",-1)),a("div",{class:"btns"},[a("button",{type:"button",class:"opt-btn",onClick:Z},"选择 Excel 文件"),a("button",{type:"button",class:"opt-btn",onClick:ss},"选择文件夹")]),a("div",ws,[p.value.length?(n(),o(g,{key:0},[(n(!0),o(g,null,B(F.value,s=>(n(),o("span",{key:s},r(s),1))),128)),p.value.length>F.value.length?(n(),o("span",ms," 还有 "+r(p.value.length-F.value.length)+" 个文件未展开显示 ",1)):i("",!0)],64)):(n(),o("span",Is,"暂未选择删除品牌文件"))])]),e[3]||(e[3]=rs('<div class="section-title" data-v-375b57cc>执行说明</div><div class="option-group" data-v-375b57cc><label class="radio-item active" data-v-375b57cc><input type="checkbox" checked disabled data-v-375b57cc><div data-v-375b57cc><span class="label" data-v-375b57cc>文件名作为店铺名</span><div class="desc" data-v-375b57cc>例如 鲍丽明.xlsx 会解析为店铺名 鲍丽明;并自动联动紫鸟进行店铺匹配</div></div></label><label class="radio-item active" data-v-375b57cc><input type="checkbox" checked disabled data-v-375b57cc><div data-v-375b57cc><span class="label" data-v-375b57cc>文件夹仅用于批量导入</span><div class="desc" data-v-375b57cc>文件夹名和子目录名不会参与店铺匹配,只是方便一次上传多个 Excel</div></div></label><label class="radio-item active" data-v-375b57cc><input type="checkbox" checked disabled data-v-375b57cc><div data-v-375b57cc><span class="label" data-v-375b57cc>按国家分组去重</span><div class="desc" data-v-375b57cc>解析后按国家返回,并在每个国家内按 ASIN 去重(保留首次出现的状态)</div></div></label></div>',2)),a("div",$s,[a("button",{type:"button",class:"btn-run",disabled:h.value,onClick:es},r(h.value?"解析中...":"开始解析"),9,Cs),a("span",xs,r(h.value?"正在读取删除品牌数据,请稍候…":"解析后会在右侧展示按国家分组的去重结果"),1)]),f.value||y.value?(n(),o("div",Ps,[e[1]||(e[1]=a("div",{class:"section-title queue-debug-title"},"Python 队列推送结果",-1)),f.value?(n(),o("div",Ss,r(f.value),1)):i("",!0),y.value?(n(),o("pre",Rs,r(y.value),1)):i("",!0)])):i("",!0)]),a("section",Fs,[e[12]||(e[12]=a("div",{class:"panel-header"},"删除品牌结果",-1)),a("div",Bs,[a("div",Ds,[a("div",Es,[e[4]||(e[4]=a("span",{class:"summary-label"},"已处理文件",-1)),a("strong",null,r(I.value.total),1)]),a("div",Ns,[e[5]||(e[5]=a("span",{class:"summary-label"},"成功结果",-1)),a("strong",null,r(I.value.successCount),1)]),a("div",Ts,[e[6]||(e[6]=a("span",{class:"summary-label"},"失败文件",-1)),a("strong",null,r(I.value.failedCount),1)])]),a("div",qs,[e[11]||(e[11]=a("div",{class:"result-list-header"},[a("span",null,"删除品牌结果列表")],-1)),L.value?(n(),o(g,{key:1},[$.value.length?(n(),o("div",js,[e[8]||(e[8]=a("div",{class:"result-subsection-title"},"当前任务",-1)),a("ul",Ms,[(n(!0),o(g,null,B($.value,s=>(n(),o("li",{key:`current-${s.resultId||s.taskId||s.sourceFilename}`,class:"task-item split-result-item"},[a("div",zs,[a("span",{class:"id",title:s.sourceFilename},r(s.sourceFilename||"-"),9,Vs),a("div",As,"店铺名:"+r(s.shopName||"-"),1),a("div",Ks,"匹配结果:"+r(s.matched?`已匹配 ${s.shopId||""}`:"未匹配到紫鸟店铺"),1),s.platform?(n(),o("div",Hs,"平台:"+r(s.platform),1)):i("",!0),s.countryCount!==void 0&&s.matched?(n(),o("div",Js,"国家数:"+r(s.countryCount),1)):i("",!0),s.totalRows!==void 0&&s.matched?(n(),o("div",Os,"去重后 "+r(s.totalRows)+" 条",1)):i("",!0),s.taskId&&s.matched?(n(),o("div",Ls,[a("div",Gs,[e[7]||(e[7]=a("span",null,"任务进度",-1)),a("span",null,r(x(s.taskId))+"%",1)]),a("div",Qs,[a("div",{class:"delete-brand-progress-bar-fill",style:J({width:`${x(s.taskId)}%`})},null,4)]),a("div",Ws,r(T(s.taskId)),1)])):i("",!0),s.previewRows?.length?(n(),o("div",Xs,r(K(s.previewRows)),1)):i("",!0),s.error?(n(),o("div",Ys,"错误信息:"+r(s.error),1)):i("",!0)]),a("div",Zs,[a("span",{class:O(["status",s.success?"success":"failed"])},r(s.success?"已完成":"失败"),3),s.openStoreUrl?(n(),o("button",{key:0,type:"button",class:"download",onClick:l=>H(s.openStoreUrl)}," 打开紫鸟 ",8,se)):i("",!0),q(s)?(n(),o("button",{key:1,type:"button",class:"download",onClick:l=>z(s)}," 下载 ",8,ee)):i("",!0),s.resultId?(n(),o("button",{key:2,type:"button",class:"btn-delete",onClick:l=>A(s.resultId)}," 删除 ",8,te)):i("",!0)])]))),128))])])):i("",!0),C.value.length?(n(),o("div",ae,[e[10]||(e[10]=a("div",{class:"result-subsection-title"},"历史记录",-1)),a("ul",le,[(n(!0),o(g,null,B(C.value,s=>(n(),o("li",{key:`history-${s.resultId||s.taskId||s.sourceFilename}`,class:"task-item split-result-item"},[a("div",ne,[a("span",{class:"id",title:s.sourceFilename},r(s.sourceFilename||"-"),9,oe),a("div",re,"店铺名:"+r(s.shopName||"-"),1),a("div",ie,"匹配结果:"+r(s.matched?`已匹配 ${s.shopId||""}`:"未匹配到紫鸟店铺"),1),s.platform?(n(),o("div",ce,"平台:"+r(s.platform),1)):i("",!0),s.countryCount!==void 0&&s.matched?(n(),o("div",ue,"国家数:"+r(s.countryCount),1)):i("",!0),s.totalRows!==void 0&&s.matched?(n(),o("div",de,"去重后 "+r(s.totalRows)+" 条",1)):i("",!0),s.taskId&&s.matched?(n(),o("div",ve,[a("div",_e,[e[9]||(e[9]=a("span",null,"任务进度",-1)),a("span",null,r(x(s.taskId))+"%",1)]),a("div",pe,[a("div",{class:"delete-brand-progress-bar-fill",style:J({width:`${x(s.taskId)}%`})},null,4)]),a("div",fe,r(T(s.taskId)),1)])):i("",!0),s.previewRows?.length?(n(),o("div",he,r(K(s.previewRows)),1)):i("",!0),s.error?(n(),o("div",ye,"错误信息:"+r(s.error),1)):i("",!0)]),a("div",be,[a("span",{class:O(["status",s.success?"success":"failed"])},r(s.success?"已完成":"失败"),3),s.openStoreUrl?(n(),o("button",{key:0,type:"button",class:"download",onClick:l=>H(s.openStoreUrl)}," 打开紫鸟 ",8,ke)):i("",!0),q(s)?(n(),o("button",{key:1,type:"button",class:"download",onClick:l=>z(s)}," 下载 ",8,ge)):i("",!0),s.resultId?(n(),o("button",{key:2,type:"button",class:"btn-delete",onClick:l=>A(s.resultId)}," 删除 ",8,we)):i("",!0)])]))),128))])])):i("",!0)],64)):(n(),o("div",Us," 暂无删除品牌结果,完成解析后会在这里展示按国家分组的去重结果 "))])])])])]))}}),Ie=ps(me,[["__scopeId","data-v-375b57cc"]]);fs(Ie).use(hs).mount("#app");
|