28 lines
920 B
JavaScript
28 lines
920 B
JavaScript
import BaseController from '../core/BaseController.js';
|
|
|
|
class PrinterController extends BaseController {
|
|
constructor(ctx) {
|
|
super(ctx);
|
|
}
|
|
|
|
async getPrinters() {
|
|
try {
|
|
const printers = await this.app.services.printer.getWindowsPrinters();
|
|
this.ctx.res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
this.ctx.res.end(JSON.stringify({ printers }));
|
|
} catch (err) {
|
|
this.ctx.res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
this.ctx.res.end(JSON.stringify({ error: '获取打印机列表失败', detail: err.message }));
|
|
}
|
|
}
|
|
|
|
componentList() {
|
|
const components = this.app.printerComponents.getAllPorts();
|
|
const status = this.app.printerComponents.getAllStatus();
|
|
this.ctx.res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
this.ctx.res.end(JSON.stringify({ components, status }));
|
|
}
|
|
}
|
|
|
|
export default PrinterController;
|