import{_ as e,o as t,k as o,C as a,j as n,t as r}from"./index-BAMs4g2N.js";function s(e,t,o){let a,n,r=window,i="application/octet-stream",l=o||i,d=e,c=!t&&!o&&d,h=document.createElement("a"),u=function(e){return String(e)},p=r.Blob||r.MozBlob||r.WebKitBlob||u,f=t||"download";if(p=p.call?p.bind(r):Blob,"true"===String(this)&&(d=[d,l],l=d[0],d=d[1]),c&&c.length<2048&&(f=c.split("/").pop().split("?")[0],h.href=c,-1!==h.href.indexOf(c))){let e=new XMLHttpRequest;return e.open("GET",c,!0),e.responseType="blob",e.onload=function(e){s(e.target.response,f,i)},setTimeout((function(){e.send()}),0),e}if(/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(d)){if(!(d.length>2096103.424&&p!==u))return navigator.msSaveBlob?navigator.msSaveBlob(m(d),f):y(d);d=m(d),l=d.type||i}else if(/([\x80-\xff])/.test(d)){let e=0,t=new Uint8Array(d.length),o=t.length;for(;enull},exportFields:{type:Object,default:()=>null},defaultValue:{type:String,required:!1,default:""},header:{default:null},footer:{default:null},name:{type:String,default:"data.xls"},fetch:{type:Function},meta:{type:Array,default:()=>[]},worksheet:{type:String,default:"Sheet1"},beforeGenerate:{type:Function},beforeFinish:{type:Function},escapeCsv:{type:Boolean,default:!0},stringifyLongNum:{type:Boolean,default:!1}},computed:{idName:()=>"export_"+(new Date).getTime(),downloadFields(){return this.fields?this.fields:this.exportFields?this.exportFields:void 0}},methods:{async generate(){"function"==typeof this.beforeGenerate&&await this.beforeGenerate();let e=this.data;if("function"!=typeof this.fetch&&e||(e=await this.fetch()),!e||!e.length)return;let t=this.getProcessedJson(e,this.downloadFields);return"html"===this.type?this.export(this.jsonToXLS(t),this.name.replace(".xls",".html"),"text/html"):"csv"===this.type?this.export(this.jsonToCSV(t),this.name.replace(".xls",".csv"),"application/csv"):this.export(this.jsonToXLS(t),this.name,"application/vnd.ms-excel")},export:async function(e,t,o){let a=this.base64ToBlob(e,o);"function"==typeof this.beforeFinish&&await this.beforeFinish(),s(a,t,o)},jsonToXLS(e){let t="";const o=Object.keys(e[0]).length;let a=this;const n=this.header||this.$attrs.title;n&&(t+=this.parseExtraData(n,'${data}')),t+="";for(let r in e[0])t+=""+r+"";return t+="",t+="",t+="",e.map((function(e,o){t+="";for(let n in e)t+=""+a.preprocessLongNum(a.valueReformattedForMultilines(e[n]))+"";t+=""})),t+="",null!=this.footer&&(t+="",t+=this.parseExtraData(this.footer,'${data}'),t+=""),' \x3c!--[if gte mso 9]>${worksheet}br {mso-data-placement: same-cell;}${table}
'.replace("${table}",t).replace("${worksheet}",this.worksheet)},jsonToCSV(e){let t=this,o=[];const a=this.header||this.$attrs.title;a&&o.push(this.parseExtraData(a,"${data}\r\n"));for(let n in e[0])o.push(n),o.push(",");return o.pop(),o.push("\r\n"),e.map((function(e){for(let a in e){let n=e[a]+"";t.escapeCsv&&(n='="'+n+'"',n.match(/[,"\n]/)&&(n='"'+n.replace(/\"/g,'""')+'"')),o.push(n),o.push(",")}o.pop(),o.push("\r\n")})),null!=this.footer&&o.push(this.parseExtraData(this.footer,"${data}\r\n")),o.join("")},getProcessedJson(e,t){let o=this.getKeys(e,t),a=[],n=this;return e.map((function(e,t){let r={};for(let a in o){let t=o[a];r[a]=n.getValue(t,e)}a.push(r)})),a},getKeys(e,t){if(t)return t;let o={};for(let a in e[0])o[a]=a;return o},parseExtraData(e,t){let o="";if(Array.isArray(e))for(let a=0;a1?this.getValueFromNestedItem(t,a):this.parseValue(t[o]):t,e.hasOwnProperty("callback")&&(n=this.getValueFromCallback(n,e.callback)),n},valueReformattedForMultilines:e=>"string"==typeof e?e.replace(/\n/gi,"
"):e,preprocessLongNum(e){if(this.stringifyLongNum){if(String(e).startsWith("0x"))return e;if(!isNaN(e)&&""!=e&&(e>99999999999||e<1e-13))return'="'+e+'"'}return e},getValueFromNestedItem(e,t){let o=e;for(let a of t)o&&(o=o[a]);return this.parseValue(o)},getValueFromCallback(e,t){if("function"!=typeof t)return this.defaultValue;const o=t(e);return this.parseValue(o)},parseValue(e){return e||0===e||"boolean"==typeof e?e:this.defaultValue},base64ToBlob(e,t){let o=window.btoa(window.unescape(encodeURIComponent(e))),a=atob(o),n=a.length,r=new Uint8ClampedArray(n);for(;n--;)r[n]=a.charCodeAt(n);return new Blob([r],{type:t})}}},[["render",function(e,s,i,l,d,c){return t(),o("div",{id:c.idName,onClick:s[0]||(s[0]=(...e)=>c.generate&&c.generate(...e))},[a(e.$slots,"default",{},(()=>[n(" Download "+r(i.name),1)]))],8,["id"])}]]);export{i as _};