index.js 2.4 KB

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