/** * 打印标签示例 * @param {Object} pinrter 打印机对象 * @param {Object} printConent 需打印的内容 * deviceCode:设备 * shift 班次 * materialCode 编码 * partNumber 名称 * batchNo 批次号 * prepareDate 生产日期 2021.3.19 * num 数量 * prepareUserName 操作人员 * state 检验状态 合格/不合格 * qrcodeContent 条码中的内容 * barcode 条码编号 */ export function printLabel(printer, content) { let title = '标签demo'; printer.print(80, 122, command => { //设置标题 command.setVerticalText(80 + 10, 24, title, { xScale: 2 }); // 创建盒子 command.setBox(2, 2, 80, 80); //绘制分割线分割左边的内容区域和右边的二维码区域 command.setBar(2, 40, 62.5); //第一列分隔线 command.setBar(2, 14, 62.5); // 第一行内容 设备\班次 command.setVerticalText(80 - 80 * 0.0466, 6, '设备'); command.setVerticalText(80 - 80 * 0.0466, 15, content.deviceCode); command.setBar(80 - 80 * 0.0466 * 3, 25, 80 * 0.0466 * 3 - 1.5); command.setVerticalText(80 - 80 * 0.0466, 26, '班次'); command.setBar(80 - 80 * 0.0466 * 3, 32, 80 * 0.0466 * 3 - 1.5); command.setVerticalText(80 - 80 * 0.0466, 34, content.shift); //line command.setBar(80 - 80 * 0.0466 * 3, 2, 0.5, 46); var t = 80 - 80 * 0.0466 * 3; // 第二行内容 编码 command.setVerticalText(t - 80 * 0.04, 4.5, '编码'); command.setVerticalText(t - 80 * 0.04, 20, content.materialCode); //line command.setBar(t - 80 * 0.12, 2, 0.5, 46); t = t - 80 * 0.12; // 第三行内容 名称 command.setVerticalText(t - 80 * 0.04, 4.5, '名称'); command.setVerticalText(t - 80 * 0.04, 20, content.partNumber); //line command.setBar(t - 80 * 0.12, 2, 0.5, 46); t = t - 80 * 0.12; // 第四行内容 批次 command.setVerticalText(t - 80 * 0.04, 6, '批次'); command.setVerticalText(t - 80 * 0.04, 20, content.batchNo); //line command.setBar(t - 80 * 0.12, 2, 0.5, 46); t = t - 80 * 0.12; // 第五行内容 生产日期 command.setVerticalText(t - 80 * 0.04, 3, '生产日期'); command.setVerticalText(t - 80 * 0.04, 16, content.prepareDate, { yScale: 2 }); //line command.setBar(t - 80 * 0.12, 2, 0.5, 46); t = t - 80 * 0.12; // 第六行内容 数量 command.setVerticalText(t - 80 * 0.06, 6, '数量'); command.setVerticalText(t - 80 * 0.06, 16, content.num); //line command.setBar(t - 80 * 0.18, 2, 0.5, 26.5); t = t - 80 * 0.18; // 第七行内容 操作人员 command.setVerticalText(t - 80 * 0.06, 3, '操作人员'); command.setVerticalText(t - 80 * 0.06, 15, content.prepareUserName); // 合格标识 command.setBar(2, 24, 23); if (content.state.length === 2) { command.setVerticalText(80 * 0.18 + 80 * 0.06, 27, content.state, { xScale: 2, yScale: 2 }); } else if (content.state.length === 3) { command.setVerticalText(80 * 0.18 + 80 * 0.06, 24.5, content.state, { xScale: 2, yScale: 2 }); } // 二维码 command.setQrCode(19, 42, content.qrcodeContent, 14); command.setVerticalText(17, 45, content.barcode, { xScale: 2, yScale: 2 }); }); }