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