@cecee/document-flip-book 1.0.19 → 1.0.21

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.
Files changed (91) hide show
  1. package/dist/cjs/AccountingBook/assets/active-line.png +0 -0
  2. package/dist/cjs/AccountingBook/assets/default-line.png +0 -0
  3. package/dist/cjs/AccountingBook/assets/filp-bg.png +0 -0
  4. package/dist/cjs/AccountingBook/components/AccountingVoucher/index.d.ts +26 -0
  5. package/dist/cjs/AccountingBook/components/AccountingVoucher/index.js +398 -0
  6. package/dist/cjs/AccountingBook/components/AccountingVoucher/index.less +231 -0
  7. package/dist/cjs/AccountingBook/components/ExportModal.d.ts +10 -0
  8. package/dist/cjs/AccountingBook/components/ExportModal.js +96 -0
  9. package/dist/cjs/AccountingBook/components/FilpPage.d.ts +7 -0
  10. package/dist/cjs/AccountingBook/components/FilpPage.js +39 -0
  11. package/dist/cjs/AccountingBook/components/HeaderBar.d.ts +28 -0
  12. package/dist/cjs/AccountingBook/components/HeaderBar.js +245 -0
  13. package/dist/cjs/AccountingBook/components/ImagePageRenderer.d.ts +11 -0
  14. package/dist/cjs/AccountingBook/components/ImagePageRenderer.js +91 -0
  15. package/dist/cjs/AccountingBook/components/LoadingComponent.d.ts +7 -0
  16. package/dist/cjs/AccountingBook/components/LoadingComponent.js +54 -0
  17. package/dist/cjs/AccountingBook/components/PDFPageRenderer.d.ts +13 -0
  18. package/dist/cjs/AccountingBook/components/PDFPageRenderer.js +259 -0
  19. package/dist/cjs/AccountingBook/components/index.less +6 -0
  20. package/dist/cjs/AccountingBook/constants.d.ts +11 -0
  21. package/dist/cjs/AccountingBook/constants.js +25 -0
  22. package/dist/cjs/AccountingBook/hooks/useAmountSearch.d.ts +24 -0
  23. package/dist/cjs/AccountingBook/hooks/useAmountSearch.js +165 -0
  24. package/dist/cjs/AccountingBook/hooks/usePageFlip.d.ts +15 -0
  25. package/dist/cjs/AccountingBook/hooks/usePageFlip.js +67 -0
  26. package/dist/cjs/AccountingBook/index.d.ts +29 -1
  27. package/dist/cjs/AccountingBook/index.js +1163 -7
  28. package/dist/cjs/AccountingBook/index.less +188 -0
  29. package/dist/cjs/AccountingBook/types.d.ts +84 -0
  30. package/dist/cjs/AccountingBook/types.js +5 -0
  31. package/dist/cjs/AccountingBook/utils/canvasUtils.d.ts +51 -0
  32. package/dist/cjs/AccountingBook/utils/canvasUtils.js +499 -0
  33. package/dist/cjs/AccountingBook/utils/html.d.ts +9 -0
  34. package/dist/cjs/AccountingBook/utils/html.js +97 -0
  35. package/dist/cjs/AccountingBook/utils/utils.d.ts +38 -0
  36. package/dist/cjs/AccountingBook/utils/utils.js +204 -0
  37. package/dist/cjs/DocumentFlipBook/ExportModal.d.ts +1 -1
  38. package/dist/cjs/DocumentFlipBook/ExportModal.js +1 -1
  39. package/dist/cjs/DocumentFlipBook/HeaderBar.d.ts +2 -1
  40. package/dist/cjs/DocumentFlipBook/HeaderBar.js +13 -11
  41. package/dist/cjs/DocumentFlipBook/SideTabs.js +111 -6
  42. package/dist/cjs/DocumentFlipBook/index.d.ts +1 -0
  43. package/dist/cjs/DocumentFlipBook/index.js +6 -3
  44. package/dist/cjs/DocumentFlipBook/index.less +235 -9
  45. package/dist/cjs/declarations.d.ts +21 -0
  46. package/dist/esm/AccountingBook/assets/active-line.png +0 -0
  47. package/dist/esm/AccountingBook/assets/default-line.png +0 -0
  48. package/dist/esm/AccountingBook/assets/filp-bg.png +0 -0
  49. package/dist/esm/AccountingBook/components/AccountingVoucher/index.d.ts +26 -0
  50. package/dist/esm/AccountingBook/components/AccountingVoucher/index.js +391 -0
  51. package/dist/esm/AccountingBook/components/AccountingVoucher/index.less +231 -0
  52. package/dist/esm/AccountingBook/components/ExportModal.d.ts +10 -0
  53. package/dist/esm/AccountingBook/components/ExportModal.js +88 -0
  54. package/dist/esm/AccountingBook/components/FilpPage.d.ts +7 -0
  55. package/dist/esm/AccountingBook/components/FilpPage.js +33 -0
  56. package/dist/esm/AccountingBook/components/HeaderBar.d.ts +28 -0
  57. package/dist/esm/AccountingBook/components/HeaderBar.js +236 -0
  58. package/dist/esm/AccountingBook/components/ImagePageRenderer.d.ts +11 -0
  59. package/dist/esm/AccountingBook/components/ImagePageRenderer.js +85 -0
  60. package/dist/esm/AccountingBook/components/LoadingComponent.d.ts +7 -0
  61. package/dist/esm/AccountingBook/components/LoadingComponent.js +48 -0
  62. package/dist/esm/AccountingBook/components/PDFPageRenderer.d.ts +13 -0
  63. package/dist/esm/AccountingBook/components/PDFPageRenderer.js +252 -0
  64. package/dist/esm/AccountingBook/components/index.less +6 -0
  65. package/dist/esm/AccountingBook/constants.d.ts +11 -0
  66. package/dist/esm/AccountingBook/constants.js +17 -0
  67. package/dist/esm/AccountingBook/hooks/useAmountSearch.d.ts +24 -0
  68. package/dist/esm/AccountingBook/hooks/useAmountSearch.js +158 -0
  69. package/dist/esm/AccountingBook/hooks/usePageFlip.d.ts +15 -0
  70. package/dist/esm/AccountingBook/hooks/usePageFlip.js +61 -0
  71. package/dist/esm/AccountingBook/index.d.ts +29 -1
  72. package/dist/esm/AccountingBook/index.js +1162 -6
  73. package/dist/esm/AccountingBook/index.less +188 -0
  74. package/dist/esm/AccountingBook/types.d.ts +84 -0
  75. package/dist/esm/AccountingBook/types.js +1 -0
  76. package/dist/esm/AccountingBook/utils/canvasUtils.d.ts +51 -0
  77. package/dist/esm/AccountingBook/utils/canvasUtils.js +493 -0
  78. package/dist/esm/AccountingBook/utils/html.d.ts +9 -0
  79. package/dist/esm/AccountingBook/utils/html.js +89 -0
  80. package/dist/esm/AccountingBook/utils/utils.d.ts +38 -0
  81. package/dist/esm/AccountingBook/utils/utils.js +195 -0
  82. package/dist/esm/DocumentFlipBook/ExportModal.d.ts +1 -1
  83. package/dist/esm/DocumentFlipBook/ExportModal.js +1 -1
  84. package/dist/esm/DocumentFlipBook/HeaderBar.d.ts +2 -1
  85. package/dist/esm/DocumentFlipBook/HeaderBar.js +13 -11
  86. package/dist/esm/DocumentFlipBook/SideTabs.js +110 -5
  87. package/dist/esm/DocumentFlipBook/index.d.ts +1 -0
  88. package/dist/esm/DocumentFlipBook/index.js +6 -3
  89. package/dist/esm/DocumentFlipBook/index.less +235 -9
  90. package/dist/esm/declarations.d.ts +21 -0
  91. package/package.json +8 -2
