UNPKG

@ohayojp.com/components

Version:

Common business components of ohayojp.

23 lines (21 loc) 7.21 kB
/** * @license ohayojp(cipchk@qq.com) v1.0.0 * (c) 2020 cipchk https://ohayojp.com/ * License: MIT */ !function (e, t) { "object" == typeof exports && "undefined" != typeof module ? t(exports, require("@angular/common/http"), require("@angular/core"), require("@ohayojp.com/util"), require("file-saver"), require("@angular/common")) : "function" == typeof define && define.amd ? define("@ohayojp.com/components/xlsx", ["exports", "@angular/common/http", "@angular/core", "@ohayojp.com/util", "file-saver", "@angular/common"], t) : t(((e = "undefined" != typeof globalThis ? globalThis : e || self).ohayo = e.ohayo || {}, e.ohayo.components = e.ohayo.components || {}, e.ohayo.components.xlsx = {}), e.ng.common.http, e.ng.core, e.ohayo.util, e.saveAs, e.ng.common) }(this, (function (e, t, n, o, r, i) { "use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */function a(e, t, n, o) { return new (n || (n = Promise))((function (r, i) { function a(e) { try { u(o.next(e)) } catch (e) { i(e) } } function c(e) { try { u(o.throw(e)) } catch (e) { i(e) } } function u(e) { var t; e.done ? r(e.value) : (t = e.value, t instanceof n ? t : new n((function (e) { e(t) }))).then(a, c) } u((o = o.apply(e, t || [])).next()) })) } function c(e, t) { var n, o, r, i, a = { label: 0, sent: function () { if (1 & r[0]) throw r[1]; return r[1] }, trys: [], ops: [] }; return i = { next: c(0), throw: c(1), return: c(2) }, "function" == typeof Symbol && (i[Symbol.iterator] = function () { return this }), i; function c(i) { return function (c) { return function (i) { if (n) throw new TypeError("Generator is already executing."); for (; a;)try { if (n = 1, o && (r = 2 & i[0] ? o.return : i[0] ? o.throw || ((r = o.return) && r.call(o), 0) : o.next) && !(r = r.call(o, i[1])).done) return r; switch (o = 0, r && (i = [2 & i[0], r.value]), i[0]) { case 0: case 1: r = i; break; case 4: return a.label++, { value: i[1], done: !1 }; case 5: a.label++, o = i[1], i = [0]; continue; case 7: i = a.ops.pop(), a.trys.pop(); continue; default: if (!(r = a.trys, (r = r.length > 0 && r[r.length - 1]) || 6 !== i[0] && 2 !== i[0])) { a = 0; continue } if (3 === i[0] && (!r || i[1] > r[0] && i[1] < r[3])) { a.label = i[1]; break } if (6 === i[0] && a.label < r[1]) { a.label = r[1], r = i; break } if (r && a.label < r[2]) { a.label = r[2], a.ops.push(i); break } r[2] && a.ops.pop(), a.trys.pop(); continue }i = t.call(e, a) } catch (e) { i = [6, e], o = 0 } finally { n = r = 0 } if (5 & i[0]) throw i[1]; return { value: i[0] ? i[1] : void 0, done: !0 } }([i, c]) } } } Object.create; function u(e, t) { var n = "function" == typeof Symbol && e[Symbol.iterator]; if (!n) return e; var o, r, i = n.call(e), a = []; try { for (; (void 0 === t || t-- > 0) && !(o = i.next()).done;)a.push(o.value) } catch (e) { r = { error: e } } finally { try { o && !o.done && (n = i.return) && n.call(i) } finally { if (r) throw r.error } } return a } function s() { for (var e = [], t = 0; t < arguments.length; t++)e = e.concat(u(arguments[t])); return e } Object.create; var l = function () { function e(e, t, n, o) { this.http = e, this.lazy = t, this.ngZone = o, this.cog = n.merge("xlsx", { url: "//cdn.bootcss.com/xlsx/0.15.6/xlsx.full.min.js", modules: [] }) } return e.prototype.init = function () { return "undefined" != typeof XLSX ? Promise.resolve([]) : this.lazy.load([this.cog.url].concat(this.cog.modules)) }, e.prototype.read = function (e, t) { var n = {}; return this.ngZone.runOutsideAngular((function () { var o = XLSX.read(e, t); o.SheetNames.forEach((function (e) { var t = o.Sheets[e]; n[e] = XLSX.utils.sheet_to_json(t, { header: 1 }) })) })), n }, e.prototype.import = function (e, t) { var n = this; return void 0 === t && (t = "readAsBinaryString"), new Promise((function (o, r) { n.init().then((function () { if ("string" != typeof e) { var i = new FileReader; i.onload = function (e) { n.ngZone.run((function () { return o(n.read(e.target.result, { type: "binary" })) })) }, i[t](e) } else n.http.request("GET", e, { responseType: "arraybuffer" }).subscribe((function (e) { n.ngZone.run((function () { return o(n.read(new Uint8Array(e), { type: "array" })) })) }), (function (e) { r(e) })) })).catch((function () { return r("Unable to load xlsx.js") })) })) }, e.prototype.export = function (e) { return a(this, void 0, void 0, (function () { var t = this; return c(this, (function (n) { return [2, new Promise((function (n, o) { t.init().then((function () { t.ngZone.runOutsideAngular((function () { var t = XLSX.utils.book_new(); Array.isArray(e.sheets) ? e.sheets.forEach((function (e, n) { var o = XLSX.utils.aoa_to_sheet(e.data); XLSX.utils.book_append_sheet(t, o, e.name || "Sheet" + (n + 1)) })) : (t.SheetNames = Object.keys(e.sheets), t.Sheets = e.sheets), e.callback && e.callback(t); var o = XLSX.write(t, Object.assign({ bookType: "xlsx", bookSST: !1, type: "array" }, e.opts)), i = e.filename || "export.xlsx"; r.saveAs(new Blob([o], { type: "application/octet-stream" }), i), n({ filename: i, wb: t }) })) })).catch((function (e) { return o(e) })) }))] })) })) }, e.prototype.numberToSchema = function (e) { var t = "A".charCodeAt(0), n = ""; do { --e, n = String.fromCharCode(t + e % 26) + n, e = e / 26 >> 0 } while (e > 0); return n }, e }(); l.decorators = [{ type: n.Injectable, args: [{ providedIn: "root" }] }], l.ctorParameters = function () { return [{ type: t.HttpClient }, { type: o.LazyService }, { type: o.OhayoConfigService }, { type: n.NgZone }] }, l.ɵprov = n.ɵɵdefineInjectable({ factory: function () { return new l(n.ɵɵinject(t.HttpClient), n.ɵɵinject(o.LazyService), n.ɵɵinject(o.OhayoConfigService), n.ɵɵinject(n.NgZone)) }, token: l, providedIn: "root" }); var f = function () { function e(e) { this.srv = e } return e.prototype._click = function () { this.srv.export(this.data) }, e }(); f.decorators = [{ type: n.Directive, args: [{ selector: "[xlsx]", exportAs: "xlsx", host: { "(click)": "_click()" } }] }], f.ctorParameters = function () { return [{ type: l }] }, f.propDecorators = { data: [{ type: n.Input, args: ["xlsx"] }] }; var p = [f], h = function () { }; h.decorators = [{ type: n.NgModule, args: [{ imports: [i.CommonModule, o.OhayoUtilModule], declarations: s(p), exports: s(p) }] }], e.XlsxDirective = f, e.XlsxModule = h, e.XlsxService = l, Object.defineProperty(e, "__esModule", { value: !0 }) })); //# sourceMappingURL=xlsx.umd.min.js.map