From fd3cd5cfdbc55618c2de1ed7c0df06d2beb087be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=93=86=E5=95=A6=E5=A5=BD=E6=A2=A6?= <530353222@qq.com> Date: Tue, 16 May 2023 14:00:37 +0800 Subject: [PATCH] example --- electron/controller/example.js | 37 ++++++++++++++++++++++++++++++++++ electron/service/example.js | 29 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 electron/controller/example.js create mode 100644 electron/service/example.js diff --git a/electron/controller/example.js b/electron/controller/example.js new file mode 100644 index 0000000..cb0c0f8 --- /dev/null +++ b/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; \ No newline at end of file diff --git a/electron/service/example.js b/electron/service/example.js new file mode 100644 index 0000000..99a81c3 --- /dev/null +++ b/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; \ No newline at end of file