"use strict";var e=require("exceljs"),t=require("file-saver");function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var t=1;t=0;--o){var l=this.tryEntries[o],i=l.completion;if("root"===l.tryLoc)return a("end");if(l.tryLoc<=this.prev){var c=n.call(l,"catchLoc"),s=n.call(l,"finallyLoc");if(c&&s){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),L(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;L(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:_(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}function o(e,t,r,n,a,o,l){try{var i=e[o](l),c=i.value}catch(e){return void r(e)}i.done?t(c):Promise.resolve(c).then(n,a)}function l(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var l=e.apply(t,r);function i(e){o(l,n,a,i,c,"next",e)}function c(e){o(l,n,a,i,c,"throw",e)}i(void 0)}))}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var r=0;r=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=f(e);if(t){var a=f(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return p(e)}(this,r)}}function y(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var g=function(){},x=function(e){return"Object"===Object.prototype.toString.call(e).slice(8,-1)},w=function(e){return"function"==typeof e},C=function(e){return"number"==typeof e},b=function(e){return JSON.stringify(e)===JSON.stringify({})},k=function(e){return Array.isArray(e)},I=function(e){return console.warn(e)},S=function(e){return![null,void 0,NaN].includes(e)};var D=function(e,t){return Array.from({length:e},(function(e,r){return t(r,e)}))},O=function e(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"children",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,a=[],o=0;o0;l.$level=n,a.push(l),c&&(delete l[r],a=a.concat(e(i,r,n+1)))}return a},E=function(e,t){return Object.hasOwnProperty.call(e,t)},F=function(e,t){var r="",n=e;k(t)?r=t:r="string"==typeof t&&null!==t.match(/\./)?t.split("."):[t];for(var a=0;a1&&void 0!==arguments[1]?arguments[1]:g,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:g,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=n.field?n.field:"children";(function e(n){for(var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=0;i0;c.$level=l,c.$parent=o,c.$sort=i,c.$leafNode=!u,t(c),u&&(c[a]=e(s,c,l+1),r(c))}return n})(e)}(r,(function(t){var r=t.$level,n=t.$leafNode,o=r-1,l=a?{col:o,row:1===r?c:null}:{row:o,col:1===r?c:null};n&&(l[a?"rowspan":"colspan"]=1,u++,e.leafNodes.push(t));1===r&&n&&c++,t._cell=l,t._leafNodeNum=1,i.push(t),s=Math.max(s,r)}),(function(e){var t=e[o],r=e.$level,l=t.reduce((function(e,t){return e+t._leafNodeNum}),0),i=a?{rowspan:l}:{colspan:l};e._leafNodeNum=l,e._cell=n(n({},e._cell),i),1===r&&(c+=l)}),{field:o});var h=[];this.callhook(this,"beforeMapCreateData");for(var f=0;f0,m=d.$level,y=d.$sort,x=d.$parent,w=d._cell,C=p?1:s-m+1;if(w[a?"colspan":"rowspan"]=C,1!==m){var b=a?"row":"col",k=void 0;k=a?0===y?x._cell.row:x[o][y-1]._cell.row+x[o][y-1]._cell.rowspan:0===y?x._cell.col:x[o][y-1]._cell.col+x[o][y-1]._cell.colspan,w[b]=k}this.mapCreateData(d),w.isNeedMerge=1!==w.rowspan||1!==w.colspan,h.push(w)}this.callhook(this,"mapCreateDataed"),this.mergeCells=h,this.totalLen=u,this.maxDepth=s}}]),e}(),_=function(e){h(r,j);var t=m(r);function r(e){var n;i(this,r);var a=e.data,o=void 0===a?[]:a,l=e.hooks,c=void 0===l?{}:l,s=e.field,u=void 0===s?"children":s,h=e.startCol,f={data:o,hooks:c,field:u,startCol:void 0===h?0:h,mapCreateColumn:e.mapCreateColumn,mapCreateData:e.mapCreateData,merge:!0,reverse:!1,combin:!1};return(n=t.call(this,f)).callhook(p(n),"beforeMapCreateColumn"),n.mapCreateColumn(),n.callhook(p(n),"mapCreateColumned"),n}return s(r,[{key:"mapCreateColumn",value:function(){var e=this.totalLen,t=this.options;if(t.mapCreateColumn){var r=t.mapCreateColumn({columnLen:e});this.handleExcelColumn(r),this.columns=r}}},{key:"handleExcelText",value:function(e,t){if(x(t)){var r=t.text,n=t.format;e.text=S(r)?r:"",b(n)||(e.format=n),k(r)&&(e.isImage=!0,e.image=t.image)}}},{key:"handleExcelColumn",value:function(e){var t=e[0];x(t)&&t.excel&&x(t.excel)&&(this.excel.columnStyle=e.map((function(e){return e.excel})))}},{key:"handleExcelRow",value:function(e){if(x(e)&&!b(e)){for(var t=n({},e),r=["text","style","format","image"],a=r.length,o=0;o1&&void 0!==arguments[1]?arguments[1]:{}).style;x(r)&&(t=r),e.style=t}},{key:"mapCreateData",value:function(e){var t=this.options;if(t.mapCreateData){var r=e._cell,a=r.row,o=r.col,l=t.mapCreateData({data:e,rowIndex:a,columnIndex:o})||{key:"",value:"",excel:{}},i=l.key,c=l.value,s=l.excel;this.data[a]?this.data[a]=n(n({},this.data[a]),{},u({},i,c)):(this.data[a]=u({},i,c),this.handleExcelRow(s)),this.handleExcelText(r,s),this.handleExcelCell(r,s)}}}]),r}(),P=function(e){h(r,j);var t=m(r);function r(e){var n;i(this,r);var a=e.startCol,o=void 0===a?0:a,l=e.data,c=void 0===l?{rowList:[],columnList:[]}:l,s=e.field,u={startCol:o,data:c,field:void 0===s?"children":s,mapCreateColumn:e.mapCreateColumn,mapCreateData:e.mapCreateData,merge:!1,reverse:!1,combin:!1};return(n=t.call(this,u)).calculate(),n}return s(r,[{key:"calculate",value:function(){for(var e=this.options,t=e.startCol,r=e.data,n=r.rowList,a=r.columnList,o=[],l=0;l1&&void 0!==arguments[1]?arguments[1]:{}).style;x(r)&&(t=r),e.style=t}},{key:"mapCreateData",value:function(e){var t=e.row,r=e.rowIndex,a=e.column,o=e.columnIndex,l=e.cell,i=this.options;if(i.mapCreateData){var c=i.mapCreateData({row:t,rowIndex:r,column:a,columnIndex:o})||{key:"",value:"",excel:{}},s=c.key,h=c.value,f=c.excel;this.data[r]?this.data[r]=n(n({},this.data[r]),{},u({},s,h)):(this.data[r]=u({},s,h),this.handleExcelRow(f)),this.handleExcelText(l,f),this.handleExcelCell(l,f)}}},{key:"mapCreateColumn",value:function(){var e=this.options.data.columnList,t=this.options;if(t.mapCreateColumn){var r=t.mapCreateColumn({columnLen:e.length});this.handleExcelColumn(r),this.columns=r}}}]),r}(),N=function(e){h(r,j);var t=m(r);function r(e){var n;i(this,r);var a=e.startCol,o=void 0===a?0:a,l=e.data,c=void 0===l?{rowList:[],columnList:[]}:l,s=e.field,u={startCol:o,data:c,field:void 0===s?"children":s,mapCreateColumn:e.mapCreateColumn,mapCreateData:e.mapCreateData,spanMethod:e.spanMethod,merge:!1,reverse:!1,combin:!0};return(n=t.call(this,u)).calculate(),n}return s(r,[{key:"calculate",value:function(){for(var e=this.options,t=e.startCol,r=e.spanMethod,n=e.data,a=n.rowList,o=n.columnList,l=[],i=w(r),c=0;c0&&p>0){for(var m=d.rowspan,y=d.colspan,g=1;g<=m;g++){var C=c+g-1,b=a[C];if(x(b)){b["_dirty".concat(C).concat(u)]=!0;for(var k=1;k<=y;k++){var I=u+k-1;b["_dirty".concat(C).concat(I)]||(b["_dirty".concat(C).concat(I)]=!0)}}}delete s["_dirty".concat(c).concat(u)]}else{for(var S=1;S<=p;S++)s["_dirty".concat(c).concat(u+S)]=!0;for(var D=1;D<=v;D++){var O=a[c+D];x(O)&&(O["_dirty".concat(c+D).concat(u)]=!0)}}this.mapCreateData({row:s,rowIndex:c,column:f,columnIndex:t+u,cell:d}),d.isNeedMerge=1!==d.rowspan||1!==d.colspan,l.push(d)}}this.mergeCells=l,this.mapCreateColumn()}},{key:"handleExcelText",value:function(e,t){if(x(t)){var r=t.text,n=t.format;e.text=S(r)?r:"",b(n)||(e.format=n),k(r)&&(e.isImage=!0,e.image=t.image)}}},{key:"handleExcelColumn",value:function(e){var t=e[0];x(t)&&t.excel&&x(t.excel)&&(this.excel.columnStyle=e.map((function(e){return e.excel})))}},{key:"handleExcelRow",value:function(e){if(x(e)&&!b(e)){for(var t=n({},e),r=["text","style","format","image"],a=r.length,o=0;o1&&void 0!==arguments[1]?arguments[1]:{}).style;x(r)&&(t=r),e.style=t}},{key:"mapCreateData",value:function(e){var t=e.row,r=e.rowIndex,a=e.column,o=e.columnIndex,l=e.cell,i=this.options;if(i.mapCreateData){var c=i.mapCreateData({row:t,rowIndex:r,column:a,columnIndex:o})||{key:"",value:"",excel:{}},s=c.key,h=c.value,f=c.excel;this.data[r]?this.data[r]=n(n({},this.data[r]),{},u({},s,h)):(this.data[r]=u({},s,h),this.handleExcelRow(f)),this.handleExcelText(l,f),this.handleExcelCell(l,f)}}},{key:"mapCreateColumn",value:function(){var e=this.options.data.columnList,t=this.options;if(t.mapCreateColumn){var r=t.mapCreateColumn({columnLen:e.length});this.handleExcelColumn(r),this.columns=r}}}]),r}();function T(e,t,r,n){if(!n)return console.warn("缺少必要的数据");var a=new(0,{"true-true-false":_,"false-false-false":P,"false-false-true":N}["".concat(e,"-").concat(t,"-").concat(r)])(n);return a.callhook(a,"mounted"),a.getTableData()}var M={alignment:{vertical:"middle",horizontal:"center",wrapText:!0},fill:{type:"pattern",pattern:"solid",fgColor:{argb:"FFF4F5FA"}},border:{top:{style:"thin",color:{argb:"FFD4D4D4"}},left:{style:"thin",color:{argb:"FFD4D4D4"}},bottom:{style:"thin",color:{argb:"FFD4D4D4"}},right:{style:"thin",color:{argb:"FFD4D4D4"}}}},R={width:20},H={height:20,font:{bold:!0}},A={header:M,main:{alignment:{vertical:"middle",horizontal:"center",wrapText:!0},fill:{type:"pattern",pattern:"solid",fgColor:{argb:"FFFFFFFF"}},border:{top:{style:"thin",color:{argb:"FFD4D4D4"}},left:{style:"thin",color:{argb:"FFD4D4D4"}},bottom:{style:"thin",color:{argb:"FFD4D4D4"}},right:{style:"thin",color:{argb:"FFD4D4D4"}}}},"insert-header":{alignment:{vertical:"middle",horizontal:"left",wrapText:!0},border:{top:{style:"thin",color:{argb:"FFD4D4D4"}},left:{style:"thin",color:{argb:"FFD4D4D4"}},bottom:{style:"thin",color:{argb:"FFD4D4D4"}},right:{style:"thin",color:{argb:"FFD4D4D4"}}},font:{bold:!0,color:{argb:"FFFF0000"}}},footer:M},$={header:"headerData",main:"mainData",footer:"footerData","insert-header":"insertHeaderData"},G=function(){function r(e){i(this,r),this.options=e}var o,c,u,h,f,d,v,p,m;return s(r,[{key:"validate",value:function(e){return new Promise((function(t,r){return x(e)?!k(e.tables)||e.tables.length<=0?r("格式错误"):void t(e):r("格式错误")}))}},{key:"init",value:function(){var e=this.options;this.validate(e).then(this.initExcel.bind(this)).catch((function(e){return I(e)}))}},{key:"initExcel",value:function(t){this.workbook=new e.Workbook,this.workSheets=[],this.processCallback=t.progress||g,this.percentage=0,this.preTotalOffset=0,this.keepAlive=t.keepAlive||!0,this.totalOffset=1,this.generateSheets(t),this.setProgress(10)}},{key:"generateSheets",value:function(e){for(var t=e.tables,r=this.workbook,n=t.length,a=0;a0;)n.push(String.fromCharCode((a-1)%26+"A".charCodeAt())),a=~~((a-1)/26);return n.reverse().join("")+r}},{key:"export",value:(m=l(a().mark((function e(){var t,r;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.setProgress(11),t=this.workSheets,r=this.options.tables,e.next=5,this.handleSheet(r,t);case 5:this.setProgress(70);case 6:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"handleSheet",value:(p=l(a().mark((function e(t,r){var n,o,l,i,c;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=t.length,o=0;case 2:if(!(o=200&&n.status<=299){var e=n.response,a=new FileReader;a.readAsDataURL(e),a.onloadend=function(e){var r=e.target.result;t(r)},a.onerror=r}},n.responseType="blob",n.open("get",e),n.send()}))}},{key:"addImage",value:function(e,t,r,n,a){for(var o,l=n.length,i=r.row,c=r.col,s=r.image,u=void 0===s?{}:s,h=u.width,f=void 0===h?100:h,d=u.height,v=void 0===d?100:d,p=0;p0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};i(this,e),this.tables=[],this.progress=r.progress,this.indentSize=r.indentSize||1,this.calculate(t)}var t;return s(e,[{key:"calculate",value:function(e){for(var t=(e=x(e)?[e]:e).length,r=0;r1&&(i.rowspan=a+s-1>l.length-1?l.length-a:s),C(u)&&u>1&&(i.colspan=o+u-1>t.length-1?t.length-o:u),i},field:c},T(!1,!1,!0,r)),x=g.mergeCells,b=g.data;m={cells:x,rowStyle:g.excel.rowStyle,rowLength:b.length}}else{var k=function(e){return T(!1,!1,!1,e)}({data:{rowList:u?O(l,c):l,columnList:t},mapCreateColumn:function(e){var t=e.columnLen;return D(t,(function(e){return{field:"".concat(e,"-field")}}))},mapCreateData:function(e){var t=e.row,r=e.column,o=e.rowIndex,l=e.columnIndex,i="".concat(l,"-field"),c=F(t,r),s=a.setRowStyle(p.setRowStyle,{data:t,columnIndex:l,rowIndex:o,type:"main"},!1),h=a.setCellStyle(p.setCellStyle,{data:t,columnIndex:l,rowIndex:o,type:"main"}),d=a.setImageStyle(p.setImageStyle,{data:t,columnIndex:l,rowIndex:o,type:"main"}),v=a.setCellFormat(p.setCellFormat,{data:t,columnIndex:l,rowIndex:o,type:"main"}),m=a.transformExcel(p.transformExcel,{data:t,columnIndex:l,rowIndex:o,type:"main"});return u&&f===r&&a.setTreeIndentStyle(t,h,y),{key:i,value:c,excel:n(n(n(n(n({text:c},s),h),v),d),m)}},field:c}),I=k.mergeCells,S=k.data;m={cells:I,rowStyle:k.excel.rowStyle,rowLength:S.length}}return m}},{key:"handleExcelSheet",value:function(e,t){return this.setSheetStyle(e,{sheetIndex:t})}},{key:"setColumnStyle",value:function(e,t){var r=R;if(w(e)){var n=e({columnIndex:t});x(n)&&(r=n)}return r}},{key:"setRowStyle",value:function(e,t){var r=t.data,n=t.columnIndex,a=t.rowIndex,o=t.type,l=arguments.length>2&&void 0!==arguments[2]&&arguments[2]?H:{};if(w(e)){var i=e({data:r,columnIndex:n,rowIndex:a,type:o});x(i)&&(l=i)}return l}},{key:"setCellStyle",value:function(e,t){var r=t.data,n=t.columnIndex,a=t.rowIndex,o=t.type,l={style:{}};if(w(e)){var i=e({data:r,columnIndex:n,rowIndex:a,type:o});x(i)&&(l.style=i)}return l}},{key:"transformExcel",value:function(e,t){var r=t.data,n=t.columnIndex,a=t.rowIndex,o=t.type,l={};if(w(e)){var i=e({data:r,columnIndex:n,rowIndex:a,type:o});x(i)&&(l=i)}return l}},{key:"setCellFormat",value:function(e,t){var r=t.data,n=t.columnIndex,a=t.rowIndex,o=t.type,l={format:{}};if(w(e)){var i=e({data:r,columnIndex:n,rowIndex:a,type:o});x(i)&&(l.format=i)}return l}},{key:"setTreeIndentStyle",value:function(e,t,r){var a=t.style.alignment||{},o={indent:(e.$level-1)*r,vertical:"middle",wrapText:!0};t.style.alignment=n(n({},a),o)}},{key:"setImageStyle",value:function(e,t){var r=t.data,n=t.columnIndex,a=t.rowIndex,o=t.type,l={image:{}};if(w(e)){var i=e({data:r,columnIndex:n,rowIndex:a,type:o});x(i)&&(l.image=i)}return l}},{key:"setSheetStyle",value:function(e,t){var r=t.sheetIndex,n={};if(w(e)){var a=e({sheetIndex:r});x(a)&&(n=a)}return n}},{key:"setInsertHeader",value:function(e,t){var r=t.sheetIndex,n={};if(w(e)){var a=e({sheetIndex:r});if(x(a)){var o=a.columnStyle,l=void 0===o?[]:o,i=a.rowStyle,c=void 0===i?[]:i,s=a.cells,u=void 0===s?[]:s;if(k(l)&&k(c)&&k(u)){var h=u[u.length-1],f=h.row,d=h.rowspan,v=void 0===d?1:d;if(!C(f)&&!C(v))return I("请输入正确的参数");n.columnStyle=l,n.rowStyle=c,n.cells=u,n.rowLength=f+v,this.calculateIsNeedMerge(u)}}}return n}},{key:"setInsertFooter",value:function(e,t){var r=t.sheetIndex,n={};if(w(e)){var a=e({sheetIndex:r});if(x(a)){var o=a.columnStyle,l=void 0===o?[]:o,i=a.rowStyle,c=void 0===i?[]:i,s=a.cells,u=void 0===s?[]:s;if(k(l)&&k(c)&&k(u)){var h=u[u.length-1],f=h.row,d=h.rowspan,v=void 0===d?1:d;if(!C(f)&&!C(v))return I("请输入正确的参数");n.columnStyle=l,n.rowStyle=c,n.cells=u,n.rowLength=f+v,this.calculateIsNeedMerge(u)}}}return n}},{key:"calculateIsNeedMerge",value:function(e){for(var t=0;t