服务层
# 介绍
业务逻辑层,建议按示例规则导出两个对象,ExampleService 和 exampleService
- exampleService: 实例化对象,避免资源的重复创建和浪费,提高资源的利用效率,
- ExampleService: 原始的类, 用于继承或 new 新的对象。
# 示例
const { logger } = require('ee-core/log');
/**
* 示例服务
* @class
*/
class ExampleService {
/**
* test
*/
async test (args, event, other) {
const obj = {
status:'ok',
params: args
}
// 主动向前端发请求
// channel 前端ipc.on(),监听的路由
const channel = "controller/example/something"
// controller 传入 event
// IpcMainInvokeEvent
event.reply(channel, {age:21})
// IpcMainEvent
event.sender.send(`${channel}`, {age:21})
return obj;
}
}
ExampleService.toString = () => '[class ExampleService]';
module.exports = {
ExampleService,
exampleService: new ExampleService()
};
上次更新: 2025/04/10, 03:07:49