哆啦好梦 il y a 2 ans
Parent
commit
fd3cd5cfdb
2 fichiers modifiés avec 66 ajouts et 0 suppressions
  1. 37 0
      electron/controller/example.js
  2. 29 0
      electron/service/example.js

+ 37 - 0
electron/controller/example.js

@@ -0,0 +1,37 @@
+'use strict';
+
+const { Controller } = require('ee-core');
+const Log = require('ee-core/log');
+
+/**
+ * example
+ * @class
+ */
+class ExampleController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+  }
+
+
+  /**
+   * 所有方法接收两个参数
+   * @param args 前端传的参数
+   * @param event - ipc通信时才有值。详情见:控制器文档
+   */
+
+  /**
+   * test
+   */
+  async test () {
+    const result = await this.service.example.test('electron');
+
+    let tmpDir = Ps.getLogDir();
+    Log.info('tmpDir:', tmpDir);
+
+    return result;
+  }
+}
+
+ExampleController.toString = () => '[class ExampleController]';
+module.exports = ExampleController;  

+ 29 - 0
electron/service/example.js

@@ -0,0 +1,29 @@
+'use strict';
+
+const { Service } = require('ee-core');
+
+/**
+ * 示例服务(service层为单例)
+ * @class
+ */
+class ExampleService extends Service {
+
+  constructor(ctx) {
+    super(ctx);
+  }
+
+  /**
+   * test
+   */
+  async test(args) {
+    let obj = {
+      status:'ok',
+      params: args
+    }
+
+    return obj;
+  }
+}
+
+ExampleService.toString = () => '[class ExampleService]';
+module.exports = ExampleService;