服务层
# 介绍
业务逻辑层(单例模式)
# 示例
const { Service } = require('ee-core');
const Services = require('ee-core/services');
/**
* 示例服务
* @class
*/
class ExampleService extends Service {
constructor(ctx) {
super(ctx);
}
/**
* test
*/
async test (args, event) {
let obj = {
status:'ok',
params: args
}
// 调用其它service
Services.get('framework').test('egg');
// 主动向前端发请求
// 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;
上次更新: 2024/09/26, 03:25:03