import{K as $,av as x,aw as A,aG as C,W as J}from"./index.17037962789732.js";import"./index.170379627897337.js";import"./index.170379627897315.js";import"./index.170379627897314.js";import"./index.170379627897319.js";import"./index.170379627897327.js";import{B as L,L as N,T}from"./comm.1703796278973.js";import{a as D}from"./dayjs.min.1703796278973.js";import{e as M}from"./eventsource.1703796278973.js";import{d as R,k as _,m as Y,o as w,c as k,a as d,b as i,z as B,A as f,u as n,t as g,B as E,x as I}from"./vue.1703796278973.js";const P={key:0},Q=R({__name:"Result",props:{data:{type:Object,default:()=>{}},list:{type:Array,default:()=>[]}},emits:["close"],setup(b,{emit:h}){const s=b,v=_(0),y=_(0),j=_(!0),p=_([]),O=()=>{var m;let o=0,a=0;const l=[],t={deviceId:(s.list||[]).map(e=>e==null?void 0:e.id),params:JSON.stringify({name:s.data.name,targetId:s.data.targetId,targetType:s.data.targetType,category:s.data.category,metadata:(m=s.data)==null?void 0:m.metadata})},r=new URLSearchParams;Object.keys(t).forEach(e=>{Array.isArray(t[e])&&t[e].length?t[e].map(u=>{r.append(e,u)}):r.append(e,t[e])});const c=new M.EventSourcePolyfill(`${L}/edge/operations/entity-template-save/invoke/_batch?:X_Access_Token=${N.get(T)}&${r}`);c.onmessage=e=>{const u=JSON.parse(e.data);u.successful?(o+=1,v.value=o):(a+=1,y.value=a,j.value=!1,l.length<5&&(l.push({...u}),p.value=[...l]))},c.onerror=()=>{c.close()},c.onopen=()=>{}},S=(o,a,l)=>{const t=document.createElement("a");t.download=`${a?"":o==null?void 0:o.name}${a}_${D(new Date).format(l||"YYYY_MM_DD")}.txt`,t.style.display="none";const r=new Blob([JSON.stringify(o)]);t.href=URL.createObjectURL(r),document.body.appendChild(t),t.click(),document.body.removeChild(t)};return Y(()=>s.data.id,o=>{o&&O()},{immediate:!0}),(o,a)=>{const l=$,t=x,r=A,c=C,m=J;return w(),k(m,{visible:"",title:"下发结果",width:900,onOk:a[1]||(a[1]=e=>h("close")),onCancel:a[2]||(a[2]=e=>h("close"))},{default:d(()=>[i(r,null,{default:d(()=>[i(t,{span:8},{default:d(()=>[B("div",null,"成功："+f(n(v)),1),B("div",null,[g(" 失败："+f(n(y))+" ",1),n(p).length?(w(),k(l,{key:0,onClick:a[0]||(a[0]=e=>S(n(p)||"","下发失败原因")),type:"link"},{default:d(()=>[g("下载")]),_:1})):E("",!0)])]),_:1}),i(t,{span:8},{default:d(()=>[g("下发设备数量："+f(b.list.length||0),1)]),_:1}),i(t,{span:8},{default:d(()=>[g("已下发数量："+f(n(y)+n(v)),1)]),_:1})]),_:1}),n(j)?E("",!0):(w(),I("div",P,[i(c,{rows:10,value:JSON.stringify(n(p))},null,8,["value"])]))]),_:1})}}});export{Q as _};
