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