uu
This commit is contained in:
parent
ba0625f368
commit
54faa1a8d2
@ -26,6 +26,7 @@ import { showLoading, showToast, hideLoading, canvasGetImageData, getImageInfo,
|
||||
import * as canvasUtil from "@/common/canvasUtil"
|
||||
import tanexPrinterUniSdk from './nativePrint/tanexPrinterUniSdk'
|
||||
import printModule from './nativePrint/print'
|
||||
import dayjs from "dayjs"
|
||||
|
||||
export default {
|
||||
props:{
|
||||
@ -52,7 +53,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async initData() {
|
||||
await this.renderCanvasImg(this.imageUrl);
|
||||
this.imageUrl && await this.renderCanvasImg(this.imageUrl);
|
||||
},
|
||||
// 打印
|
||||
handlePrint(){
|
||||
@ -81,11 +82,8 @@ export default {
|
||||
console.log("===renderCanvasImg:filePath=====", filePath)
|
||||
return new Promise(async (resolve, reject)=> {
|
||||
try{
|
||||
// 多次渲染,createCanvasContext,必须使用新的才可以
|
||||
that.canvasId = uni.$u.guid(20)
|
||||
await promiseTimeout(500)
|
||||
let res = await getImageInfo(filePath)
|
||||
console.log("getImageInfo res====", res)
|
||||
console.log("getImageInfo res====", res)
|
||||
const ctx = uni.createCanvasContext(that.canvasId, that);
|
||||
// 打印宽度须是8的整数倍,这里处理掉多余的,使得宽度合适,不然有可能乱码
|
||||
const remainder = that.paperWidth % 8;
|
||||
@ -102,15 +100,19 @@ export default {
|
||||
ctx.fillRect(...ctData);
|
||||
// 把原图缩放到 打印宽度的比例 绘制
|
||||
ctx.drawImage(filePath, ...ctData);
|
||||
|
||||
ctx.draw(false, async() => {
|
||||
await promiseTimeout(1000)
|
||||
// await promiseTimeout(1000)
|
||||
let imgData = await canvasGetImageData({ canvasId: that.canvasId, width: w, height: h, })
|
||||
hideLoading()
|
||||
that.imgData = imgData
|
||||
console.log("canvasGetImageData imgData.data.length =====", imgData.data.length)
|
||||
// 多次渲染,createCanvasContext,必须使用新的才可以
|
||||
that.canvasId = uni.$u.guid(20)
|
||||
resolve()
|
||||
});
|
||||
}catch(e){
|
||||
// 多次渲染,createCanvasContext,必须使用新的才可以
|
||||
that.canvasId = uni.$u.guid(20)
|
||||
hideLoading()
|
||||
reject(e)
|
||||
}
|
||||
@ -140,7 +142,7 @@ export default {
|
||||
}
|
||||
let conSta = await this.$refs.curBlueTooth.autoConnect()
|
||||
if(conSta) {
|
||||
await this.handlePrint()
|
||||
// await this.handlePrint()
|
||||
return true
|
||||
}
|
||||
} catch(e){
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
<script>
|
||||
|
||||
import RenderTemplate from "./render-template"
|
||||
import RenderTemplate from "./render-template-native"
|
||||
import { promiseTimeout } from "@/common/untool"
|
||||
|
||||
export default {
|
||||
@ -42,12 +42,13 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
imageUrl: '',
|
||||
paperWidth: 320,
|
||||
// paperWidth: 72,
|
||||
paperWidth: 560,
|
||||
show: false,
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
|
||||
this.startPrint({ imageUrl: 'https://image-c.weimobwmc.com/ol-6NoX9/ed4f6d5da41f4606811aa8018e2918da.jpg', paperWidth: this.paperWidth })
|
||||
},
|
||||
unmounted() {
|
||||
|
||||
@ -63,9 +64,8 @@ export default {
|
||||
imageUrl = imageUrl[0]
|
||||
}
|
||||
this.imageUrl = imageUrl
|
||||
this.paperWidth = paperWidth
|
||||
this.paperWidth = paperWidth || this.paperWidth
|
||||
this.show = true
|
||||
await promiseTimeout(1000)
|
||||
let res = await this.$refs.curPrint.callPrint({
|
||||
imageUrl,
|
||||
paperWidth
|
||||
|
||||
@ -207,7 +207,6 @@
|
||||
const imgUrls = await this.getPrintImages()
|
||||
this.$refs.curPrint.startPrint({
|
||||
imageUrl: imgUrls.filter(v=> !!v),
|
||||
paperWidth: 480,
|
||||
})
|
||||
},
|
||||
handleSelAll() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user