emis-app/components/tpx-bluetooth-print/tpx-bluetooth-print.vue

118 lines
2.7 KiB
Vue
Raw Normal View History

2024-05-10 14:32:39 +00:00
<template>
2024-06-24 18:19:58 +00:00
<!-- 打印预览 -->
<tpx-dialog
v-model:show="previewModel.show"
@onClose="handleCloseModal"
custom-style="width: 600rpx;padding: 10rpx;"
title="打印预览"
>
<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">
<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>
<view class="blcok-white-noradius">
<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>
<!-- 打印+蓝牙连接 -->
<tpx-dialog
v-model:show="printModel.show"
@onClose="handleCloseModal"
custom-style="width: 600rpx;padding: 10rpx;"
title="打印设备"
>
<view style="height: calc(75vh);">
<render-template ref="curPrint" @autoConnectCallback="autoConnectCallback"></render-template>
</view>
</tpx-dialog>
2024-05-12 03:18:44 +00:00
2024-05-10 14:32:39 +00:00
</template>
<script>
2024-06-23 07:32:32 +00:00
import RenderTemplate from "./render-template-native"
2024-05-13 09:47:19 +00:00
import { promiseTimeout } from "@/common/untool"
2024-05-12 03:18:44 +00:00
2024-05-10 14:32:39 +00:00
export default {
2024-05-11 05:11:46 +00:00
props:{
2024-06-24 18:19:58 +00:00
2024-05-11 05:11:46 +00:00
},
2024-05-10 14:32:39 +00:00
computed: {
2024-05-12 12:49:00 +00:00
},
components: {
RenderTemplate, RenderTemplate
2024-05-10 14:32:39 +00:00
},
data () {
return {
2024-06-24 18:19:58 +00:00
previewModel: { show: false },
printModel: { show: false },
imageUrl: [],
2024-06-24 18:35:58 +00:00
paperWidth: 480,
2024-05-12 12:49:00 +00:00
show: false,
2024-05-10 14:32:39 +00:00
}
},
mounted () {
2024-06-23 07:56:29 +00:00
// Test
// this.startPrint({ imageUrl: 'https://image-c.weimobwmc.com/ol-6NoX9/ed4f6d5da41f4606811aa8018e2918da.jpg', paperWidth: this.paperWidth })
2024-05-10 14:32:39 +00:00
},
unmounted() {
2024-05-12 12:49:00 +00:00
2024-05-10 14:32:39 +00:00
},
methods: {
2024-05-12 12:49:00 +00:00
handleCloseModal(){
2024-05-10 15:33:45 +00:00
},
2024-06-24 18:19:58 +00:00
handlePreview(index){
uni.previewImage({
urls: this.imageUrl,
current:index
})
},
async startPrint({ imageUrl, paperWidth } = {}, preview = true) {
// 默认先做预览
2024-05-12 12:49:00 +00:00
if(imageUrl.length > 0) {
2024-06-24 18:19:58 +00:00
if(!Array.isArray(imageUrl)){
imageUrl = [imageUrl]
2024-05-12 03:18:44 +00:00
}
2024-05-12 12:49:00 +00:00
this.imageUrl = imageUrl
2024-06-23 07:32:32 +00:00
this.paperWidth = paperWidth || this.paperWidth
2024-06-24 18:19:58 +00:00
if(preview) {
this.previewModel.show = true
} else {
this.confirmPrint()
}
2024-05-12 12:49:00 +00:00
} else {
this.showToast('缺少打印内容')
2024-05-10 14:32:39 +00:00
}
2024-06-24 18:19:58 +00:00
},
async confirmPrint(){
let res = await this.$refs.curPrint.callPrint({
imageUrl: this.imageUrl[0],
paperWidth: this.paperWidth
})
},
autoConnectCallback(bl){
// 如果打印设备连接失败 需要显示打印设备弹框
this.printModel.show = !bl
2024-05-10 14:32:39 +00:00
}
}
}
</script>
<style scoped lang="scss">
2024-05-12 12:49:00 +00:00
2024-05-10 14:32:39 +00:00
</style>