This commit is contained in:
aihe 2024-06-26 23:14:41 +08:00
parent 9ade67d3aa
commit 5663896055
4 changed files with 33 additions and 18 deletions

View File

@ -68,9 +68,8 @@ export default {
} }
prtInstance.setPagePrint() prtInstance.setPagePrint()
let commond = prtInstance.getPrintCmd() let commond = prtInstance.getPrintCmd()
console.log("打印命令组装完成,开始打印=====", commond) console.log("打印命令组装完成,开始打印=====")
printModule.print(commond) printModule.print(commond)
that.showToast('数据发送成功,如果无法打印请重连设备重试')
resolve(true) resolve(true)
// await that.loadPrintProcess() // await that.loadPrintProcess()
// printModule.printTestSimple(deviceId) // printModule.printTestSimple(deviceId)
@ -97,12 +96,20 @@ export default {
if(!Array.isArray(imgsRes)) { if(!Array.isArray(imgsRes)) {
imgsRes = [imgsRes] imgsRes = [imgsRes]
} }
let cBl = false
if(conSta) { if(conSta) {
await this.handlePrint(imgsRes) showLoading('正在发送打印数据..')
return true try{
} else { await this.handlePrint(imgsRes)
return false showToast('数据发送成功,如果无法打印请重连设备重试')
cBl = true
}catch(e){
console.log('callPrint 打印异常=======')
console.error(e)
}
hideLoading()
} }
return cBl
} }
} }
} }

View File

@ -19,7 +19,7 @@
<template v-slot:footer> <template v-slot:footer>
<view class="blcok-white-noradius"> <view class="blcok-white-noradius">
<u-row> <u-row>
<u-button @click="confirmPrint" type="primary" size="large" shape="square" <u-button @click="confirmPrint" :disabled="allImgRes.length == 0" type="primary" size="large" shape="square"
custom-style="height:80rpx;font-size: 30rpx;border-radius: 14rpx;margin: 0 10rpx;">确认打印</u-button> custom-style="height:80rpx;font-size: 30rpx;border-radius: 14rpx;margin: 0 10rpx;">确认打印</u-button>
</u-row> </u-row>
</view> </view>
@ -72,6 +72,7 @@ export default {
imageUrl: [], imageUrl: [],
paperWidth: 600, paperWidth: 600,
show: false, show: false,
allImgRes: []
} }
}, },
mounted () { mounted () {
@ -92,7 +93,7 @@ export default {
}, },
async startPrint({ imageUrl, paperWidth } = {}, preview = true) { async startPrint({ imageUrl, paperWidth } = {}, preview = true) {
this.imageUrl = [] // 每次打印前,清空历史数据 this.imageUrl = [] // 每次打印前,清空历史数据
this.allImgRes = []
// 默认先做预览 // 默认先做预览
if(imageUrl.length > 0) { if(imageUrl.length > 0) {
if(!Array.isArray(imageUrl)){ if(!Array.isArray(imageUrl)){
@ -102,24 +103,30 @@ export default {
this.paperWidth = paperWidth || this.paperWidth this.paperWidth = paperWidth || this.paperWidth
if(preview) { if(preview) {
this.previewModel.show = true this.previewModel.show = true
} else {
this.confirmPrint()
} }
await promiseTimeout(450) // 保证页面节点渲染出来
await this.setAllImgRes()
!preview && this.confirmPrint()
} else { } else {
this.showToast('缺少打印内容') this.showToast('缺少打印内容')
} }
}, },
async confirmPrint(){ setAllImgRes(){
let that = this
let allRes = this.imageUrl.map((url, index)=> { let allRes = this.imageUrl.map((url, index)=> {
// !!!注意:必须修改。 canvas渲染的图必须修改url,否则渲染不出来 // !!!注意:必须修改。 canvas渲染的图必须修改url,否则渲染不出来
url = `${url}?t=${new Date().valueOf()}` url = `${url}?t=${new Date().valueOf()}`
return this.$refs[`curCanvas${index}`][0].renderCanvasImg(url, this.paperWidth) return this.$refs[`curCanvas${index}`][0].renderCanvasImg(url, this.paperWidth)
}) })
Promise.all(allRes).then(async (imgsRes)=> { return Promise.all(allRes).then((imgsRes)=> {
let res = await this.$refs.curPrint.callPrint({ that.allImgRes = imgsRes
imgsRes, return imgsRes
paperWidth: this.paperWidth })
}) },
async confirmPrint(){
let res = await this.$refs.curPrint.callPrint({
imgsRes: this.allImgRes,
paperWidth: this.paperWidth
}) })
}, },
autoConnectCallback(bl){ autoConnectCallback(bl){

View File

@ -3,7 +3,7 @@
"appid" : "__UNI__BCB0FB5", "appid" : "__UNI__BCB0FB5",
"description" : "探路国际速运", "description" : "探路国际速运",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "109", "versionCode" : "1010",
"transformPx" : false, "transformPx" : false,
/* 5+App特有相关 */ /* 5+App特有相关 */
"app-plus" : { "app-plus" : {

View File

@ -46,7 +46,7 @@
</template> </template>
<script> <script>
import { USERKEY } from "@/store/actionKey" import { USERKEY } from "@/store/actionKey"
import { getSessionLoginInfo, setSessionLoginInfo } from "@/session" import { getSessionLoginInfo, setSessionLoginInfo, setSessionXToken } from "@/session"
import { encrypt } from "@/common/libs/jsencrypt_utils" import { encrypt } from "@/common/libs/jsencrypt_utils"
@ -81,6 +81,7 @@
const { submitParams } = this const { submitParams } = this
this.showLoading() this.showLoading()
try{ try{
setSessionXToken() // 登录前先清除xtoke
await this.$store.dispatch(USERKEY.LOGIN, { await this.$store.dispatch(USERKEY.LOGIN, {
...submitParams, ...submitParams,
...(submitParams.isEncrypt ? { ...(submitParams.isEncrypt ? {