Kevin 4 роки тому
батько
коміт
3c17bfd311
1 змінених файлів з 39 додано та 21 видалено
  1. 39 21
      GetEasy.Node.Printer/index.js

+ 39 - 21
GetEasy.Node.Printer/index.js

@@ -18,10 +18,13 @@ var dllPath = path.join(execDir, dllName);
 if (!fs.existsSync(dllPath)) {
     dllPath = path.join(__dirname, 'dll', dllName);
 }
+var callbackPointer;
 var dll = ffi.Library(dllPath, {
-    designerReport: ['void', ['string', 'string', 'pointer']],
+    designerReport: ['void', ['string', 'string']],
     reportShowPreview: ['void', ['string', 'string']],
-    reportPrinter: ['void', ['string', 'string']]
+    reportPrinter: ['void', ['string', 'string', 'bool']],
+    reportToImage: ['string', ['string', 'string']],
+    waitSaveOrClose: ['void', ['pointer']]
 });
 var ReportApi = /** @class */ (function () {
     function ReportApi() {
@@ -34,24 +37,29 @@ var ReportApi = /** @class */ (function () {
      * @memberof ReportApi
      */
     ReportApi.designerReport = function (template, tempData, saveCallback) {
-        var callbackPointer = ffi.Callback('void', ['string', 'pointer'], function (data, func) {
-            var nativeCallback = ffi.ForeignFunction(func, 'void', ['bool']);
-            try {
-                saveCallback(data, function (result) {
-                    if (result) {
-                        nativeCallback(true);
-                    }
-                    else {
-                        nativeCallback(false);
-                    }
-                });
-            }
-            catch (e) {
-                console.error(e);
-                nativeCallback(false);
+        callbackPointer = ffi.Callback('void', ['string', 'pointer'], function (data, func) {
+            if (data) {
+                var nativeCallback_1 = ffi.ForeignFunction(func, 'void', ['bool']);
+                try {
+                    saveCallback(data, function (result) {
+                        if (result) {
+                            nativeCallback_1(true);
+                        }
+                        else {
+                            nativeCallback_1(false);
+                        }
+                        dll.waitSaveOrClose(callbackPointer);
+                    });
+                }
+                catch (e) {
+                    console.error(e);
+                    nativeCallback_1(false);
+                    dll.waitSaveOrClose(callbackPointer);
+                }
             }
         });
-        dll.designerReport(template, tempData, callbackPointer);
+        dll.designerReport(template, tempData);
+        dll.waitSaveOrClose(callbackPointer);
     };
     /**
      *打印预览
@@ -70,9 +78,19 @@ var ReportApi = /** @class */ (function () {
      * @param {string} jsonData 数据
      * @memberof ReportApi
      */
-    ReportApi.reportPrinter = function (fileName, jsonData) {
-        dll.reportPrinter(fileName, jsonData);
+    ReportApi.reportPrinter = function (fileName, jsonData, isSelectPrinter) {
+        dll.reportPrinter(fileName, jsonData, isSelectPrinter);
+    };
+    /**
+     * 打印到图片(返回base64图片)
+     *
+     * @param {string} fileName 模板路径
+     * @param {string} jsonData 数据
+     * @memberof ReportApi
+     */
+    ReportApi.reportToImage = function (fileName, jsonData) {
+        return dll.reportToImage(fileName, jsonData);
     };
     return ReportApi;
 }());
-exports["default"] = ReportApi;
+exports["default"] = ReportApi;