@@ -0,0 +1,252 @@
1
+ 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); }
2
+ 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; }
3
+ 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); } }
4
+ 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); }); }; }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import React, { useEffect, useState, useRef } from 'react';
12
+ import { GlassMagnifier } from "react-image-magnifiers";
13
+ import { globalPdfCache } from "../utils/utils";
14
+ import 'react-pdf/dist/Page/AnnotationLayer.css';
15
+ import 'react-pdf/dist/Page/TextLayer.css';
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ import { jsxs as _jsxs } from "react/jsx-runtime";
18
+ export var PDFPageRenderer = function PDFPageRenderer(_ref) {
19
+ var pdfPath = _ref.pdfPath,
20
+ attachmentId = _ref.attachmentId,
21
+ pageNumber = _ref.pageNumber,
22
+ currentIndex = _ref.currentIndex,
23
+ totalCount = _ref.totalCount,
24
+ amount = _ref.amount;
25
+ var _useState = useState(''),
26
+ _useState2 = _slicedToArray(_useState, 2),
27
+ pdfImageUrl = _useState2[0],
28
+ setPdfImageUrl = _useState2[1];
29
+ var _useState3 = useState(''),
30
+ _useState4 = _slicedToArray(_useState3, 2),
31
+ highResImageUrl = _useState4[0],
32
+ setHighResImageUrl = _useState4[1];
33
+ var _useState5 = useState(true),
34
+ _useState6 = _slicedToArray(_useState5, 2),
35
+ isLoading = _useState6[0],
36
+ setIsLoading = _useState6[1];
37
+ var _useState7 = useState(''),
38
+ _useState8 = _slicedToArray(_useState7, 2),
39
+ error = _useState8[0],
40
+ setError = _useState8[1];
41
+ var canvasRef = useRef(null);
42
+ var highResCanvasRef = useRef(null);
43
+ var formattedAmount = amount ? Number(amount).toLocaleString('zh-CN', {
44
+ minimumFractionDigits: 2,
45
+ maximumFractionDigits: 2
46
+ }) : '0.00';
47
+ useEffect(function () {
48
+ var isCancelled = false;
49
+ var convertPDFToImage = /*#__PURE__*/function () {
50
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
51
+ var pdf, page, normalCanvas, normalContext, normalViewport, highResCanvas, highResContext, highResViewport;
52
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
53
+ while (1) switch (_context.prev = _context.next) {
54
+ case 0:
55
+ setIsLoading(true);
56
+ setError('');
57
+ _context.prev = 2;
58
+ _context.next = 5;
59
+ return globalPdfCache.getDocument(pdfPath);
60
+ case 5:
61
+ pdf = _context.sent;
62
+ if (!isCancelled) {
63
+ _context.next = 8;
64
+ break;
65
+ }
66
+ return _context.abrupt("return");
67
+ case 8:
68
+ _context.next = 10;
69
+ return pdf.getPage(pageNumber);
70
+ case 10:
71
+ page = _context.sent;
72
+ if (!isCancelled) {
73
+ _context.next = 13;
74
+ break;
75
+ }
76
+ return _context.abrupt("return");
77
+ case 13:
78
+ normalCanvas = canvasRef.current;
79
+ if (!normalCanvas) {
80
+ _context.next = 23;
81
+ break;
82
+ }
83
+ normalContext = normalCanvas.getContext('2d');
84
+ if (!normalContext) {
85
+ _context.next = 23;
86
+ break;
87
+ }
88
+ normalViewport = page.getViewport({
89
+ scale: 1.2
90
+ });
91
+ normalCanvas.height = normalViewport.height;
92
+ normalCanvas.width = normalViewport.width;
93
+ _context.next = 22;
94
+ return page.render({
95
+ canvasContext: normalContext,
96
+ viewport: normalViewport
97
+ }).promise;
98
+ case 22:
99
+ if (!isCancelled) setPdfImageUrl(normalCanvas.toDataURL('image/png', 0.95));
100
+ case 23:
101
+ highResCanvas = highResCanvasRef.current;
102
+ if (!highResCanvas) {
103
+ _context.next = 33;
104
+ break;
105
+ }
106
+ highResContext = highResCanvas.getContext('2d');
107
+ if (!highResContext) {
108
+ _context.next = 33;
109
+ break;
110
+ }
111
+ highResViewport = page.getViewport({
112
+ scale: 2.0
113
+ });
114
+ highResCanvas.height = highResViewport.height;
115
+ highResCanvas.width = highResViewport.width;
116
+ _context.next = 32;
117
+ return page.render({
118
+ canvasContext: highResContext,
119
+ viewport: highResViewport
120
+ }).promise;
121
+ case 32:
122
+ if (!isCancelled) setHighResImageUrl(highResCanvas.toDataURL('image/png', 0.95));
123
+ case 33:
124
+ if (!isCancelled) setIsLoading(false);
125
+ _context.next = 40;
126
+ break;
127
+ case 36:
128
+ _context.prev = 36;
129
+ _context.t0 = _context["catch"](2);
130
+ console.error('PDF转图片失败:', _context.t0);
131
+ if (!isCancelled) {
132
+ setError(_context.t0 instanceof Error ? _context.t0.message : 'PDF加载失败');
133
+ setIsLoading(false);
134
+ }
135
+ case 40:
136
+ case "end":
137
+ return _context.stop();
138
+ }
139
+ }, _callee, null, [[2, 36]]);
140
+ }));
141
+ return function convertPDFToImage() {
142
+ return _ref2.apply(this, arguments);
143
+ };
144
+ }();
145
+ convertPDFToImage();
146
+ return function () {
147
+ isCancelled = true;
148
+ };
149
+ }, [pdfPath, pageNumber]);
150
+ return /*#__PURE__*/_jsxs("div", {
151
+ style: {
152
+ width: '100%',
153
+ height: '100%',
154
+ backgroundColor: '#fff',
155
+ position: 'relative'
156
+ },
157
+ children: [/*#__PURE__*/_jsx("div", {
158
+ style: {
159
+ margin: '0 auto',
160
+ padding: '10px',
161
+ textAlign: 'center',
162
+ fontSize: '26px',
163
+ width: '220px',
164
+ fontWeight: 'bold',
165
+ color: '#597461'
166
+ },
167
+ children: "\u539F\u59CB\u51ED\u8BC1\u7C98\u8D34\u5355"
168
+ }), /*#__PURE__*/_jsxs("div", {
169
+ style: {
170
+ position: 'absolute',
171
+ top: '10px',
172
+ right: '20px',
173
+ textAlign: 'right',
174
+ fontSize: '14px',
175
+ color: '#597461',
176
+ lineHeight: '1.5'
177
+ },
178
+ children: [/*#__PURE__*/_jsxs("div", {
179
+ children: ["\u539F\u59CB\u51ED\u8BC1 ", /*#__PURE__*/_jsxs("span", {
180
+ style: {
181
+ borderBottom: '1px solid #597461'
182
+ },
183
+ children: [currentIndex, "/", totalCount]
184
+ }), " \u5F20"]
185
+ }), /*#__PURE__*/_jsxs("div", {
186
+ children: ["\u91D1\u989D ", /*#__PURE__*/_jsx("span", {
187
+ style: {
188
+ borderBottom: '1px solid #597461'
189
+ },
190
+ children: formattedAmount
191
+ })]
192
+ })]
193
+ }), /*#__PURE__*/_jsxs("div", {
194
+ style: {
195
+ width: '100%',
196
+ height: '85%',
197
+ display: 'flex',
198
+ justifyContent: 'center',
199
+ alignItems: 'center',
200
+ border: '1px solid #597461',
201
+ overflow: 'hidden'
202
+ },
203
+ children: [/*#__PURE__*/_jsx("canvas", {
204
+ ref: canvasRef,
205
+ style: {
206
+ display: 'none'
207
+ }
208
+ }), /*#__PURE__*/_jsx("canvas", {
209
+ ref: highResCanvasRef,
210
+ style: {
211
+ display: 'none'
212
+ }
213
+ }), isLoading ? /*#__PURE__*/_jsx("span", {
214
+ style: {
215
+ color: '#999',
216
+ fontSize: '20px'
217
+ },
218
+ children: "PDF \u8F6C\u6362\u4E2D..."
219
+ }) : error ? /*#__PURE__*/_jsxs("div", {
220
+ style: {
221
+ textAlign: 'center',
222
+ color: '#f00',
223
+ fontSize: '16px'
224
+ },
225
+ children: [/*#__PURE__*/_jsx("div", {
226
+ children: "PDF \u52A0\u8F7D\u5931\u8D25"
227
+ }), /*#__PURE__*/_jsx("div", {
228
+ style: {
229
+ fontSize: '12px',
230
+ marginTop: '5px'
231
+ },
232
+ children: error
233
+ })]
234
+ }) : pdfImageUrl && highResImageUrl ? /*#__PURE__*/_jsx(GlassMagnifier, {
235
+ imageSrc: pdfImageUrl,
236
+ imageAlt: "PDF\u9884\u89C8",
237
+ largeImageSrc: highResImageUrl,
238
+ magnifierBorderSize: 3,
239
+ magnifierBorderColor: "rgba(255, 255, 255, 0.5)",
240
+ magnifierBackgroundColor: "rgba(0, 0, 0, 0.1)",
241
+ square: false,
242
+ magnifierSize: "25%",
243
+ style: {
244
+ maxWidth: '100%',
245
+ maxHeight: '100%',
246
+ objectFit: 'contain',
247
+ cursor: 'zoom-in'
248
+ }
249
+ }) : null]
250
+ })]
251
+ });
252
+ };
@@ -0,0 +1,6 @@
1
+ .dfb-divider {
2
+ width: 1px !important;
3
+ height: 18px !important;
4
+ background: #e8e8e8;
5
+ margin: 0 8px;
6
+ }
@@ -0,0 +1,11 @@
1
+ export declare const filpBg: string;
2
+ export declare const defaultLine: string;
3
+ export declare const activeLine: string;
4
+ export declare const VOUCHER_MIN_ROWS = 5;
5
+ export declare const PAGE_SIZE: {
6
+ width: number;
7
+ height: number;
8
+ };
9
+ export declare const MIN_ROWS = 5;
10
+ export declare const PAGE_WIDTH = 998;
11
+ export declare const PAGE_HEIGHT = 520;
@@ -0,0 +1,17 @@
1
+ // 图片资源
2
+ import filpBgImg from "./assets/filp-bg.png";
3
+ import defaultLineImg from "./assets/default-line.png";
4
+ import activeLineImg from "./assets/active-line.png";
5
+ export var filpBg = filpBgImg;
6
+ export var defaultLine = defaultLineImg;
7
+ export var activeLine = activeLineImg;
8
+
9
+ // 渲染配置
10
+ export var VOUCHER_MIN_ROWS = 5;
11
+ export var PAGE_SIZE = {
12
+ width: 998,
13
+ height: 520
14
+ };
15
+ export var MIN_ROWS = 5;
16
+ export var PAGE_WIDTH = 998;
17
+ export var PAGE_HEIGHT = 520;
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ export interface AmountSearchItem {
3
+ label: string;
4
+ value: string;
5
+ amount: string;
6
+ pageKey: string;
7
+ }
8
+ export interface UseAmountSearchProps {
9
+ originalPagesFull: React.ReactNode[];
10
+ bookRef: React.RefObject<any>;
11
+ setCurrentFilterTitle: (title: string) => void;
12
+ setPages: (pages: React.ReactNode[]) => void;
13
+ setCurrentPageIndex: (index: number) => void;
14
+ goToFirstPage: () => void;
15
+ }
16
+ export declare const useAmountSearch: ({ originalPagesFull, bookRef, setCurrentFilterTitle, setPages, setCurrentPageIndex, goToFirstPage, }: UseAmountSearchProps) => {
17
+ searchValue: string;
18
+ setSearchValue: React.Dispatch<React.SetStateAction<string>>;
19
+ searchOptions: AmountSearchItem[];
20
+ handleAmountSearch: (value: string) => void;
21
+ handleGotoPageByAmount: (value: string) => void;
22
+ handleSearchClear: () => void;
23
+ buildAllAmountOptions: (data: any) => void;
24
+ };
@@ -0,0 +1,158 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useState, useRef } from 'react';
8
+ import React from 'react';
9
+
10
+ // ====================== TS 类型 ======================
11
+
12
+ // ====================== 独立 Hook ======================
13
+ export var useAmountSearch = function useAmountSearch(_ref) {
14
+ var originalPagesFull = _ref.originalPagesFull,
15
+ bookRef = _ref.bookRef,
16
+ setCurrentFilterTitle = _ref.setCurrentFilterTitle,
17
+ setPages = _ref.setPages,
18
+ setCurrentPageIndex = _ref.setCurrentPageIndex,
19
+ goToFirstPage = _ref.goToFirstPage;
20
+ var _useState = useState(''),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ searchValue = _useState2[0],
23
+ setSearchValue = _useState2[1];
24
+ var _useState3 = useState([]),
25
+ _useState4 = _slicedToArray(_useState3, 2),
26
+ searchOptions = _useState4[0],
27
+ setSearchOptions = _useState4[1];
28
+ var allSearchItems = useRef([]);
29
+ var amountToPageMap = useRef(new Map());
30
+
31
+ // 输入搜索
32
+ var handleAmountSearch = function handleAmountSearch(value) {
33
+ setSearchValue(value);
34
+ if (allSearchItems.current.length === 0) return;
35
+ var keywords = (value === null || value === void 0 ? void 0 : value.trim().toLowerCase()) || '';
36
+ var filtered = keywords ? allSearchItems.current.filter(function (item) {
37
+ return item.amount.toLowerCase().includes(keywords) || item.label.toLowerCase().includes(keywords);
38
+ }) : allSearchItems.current;
39
+ setSearchOptions(filtered);
40
+ };
41
+
42
+ // 点击搜索项 → 跳转到对应凭证
43
+ var handleGotoPageByAmount = function handleGotoPageByAmount(value) {
44
+ var targetItem = allSearchItems.current.find(function (item) {
45
+ return item.value === value;
46
+ });
47
+ if (!targetItem) return;
48
+ goToFirstPage();
49
+ setSearchValue(targetItem.label);
50
+ var targetPageKey = targetItem.pageKey;
51
+ // 匹配 key 筛选页面
52
+ var filteredPages = originalPagesFull.filter(function (p) {
53
+ if (! /*#__PURE__*/React.isValidElement(p)) return false;
54
+ var pageKey = p.key || '';
55
+ return pageKey.includes(targetPageKey);
56
+ });
57
+ if (!filteredPages.length) return;
58
+ setCurrentFilterTitle('');
59
+ setPages(filteredPages);
60
+ setCurrentPageIndex(0);
61
+ setTimeout(function () {
62
+ var _bookRef$current;
63
+ (_bookRef$current = bookRef.current) === null || _bookRef$current === void 0 || _bookRef$current.pageFlip().turnToPage(0);
64
+ }, 50);
65
+ };
66
+
67
+ // 清空搜索
68
+ var handleSearchClear = function handleSearchClear() {
69
+ setSearchValue('');
70
+ setSearchOptions(allSearchItems.current);
71
+ setPages(originalPagesFull);
72
+ setCurrentFilterTitle('all');
73
+ setCurrentPageIndex(0);
74
+ setTimeout(function () {
75
+ var _bookRef$current2;
76
+ (_bookRef$current2 = bookRef.current) === null || _bookRef$current2 === void 0 || _bookRef$current2.pageFlip().turnToPage(0);
77
+ }, 50);
78
+ };
79
+
80
+ // 构建搜索选项
81
+ var buildAllAmountOptions = function buildAllAmountOptions(data) {
82
+ var _data$items;
83
+ var stubPages = (data === null || data === void 0 || (_data$items = data.items) === null || _data$items === void 0 ? void 0 : _data$items.stub_pages) || [];
84
+ if (!stubPages.length) return;
85
+ var items = [];
86
+ var pageMap = new Map();
87
+ var addSearchItem = function addSearchItem(key, label, amount, pageKey) {
88
+ items.push({
89
+ label: label,
90
+ value: key,
91
+ amount: amount,
92
+ pageKey: pageKey
93
+ });
94
+ pageMap.set(key, pageKey);
95
+ };
96
+
97
+ // 金额格式化:保留2位小数,避免科学计数/截断
98
+ var formatAmount = function formatAmount(amt) {
99
+ var num = Number(amt) || 0;
100
+ return num.toFixed(2);
101
+ };
102
+ stubPages.forEach(function (stubPage) {
103
+ var _stubPage$stub_page_d2;
104
+ var stubId = stubPage.id,
105
+ _stubPage$code = stubPage.code,
106
+ code = _stubPage$code === void 0 ? '' : _stubPage$code,
107
+ _stubPage$remark = stubPage.remark,
108
+ remark = _stubPage$remark === void 0 ? '无备注' : _stubPage$remark,
109
+ _stubPage$amount = stubPage.amount,
110
+ amount = _stubPage$amount === void 0 ? '0' : _stubPage$amount,
111
+ _stubPage$stub_page_d = stubPage.stub_page_details,
112
+ stub_page_details = _stubPage$stub_page_d === void 0 ? [] : _stubPage$stub_page_d,
113
+ _stubPage$stub_page_r = stubPage.stub_page_raws,
114
+ stub_page_raws = _stubPage$stub_page_r === void 0 ? [] : _stubPage$stub_page_r;
115
+ var voucherText = "\u8BB0".concat(code);
116
+ var voucherKey = "voucher-".concat(((_stubPage$stub_page_d2 = stubPage.stub_page_details) === null || _stubPage$stub_page_d2 === void 0 || (_stubPage$stub_page_d2 = _stubPage$stub_page_d2[0]) === null || _stubPage$stub_page_d2 === void 0 ? void 0 : _stubPage$stub_page_d2.id) || '', "-1");
117
+ var formattedTotalAmt = formatAmount(amount);
118
+ // 1. 总金额项(完全匹配截图样式:记XX|备注|总金额 → 金额)
119
+ addSearchItem("stub_".concat(stubId), "".concat(voucherText, "\uFF5C").concat(remark, "\uFF5C").concat(formattedTotalAmt), formattedTotalAmt, voucherKey);
120
+
121
+ // 2. 凭证明细项(完全匹配截图样式:记XX|备注|凭证明细 → 金额)
122
+ stub_page_details.forEach(function (detail) {
123
+ var detailAmt = detail.amount || '0';
124
+ var formattedDetailAmt = formatAmount(detailAmt);
125
+ var tradeDirection = detail.trade_direction || '';
126
+
127
+ // addSearchItem(
128
+ // `detail_${detail.id}`,
129
+ // `${voucherText}|${remark}(${tradeDirection})|${formattedDetailAmt}`,
130
+ // formattedDetailAmt,
131
+ // voucherKey
132
+ // );
133
+ });
134
+
135
+ // 3. 原始单据/附件项(完全匹配截图样式:记XX|附件标题|附件N → 金额)
136
+ stub_page_raws.forEach(function (raw, idx) {
137
+ var _raw$attachments;
138
+ var rawAmt = raw.amount || '0';
139
+ var title = raw.title || '无标题';
140
+ var formattedRawAmt = formatAmount(rawAmt);
141
+ var attachKey = (_raw$attachments = raw.attachments) !== null && _raw$attachments !== void 0 && (_raw$attachments = _raw$attachments[0]) !== null && _raw$attachments !== void 0 && _raw$attachments.id ? "attachment-".concat(raw.attachments[0].id) : voucherKey;
142
+ addSearchItem("raw_".concat(raw.id), "".concat(voucherText, "\uFF5C").concat(title, "\uFF5C\u9644\u4EF6").concat(idx + 1, " | ").concat(formattedRawAmt), formattedRawAmt, attachKey);
143
+ });
144
+ });
145
+ allSearchItems.current = items;
146
+ amountToPageMap.current = pageMap;
147
+ setSearchOptions(items);
148
+ };
149
+ return {
150
+ searchValue: searchValue,
151
+ setSearchValue: setSearchValue,
152
+ searchOptions: searchOptions,
153
+ handleAmountSearch: handleAmountSearch,
154
+ handleGotoPageByAmount: handleGotoPageByAmount,
155
+ handleSearchClear: handleSearchClear,
156
+ buildAllAmountOptions: buildAllAmountOptions
157
+ };
158
+ };
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ interface Props {
3
+ bookRef: React.RefObject<any>;
4
+ currentPageIndex: number;
5
+ totalPages: number;
6
+ setCurrentPageIndex: (index: number) => void;
7
+ }
8
+ export declare function usePageFlip({ bookRef, currentPageIndex, totalPages, setCurrentPageIndex, }: Props): {
9
+ handleFlip: (e: any) => void;
10
+ loadPrevVoucher: () => void;
11
+ loadNextVoucher: () => void;
12
+ goToFirstPage: () => void;
13
+ goToLastPage: () => void;
14
+ };
15
+ export {};
@@ -0,0 +1,61 @@
1
+ import { useCallback } from 'react';
2
+ import { message } from 'antd';
3
+ export function usePageFlip(_ref) {
4
+ var bookRef = _ref.bookRef,
5
+ currentPageIndex = _ref.currentPageIndex,
6
+ totalPages = _ref.totalPages,
7
+ setCurrentPageIndex = _ref.setCurrentPageIndex;
8
+ var isNavigating = useCallback(function () {
9
+ return false;
10
+ }, []);
11
+
12
+ // 上一页
13
+ var loadPrevVoucher = useCallback(function () {
14
+ if (!bookRef.current || currentPageIndex <= 0) {
15
+ message.info('已经是第一页', 1);
16
+ return;
17
+ }
18
+ bookRef.current.pageFlip().flipPrev();
19
+ }, [bookRef, currentPageIndex]);
20
+
21
+ // 下一页 ✅
22
+ var loadNextVoucher = useCallback(function () {
23
+ if (!bookRef.current || currentPageIndex >= totalPages - 1) {
24
+ message.info('已经是最后一页', 1);
25
+ return;
26
+ }
27
+ bookRef.current.pageFlip().flipNext();
28
+ }, [bookRef, currentPageIndex, totalPages]);
29
+
30
+ // 首页
31
+ var goToFirstPage = useCallback(function () {
32
+ if (!bookRef.current) return;
33
+ bookRef.current.pageFlip().turnToPage(0);
34
+ }, [bookRef]);
35
+
36
+ // 尾页
37
+ var goToLastPage = useCallback(function () {
38
+ if (!bookRef.current || totalPages === 0) return;
39
+ var last = totalPages - 1;
40
+ bookRef.current.pageFlip().flip(last, {
41
+ duration: 0
42
+ });
43
+ }, [bookRef, totalPages]);
44
+
45
+ // 翻页事件(这里会自动同步 index)
46
+ var handleFlip = useCallback(function (e) {
47
+ var newPage = e.data;
48
+ if (newPage < 0 || newPage >= totalPages) {
49
+ message.info(newPage < 0 ? '已经是第一页' : '已经是最后一页', 2);
50
+ return;
51
+ }
52
+ setCurrentPageIndex(newPage);
53
+ }, [totalPages, setCurrentPageIndex]);
54
+ return {
55
+ handleFlip: handleFlip,
56
+ loadPrevVoucher: loadPrevVoucher,
57
+ loadNextVoucher: loadNextVoucher,
58
+ goToFirstPage: goToFirstPage,
59
+ goToLastPage: goToLastPage
60
+ };
61
+ }
@@ -1,3 +1,31 @@
1
1
  import React from 'react';
2
- declare const AccountingBook: React.FC;
2
+ import './index.less';
3
+ import 'react-pdf/dist/Page/AnnotationLayer.css';
4
+ import 'react-pdf/dist/Page/TextLayer.css';
5
+ import { StubPage } from './types';
6
+ interface AccountingBookProps {
7
+ data: {
8
+ stub_pages: StubPage[];
9
+ total_page: number;
10
+ };
11
+ loading?: boolean;
12
+ loadingMessage?: string;
13
+ pdfLoading?: boolean;
14
+ companyInfo?: {
15
+ name: string;
16
+ };
17
+ baseVoucherInfo: {
18
+ company: string;
19
+ accountant: string;
20
+ recorder: string;
21
+ maker: string;
22
+ };
23
+ onUnbinding?: () => void;
24
+ onLoadMore?: (nextPage: number) => Promise<void>;
25
+ ledgerBookListApi?: (params: any) => Promise<any>;
26
+ onRefresh?: () => void;
27
+ iconColor?: string;
28
+ themeColor?: string;
29
+ }
30
+ export declare const AccountingBook: React.FC<AccountingBookProps>;
3
31
  export default AccountingBook;