2024-07-24 17:32:26 +00:00
|
|
|
<template>
|
|
|
|
|
<!-- 打印预览 -->
|
|
|
|
|
<tpx-dialog
|
|
|
|
|
v-model:show="previewModel.show"
|
|
|
|
|
@onClose="handleCloseModal"
|
|
|
|
|
custom-style="width: 600rpx;padding: 10rpx;"
|
2024-08-01 05:52:44 +00:00
|
|
|
title="预览"
|
2024-07-24 17:32:26 +00:00
|
|
|
>
|
|
|
|
|
<view style="height: calc(75vh);">
|
|
|
|
|
<tpx-layout>
|
|
|
|
|
<template v-slot:header></template>
|
|
|
|
|
<template v-slot:body>
|
|
|
|
|
<view v-for="(imgUrl, index) in imageUrl" class="mb-20">
|
|
|
|
|
<!-- canvas绘图后再显示预览图 -->
|
|
|
|
|
<u-row justify="center" @click="handlePreview(index)">
|
|
|
|
|
<image :src="imgUrl" mode="widthFix" style="max-width: 100%;"></image>
|
|
|
|
|
</u-row>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot:footer>
|
2024-08-01 05:52:44 +00:00
|
|
|
<view v-if="showPrint" class="blcok-white-noradius">
|
2024-07-24 17:32:26 +00:00
|
|
|
<u-row>
|
|
|
|
|
<u-button @click="confirmPrint" type="primary" size="large" shape="square"
|
|
|
|
|
custom-style="height:80rpx;font-size: 30rpx;border-radius: 14rpx;margin: 0 10rpx;">确认打印</u-button>
|
|
|
|
|
</u-row>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
</tpx-layout>
|
|
|
|
|
</view>
|
|
|
|
|
</tpx-dialog>
|
|
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
import { promiseTimeout } from "@/common/untool"
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
props:{
|
2024-08-01 05:52:44 +00:00
|
|
|
showPrint: {
|
|
|
|
|
default () {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-07-24 17:32:26 +00:00
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
previewModel: { show: false },
|
|
|
|
|
imageUrl: []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
|
|
|
|
// Test
|
|
|
|
|
// this.startPrint({ imageUrl: 'https://image-c.weimobwmc.com/ol-6NoX9/ed4f6d5da41f4606811aa8018e2918da.jpg', paperWidth: this.paperWidth })
|
|
|
|
|
},
|
|
|
|
|
unmounted() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handleCloseModal(){
|
2024-08-27 15:56:39 +00:00
|
|
|
this.imageUrl = []
|
2024-07-24 17:32:26 +00:00
|
|
|
},
|
|
|
|
|
handlePreview(index){
|
|
|
|
|
uni.previewImage({
|
|
|
|
|
urls: this.imageUrl,
|
|
|
|
|
current:index
|
|
|
|
|
})
|
|
|
|
|
},
|
2024-08-01 05:52:44 +00:00
|
|
|
async showPreview({ imageUrl } = {}) {
|
2024-07-24 17:32:26 +00:00
|
|
|
this.imageUrl = [] // 每次打印前,清空历史数据
|
|
|
|
|
// 默认先做预览
|
|
|
|
|
if(imageUrl.length > 0) {
|
|
|
|
|
if(!Array.isArray(imageUrl)){
|
|
|
|
|
imageUrl = [imageUrl]
|
|
|
|
|
}
|
|
|
|
|
this.imageUrl = imageUrl
|
|
|
|
|
this.previewModel.show = true
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-08-08 16:35:12 +00:00
|
|
|
async confirmPrint(opt = { }){
|
|
|
|
|
let { imageUrl, prtCmdData } = opt
|
|
|
|
|
imageUrl = imageUrl || this.imageUrl || []
|
2024-08-08 17:05:36 +00:00
|
|
|
prtCmdData = encodeURIComponent(prtCmdData || '')
|
2024-08-08 16:35:12 +00:00
|
|
|
if(imageUrl.length == 0 && !prtCmdData) {
|
|
|
|
|
this.showToast('缺少打印内容')
|
2024-07-24 17:32:26 +00:00
|
|
|
} else {
|
2024-08-08 16:35:12 +00:00
|
|
|
this.goto(`print/bluetoothPrinter?imageUrl=${imageUrl.join(",")}&prtCmdData=${prtCmdData}`)
|
2024-07-24 17:32:26 +00:00
|
|
|
}
|
2024-08-01 05:52:44 +00:00
|
|
|
},
|
2024-07-24 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
|
|
|
|
</style>
|