import{k as q,E as i,h as L,t as k,z as C,y as N}from"./index.Df8UJ10K.js";import{createCrudOptions as O}from"./crud.PUXZoE7q.js";import{a as x,r as h,q as P,aj as c,J,o as M,K as l,S as n,H as $,u as j,P as d}from"./vue.D1BjjNmv.js";import{_ as E}from"./_plugin-vue_export-helper.DlAUqK2U.js";import"./api.CWkru0hL.js";import"./authFunction.Cmg2kwFe.js";const H=x({name:"device"}),K=x({...H,setup(U,{expose:R}){const{crudBinding:A,crudRef:D,crudExpose:s,crudOptions:W,resetCrudOptions:G}=q({createCrudOptions:O}),f=h(!1),u=h(!1),m=h([]),g=h(!1);R({importLoading:u,exportAllLoading:g});const F=()=>{f.value=!0},B=a=>{m.value=[a.raw]},I=async()=>{if(u.value)return;if(m.value.length===0){i.warning("请先选择文件");return}const a=m.value[0];if(!a){i.error("文件无效，请重新选择");return}const e=new FormData;e.append("file",a);const o=L.get("token");try{u.value=!0;const r=await k({url:"/api/system/device/batch_import/",method:"post",data:e,headers:{"Content-Type":"multipart/form-data",Authorization:o?`JWT ${o}`:""}});console.log("导入resssss:::",r),i.success(r.msg),f.value=!1,m.value=[],s.doRefresh()}catch(r){i.error("导入失败，请检查文件格式或内容"),console.error(r)}finally{u.value=!1}},V=async()=>{var e;const a=((e=s.selectedIds)==null?void 0:e.value)||[];if(console.log("selectedRows::",a),a.length===0){i.warning("请先选择要导出的设备");return}C({url:"/api/system/device/export_selected/",method:"post",data:{device_ids:a},filename:"设备导出"})},S=async()=>{var a,e,o;g.value=!0;try{const r=s!=null&&s.getSearchFormData?s.getSearchFormData():{},y=((o=(e=(a=s==null?void 0:s.crudBinding)==null?void 0:a.value)==null?void 0:e.pagination)==null?void 0:o.pageSize)||50;let v=1;const p=[];for(;;){const t=await k({url:"/api/system/device/",method:"get",params:{...r,page:v,limit:y},timeout:0}),_=Array.isArray(t==null?void 0:t.data)?t.data:Array.isArray(t==null?void 0:t.results)?t.results:[];if(!Array.isArray(_)||_.length===0)break;for(const w of _)(w==null?void 0:w.id)!=null&&p.push(w.id);const b=(t==null?void 0:t.total)??(t==null?void 0:t.count)??void 0;if(b!==void 0&&p.length>=Number(b)||_.length<y)break;v+=1}if(p.length===0){i.warning("当前筛选结果为空，无法导出");return}await C({url:"/api/system/device/export_selected/",method:"post",data:{device_ids:p},filename:"设备导出",timeout:0})}finally{g.value=!1}},z=async()=>{N({url:"/api/system/device/download_template/",method:"get",filename:"设备模板"})},T=async()=>{var e;const a=((e=s.selectedIds)==null?void 0:e.value)||[];if(console.log("selectedRows::",a),a.length===0){i.warning("请先选择要删除的设备");return}await k({url:"/api/system/device/multiple_delete/",method:"delete",data:{keys:a}}).then(o=>{i.success("删除成功"),s.doRefresh()})};return P(async()=>{s.doRefresh()}),(a,e)=>{const o=c("el-button"),r=c("fs-crud"),y=c("el-upload"),v=c("el-dialog"),p=c("fs-page");return M(),J(p,null,{default:l(()=>[n(r,$({ref_key:"crudRef",ref:D},j(A)),{"actionbar-right":l(()=>[n(o,{type:"primary",onClick:F,class:"batch-imports"},{default:l(()=>e[2]||(e[2]=[d("批量导入")])),_:1}),n(o,{type:"primary",onClick:S,loading:g.value},{default:l(()=>e[3]||(e[3]=[d("全部导出")])),_:1},8,["loading"]),n(o,{type:"primary",onClick:V},{default:l(()=>e[4]||(e[4]=[d("批量导出")])),_:1}),n(o,{type:"primary",onClick:z},{default:l(()=>e[5]||(e[5]=[d("下载模板")])),_:1}),n(o,{type:"danger",onClick:T},{default:l(()=>e[6]||(e[6]=[d("批量删除")])),_:1})]),_:1},16),n(v,{modelValue:f.value,"onUpdate:modelValue":e[1]||(e[1]=t=>f.value=t),title:"批量导入设备",width:"30%"},{footer:l(()=>[n(o,{onClick:e[0]||(e[0]=t=>f.value=!1)},{default:l(()=>e[8]||(e[8]=[d("取消")])),_:1}),n(o,{type:"primary",loading:u.value,disabled:u.value,onClick:I},{default:l(()=>e[9]||(e[9]=[d("确认导入")])),_:1},8,["loading","disabled"])]),default:l(()=>[n(y,{ref:"uploadRef","auto-upload":!1,"file-list":m.value,limit:1,"on-change":B,"before-upload":()=>!1,accept:".xls,.xlsx"},{default:l(()=>[n(o,{type:"primary"},{default:l(()=>e[7]||(e[7]=[d("选择文件")])),_:1})]),_:1},8,["file-list"])]),_:1},8,["modelValue"])]),_:1})}}}),ae=E(K,[["__scopeId","data-v-6bfa85ea"]]);export{ae as default};
