printServer/services/printerComponent.js
2026-03-29 13:26:23 +08:00

36 lines
1.0 KiB
JavaScript

import service from '../core/BaseService.js';
class PrinterComponentService extends service {
constructor() {
super();
this.getAll = this.getAll.bind(this); // 确保上下文绑定
this.getStatus = this.getStatus.bind(this);
}
// 获取所有打印组件
getAll() {
const { app } = this;
if (app && app.printerComponents) {
const components = app.printerComponents.getAllPorts();
const status = app.printerComponents.getAllStatus();
return { components, status };
}
// 默认返回静态数据
return { components: this.components, status: this.components.map(c => ({ name: c.name, status: c.status })) };
}
// 获取指定组件状态
getStatus(name) {
const { app } = this;
if (app && app.printerComponents) {
return app.printerComponents.getStatus(name);
}
const comp = this.components.find(c => c.name === name);
return comp ? comp.status : '未知';
}
// 可扩展:添加、删除、更新组件等
}
export default new PrinterComponentService();