index.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. // import * as edge from 'edge-js';
  3. exports.__esModule = true;
  4. // let designerReport = edge.func({
  5. // assemblyFile: 'lib/GetEasy.Node.Printer.dll',
  6. // typeName: 'GetEasy.Node.Printer.NodeReportDesigner',
  7. // methodName: 'DesignerReport'
  8. // });
  9. // designerReport('', true);
  10. var ffi = require("ffi");
  11. var os = require("os");
  12. var fs = require("fs");
  13. var path = require("path");
  14. var cpu = os.arch() === 'x64' ? '64' : '86';
  15. var dllName = 'GetEasy.Node.Printer.' + cpu + '.dll';
  16. var execDir = path.dirname(process.execPath);
  17. var dllPath = path.join(execDir, dllName);
  18. if (!fs.existsSync(dllPath)) {
  19. dllPath = path.join(__dirname, 'dll', dllName);
  20. }
  21. var callbackPointer;
  22. var dll = ffi.Library(dllPath, {
  23. designerReport: ['void', ['string', 'string']],
  24. reportShowPreview: ['void', ['string', 'string']],
  25. reportPrinter: ['void', ['string', 'string']],
  26. waitSaveOrClose: ['void', ['pointer']]
  27. });
  28. var ReportApi = /** @class */ (function () {
  29. function ReportApi() {
  30. }
  31. /**
  32. *设计模板
  33. *
  34. * @param {string} fileName 模板
  35. * @param {string} tempData 临时演示数据
  36. * @memberof ReportApi
  37. */
  38. ReportApi.designerReport = function (template, tempData, saveCallback) {
  39. callbackPointer = ffi.Callback('void', ['string', 'pointer'], function (data, func) {
  40. if (data) {
  41. var nativeCallback_1 = ffi.ForeignFunction(func, 'void', ['bool']);
  42. try {
  43. saveCallback(data, function (result) {
  44. if (result) {
  45. nativeCallback_1(true);
  46. }
  47. else {
  48. nativeCallback_1(false);
  49. }
  50. dll.waitSaveOrClose(callbackPointer);
  51. });
  52. }
  53. catch (e) {
  54. console.error(e);
  55. nativeCallback_1(false);
  56. dll.waitSaveOrClose(callbackPointer);
  57. }
  58. }
  59. });
  60. dll.designerReport(template, tempData);
  61. dll.waitSaveOrClose(callbackPointer);
  62. };
  63. /**
  64. *打印预览
  65. *
  66. * @param {string} fileName 模板路径
  67. * @param {string} jsonData 数据
  68. * @memberof ReportApi
  69. */
  70. ReportApi.reportShowPreview = function (fileName, jsonData) {
  71. dll.reportShowPreview(fileName, jsonData);
  72. };
  73. /**
  74. *打印
  75. *
  76. * @param {string} fileName 模板路径
  77. * @param {string} jsonData 数据
  78. * @memberof ReportApi
  79. */
  80. ReportApi.reportPrinter = function (fileName, jsonData) {
  81. dll.reportPrinter(fileName, jsonData);
  82. };
  83. return ReportApi;
  84. }());
  85. exports["default"] = ReportApi;