index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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', 'bool']],
  26. ReportToImage: ['string', ['string', 'string']],
  27. waitSaveOrClose: ['void', ['pointer']]
  28. });
  29. var ReportApi = /** @class */ (function () {
  30. function ReportApi() {
  31. }
  32. /**
  33. *设计模板
  34. *
  35. * @param {string} fileName 模板
  36. * @param {string} tempData 临时演示数据
  37. * @memberof ReportApi
  38. */
  39. ReportApi.designerReport = function (template, tempData, saveCallback) {
  40. callbackPointer = ffi.Callback('void', ['string', 'pointer'], function (data, func) {
  41. if (data) {
  42. var nativeCallback_1 = ffi.ForeignFunction(func, 'void', ['bool']);
  43. try {
  44. saveCallback(data, function (result) {
  45. if (result) {
  46. nativeCallback_1(true);
  47. }
  48. else {
  49. nativeCallback_1(false);
  50. }
  51. dll.waitSaveOrClose(callbackPointer);
  52. });
  53. }
  54. catch (e) {
  55. console.error(e);
  56. nativeCallback_1(false);
  57. dll.waitSaveOrClose(callbackPointer);
  58. }
  59. }
  60. });
  61. dll.designerReport(template, tempData);
  62. dll.waitSaveOrClose(callbackPointer);
  63. };
  64. /**
  65. *打印预览
  66. *
  67. * @param {string} fileName 模板路径
  68. * @param {string} jsonData 数据
  69. * @memberof ReportApi
  70. */
  71. ReportApi.reportShowPreview = function (fileName, jsonData) {
  72. dll.reportShowPreview(fileName, jsonData);
  73. };
  74. /**
  75. *打印
  76. *
  77. * @param {string} fileName 模板路径
  78. * @param {string} jsonData 数据
  79. * @memberof ReportApi
  80. */
  81. ReportApi.reportPrinter = function (fileName, jsonData, isSelectPrinter) {
  82. dll.reportPrinter(fileName, jsonData, isSelectPrinter);
  83. };
  84. /**
  85. * 打印到图片(返回base64图片)
  86. *
  87. * @param {string} fileName 模板路径
  88. * @param {string} jsonData 数据
  89. * @memberof ReportApi
  90. */
  91. ReportApi.reportToImage = function (fileName, jsonData) {
  92. return dll.reportToImage(fileName, jsonData);
  93. };
  94. return ReportApi;
  95. }());
  96. exports["default"] = ReportApi;