index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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-napi");
  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 dll = ffi.Library(dllPath, {
  22. designerReport: ['void', ['string', 'string', 'pointer']],
  23. reportShowPreview: ['void', ['string', 'string']],
  24. reportPrinter: ['void', ['string', 'string']]
  25. });
  26. var ReportApi = /** @class */ (function () {
  27. function ReportApi() {
  28. }
  29. /**
  30. *设计模板
  31. *
  32. * @param {string} fileName 模板
  33. * @param {string} tempData 临时演示数据
  34. * @memberof ReportApi
  35. */
  36. ReportApi.designerReport = function (template, tempData, saveCallback) {
  37. var callbackPointer = ffi.Callback('void', ['string', 'pointer'], function (data, func) {
  38. var nativeCallback = ffi.ForeignFunction(func, 'void', ['bool']);
  39. try {
  40. saveCallback(data, function (result) {
  41. if (result) {
  42. nativeCallback(true);
  43. }
  44. else {
  45. nativeCallback(false);
  46. }
  47. });
  48. }
  49. catch (e) {
  50. console.error(e);
  51. nativeCallback(false);
  52. }
  53. });
  54. dll.designerReport(template, tempData, callbackPointer);
  55. };
  56. /**
  57. *打印预览
  58. *
  59. * @param {string} fileName 模板路径
  60. * @param {string} jsonData 数据
  61. * @memberof ReportApi
  62. */
  63. ReportApi.reportShowPreview = function (fileName, jsonData) {
  64. dll.reportShowPreview(fileName, jsonData);
  65. };
  66. /**
  67. *打印
  68. *
  69. * @param {string} fileName 模板路径
  70. * @param {string} jsonData 数据
  71. * @memberof ReportApi
  72. */
  73. ReportApi.reportPrinter = function (fileName, jsonData) {
  74. dll.reportPrinter(fileName, jsonData);
  75. };
  76. return ReportApi;
  77. }());
  78. exports["default"] = ReportApi;
  79. ReportApi.designerReport(null, null, function (data, callback) {
  80. callback(false);
  81. });