liufumingren 561cd27f81 初始化
2026-07-25 00:46:47 +08:00

45 lines
1007 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const Service = require('egg').Service;
/**
* 通用方法调度服务
* method 固定为 workbench.business,name 为变量入参
*/
class SystemService extends Service {
/**
* 调度入口
* @param {string} name - 操作名称
* @param {object} data - 请求数据
*/
async dispatch(name, data) {
const { ctx } = this;
// method 固定为 workbench.business,调用 workbench service
if (ctx.service.workbench) {
return await this._callService(ctx.service.workbench, name, data);
}
return {
success: false,
message: `workbench 服务未实现`,
};
}
/**
* 调用 service 实例上的指定方法
*/
async _callService(serviceInstance, name, data) {
if (!serviceInstance || typeof serviceInstance[name] !== 'function') {
return {
success: false,
message: `方法 ${name} 不存在`,
};
}
return await serviceInstance[name](data);
}
}
module.exports = SystemService;