<template>
<view>
<button @click="scanCode">扫描</button>
<button @click="printHis">打印医疗废物标签</button>
<button @click="test">测试</button>
</view>
</template>
<script>
const pda5501 = uni.requireNativePlugin("QS-PDA5501")
export default {
data() {
return {
}
},
onLoad() {
pda5501.connect({
checkBlack: true //checkBlack 是黑标检测 默认是开启 间隙纸需要true 非间隙纸 false
}, res => { //初始化成功 打印成功 和 缺纸 还有扫码结果 都在这里回调
var {
type,
result,
msg
} = res;
switch (type) {
case "message":
if (msg == 0) {
/* 0 是打印成功 1 是缺纸 注意这里文字打印成功的时候不回调*/
}
break;
case "scancode":
/*
msg 是扫码的内容
*/
break;
case "connect":
/*
msg=complete 连接外设成功
*/
break;
default:
}
uni.showToast({
icon: "none",
title: JSON.stringify(res)
})
console.log(res)
});
/*
* 关闭
*/
pda5501.close();
},
methods: {
scanCode() {
pda5501.scanCode()
// console.log(123)
},
printHis() {
pda5501.printQRCode({
data: "http://www.baidu.com"
}, result => {
uni.showToast({
title: JSON.stringify(result)
})
});
},
test() {
const ctx = uni.requireNativePlugin("QS-PDA5501-Canvas")
ctx.track(res => {
console.log("track", res)
})
ctx.createCanvasContext({
width: 384,
height: 330,
backgroundColor: "#FFFFFF",
color: "#000000",
textSize: 20
})
var title = "上海华美医院"
ctx.setColor("#000000")
ctx.setTextSize(25)
ctx.setTextAlign("center")
ctx.drawText(title, ctx.getWidth() / 2, 40)
ctx.setTextSize(21)
ctx.setTextAlign("left")
var label = {
"科室": "美容科",
"医废类型": "感染性",
"医废重量": "12 kg",
"收集人": "郑小明",
"时间": "2010-05-11 12:12:44",
}
var x = 180
var y = 100
Object.keys(label).forEach(res => {
ctx.setTextSize(21)
ctx.drawText(res + ": ", x, y)
var pos = ctx.measureText(res + ": ")
ctx.setTextSize(16)
ctx.drawText(label[res], x + pos, y - 2)
y = y + 28
})
ctx.drawQrcode("我是二维码喽", 140, 140, 25, 80)
/*
* 这里获取图片的 base64 直接赋值给 图片的 src 完事了
* 当然你要打印的话 直接用 pda5501.printBitmap({bitmap:base64},res=>{});
*/
this.src = ctx.toDataURL()
pda5501.printBitmap({
bitmap: this.src
}, res => {
console.log(res)
});
}
}
}
</script>
<style>
</style>
最后在点击测试按钮时pda5501.printBitmap 这个方法也返回了正确的日志,但pos机纸并没走和打印内容出来
0 个回复