UNPKG

yoyo-ng-modulewindy

Version:

服务于52ABP模板的前端开源的相关组件内容。整合了ng-alain和你NG ZORRO的内容

79 lines 2.79 kB
import { Injectable, Optional } from '@angular/core'; import { deepGet } from 'yoyo-ng-module/util'; import { XlsxService } from '../xlsx/xlsx.service'; var SimpleTableExport = /** @class */ (function () { function SimpleTableExport(xlsxSrv) { this.xlsxSrv = xlsxSrv; } SimpleTableExport.prototype._stGet = function (item, col) { var ret = { t: 's', v: '' }; if (col.format) { ret.v = col.format(item, col); } else { var val = deepGet(item, col.index, ''); ret.v = val; switch (col.type) { case 'currency': ret.t = 'n'; break; case 'date': ret.t = 'd'; break; case 'yn': ret.v = ret.v === col.ynTruth ? col.ynYes || '是' : col.ynNo || '否'; break; } } return ret; }; SimpleTableExport.prototype.genSheet = function (opt) { var sheets = {}; var sheet = (sheets[opt.sheetname || 'Sheet1'] = {}); var colData = opt._c.filter(function (w) { return w.exported !== false && w.index && (!w.buttons || w.buttons.length === 0); }); var cc = colData.length, dc = opt._d.length; // region: column for (var i = 0; i < cc; i++) { sheet[String.fromCharCode(65 + i) + "1"] = { t: 's', v: colData[i].title, }; } // endregion // region: content for (var i = 0; i < dc; i++) { for (var j = 0; j < cc; j++) { sheet["" + String.fromCharCode(65 + j) + (i + 2)] = this._stGet(opt._d[i], colData[j]); } } // endregion if (cc > 0 && dc > 0) { sheet['!ref'] = "A1:" + String.fromCharCode(65 + cc - 1) + (dc + 1); } return sheets; }; SimpleTableExport.prototype.export = function (opt) { if (!this.xlsxSrv) throw new Error("muse be import 'AdXlsxModule' module, but got null"); var sheets = this.genSheet(opt); return this.xlsxSrv.export({ sheets: sheets, filename: opt.filename, callback: opt.callback, }); }; SimpleTableExport.decorators = [ { type: Injectable }, ]; /** @nocollapse */ SimpleTableExport.ctorParameters = function () { return [ { type: XlsxService, decorators: [{ type: Optional }] } ]; }; return SimpleTableExport; }()); export { SimpleTableExport }; //# sourceMappingURL=simple-table-export.js.map