GitBucket
4.23.0
Toggle navigation
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
hanfei
/
VueSharedPrinting
Browse code
han
master
1 parent
f4b2604
commit
df84b0896acd81c130003d40723b625a445c9389
hanfei
authored
on 22 Jan 2024
Patch
Showing
3 changed files
src/components/global.vue
src/components/top.vue
src/utils/cite.js
Ignore Space
Show notes
View
src/components/global.vue
<template> <div> <!-- 打印中提示--> <div class="dyzTip" v-show="DYZshow"> <div class="curtain"></div> <div class="content"> <img src="../assets/printing.png" alt=""> <div class="name">正在进行{{ listData.printFileType=='PDF'?'文档':'照片' }}打印...</div> <!-- <div class="flex-center">{{ listData.printFileName }}</div>--> <div class="flex-center">{{ cite.selectedFile.length||1 }}/{{ cite.fileNum||1 }}</div> </div> </div> <!-- 提示--> <div class="tkTip flex-center" v-if="state.sta"> <div>{{ state.name }}</div> </div> <!-- 小程序支付--> <div class="dyzTip" v-if="zfShow"> <div class="curtain"></div> <div class="content content2"> <VueQr v-show="src" :auto-color="true" :dot-scale="1" :logo-src="require('@/assets/logo.png')" :logoMargin="0" :logoScale=".2" :margin="0" :size="300" :text="src" logoBackgroundColor="white"></VueQr> <p> <img @click="onChange('zfShow',false)" class="icon" src="../assets/demo10.png" alt=""> </p> </div> </div> </div> </template> <script> import mqtt from "mqtt/dist/mqtt" import {getAdvertisement, getDeviceByCode} from "@/api/resultApi"; import VueQr from 'vue-qr' import {apiPrint, getDeviceCode, readDownload} from "@/api/bdResultApi"; export default { name: "global", components: { VueQr }, data() { return { client: null, code: '', listData: '', DYZshow: false, // 是否显示打印中 downloadPath: 'D:\\TZDYSHARE\\TEMPFILES\\', state: '', src: '', zfShow: false, }; }, created() { this.toLoad() }, methods: { onChange(name,val){ this[name] = val }, toLoad() { // this.cite.code = 'SNJ-XX-EPSON-X001-00001' // this.code = 'SNJ-XX-EPSON-X001-00001' // this.load() getDeviceCode().then(res =>{ this.cite.code = res.data this.code = res.data this.load() }) }, load() { // 获取名为code的查询参数值 // if (this.cite.code === "") { // this.code = this.$route.query.code; // this.cite.code = this.code; // }else{ // this.code = this.cite.code; // } if (this.cite.facility === "") { this.getDeviceByCode(); } // 判断是否是广告屏 // console.log(this.cite) if(this.cite.name != 'advertising') { this.initMqtt() setInterval(()=>{ if(!this.state.sta&&this.cite.state.sta) { setTimeout(()=>{ this.cite.state.sta = false },3000) } this.state = this.cite.state },1000) } }, initMqtt() { // 连接配置选项 let options = { connectTimeout: 4000, // 超时时间 // 认证信息 clientId: '', //不填默认随机生成一个ID username: 'admin', //用户名 password: 'public' //密码 } this.client = mqtt.connect('wss://mps.xlmalls.com:8084/mqtt', options) //调用连接的api //连接成功 this.client.on('connect', (e) => { console.log('连接成功', e) this.subscribes() }) //重连提醒 this.client.on('reconnect', (error) => { console.log('正在重连', error) }) //连接失败提醒 this.client.on('error', (error) => { console.log('连接失败', error) }) //接收消息 this.client.on('message', (topic, message) => { const data = JSON.parse(message) //接受到控制信号的数据 console.log('接收消息',data) if(data.cmd=='ORDER_INFO') { //小程序支付 this.cite.url = data.payCodeUrl if(this.cite.selectedFile.length<1) { this.src = data.payCodeUrl this.zfShow=true } }else if(data.cmd=='LOGIN') { //登录 if(this.cite.memberLoginVo=='') { this.cite.memberLoginVo = data this.cite.state = { name: '登录设备成功!', sta: true } } }else if(data.cmd=='LOGOUT'){ //登出 this.cite.memberLoginVo = '' }else if(data.cmd=='PRINT'){ //打印任务 this.listData = data this.dayin() }else if(data.cmd=='PRINT_STATUS'){ //打印任务完成 console.log(this.cite.selectedFile.length,this.cite.selectedFile) if(data.taskStatus=='COMPLETE') { if(this.cite.selectedFile.length>1) { this.cite.selectedFile.forEach((item,index)=>{ if(item.code == data.taskCode) { this.cite.selectedFile.splice(index, 1) } }) }else{ this.DYZshow = false this.$router.push({ name: 'complete' }) getDeviceByCode({ code: this.code }).then((res) => { this.cite.facility = res; }); } } } }) }, //订阅多个主题 subscribes() { const arr = ['/tzdy/send/device/'+this.code] this.client.subscribe(arr, { qos: 0 }, (err) => { if (!err) { console.log(`消息订阅成功`) } else { console.log('消息订阅失败') } }) }, //获取设备信息 getDeviceByCode() { getDeviceByCode({ code: this.code }).then((res) => { console.log(res) this.cite.facility = res; this.getAdvertisement() }); }, // 获取广告链接 getAdvertisement() { let name = 'DeviceScreen' if(this.cite.name=='advertising') { name = 'AdvertisingScreen' } getAdvertisement({deviceId:this.cite.facility.id,screen: name}).then((res) =>{ // console.log(res) this.cite.advertisement = res || '' }) }, // 小程序下载 downloadPDF(id,name) { // downloadPDF({id: id}).then(res => { // console.log(res) // const fileName = name // const blob = new Blob([res], {type: 'application/octet-stream'}) // if (window.navigator.msSaveOrOpenBlob) { // navigator.msSaveBlob(blob, fileName) // } else { // let link = document.createElement('a') // link.href = window.URL.createObjectURL(blob) // link.download = fileName // link.click() // window.URL.revokeObjectURL(link.href) // } // }).catch(() => { // }) let data = { destUrl: this.downloadPath+name,//下载路径 downloadUrl: 'https://mps.xlmalls.com/api/file/download?id='+id,//名称 } readDownload(data).then(res =>{ console.log(res,id,name) }) }, async dayin() { let _this = this _this.DYZshow = true _this.zfShow = false // let {listData} = _this // await this.downloadPDF(listData.printFileId,listData.printFileName) // setTimeout(() =>{ // _this.DYZshow = true // _this.zfShow = false // _this.setDy(listData,listData.copies) // },4000) }, setDy(listData,num) { let name = this.cite.memberLoginVo.printerGlossy || 'EPSON WF-C5890 Series3' let type = 'img' if(listData.printFileType=='PDF') { name = this.cite.memberLoginVo.printerA4 || 'EPSON WF-C5890 Series2' type = 'pdf' } let PrintColor = '' if(listData.printingColor == 'BW') { PrintColor = '黑白' } let DblPrt = '' if(listData.printingFaces == 'DOUBLE') { DblPrt = '双面打印' } console.log('设备名称',name,type,PrintColor,DblPrt) let res = apiPrint({ "PrinterName": name, "SourceFile": this.downloadPath+listData.printFileName, "FileType": type, "PrintColor": PrintColor, "DblPrt": DblPrt }) console.log(res) if(res) { num = num-1 if(num>0) { this.setDy(listData,num) }else{ setTimeout(()=>{ this.DYZshow = false this.$router.push({ name: 'complete' }) },2000) } }else{ setTimeout(() =>{ this.setDy(listData,num) },2000) } }, } } </script> <style scoped lang="less"> .dyzTip { position: fixed; width: 100%; height: 100%; top: 0; left: 0; .curtain { background: #000; width: 100%; height: 100%; opacity: .3; } .content { position: absolute; left: 50%; margin-left: -19rem; top: 50%; margin-top: -14.5rem; width: 38.56rem; height: 29rem; background: #FFFFFF; border-radius: 1.25rem; overflow: hidden; img { width: 100%; } div { font-size: 1.38rem; font-family: PingFang SC, PingFang SC; font-weight: bold; color: #323232; line-height: 1.88rem; margin-top: 1.3rem; } .name { font-size: 1rem; font-family: PingFang SC, PingFang SC; font-weight: 400; color: #323232; line-height: 1.38rem; text-align: left; padding: 0 3rem; } } .content2 { background: transparent; height: auto; img { width: 18rem; } .icon { width: 3rem; margin-top: 3rem; } } } .tkTip { position: fixed; top: 5%; width: 100%; div { background: rgba(51, 51, 51, 0.5); color: #fff; padding: 1rem 2rem; border-radius: 1rem; } } </style>
<template> <div> <!-- 打印中提示--> <div class="dyzTip" v-show="DYZshow"> <div class="curtain"></div> <div class="content"> <img src="../assets/printing.png" alt=""> <div class="name">正在进行{{ listData.printFileType=='PDF'?'文档':'照片' }}打印...</div> <!-- <div class="flex-center">{{ listData.printFileName }}</div>--> <div class="flex-center">{{ cite.selectedFile.length||1 }}/{{ cite.fileNum||1 }}</div> </div> </div> <!-- 提示--> <div class="tkTip flex-center" v-if="state.sta"> <div>{{ state.name }}</div> </div> <!-- 小程序支付--> <div class="dyzTip" v-if="zfShow"> <div class="curtain"></div> <div class="content content2"> <VueQr v-show="src" :auto-color="true" :dot-scale="1" :logo-src="require('@/assets/logo.png')" :logoMargin="0" :logoScale=".2" :margin="0" :size="300" :text="src" logoBackgroundColor="white"></VueQr> <p> <img @click="onChange('zfShow',false)" class="icon" src="../assets/demo10.png" alt=""> </p> </div> </div> </div> </template> <script> import mqtt from "mqtt/dist/mqtt" import {getAdvertisement, getDeviceByCode} from "@/api/resultApi"; import VueQr from 'vue-qr' import {apiPrint, getDeviceCode, readDownload} from "@/api/bdResultApi"; export default { name: "global", components: { VueQr }, data() { return { client: null, code: '', listData: '', DYZshow: false, // 是否显示打印中 downloadPath: 'D:\\TZDYSHARE\\TEMPFILES\\', state: '', src: '', zfShow: false, }; }, created() { this.toLoad() }, methods: { onChange(name,val){ this[name] = val }, toLoad() { // this.cite.code = 'SNJ-XX-EPSON-X001-00001' // this.code = 'SNJ-XX-EPSON-X001-00001' // this.load() getDeviceCode().then(res =>{ this.cite.code = res.data this.code = res.data this.load() }) }, load() { // 获取名为code的查询参数值 // if (this.cite.code === "") { // this.code = this.$route.query.code; // this.cite.code = this.code; // }else{ // this.code = this.cite.code; // } if (this.cite.facility === "") { this.getDeviceByCode(); } // 判断是否是广告屏 // console.log(this.cite) if(this.cite.name != 'advertising') { this.initMqtt() setInterval(()=>{ if(!this.state.sta&&this.cite.state.sta) { setTimeout(()=>{ this.cite.state.sta = false },3000) } this.state = this.cite.state },1000) } }, initMqtt() { // 连接配置选项 let options = { connectTimeout: 4000, // 超时时间 // 认证信息 clientId: '', //不填默认随机生成一个ID username: 'admin', //用户名 password: 'public' //密码 } this.client = mqtt.connect('wss://mps.xlmalls.com:8084/mqtt', options) //调用连接的api //连接成功 this.client.on('connect', (e) => { console.log('连接成功', e) this.subscribes() }) //重连提醒 this.client.on('reconnect', (error) => { console.log('正在重连', error) }) //连接失败提醒 this.client.on('error', (error) => { console.log('连接失败', error) }) //接收消息 this.client.on('message', (topic, message) => { const data = JSON.parse(message) //接受到控制信号的数据 console.log('接收消息',data) if(data.cmd=='ORDER_INFO') { //小程序支付 this.cite.url = data.payCodeUrl if(this.cite.selectedFile.length<1) { this.src = data.payCodeUrl this.zfShow=true } }else if(data.cmd=='LOGIN') { //登录 this.cite.memberLoginVo = data this.cite.state = { name: '登录设备成功!', sta: true } }else if(data.cmd=='LOGOUT'){ //登出 this.cite.memberLoginVo = '' }else if(data.cmd=='PRINT'){ //打印任务 this.listData = data this.dayin() }else if(data.cmd=='PRINT_STATUS'){ //打印任务完成 console.log(this.cite.selectedFile.length,this.cite.selectedFile) if(data.taskStatus=='COMPLETE') { if(this.cite.selectedFile.length>1) { this.cite.selectedFile.forEach((item,index)=>{ if(item.code == data.taskCode) { this.cite.selectedFile.splice(index, 1) } }) }else{ this.DYZshow = false this.$router.push({ name: 'complete' }) getDeviceByCode({ code: this.code }).then((res) => { this.cite.facility = res; }); } } } }) }, //订阅多个主题 subscribes() { const arr = ['/tzdy/send/device/'+this.code] this.client.subscribe(arr, { qos: 0 }, (err) => { if (!err) { console.log(`消息订阅成功`) } else { console.log('消息订阅失败') } }) }, //获取设备信息 getDeviceByCode() { getDeviceByCode({ code: this.code }).then((res) => { console.log(res) this.cite.facility = res; this.getAdvertisement() }); }, // 获取广告链接 getAdvertisement() { let name = 'DeviceScreen' if(this.cite.name=='advertising') { name = 'AdvertisingScreen' } getAdvertisement({deviceId:this.cite.facility.id,screen: name}).then((res) =>{ // console.log(res) this.cite.advertisement = res || '' }) }, // 小程序下载 downloadPDF(id,name) { // downloadPDF({id: id}).then(res => { // console.log(res) // const fileName = name // const blob = new Blob([res], {type: 'application/octet-stream'}) // if (window.navigator.msSaveOrOpenBlob) { // navigator.msSaveBlob(blob, fileName) // } else { // let link = document.createElement('a') // link.href = window.URL.createObjectURL(blob) // link.download = fileName // link.click() // window.URL.revokeObjectURL(link.href) // } // }).catch(() => { // }) let data = { destUrl: this.downloadPath+name,//下载路径 downloadUrl: 'https://mps.xlmalls.com/api/file/download?id='+id,//名称 } readDownload(data).then(res =>{ console.log(res,id,name) }) }, async dayin() { let _this = this _this.DYZshow = true _this.zfShow = false // let {listData} = _this // await this.downloadPDF(listData.printFileId,listData.printFileName) // setTimeout(() =>{ // _this.DYZshow = true // _this.zfShow = false // _this.setDy(listData,listData.copies) // },4000) }, setDy(listData,num) { let name = this.cite.memberLoginVo.printerGlossy || 'EPSON WF-C5890 Series3' let type = 'img' if(listData.printFileType=='PDF') { name = this.cite.memberLoginVo.printerA4 || 'EPSON WF-C5890 Series2' type = 'pdf' } let PrintColor = '' if(listData.printingColor == 'BW') { PrintColor = '黑白' } let DblPrt = '' if(listData.printingFaces == 'DOUBLE') { DblPrt = '双面打印' } console.log('设备名称',name,type,PrintColor,DblPrt) let res = apiPrint({ "PrinterName": name, "SourceFile": this.downloadPath+listData.printFileName, "FileType": type, "PrintColor": PrintColor, "DblPrt": DblPrt }) console.log(res) if(res) { num = num-1 if(num>0) { this.setDy(listData,num) }else{ setTimeout(()=>{ this.DYZshow = false this.$router.push({ name: 'complete' }) },2000) } }else{ setTimeout(() =>{ this.setDy(listData,num) },2000) } }, } } </script> <style scoped lang="less"> .dyzTip { position: fixed; width: 100%; height: 100%; top: 0; left: 0; .curtain { background: #000; width: 100%; height: 100%; opacity: .3; } .content { position: absolute; left: 50%; margin-left: -19rem; top: 50%; margin-top: -14.5rem; width: 38.56rem; height: 29rem; background: #FFFFFF; border-radius: 1.25rem; overflow: hidden; img { width: 100%; } div { font-size: 1.38rem; font-family: PingFang SC, PingFang SC; font-weight: bold; color: #323232; line-height: 1.88rem; margin-top: 1.3rem; } .name { font-size: 1rem; font-family: PingFang SC, PingFang SC; font-weight: 400; color: #323232; line-height: 1.38rem; text-align: left; padding: 0 3rem; } } .content2 { background: transparent; height: auto; img { width: 18rem; } .icon { width: 3rem; margin-top: 3rem; } } } .tkTip { position: fixed; top: 5%; width: 100%; div { background: rgba(51, 51, 51, 0.5); color: #fff; padding: 1rem 2rem; border-radius: 1rem; } } </style>
Ignore Space
Show notes
View
src/components/top.vue
<template> <div class="top flex-between"> <div class="logo flex-start" @click="_goHome()"> <img src="../assets/logo.png" /> <span></span> <div>天章自助打印</div> </div> <div class="time flex-start"> <div> <div>{{ time.week }}</div> <div>{{ time.y }}/{{ time.M }}/{{ time.d }}</div> </div> <div class="info">{{ time.h }}:{{ time.m }}</div> </div> <div class="tip flex-start"> <div v-for="(item, index) in cite.facility.paperNumber" :key="index">{{ item.name }}*{{ item.residue }}</div> <div>{{cite.memberLoginVo?'已登录':'未登录'}}</div> </div> </div> </template> <script> export default { name: "top", data() { return { time: {}, } }, mounted() { this.format() }, methods: { add(t) { if(t<10) { return '0' + t } return t }, format() { let date = new Date(); let o = { "y": date.getFullYear(), //年 "M": this.add(date.getMonth() + 1), //月份 "d": this.add(date.getDate()), //日 "h": this.add(date.getHours()), //小时 "m": this.add(date.getMinutes()), //分 "week": '', }; let str = "星期"; switch (date.getDay()) { case 0 : str += "日"; break; case 1 : str += "一"; break; case 2 : str += "二"; break; case 3 : str += "三"; break; case 4 : str += "四"; break; case 5 : str += "五"; break; case 6 : str += "六"; break; } o.week = str this.time = o setTimeout(() =>{ this.format() },1000) }, _goHome() { this.quit() // this.$router.push({ // name: 'device' // }) } } } </script> <style scoped lang="less"> .top { width: 100%; height: 9.81rem; background: #52A39D; position: relative; .logo { padding-left: 5.5rem; font-size: 3.5rem; font-weight: 400; color: #FFFFFF; line-height: 3.69rem; img { width: 5.56rem; height: 5.56rem; } span { width: 0; height: 4.43rem; border-left: 1px solid #FFFFFF; margin: 0 1.94rem; } } .time { padding-right: 3.88rem; font-size: 1.38rem; font-weight: 400; color: #FFFFFF; line-height: 1.94rem; text-align: right; .info { font-weight: bold; color: #FFFFFF; margin-left: 1.13rem; font-size: 3.69rem; line-height: 5.2rem; } } .tip { position: absolute; bottom: .5rem; right: 3.88rem; font-size: 1.2rem; color: #fff; div { margin-left: 2rem; } } } </style>
<template> <div class="top flex-between"> <div class="logo flex-start" @click="_goHome()"> <img src="../assets/logo.png" /> <span></span> <div>天章自助打印</div> </div> <div class="time flex-start"> <div> <div>{{ time.week }}</div> <div>{{ time.y }}/{{ time.M }}/{{ time.d }}</div> </div> <div class="info">{{ time.h }}:{{ time.m }}</div> </div> <div class="tip flex-start"> <div v-for="(item, index) in cite.facility.paperNumber" :key="index">{{ item.name }}*{{ item.residue }}</div> <div>{{cite.memberLoginVo?'已登录':'未登录'}}</div> </div> </div> </template> <script> export default { name: "top", data() { return { time: {}, } }, mounted() { this.format() }, methods: { add(t) { if(t<10) { return '0' + t } return t }, format() { let date = new Date(); let o = { "y": date.getFullYear(), //年 "M": this.add(date.getMonth() + 1), //月份 "d": this.add(date.getDate()), //日 "h": this.add(date.getHours()), //小时 "m": this.add(date.getMinutes()), //分 "week": '', }; let str = "星期"; switch (date.getDay()) { case 0 : str += "日"; break; case 1 : str += "一"; break; case 2 : str += "二"; break; case 3 : str += "三"; break; case 4 : str += "四"; break; case 5 : str += "五"; break; case 6 : str += "六"; break; } o.week = str this.time = o setTimeout(() =>{ this.format() },1000) }, _goHome() { // this.quit() this.$router.push({ name: 'device' }) } } } </script> <style scoped lang="less"> .top { width: 100%; height: 9.81rem; background: #52A39D; position: relative; .logo { padding-left: 5.5rem; font-size: 3.5rem; font-weight: 400; color: #FFFFFF; line-height: 3.69rem; img { width: 5.56rem; height: 5.56rem; } span { width: 0; height: 4.43rem; border-left: 1px solid #FFFFFF; margin: 0 1.94rem; } } .time { padding-right: 3.88rem; font-size: 1.38rem; font-weight: 400; color: #FFFFFF; line-height: 1.94rem; text-align: right; .info { font-weight: bold; color: #FFFFFF; margin-left: 1.13rem; font-size: 3.69rem; line-height: 5.2rem; } } .tip { position: absolute; bottom: .5rem; right: 3.88rem; font-size: 1.2rem; color: #fff; div { margin-left: 2rem; } } } </style>
Ignore Space
Show notes
View
src/utils/cite.js
// 引用地址 let inWebURL = "ws://127.0.0.1:7000/"; let baseURL = "http://127.0.0.1"; // let baseURL = "http://192.168.250.110"; // 刘竞 // let baseURL = "http://192.168.250.29"; // 家亮 // 记录首页名称 let name = "" // 设备编号 let code = "" // 用户信息 let memberLoginVo = '' // 设备信息 let facility = ""; // 选中的文件 let selectedFile = []; // 选中的文件数 let fileNum = 0 // 打印的参数 let parameter = '' // 订单id let orderId = '' // 广告位 let advertisement = '' // 页面停留时间(秒) let tlTime = { djs: 5*60,//倒计时时间 mrT: 5*60,//默认时间 } let url = '' // 打印方式名称 let modeName = '' // 提示的内容及状态 let state = { name: '', sta: false } export default { state, modeName, url, inWebURL, baseURL, facility, selectedFile, fileNum, parameter, orderId, code, memberLoginVo, name, advertisement, tlTime };
// 引用地址 let inWebURL = "ws://127.0.0.1:7000/"; let baseURL = "http://127.0.0.1"; // let baseURL = "http://192.168.250.110"; // 刘竞 // let baseURL = "http://192.168.250.29"; // 家亮 // 记录首页名称 let name = "" // 设备编号 let code = "" // 用户信息 let memberLoginVo = '' // 设备信息 let facility = ""; // 选中的文件 let selectedFile = []; // 选中的文件数 let fileNum = 0 // 打印的参数 let parameter = '' // 订单id let orderId = '' // 广告位 let advertisement = '' // 页面停留时间(秒) let tlTime = { djs: 10*60,//倒计时时间 mrT: 10*60,//默认时间 } let url = '' // 打印方式名称 let modeName = '' // 提示的内容及状态 let state = { name: '', sta: false } export default { state, modeName, url, inWebURL, baseURL, facility, selectedFile, fileNum, parameter, orderId, code, memberLoginVo, name, advertisement, tlTime };
Show line notes below