/** * 打印服务客户端协议类型(与 yh-printer-service/src/shared/protocol.ts 结构对齐)。 * * yh-hiprint 自包含的精简定义,不跨包 import yh-printer-service / yh-report, * 保证 yh-hiprint 单独可用。两端需保持字段一致。 */ /** 打印机状态中文描述 */ export type PrinterStatusText = '空闲' | '打印中' | '已停止' | '错误' | '未知'; /** 单台打印机信息 */ export interface PrinterInfoDTO { /** 系统名(CUPS 队列名),打印时 deviceName 用这个 */ name: string; /** 显示名 */ displayName: string; /** 描述 */ description: string; /** 原始状态码 */ status: number; /** 状态中文描述 */ statusText: PrinterStatusText; /** 是否系统默认打印机 */ isDefault: boolean; /** CUPS PPD 选项(key-value 全量透传) */ options: Record; } /** 打印错误码 */ export type PrintErrorCode = | 'NO_PRINTER' | 'PRINTER_NOT_FOUND' | 'RENDER_ERROR' | 'PRINT_FAILED' | 'INVALID_PARAM' | 'INTERNAL'; /** * 纸张尺寸(毫米)。与服务端 yh-printer-service 的 PageSize 对齐, * 传给 webContents.print 的 pageSize(服务端转微米),避免缩放。 */ export interface PageSize { /** 纸张宽度(mm) */ widthMm: number; /** 纸张高度(mm) */ heightMm: number; } /** 直接打印 HTML 请求载荷(对应 printHtml.data) */ export interface PrintHtmlData { /** 浏览器渲染好的完整 HTML(含样式) */ html: string; /** 指定打印机 name;空则用默认/选中 */ printerName?: string; /** 打印份数,默认 1 */ copies?: number; /** 打印任务名称(打印记录用) */ title?: string; /** 纸张尺寸(mm);未传则用打印机默认纸张 */ pageSize?: PageSize; } /** 打印结果(字段名与服务端 PrintReportFailureData 对齐) */ export interface PrintResult { success: boolean; copies?: number; printer?: string; /** 失败错误码(服务端字段名为 error) */ error?: PrintErrorCode; message?: string; } // ============================== WS 消息帧 ============================== /** 请求消息(客户端 → 服务端) */ export type ClientMessage = | {type: 'getPrinters'; id: string} | {type: 'printHtml'; id: string; data: PrintHtmlData}; /** 响应消息(服务端 → 客户端) */ export type ServerMessage = | {type: 'printers'; id: string; data: {printers: PrinterInfoDTO[]}} | {type: 'printResult'; id: string; data: PrintResult};