@cecee/document-flip-book 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ArchiveCover.d.ts +9 -0
- package/dist/cjs/ArchiveCover.js +142 -0
- package/dist/cjs/DocumentFlipBook.d.ts +32 -0
- package/dist/cjs/DocumentFlipBook.js +644 -0
- package/dist/cjs/ExportModal.d.ts +10 -0
- package/dist/cjs/ExportModal.js +96 -0
- package/dist/cjs/HeaderBar.d.ts +25 -0
- package/dist/cjs/HeaderBar.js +220 -0
- package/dist/cjs/PdfPage.d.ts +9 -0
- package/dist/cjs/PdfPage.js +143 -0
- package/dist/cjs/ProjectCover.d.ts +8 -0
- package/dist/cjs/ProjectCover.js +201 -0
- package/dist/cjs/SideTabs.d.ts +8 -0
- package/dist/cjs/SideTabs.js +34 -0
- package/dist/cjs/exportHtml.d.ts +19 -0
- package/dist/cjs/exportHtml.js +189 -0
- package/dist/cjs/exportPdf.d.ts +27 -0
- package/dist/cjs/exportPdf.js +232 -0
- package/dist/cjs/globalCache.d.ts +5 -0
- package/dist/cjs/globalCache.js +20 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.less +637 -0
- package/dist/cjs/printPdf.d.ts +6 -0
- package/dist/cjs/printPdf.js +51 -0
- package/dist/cjs/types.d.ts +31 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/utils.d.ts +17 -0
- package/dist/cjs/utils.js +220 -0
- package/dist/esm/ArchiveCover.d.ts +9 -0
- package/dist/esm/ArchiveCover.js +136 -0
- package/dist/esm/DocumentFlipBook.d.ts +32 -0
- package/dist/esm/DocumentFlipBook.js +630 -0
- package/dist/esm/ExportModal.d.ts +10 -0
- package/dist/esm/ExportModal.js +88 -0
- package/dist/esm/HeaderBar.d.ts +25 -0
- package/dist/esm/HeaderBar.js +211 -0
- package/dist/esm/PdfPage.d.ts +9 -0
- package/dist/esm/PdfPage.js +136 -0
- package/dist/esm/ProjectCover.d.ts +8 -0
- package/dist/esm/ProjectCover.js +195 -0
- package/dist/esm/SideTabs.d.ts +8 -0
- package/dist/esm/SideTabs.js +27 -0
- package/dist/esm/exportHtml.d.ts +19 -0
- package/dist/esm/exportHtml.js +178 -0
- package/dist/esm/exportPdf.d.ts +27 -0
- package/dist/esm/exportPdf.js +223 -0
- package/dist/esm/globalCache.d.ts +5 -0
- package/dist/esm/globalCache.js +15 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.less +637 -0
- package/dist/esm/printPdf.d.ts +6 -0
- package/dist/esm/printPdf.js +45 -0
- package/dist/esm/types.d.ts +31 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.d.ts +17 -0
- package/dist/esm/utils.js +214 -0
- package/package.json +57 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface AttachmentItem {
|
|
2
|
+
id: string;
|
|
3
|
+
path: string;
|
|
4
|
+
acc17c_fd: string;
|
|
5
|
+
}
|
|
6
|
+
export type DocumentFlipBookMode = 'page' | 'modal';
|
|
7
|
+
export type SideTabItem = {
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
color: string;
|
|
11
|
+
pageIndex: number;
|
|
12
|
+
};
|
|
13
|
+
export type BuiltPage = {
|
|
14
|
+
type: 'pdf';
|
|
15
|
+
file: string;
|
|
16
|
+
pageNum: number;
|
|
17
|
+
acc17c_fd: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'pdf-error';
|
|
20
|
+
file: string;
|
|
21
|
+
acc17c_fd: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'image';
|
|
24
|
+
file: string;
|
|
25
|
+
acc17c_fd: string;
|
|
26
|
+
};
|
|
27
|
+
export interface PdfDocumentLike {
|
|
28
|
+
numPages: number;
|
|
29
|
+
getPage: (pageNum: number) => Promise<any>;
|
|
30
|
+
cleanup?: () => void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AttachmentItem, BuiltPage, PdfDocumentLike } from './types';
|
|
2
|
+
export declare const setupPdfWorker: (customSrc?: string) => void;
|
|
3
|
+
export declare const PDF_OPTIONS: {};
|
|
4
|
+
export declare const PDF_PRELOAD_TIMEOUT = 60000;
|
|
5
|
+
export declare const VIEWPORT_WIDTH = 570;
|
|
6
|
+
export declare const VIEWPORT_HEIGHT = 670;
|
|
7
|
+
export declare const HEIGHT = "100%";
|
|
8
|
+
export declare const isPdfFile: (path: string) => boolean;
|
|
9
|
+
export declare const formatPath: (path: string) => string;
|
|
10
|
+
export declare const buildPagesFromSingleAttachment: (attachment: AttachmentItem, getPdfPageCount: (path: string) => Promise<number>) => Promise<BuiltPage[]>;
|
|
11
|
+
export declare const buildPagesFromAttachments: (attachments: AttachmentItem[], getPdfPageCount: (path: string) => Promise<number>) => Promise<BuiltPage[]>;
|
|
12
|
+
export declare const withTimeout: <T>(promise: Promise<T>, timeoutMs: number, errorMessage: string) => Promise<T>;
|
|
13
|
+
export declare const createPdfDocumentCache: (loadDocument: (path: string) => Promise<PdfDocumentLike>) => {
|
|
14
|
+
getDocument(path: string): Promise<PdfDocumentLike>;
|
|
15
|
+
getPageCount(path: string): Promise<number>;
|
|
16
|
+
clear(path: string): void;
|
|
17
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.withTimeout = exports.setupPdfWorker = exports.isPdfFile = exports.formatPath = exports.createPdfDocumentCache = exports.buildPagesFromSingleAttachment = exports.buildPagesFromAttachments = exports.VIEWPORT_WIDTH = exports.VIEWPORT_HEIGHT = exports.PDF_PRELOAD_TIMEOUT = exports.PDF_OPTIONS = exports.HEIGHT = void 0;
|
|
8
|
+
var _reactPdf = require("react-pdf");
|
|
9
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
10
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
+
// PDF 配置
|
|
13
|
+
// 注意:在组件库中,workerSrc 建议由调用方配置,或者引用本地静态资源。
|
|
14
|
+
var setupPdfWorker = exports.setupPdfWorker = function setupPdfWorker(customSrc) {
|
|
15
|
+
if (typeof window === 'undefined') return;
|
|
16
|
+
if (customSrc) {
|
|
17
|
+
_reactPdf.pdfjs.GlobalWorkerOptions.workerSrc = customSrc;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 默认使用本地路径,需确保项目中 public 目录下存在该文件
|
|
22
|
+
// 如果需要使用 CDN,可以通过 pdfWorkerSrc 属性传入
|
|
23
|
+
_reactPdf.pdfjs.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.js';
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// 执行默认初始化
|
|
27
|
+
setupPdfWorker();
|
|
28
|
+
var PDF_OPTIONS = exports.PDF_OPTIONS = {};
|
|
29
|
+
var PDF_PRELOAD_TIMEOUT = exports.PDF_PRELOAD_TIMEOUT = 60000; // 增加到 60 秒,适配超大文件或慢速网络
|
|
30
|
+
var VIEWPORT_WIDTH = exports.VIEWPORT_WIDTH = 570;
|
|
31
|
+
var VIEWPORT_HEIGHT = exports.VIEWPORT_HEIGHT = 670;
|
|
32
|
+
var HEIGHT = exports.HEIGHT = '100%';
|
|
33
|
+
|
|
34
|
+
// 判断是否为 PDF
|
|
35
|
+
var isPdfFile = exports.isPdfFile = function isPdfFile(path) {
|
|
36
|
+
return /\.pdf(?:$|\?)/i.test(path);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// 路径格式化
|
|
40
|
+
var formatPath = exports.formatPath = function formatPath(path) {
|
|
41
|
+
if (!path) return '';
|
|
42
|
+
// 清除首尾空格和可能的引号/反引号(针对部分接口返回异常)
|
|
43
|
+
var formatted = String(path).trim().replace(/^[`'"]|[`'"]$/g, '').trim();
|
|
44
|
+
if (process.env.NODE_ENV === 'development') {
|
|
45
|
+
return formatted.replace('assets.gks.cc', 'pub.gks.cc');
|
|
46
|
+
}
|
|
47
|
+
return formatted;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// 构建页面数组 - 支持单个附件处理以实现渐进式加载
|
|
51
|
+
var buildPagesFromSingleAttachment = exports.buildPagesFromSingleAttachment = /*#__PURE__*/function () {
|
|
52
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(attachment, getPdfPageCount) {
|
|
53
|
+
var pageCount, pages, pageNum;
|
|
54
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
55
|
+
while (1) switch (_context.prev = _context.next) {
|
|
56
|
+
case 0:
|
|
57
|
+
if (isPdfFile(attachment.path)) {
|
|
58
|
+
_context.next = 4;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (attachment.path) {
|
|
62
|
+
_context.next = 3;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
return _context.abrupt("return", [{
|
|
66
|
+
type: 'pdf-error',
|
|
67
|
+
file: '',
|
|
68
|
+
acc17c_fd: attachment.acc17c_fd
|
|
69
|
+
}]);
|
|
70
|
+
case 3:
|
|
71
|
+
return _context.abrupt("return", [{
|
|
72
|
+
type: 'image',
|
|
73
|
+
file: attachment.path,
|
|
74
|
+
acc17c_fd: attachment.acc17c_fd
|
|
75
|
+
}]);
|
|
76
|
+
case 4:
|
|
77
|
+
_context.prev = 4;
|
|
78
|
+
_context.next = 7;
|
|
79
|
+
return getPdfPageCount(attachment.path);
|
|
80
|
+
case 7:
|
|
81
|
+
pageCount = _context.sent;
|
|
82
|
+
pages = [];
|
|
83
|
+
for (pageNum = 1; pageNum <= pageCount; pageNum++) {
|
|
84
|
+
pages.push({
|
|
85
|
+
type: 'pdf',
|
|
86
|
+
file: attachment.path,
|
|
87
|
+
pageNum: pageNum,
|
|
88
|
+
acc17c_fd: attachment.acc17c_fd
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return _context.abrupt("return", pages);
|
|
92
|
+
case 13:
|
|
93
|
+
_context.prev = 13;
|
|
94
|
+
_context.t0 = _context["catch"](4);
|
|
95
|
+
console.error('PDF 加载失败', _context.t0);
|
|
96
|
+
return _context.abrupt("return", [{
|
|
97
|
+
type: 'pdf-error',
|
|
98
|
+
file: attachment.path,
|
|
99
|
+
acc17c_fd: attachment.acc17c_fd
|
|
100
|
+
}]);
|
|
101
|
+
case 17:
|
|
102
|
+
case "end":
|
|
103
|
+
return _context.stop();
|
|
104
|
+
}
|
|
105
|
+
}, _callee, null, [[4, 13]]);
|
|
106
|
+
}));
|
|
107
|
+
return function buildPagesFromSingleAttachment(_x, _x2) {
|
|
108
|
+
return _ref.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
}();
|
|
111
|
+
|
|
112
|
+
// 保持向下兼容,但内部改为调用 buildPagesFromSingleAttachment 并支持并行
|
|
113
|
+
var buildPagesFromAttachments = exports.buildPagesFromAttachments = /*#__PURE__*/function () {
|
|
114
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(attachments, getPdfPageCount) {
|
|
115
|
+
var attachmentResults;
|
|
116
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
117
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
118
|
+
case 0:
|
|
119
|
+
_context2.next = 2;
|
|
120
|
+
return Promise.all(attachments.map(function (attachment) {
|
|
121
|
+
return buildPagesFromSingleAttachment(attachment, getPdfPageCount);
|
|
122
|
+
}));
|
|
123
|
+
case 2:
|
|
124
|
+
attachmentResults = _context2.sent;
|
|
125
|
+
return _context2.abrupt("return", attachmentResults.flat());
|
|
126
|
+
case 4:
|
|
127
|
+
case "end":
|
|
128
|
+
return _context2.stop();
|
|
129
|
+
}
|
|
130
|
+
}, _callee2);
|
|
131
|
+
}));
|
|
132
|
+
return function buildPagesFromAttachments(_x3, _x4) {
|
|
133
|
+
return _ref2.apply(this, arguments);
|
|
134
|
+
};
|
|
135
|
+
}();
|
|
136
|
+
|
|
137
|
+
// 超时控制
|
|
138
|
+
var withTimeout = exports.withTimeout = /*#__PURE__*/function () {
|
|
139
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(promise, timeoutMs, errorMessage) {
|
|
140
|
+
var timeoutId;
|
|
141
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
142
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
143
|
+
case 0:
|
|
144
|
+
_context3.prev = 0;
|
|
145
|
+
_context3.next = 3;
|
|
146
|
+
return Promise.race([promise, new Promise(function (_, reject) {
|
|
147
|
+
timeoutId = setTimeout(function () {
|
|
148
|
+
return reject(new Error(errorMessage));
|
|
149
|
+
}, timeoutMs);
|
|
150
|
+
})]);
|
|
151
|
+
case 3:
|
|
152
|
+
return _context3.abrupt("return", _context3.sent);
|
|
153
|
+
case 4:
|
|
154
|
+
_context3.prev = 4;
|
|
155
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
156
|
+
return _context3.finish(4);
|
|
157
|
+
case 7:
|
|
158
|
+
case "end":
|
|
159
|
+
return _context3.stop();
|
|
160
|
+
}
|
|
161
|
+
}, _callee3, null, [[0,, 4, 7]]);
|
|
162
|
+
}));
|
|
163
|
+
return function withTimeout(_x5, _x6, _x7) {
|
|
164
|
+
return _ref3.apply(this, arguments);
|
|
165
|
+
};
|
|
166
|
+
}();
|
|
167
|
+
|
|
168
|
+
// PDF 缓存工厂
|
|
169
|
+
var createPdfDocumentCache = exports.createPdfDocumentCache = function createPdfDocumentCache(loadDocument) {
|
|
170
|
+
var cache = new Map();
|
|
171
|
+
return {
|
|
172
|
+
getDocument: function getDocument(path) {
|
|
173
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
174
|
+
var doc;
|
|
175
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
176
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
177
|
+
case 0:
|
|
178
|
+
if (!cache.has(path)) {
|
|
179
|
+
_context4.next = 2;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
return _context4.abrupt("return", cache.get(path));
|
|
183
|
+
case 2:
|
|
184
|
+
_context4.next = 4;
|
|
185
|
+
return loadDocument(path);
|
|
186
|
+
case 4:
|
|
187
|
+
doc = _context4.sent;
|
|
188
|
+
cache.set(path, doc);
|
|
189
|
+
return _context4.abrupt("return", doc);
|
|
190
|
+
case 7:
|
|
191
|
+
case "end":
|
|
192
|
+
return _context4.stop();
|
|
193
|
+
}
|
|
194
|
+
}, _callee4);
|
|
195
|
+
}))();
|
|
196
|
+
},
|
|
197
|
+
getPageCount: function getPageCount(path) {
|
|
198
|
+
var _this = this;
|
|
199
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
200
|
+
var doc;
|
|
201
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
202
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
203
|
+
case 0:
|
|
204
|
+
_context5.next = 2;
|
|
205
|
+
return _this.getDocument(path);
|
|
206
|
+
case 2:
|
|
207
|
+
doc = _context5.sent;
|
|
208
|
+
return _context5.abrupt("return", doc.numPages);
|
|
209
|
+
case 4:
|
|
210
|
+
case "end":
|
|
211
|
+
return _context5.stop();
|
|
212
|
+
}
|
|
213
|
+
}, _callee5);
|
|
214
|
+
}))();
|
|
215
|
+
},
|
|
216
|
+
clear: function clear(path) {
|
|
217
|
+
cache.delete(path);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import "./index.less";
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
var ArchiveCover = function ArchiveCover(_ref) {
|
|
7
|
+
var _archiveInfo$com00cs, _archiveInfo$nsp24c;
|
|
8
|
+
var data = _ref.data,
|
|
9
|
+
archiveInfo = _ref.archiveInfo,
|
|
10
|
+
_ref$themeColor = _ref.themeColor,
|
|
11
|
+
themeColor = _ref$themeColor === void 0 ? '#9F7D4E' : _ref$themeColor;
|
|
12
|
+
var acc51c = data || {};
|
|
13
|
+
var user = archiveInfo === null || archiveInfo === void 0 ? void 0 : archiveInfo.user;
|
|
14
|
+
var _ref2 = user || {},
|
|
15
|
+
company = _ref2.company;
|
|
16
|
+
var coverData = {
|
|
17
|
+
company: (company === null || company === void 0 ? void 0 : company.fd) || '-',
|
|
18
|
+
title: (archiveInfo === null || archiveInfo === void 0 ? void 0 : archiveInfo.fd) || '项目档案',
|
|
19
|
+
archiveNo: (archiveInfo === null || archiveInfo === void 0 ? void 0 : archiveInfo.fd_dam) || '-',
|
|
20
|
+
projectNo: acc51c.fd_dam || '-',
|
|
21
|
+
projectName: acc51c.fd || '-',
|
|
22
|
+
budget: '-',
|
|
23
|
+
bindPeriod: "".concat((archiveInfo === null || archiveInfo === void 0 ? void 0 : archiveInfo.fd_start) || '-', " \u81F3 ").concat((archiveInfo === null || archiveInfo === void 0 ? void 0 : archiveInfo.fd_beover) || '-'),
|
|
24
|
+
projectPeriod: "".concat(acc51c.fd_06 || '-', " \u81F3 ").concat(acc51c.fd_07 || '-'),
|
|
25
|
+
compileDate: archiveInfo !== null && archiveInfo !== void 0 && archiveInfo.created_at ? dayjs(archiveInfo.created_at).format('YYYY-MM-DD HH:mm') : '-',
|
|
26
|
+
manager: acc51c.fd_04 || '-',
|
|
27
|
+
totalFiles: (archiveInfo === null || archiveInfo === void 0 ? void 0 : archiveInfo.fd_su) || 0,
|
|
28
|
+
attachmentsCount: (archiveInfo === null || archiveInfo === void 0 || (_archiveInfo$com00cs = archiveInfo.com00cs) === null || _archiveInfo$com00cs === void 0 ? void 0 : _archiveInfo$com00cs.length) || 0,
|
|
29
|
+
nsp24cFd: (archiveInfo === null || archiveInfo === void 0 || (_archiveInfo$nsp24c = archiveInfo.nsp24c) === null || _archiveInfo$nsp24c === void 0 ? void 0 : _archiveInfo$nsp24c.fd) || '-'
|
|
30
|
+
};
|
|
31
|
+
return /*#__PURE__*/_jsx("div", {
|
|
32
|
+
className: "archive-cover",
|
|
33
|
+
style: {
|
|
34
|
+
backgroundColor: themeColor
|
|
35
|
+
},
|
|
36
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
37
|
+
className: "archive-cover__outer-border",
|
|
38
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
39
|
+
className: "archive-cover__inner",
|
|
40
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
41
|
+
className: "archive-cover__company",
|
|
42
|
+
children: coverData.company
|
|
43
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
44
|
+
className: "archive-cover__title",
|
|
45
|
+
children: coverData.title
|
|
46
|
+
}), /*#__PURE__*/_jsx("table", {
|
|
47
|
+
className: "archive-cover__table",
|
|
48
|
+
children: /*#__PURE__*/_jsxs("tbody", {
|
|
49
|
+
children: [/*#__PURE__*/_jsxs("tr", {
|
|
50
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
51
|
+
className: "label",
|
|
52
|
+
children: "\u6863\u6848\u7F16\u53F7"
|
|
53
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
54
|
+
className: "value",
|
|
55
|
+
children: coverData.archiveNo
|
|
56
|
+
})]
|
|
57
|
+
}), /*#__PURE__*/_jsxs("tr", {
|
|
58
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
59
|
+
className: "label",
|
|
60
|
+
children: "\u9879\u76EE\u7F16\u53F7"
|
|
61
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
62
|
+
className: "value",
|
|
63
|
+
children: coverData.projectNo
|
|
64
|
+
})]
|
|
65
|
+
}), /*#__PURE__*/_jsxs("tr", {
|
|
66
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
67
|
+
className: "label tall-row",
|
|
68
|
+
children: "\u9879\u76EE\u540D\u79F0"
|
|
69
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
70
|
+
className: "value tall-row",
|
|
71
|
+
children: coverData.projectName
|
|
72
|
+
})]
|
|
73
|
+
}), /*#__PURE__*/_jsxs("tr", {
|
|
74
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
75
|
+
className: "label",
|
|
76
|
+
children: "\u9879\u76EE\u8D1F\u8D23\u4EBA"
|
|
77
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
78
|
+
className: "value",
|
|
79
|
+
children: coverData.manager
|
|
80
|
+
})]
|
|
81
|
+
}), /*#__PURE__*/_jsxs("tr", {
|
|
82
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
83
|
+
className: "label",
|
|
84
|
+
children: "\u88C5\u8BA2\u671F\u95F4"
|
|
85
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
86
|
+
className: "value",
|
|
87
|
+
children: coverData.bindPeriod
|
|
88
|
+
})]
|
|
89
|
+
}), /*#__PURE__*/_jsxs("tr", {
|
|
90
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
91
|
+
className: "label",
|
|
92
|
+
children: "\u9879\u76EE\u671F\u95F4"
|
|
93
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
94
|
+
className: "value",
|
|
95
|
+
children: coverData.projectPeriod
|
|
96
|
+
})]
|
|
97
|
+
}), /*#__PURE__*/_jsxs("tr", {
|
|
98
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
99
|
+
className: "label",
|
|
100
|
+
children: "\u88C5\u8BA2\u65E5\u671F"
|
|
101
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
102
|
+
className: "value",
|
|
103
|
+
children: coverData.compileDate
|
|
104
|
+
})]
|
|
105
|
+
}), /*#__PURE__*/_jsxs("tr", {
|
|
106
|
+
children: [/*#__PURE__*/_jsx("td", {
|
|
107
|
+
className: "label",
|
|
108
|
+
children: "\u88C5\u8BA2\u4EBA"
|
|
109
|
+
}), /*#__PURE__*/_jsx("td", {
|
|
110
|
+
className: "value",
|
|
111
|
+
children: coverData.nsp24cFd
|
|
112
|
+
})]
|
|
113
|
+
}), /*#__PURE__*/_jsx("tr", {
|
|
114
|
+
className: "archive-cover__stats-row",
|
|
115
|
+
children: /*#__PURE__*/_jsx("td", {
|
|
116
|
+
colSpan: 2,
|
|
117
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
118
|
+
className: "stats-content",
|
|
119
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
120
|
+
children: "\u5171"
|
|
121
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
122
|
+
className: "num",
|
|
123
|
+
children: coverData.totalFiles
|
|
124
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
125
|
+
children: "\u4EFD\u6587\u4EF6"
|
|
126
|
+
})]
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
})]
|
|
130
|
+
})
|
|
131
|
+
})]
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
export default /*#__PURE__*/React.memo(ArchiveCover);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DocumentFlipBookMode } from './types';
|
|
3
|
+
import './index.less';
|
|
4
|
+
interface DocumentFlipBookProps {
|
|
5
|
+
mode?: DocumentFlipBookMode;
|
|
6
|
+
title?: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
themeColor?: string;
|
|
9
|
+
documentInfo: {
|
|
10
|
+
com00cs?: any[];
|
|
11
|
+
attachments?: any[];
|
|
12
|
+
edr04bs?: any[];
|
|
13
|
+
acc51c?: any;
|
|
14
|
+
code?: string;
|
|
15
|
+
acc56c_fd?: string;
|
|
16
|
+
fd_dam?: string;
|
|
17
|
+
created_at?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
companyName?: string;
|
|
20
|
+
user?: any;
|
|
21
|
+
dt?: string;
|
|
22
|
+
amount?: number;
|
|
23
|
+
};
|
|
24
|
+
onBack?: () => void;
|
|
25
|
+
onRequestFullscreen?: () => void;
|
|
26
|
+
onClose?: () => void;
|
|
27
|
+
onSearch?: (v: string) => void;
|
|
28
|
+
showHeaderBar?: boolean;
|
|
29
|
+
pdfWorkerSrc?: string;
|
|
30
|
+
}
|
|
31
|
+
declare const DocumentFlipBook: React.FC<DocumentFlipBookProps>;
|
|
32
|
+
export default DocumentFlipBook;
|