index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 cpu = os.arch() === 'x64' ? '64' : '86';
  13. var dll = ffi.Library(__dirname + '/dll/GetEasy.Node.Printer.' + cpu + '.dll', {
  14. designerReport: ['void', ['string', 'string', 'pointer']],
  15. reportShowPreview: ['void', ['string', 'string']],
  16. reportPrinter: ['void', ['string', 'string']]
  17. });
  18. var ReportApi = /** @class */ (function () {
  19. function ReportApi() {
  20. }
  21. /**
  22. *设计模板
  23. *
  24. * @param {string} fileName 模板
  25. * @param {string} tempData 临时演示数据
  26. * @memberof ReportApi
  27. */
  28. ReportApi.designerReport = function (template, tempData, saveCallback) {
  29. var callbackPointer = ffi.Callback('void', ['string', 'pointer'], function (data, func) {
  30. var nativeCallback = ffi.ForeignFunction(func, 'void', ['bool']);
  31. try {
  32. saveCallback(data, function (result) {
  33. if (result) {
  34. nativeCallback(true);
  35. }
  36. else {
  37. nativeCallback(false);
  38. }
  39. });
  40. }
  41. catch (e) {
  42. console.error(e);
  43. nativeCallback(false);
  44. }
  45. });
  46. dll.designerReport(template, tempData, callbackPointer);
  47. };
  48. /**
  49. *打印预览
  50. *
  51. * @param {string} fileName 模板路径
  52. * @param {string} jsonData 数据
  53. * @memberof ReportApi
  54. */
  55. ReportApi.reportShowPreview = function (fileName, jsonData) {
  56. dll.reportPrinter(fileName, jsonData);
  57. };
  58. /**
  59. *打印
  60. *
  61. * @param {string} fileName 模板路径
  62. * @param {string} jsonData 数据
  63. * @memberof ReportApi
  64. */
  65. ReportApi.reportPrinter = function (fileName, jsonData) {
  66. dll.reportPrinter(fileName, jsonData);
  67. };
  68. return ReportApi;
  69. }());
  70. exports["default"] = ReportApi;