Files
zyt/server/public/admin/assets/PrescriptionAiBatchGenerateDialog-WzKyH4aX.js
T
2026-08-28 18:24:37 +08:00

2 lines
10 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{o as de,q as r,O as g,D as u,s as l,v as c,bh as ce,u as t,r as h,bZ as pe,bB as ve,T as i,K as fe,L as v,F as me,br as ge,P as C,bX as _e,bj as ye,bk as he,C as be,bt as ke,M as d,p as J,a8 as we}from"./.pnpm-Dwh6tNxD.js";import{a as Ce,b as Ee}from"./tcm--WHZCSMq.js";import{i as L,_ as Me}from"./index-a_ZxLOOo.js";const $e={class:"batch-dialog-body"},xe={key:0,class:"loading-state"},Ae={key:1,class:"load-error-state"},Be={class:"state-description"},Ie={class:"overview-panel"},Re={class:"overview-meta"},Se={key:0,class:"refresh-error"},Te={key:2,class:"progress-panel"},ze={class:"progress-heading"},Ne={key:0,class:"current-prescription"},Ge={class:"counter-grid"},Le={class:"counter-item counter-processed"},Ve={class:"counter-item counter-success"},qe={class:"counter-item counter-partial"},Pe={class:"counter-item counter-failed"},De={key:3,class:"issues-panel"},Fe={class:"section-heading"},je={class:"issue-name"},We={class:"state-description"},He={key:5,class:"pending-panel"},Ke={class:"section-heading"},Oe={class:"pending-count"},Ue={class:"dialog-footer"},Xe={key:0,class:"footer-tip"},Ze={key:1},B=500,Je=de({__name:"PrescriptionAiBatchGenerateDialog",emits:["changed"],setup(Qe,{expose:Q,emit:Y}){const ee=Y,E=d(!1),z=d(0),I=d(0),N=d(!1),R=d(""),S=d(""),f=d([]),M=d(0),V=d(B),F=d(!1),p=d(!1),_=d(!1),j=d("idle"),y=d(0),w=d(0),W=d(0),q=d(0),G=d(0),b=d(null),$=d([]),P=we(null),te=J(()=>y.value?Math.min(100,Math.round(w.value/y.value*100)):0),se=J(()=>{const s=Math.max(0,M.value-f.value.length);return s>0?`待生成数量超过单次上限,本次最多处理 ${f.value.length} 份;完成后可再次继续处理其余约 ${s} 份。`:`后端标记清单已截断,本次最多处理 ${V.value} 份;完成后可再次继续。`}),K=()=>{_.value=!1,j.value="idle",y.value=0,w.value=0,W.value=0,q.value=0,G.value=0,b.value=null,$.value=[]},O=()=>{N.value=!1,R.value="",S.value="",f.value=[],M.value=0,V.value=B,F.value=!1,K()},H=s=>{if(typeof s=="string"&&s.trim())return s;if(s&&typeof s=="object"){const e=s,n=e.response,a=n==null?void 0:n.data,o=e.msg||e.message||e.error||(a==null?void 0:a.msg)||(a==null?void 0:a.message);if(typeof o=="string"&&o.trim())return o}return"请求失败,请稍后重试"},k=s=>s===z.value&&E.value,D=async(s=z.value,e={})=>{const n=++I.value;e.silent||(N.value=!0,R.value="");try{const a=await Ce({limit:B});if(!k(s)||n!==I.value)return;const o=Array.isArray(a.items)?a.items.slice(0,B):[];f.value=o,M.value=Math.max(o.length,Number(a.total||0)),V.value=Math.min(B,Math.max(1,Number(a.limit||B))),F.value=a.truncated===!0||M.value>o.length,S.value=""}catch(a){if(!k(s)||n!==I.value)return;e.silent?S.value=`本轮已结束,但最新待生成清单读取失败:${H(a)}`:R.value=H(a)}finally{k(s)&&n===I.value&&(N.value=!1)}},U=s=>(s.results||[]).filter(n=>n.status==="error").map(n=>`${n.model_label||n.model_name}: ${n.error_message||"生成失败"}`).join("")||"模型未返回完整报告",le=(s,e)=>{const n=Number(e.success_count||0),a=Number(e.failure_count||0),o=e.status==="partial"||e.partial===!0||n>0&&a>0,T=e.status==="error"||a>0&&n===0;return o?(q.value+=1,$.value.push({id:s.id,prescription_name:s.prescription_name||`处方 #${s.id}`,status:"partial",message:U(e)}),!0):T?(G.value+=1,$.value.push({id:s.id,prescription_name:s.prescription_name||`处方 #${s.id}`,status:"failed",message:U(e)}),!1):(W.value+=1,!0)},ae=(s,e)=>{G.value+=1,$.value.push({id:s.id,prescription_name:s.prescription_name||`处方 #${s.id}`,status:"failed",message:H(e)})},X=()=>{!p.value||_.value||(_.value=!0)},ne=async()=>{if(p.value||!f.value.length)return;const s=z.value,e=f.value.slice(0,B);try{await L.confirm(`确定按顺序为 ${e.length} 份处方生成 AI 报告吗?每份会调用双模型,过程中可请求停止。`)}catch{return}if(!k(s)||p.value)return;K(),y.value=e.length,p.value=!0,S.value="";const n=new Set;try{for(const a of e){if(!k(s)||_.value)break;b.value=a;try{const o=await Ee({id:a.id});if(!k(s))return;le(a,o)&&n.add(a.id)}catch(o){if(!k(s))return;ae(a,o)}w.value+=1,b.value=null}}finally{if(!k(s))return;const a=_.value&&w.value<y.value;j.value=a?"stopped":"completed",p.value=!1,b.value=null,n.size&&(f.value=f.value.filter(T=>!n.has(T.id)),M.value=Math.max(0,M.value-n.size)),w.value>0&&ee("changed");const o=P.value;if(P.value=null,o){o();return}if(await D(s,{silent:!0}),!k(s))return;a?L.msgWarning(`已停止,本轮共处理 ${w.value} 份处方`):G.value>0||q.value>0?L.msgWarning("批量生成已完成,请查看失败与部分成功明细"):L.msgSuccess("批量生成报告完成")}},oe=s=>{if(!p.value){s();return}X(),P.value=s,L.msgWarning("已请求停止,当前处方完成后将关闭窗口")},ie=()=>{++z.value,++I.value,P.value=null,p.value=!1,O()};return Q({open:()=>{if(p.value){E.value=!0;return}const s=++z.value;++I.value,O(),E.value=!0,D(s)}}),(s,e)=>{const n=ce,a=pe,o=fe,T=ve,x=ge,re=_e,A=he,Z=ye,ue=ke;return r(),g(ue,{modelValue:t(E),"onUpdate:modelValue":e[3]||(e[3]=m=>be(E)?E.value=m:null),class:"prescription-ai-batch-dialog",width:"min(820px, calc(100vw - 32px))",top:"6vh",title:"批量生成处方 AI 报告","close-on-click-modal":!1,"destroy-on-close":"","before-close":oe,onClosed:ie},{footer:u(()=>[l("div",Ue,[t(p)?(r(),h("span",Xe,"生成请求不会自动重试,也不会并发执行。")):(r(),h("span",Ze)),l("div",null,[t(p)?C("",!0):(r(),g(o,{key:0,onClick:e[2]||(e[2]=m=>E.value=!1)},{default:u(()=>[...e[20]||(e[20]=[v("关闭",-1)])]),_:1})),t(p)?(r(),g(o,{key:1,type:"warning",plain:"",disabled:t(_),onClick:X},{default:u(()=>[v(i(t(_)?"正在停止…":"停止"),1)]),_:1},8,["disabled"])):(r(),g(o,{key:2,type:"primary",disabled:t(N)||!!t(R)||!t(f).length,onClick:ne},{default:u(()=>[v(i(t(y)>0?"继续生成剩余报告":"开始批量生成"),1)]),_:1},8,["disabled"]))])])]),default:u(()=>[l("div",$e,[c(n,{type:"info",closable:!1,"show-icon":"",title:"仅统计完全没有任何 AI 报告的处方;已有报告不会被本批次覆盖。"}),t(N)?(r(),h("div",xe,[c(a,{rows:5,animated:""})])):t(R)?(r(),h("div",Ae,[c(T,{description:"待生成清单加载失败","image-size":72},{default:u(()=>[l("p",Be,i(t(R)),1),c(o,{type:"primary",plain:"",onClick:e[0]||(e[0]=m=>D())},{default:u(()=>[...e[4]||(e[4]=[v("重新加载",-1)])]),_:1})]),_:1})])):(r(),h(me,{key:2},[l("section",Ie,[l("div",null,[e[5]||(e[5]=l("span",{class:"overview-label"},"当前完全缺失报告",-1)),l("strong",null,i(t(M)),1),e[6]||(e[6]=l("span",{class:"overview-unit"},"份处方",-1))]),l("div",Re,[v(" 本次载入 "+i(t(f).length)+" 份 ",1),c(x,{size:"small",type:"info",effect:"plain"},{default:u(()=>[v("上限 "+i(t(V)),1)]),_:1})])]),t(S)?(r(),h("div",Se,[c(n,{type:"error",closable:!1,"show-icon":"",title:t(S)},null,8,["title"]),c(o,{type:"primary",plain:"",onClick:e[1]||(e[1]=m=>D())},{default:u(()=>[...e[7]||(e[7]=[v("重新读取清单",-1)])]),_:1})])):C("",!0),t(F)?(r(),g(n,{key:1,class:"truncated-alert",type:"warning",closable:!1,"show-icon":"",title:t(se)},null,8,["title"])):C("",!0),t(p)||t(y)>0?(r(),h("section",Te,[l("div",ze,[l("div",null,[e[8]||(e[8]=l("span",{class:"section-kicker"},"本轮进度",-1)),l("strong",null,i(t(w))+" / "+i(t(y)),1)]),t(p)&&!t(_)?(r(),g(x,{key:0,type:"primary"},{default:u(()=>[...e[9]||(e[9]=[v("顺序生成中",-1)])]),_:1})):t(p)&&t(_)?(r(),g(x,{key:1,type:"warning"},{default:u(()=>[...e[10]||(e[10]=[v("等待当前请求完成",-1)])]),_:1})):t(j)==="stopped"?(r(),g(x,{key:2,type:"warning"},{default:u(()=>[...e[11]||(e[11]=[v("已停止",-1)])]),_:1})):(r(),g(x,{key:3,type:"success"},{default:u(()=>[...e[12]||(e[12]=[v("本轮完成",-1)])]),_:1}))]),c(re,{percentage:t(te),"stroke-width":10},null,8,["percentage"]),t(b)?(r(),h("div",Ne,[e[13]||(e[13]=l("span",null,"当前处方",-1)),l("strong",null,i(t(b).prescription_name||`处方 #${t(b).id}`),1),l("small",null,"#"+i(t(b).id)+" · "+i(t(b).formula_type||"未分类"),1)])):C("",!0),l("div",Ge,[l("div",Le,[e[14]||(e[14]=l("span",null,"已处理",-1)),l("strong",null,i(t(w)),1)]),l("div",Ve,[e[15]||(e[15]=l("span",null,"成功",-1)),l("strong",null,i(t(W)),1)]),l("div",qe,[e[16]||(e[16]=l("span",null,"部分成功",-1)),l("strong",null,i(t(q)),1)]),l("div",Pe,[e[17]||(e[17]=l("span",null,"失败",-1)),l("strong",null,i(t(G)),1)])]),t(_)&&t(p)?(r(),g(n,{key:1,class:"stop-alert",type:"warning",closable:!1,"show-icon":"",title:"已请求停止;当前处方生成完成后,不会继续发起下一条请求。"})):C("",!0)])):C("",!0),t($).length?(r(),h("section",De,[l("div",Fe,[e[18]||(e[18]=l("div",null,[l("span",{class:"section-kicker"},"失败清单"),l("strong",null,"失败与部分成功明细")],-1)),c(x,{type:"danger",effect:"plain"},{default:u(()=>[v(i(t($).length)+" 条",1)]),_:1})]),c(Z,{data:t($),"max-height":"240",size:"small"},{default:u(()=>[c(A,{label:"处方","min-width":"180"},{default:u(({row:m})=>[l("div",je,i(m.prescription_name),1),l("small",null,"#"+i(m.id),1)]),_:1}),c(A,{label:"结果",width:"100"},{default:u(({row:m})=>[c(x,{size:"small",type:m.status==="partial"?"warning":"danger"},{default:u(()=>[v(i(m.status==="partial"?"部分成功":"失败"),1)]),_:2},1032,["type"])]),_:1}),c(A,{label:"原因","min-width":"300","show-overflow-tooltip":"",prop:"message"})]),_:1},8,["data"])])):C("",!0),!t(f).length&&!t(p)?(r(),g(T,{key:4,description:t(y)>0?"当前范围已无待生成处方":"暂无完全缺失 AI 报告的处方","image-size":76},{default:u(()=>[l("p",We,i(t(y)>0?"已重新读取数据库中的最新待生成清单。":"所有可见处方均已有至少一份持久化报告。"),1)]),_:1},8,["description"])):t(p)?C("",!0):(r(),h("section",He,[l("div",Ke,[e[19]||(e[19]=l("div",null,[l("span",{class:"section-kicker"},"待生成清单"),l("strong",null,"本次将按以下顺序逐条处理")],-1)),l("span",Oe,i(t(f).length)+" 份",1)]),c(Z,{data:t(f),"max-height":"280",size:"small"},{default:u(()=>[c(A,{label:"ID",prop:"id",width:"80"}),c(A,{label:"处方名称",prop:"prescription_name","min-width":"220","show-overflow-tooltip":""}),c(A,{label:"类型",prop:"formula_type",width:"100"}),c(A,{label:"药材数",width:"100",align:"right"},{default:u(({row:m})=>[v(i(m.herb_count)+" 味",1)]),_:1})]),_:1},8,["data"])]))],64))])]),_:1},8,["modelValue"])}}}),lt=Me(Je,[["__scopeId","data-v-e1699253"]]);export{lt as default};