import{a1 as K,k as $,a2 as J,r as P,K as X,q,F as z,L as R,M as Y}from"./index.17037962789732.js";import"./index.170379627897333.js";import"./index.170379627897318.js";import"./index.170379627897319.js";import"./index.170379627897329.js";import"./index.170379627897315.js";import"./index.170379627897330.js";import"./default.1703796278973.js";import"./index.17037962789736.js";import{F as G}from"./system.1703796278973.js";import{L as H,T as Q,o as B}from"./comm.1703796278973.js";import{d as W}from"./utils.1703796278973.js";import{t as Z,d as ee}from"./instance.1703796278973.js";import{e as oe}from"./eventsource.1703796278973.js";import{d as E,v as te,k as f,r as se,o as x,x as U,b as s,a,z as y,u as o,t as u,c as F,A as j,B as ae}from"./vue.1703796278973.js";import{_ as le}from"./_plugin-vue_export-helper.1703796278973.js";import"./index.17037962789733.js";import"./dayjs.min.1703796278973.js";import"./isArray.1703796278973.js";import"./editor.api.1703796278973.js";import"./preload-helper.1703796278973.js";import"./monaco.contribution.1703796278973.js";import"./index.170379627897332.js";import"./index.170379627897334.js";import"./permission.1703796278973.js";import"./consts.1703796278973.js";import"./404.1703796278973.js";import"./moment.1703796278973.js";const ne={class:"file"},ce={class:"file-type-label"},ie={class:"file-download"},pe={key:0},re={style:{color:"red"}},ue=E({name:"DeviceImportFile"}),de=E({...ue,props:{product:{type:String,default:void 0}},setup(I){const g=I,l=te({product:g.product,upload:[],file:{fileType:"xlsx",autoDeploy:!1}}),k=f(!1),w=f(!1),b=f(0),m=f(""),v=f(!1),L=async t=>{const e=await Z(g.product,t);if(e){const n=new Blob([e],{type:t}),c=URL.createObjectURL(n);W(c,"设备导入模板",t)}},N=t=>{var i;const e=((i=l.file)==null?void 0:i.fileType)==="csv"?"csv":"xlsx",n=t.type==="text/csv",c=t.type==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";return!n&&e!=="xlsx"&&B("请上传.csv格式文件","warning"),!c&&e!=="csv"&&B("请上传.xlsx格式文件","warning"),n&&e!=="xlsx"||c&&e!=="csv"},A=async t=>{var e;if(t){b.value=0,m.value="";const n=!!((e=l==null?void 0:l.file)!=null&&e.autoDeploy)||!1;k.value=!0;let c=0;const i=new oe.EventSourcePolyfill(ee(g.product,t,n));i.onmessage=r=>{const d=JSON.parse(r.data);if(d.success){const _=d.result.total;c+=_,b.value=c}else m.value=d.message||"失败";v.value=!1},i.onerror=r=>{r.status===403&&(m.value="暂无权限，请联系管理员"),w.value=!1,v.value=!1,i.close()},i.onopen=()=>{}}else Y.error("请先上传文件")},O=async t=>{if(v.value=!0,console.log(t.file),t.file.status==="done"){const e=t.file.response||{result:""};await A((e==null?void 0:e.result)||"")}};return(t,e)=>{const n=K,c=$,i=J,r=P,d=se("AIcon"),_=X,S=q,M=z,C=R;return x(),U("div",ne,[s(M,{layout:"vertical"},{default:a(()=>[s(r,{label:"文件格式"},{default:a(()=>[y("div",ce,[s(c,{class:"file-type-radio",value:o(l).file.fileType,"onUpdate:value":e[0]||(e[0]=p=>o(l).file.fileType=p)},{default:a(()=>[s(n,{value:"xlsx"},{default:a(()=>[u("xlsx")]),_:1}),s(n,{value:"csv"},{default:a(()=>[u("csv")]),_:1})]),_:1},8,["value"]),s(i,{checked:o(l).file.autoDeploy,"onUpdate:checked":e[1]||(e[1]=p=>o(l).file.autoDeploy=p)},{default:a(()=>[u("自动启用")]),_:1},8,["checked"])])]),_:1}),s(r,{label:"文件上传"},{default:a(()=>{var p,T,h,D;return[s(S,{fileList:o(l).upload,"onUpdate:fileList":e[2]||(e[2]=V=>o(l).upload=V),name:"file",action:o(G),headers:{"X-Access-Token":o(H).get(o(Q))},maxCount:1,showUploadList:!1,onChange:O,accept:(T=(p=o(l))==null?void 0:p.file)!=null&&T.fileType?`.${(D=(h=o(l))==null?void 0:h.file)==null?void 0:D.fileType}`:".xlsx","before-upload":N,disabled:o(v)},{default:a(()=>[s(_,{style:{width:"760px"}},{icon:a(()=>[s(d,{type:"UploadOutlined"})]),default:a(()=>[u(" 上传文件 ")]),_:1})]),_:1},8,["fileList","action","headers","accept","disabled"])]}),_:1}),s(r,{label:"下载模板"},{default:a(()=>[y("div",ie,[s(_,{onClick:e[3]||(e[3]=p=>L("xlsx"))},{default:a(()=>[u(".xlsx")]),_:1}),s(_,{onClick:e[4]||(e[4]=p=>L("csv"))},{default:a(()=>[u(".csv")]),_:1})])]),_:1})]),_:1}),o(k)?(x(),U("div",pe,[o(w)?(x(),F(C,{key:0,status:"processing",text:"进行中"})):(x(),F(C,{key:1,status:"success",text:"已完成"})),y("span",null,"总数量："+j(o(b)),1),y("p",re,j(o(m)),1)])):ae("",!0)])}}});const $e=le(de,[["__scopeId","data-v-c7132bc1"]]);export{$e as default};
