import{K as A,q as E,a0 as F,M as N,L as S,a1 as I,k as M,a2 as $,a3 as J}from"./index.17037962789732.js";import"./index.170379627897333.js";import"./index.170379627897336.js";import"./index.170379627897329.js";import"./index.170379627897315.js";import"./index.170379627897330.js";import{F as K}from"./system.1703796278973.js";import{L as P,T as R,o as C}from"./comm.1703796278973.js";import{d as X}from"./utils.1703796278973.js";import{t as q,d as z}from"./instance.1703796278973.js";import{e as Y}from"./eventsource.1703796278973.js";import{d as B,k as V,r as G,o as v,x as D,b as n,a,u as r,t as g,z as y,c as T,A as h,B as H,F as Q}from"./vue.1703796278973.js";import"./default.1703796278973.js";import"./index.17037962789736.js";const W={style:{"margin-left":"20px"}},Z={key:0,style:{"margin-top":"20px"}},ee={style:{color:"red"}},_e=B({__name:"index",props:{modelValue:{type:Array,default:()=>[]},product:{type:String,default:""},file:{type:Object,default:()=>({fileType:"xlsx",autoDeploy:!1})},url:{type:Object,default:()=>({fileType:"xlsx",autoDeploy:!1})}},emits:["update:modelValue"],setup(c,{emit:U}){const t=c,i=V(!1),d=V(!1),_=V(0),p=V(""),b=async o=>{const e=await q(t.product,o);if(e){const u=new Blob([e],{type:o}),s=URL.createObjectURL(u);X(s,"设备导入模板",o)}},x=o=>{var l;const e=((l=t==null?void 0:t.file)==null?void 0:l.fileType)==="csv"?"csv":"xlsx",u=o.type==="text/csv",s=o.type==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";return!u&&e!=="xlsx"&&C("请上传.csv格式文件","warning"),!s&&e!=="csv"&&C("请上传.xlsx格式文件","warning"),u&&e!=="xlsx"||s&&e!=="csv"},j=async o=>{var e;if(o){_.value=0,p.value="",d.value=!0;const u=!!((e=t==null?void 0:t.file)!=null&&e.autoDeploy)||!1;i.value=!0;let s=0;const l=new Y.EventSourcePolyfill(z(t.product,o,u));l.onmessage=m=>{const f=JSON.parse(m.data);if(f.success){const k=f.result.total;s+=k,_.value=s}else p.value=f.message||"失败"},l.onerror=m=>{m.status===403&&(p.value="暂无权限，请联系管理员"),d.value=!1,l.close()},l.onopen=()=>{}}else N.error("请先上传文件")},O=async o=>{if(o.file.status==="done"){const e=o.file.response||{result:""};await j((e==null?void 0:e.result)||"")}};return(o,e)=>{const u=G("AIcon"),s=A,l=E,m=F,f=S;return v(),D(Q,null,[n(m,{align:"end"},{default:a(()=>{var k,w;return[n(l,{fileList:c.modelValue.upload,"onUpdate:fileList":e[0]||(e[0]=L=>c.modelValue.upload=L),name:"file",action:r(K),headers:{"X-Access-Token":r(P).get(r(R))},maxCount:1,showUploadList:!1,onChange:O,accept:(k=t==null?void 0:t.file)!=null&&k.fileType?`.${(w=t==null?void 0:t.file)==null?void 0:w.fileType}`:".xlsx","before-upload":x},{default:a(()=>[n(s,null,{icon:a(()=>[n(u,{type:"UploadOutlined"})]),default:a(()=>[g(" 文件上传 ")]),_:1})]),_:1},8,["fileList","action","headers","accept"]),y("div",W,[n(m,null,{default:a(()=>[g(" 下载模板 "),y("a",{onClick:e[1]||(e[1]=L=>b("xlsx"))},".xlsx"),y("a",{onClick:e[2]||(e[2]=L=>b("csv"))},".csv")]),_:1})])]}),_:1}),r(i)?(v(),D("div",Z,[r(d)?(v(),T(f,{key:0,status:"processing",text:"进行中"})):(v(),T(f,{key:1,status:"success",text:"已完成"})),y("span",null,"总数量："+h(r(_)),1),y("p",ee,h(r(p)),1)])):H("",!0)],64)}}});const xe=B({__name:"index",props:{modelValue:{type:Object,default:()=>({fileType:"xlsx",autoDeploy:!1})}},emits:["update:modelValue"],setup(c,{emit:U}){return(t,i)=>{const d=I,_=M,p=$,b=J;return v(),T(b,{align:"end"},{default:a(()=>[n(_,{"button-style":"solid",value:c.modelValue.fileType,"onUpdate:value":i[0]||(i[0]=x=>c.modelValue.fileType=x),placeholder:"请选择文件格式"},{default:a(()=>[n(d,{value:"xlsx"},{default:a(()=>[g("xlsx")]),_:1}),n(d,{value:"csv"},{default:a(()=>[g("csv")]),_:1})]),_:1},8,["value"]),n(p,{checked:c.modelValue.autoDeploy,"onUpdate:checked":i[1]||(i[1]=x=>c.modelValue.autoDeploy=x)},{default:a(()=>[g("自动启用")]),_:1},8,["checked"])]),_:1})}}});export{_e as _,xe as a};
