ソースを参照

升级1.0.5版本

Kevin 6 年 前
コミット
d98159ade8
5 ファイル変更26 行追加12 行削除
  1. BIN
      dll/GetEasy.Node.Printer.64.dll
  2. BIN
      dll/GetEasy.Node.Printer.86.dll
  3. 3 1
      index.d.ts
  4. 22 10
      index.js
  5. 1 1
      package.json

BIN
dll/GetEasy.Node.Printer.64.dll


BIN
dll/GetEasy.Node.Printer.86.dll


+ 3 - 1
index.d.ts

@@ -1,3 +1,4 @@
+declare type SaveCallback = (saveTemplate: string, callback: (result: boolean) => void) => void;
 export default class ReportApi {
     /**
      *设计模板
@@ -6,7 +7,7 @@ export default class ReportApi {
      * @param {string} tempData 临时演示数据
      * @memberof ReportApi
      */
-    static designerReport(template: string, tempData: string, saveCallback: (saveTemplate: string) => boolean): void;
+    static designerReport(template: string, tempData: string, saveCallback: SaveCallback): void;
     /**
      *打印预览
      *
@@ -24,3 +25,4 @@ export default class ReportApi {
      */
     static reportPrinter(fileName: string, jsonData: string): void;
 }
+export {};

+ 22 - 10
index.js

@@ -9,15 +9,11 @@ exports.__esModule = true;
 // designerReport('', true);
 var ffi = require("ffi");
 var os = require("os");
-var cpu = os.arch() === "x64" ? "64" : "86";
-var callback = ffi.Callback('void', ['int', 'string'], function (id, name) {
-    console.log("id: ", id);
-    console.log("name: ", name);
-});
-var dll = ffi.Library(__dirname + "/dll/GetEasy.Node.Printer." + cpu + ".dll", {
-    designerReport: ["void", ["string", "string", "pointer"]],
-    reportShowPreview: ["void", ["string", "string"]],
-    reportPrinter: ["void", ["string", "string"]]
+var cpu = os.arch() === 'x64' ? '64' : '86';
+var dll = ffi.Library(__dirname + '/dll/GetEasy.Node.Printer.' + cpu + '.dll', {
+    designerReport: ['void', ['string', 'string', 'pointer']],
+    reportShowPreview: ['void', ['string', 'string']],
+    reportPrinter: ['void', ['string', 'string']]
 });
 var ReportApi = /** @class */ (function () {
     function ReportApi() {
@@ -30,7 +26,23 @@ var ReportApi = /** @class */ (function () {
      * @memberof ReportApi
      */
     ReportApi.designerReport = function (template, tempData, saveCallback) {
-        var callbackPointer = ffi.Callback('bool', ['string'], 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);
+            }
+        });
         dll.designerReport(template, tempData, callbackPointer);
     };
     /**

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "geteasy.node.printer",
-  "version": "1.0.4",
+  "version": "1.0.5",
   "description": "",
   "main": "index.js",
   "scripts": {