5 lines
2.5 KiB
Java
5 lines
2.5 KiB
Java
var g=(f,x,r)=>new Promise((e,i)=>{var t=s=>{try{n(r.next(s))}catch(o){i(o)}},l=s=>{try{n(r.throw(s))}catch(o){i(o)}},n=s=>s.done?e(s.value):Promise.resolve(s.value).then(t,l);n((r=r.apply(f,x)).next())});import{u as b,q as h,f as w}from"./index-BI6CMai0.js";import"./vue-vendor-C7Zq48Yl.js";import"./antd-vue-vendor-BPnV8VqP.js";import"./vxe-table-vendor-B88kchpX.js";const{createMessage:p,createWarningModal:m}=b(),v=h(),X="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",S=".xlsx";function O(){function f(e,i,t,l=!1,n=6e4){return g(this,null,function*(){if(t!=null&&t.selections){let d=t.selections.split(",");if(d&&d.length>100){p.warning("最多可选择 100 项进行导出!");return}}const s=yield w.get({url:i,params:t,responseType:"blob",timeout:n},{isTransformResponse:!1,isReturnNativeResponse:!0});if(!s||!s.data){p.warning("文件下载失败");return}let o=l;const u=s.headers&&s.headers["content-disposition"];u&&u.indexOf(".xlsx")!==-1&&(o=!0);const c=s.data;let a=new FileReader;a.readAsText(c,"utf-8"),a.onload=()=>g(null,null,function*(){if(a.result&&a.result.toString().indexOf("success")!=-1)try{const{success:d,message:y}=JSON.parse(a.result.toString());d?r(e,o,c):p.warning("导出失败,失败原因:"+y);return}catch(d){r(e,o,c)}r(e,o,c)})})}function x(e,i,t){return g(this,null,function*(){const l=n=>{try{if(n.code===201){let{message:s,result:{msg:o,fileUrl:u,fileName:c}}=n,a=v.uploadUrl+u;m({title:s,centered:!1,content:`<div>
|
|
<span>${o}</span><br/>
|
|
<span>具体详情请<a href = ${a} download = ${c}> 点击下载 </a> </span>
|
|
</div>`})}else n.code===500||n.code===510?p.error(n.message||`${e.file.name} 导入失败`):p.success(n.message||`${e.file.name} 文件上传成功`)}catch(s){}finally{typeof t=="function"&&t(n)}};yield w.uploadFile({url:i},{file:e.file},{success:l})})}return{handleExportXls:(e,i,t,l)=>f(e,i,t,!1,l),handleImportXls:(e,i,t)=>x(e,i,t),handleExportXlsx:(e,i,t,l)=>f(e,i,t,!0,l)};function r(e,i,t){(!e||typeof e!="string")&&(e="导出文件");let l={type:"application/vnd.ms-excel"},n=".xls";if(i&&(l.type=X,n=S),typeof window.navigator.msSaveBlob!="undefined")window.navigator.msSaveBlob(new Blob([t],l),e+n);else{let s=window.URL.createObjectURL(new Blob([t],l)),o=document.createElement("a");o.style.display="none",o.href=s,o.setAttribute("download",e+n),document.body.appendChild(o),o.click(),document.body.removeChild(o),window.URL.revokeObjectURL(s)}}}export{S as XLSX_FILE_SUFFIX,X as XLSX_MIME_TYPE,O as useMethods};
|