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
432cea8
commit
1b41256912daba5c283d2400c2e7192f401f2355
hanfei
authored
on 12 Jan 2024
Patch
Showing
5 changed files
src/components/global.vue
src/utils/cite.js
src/views/device.vue
src/views/expense.vue
src/views/selectFile.vue
Ignore Space
Show notes
View
src/components/global.vue
<template> <div></div> </template> <script> import mqtt from "mqtt/dist/mqtt" import {downloadPDF, getAdvertisement, getDeviceByCode} from "@/api/resultApi"; import bdRequest from "@/utils/bdRequest"; export default { name: "global", data() { return { client: null, code: '', listData: '' }; }, created() { this.load() }, methods: { 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() } }, 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=='pay') { this.cite.url = data.payCodeUrl }else if(data.login) { this.cite.memberLoginVo = data.memberLoginVo }else if(data.code){ this.listData = data this.dayin() }else{ this.cite.memberLoginVo = '' } }) }, //订阅多个主题 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) => { 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(() => { }) }, async dayin() { let _this = this let {listData} = _this await this.downloadPDF(listData.printFileId,listData.printFileName) setTimeout(() =>{ let res = bdRequest({ method: 'post', url: '/api/Printer/Print', post: '8080', data: { "PrinterName": "EPSON WF-C5890 Series", // "SourceFile": 'D:\\TZDYSHARE\\TEMPFILES\\'+listData.printFileName, "SourceFile": 'C:\\datasource\\'+listData.printFileName, "FileType": "pdf", "PrintColor": listData.printingColor || "", "DblPrt": listData.printingFaces || "" } }) console.log(res) },2000) }, } } </script>
<template> <div></div> </template> <script> import mqtt from "mqtt/dist/mqtt" import {downloadPDF, getAdvertisement, getDeviceByCode} from "@/api/resultApi"; import bdRequest from "@/utils/bdRequest"; export default { name: "global", data() { return { client: null, code: '', listData: '' }; }, created() { this.load() }, methods: { 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() } }, 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.login) { this.cite.memberLoginVo = data.memberLoginVo }else if(data.code){ this.listData = data this.dayin() }else{ this.cite.memberLoginVo = '' } }) }, //订阅多个主题 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) => { 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(() => { }) }, async dayin() { let _this = this let {listData} = _this await this.downloadPDF(listData.printFileId,listData.printFileName) setTimeout(() =>{ let res = bdRequest({ method: 'post', url: '/api/Printer/Print', post: '8080', data: { "PrinterName": "EPSON WF-C5890 Series", // "SourceFile": 'D:\\TZDYSHARE\\TEMPFILES\\'+listData.printFileName, "SourceFile": 'C:\\datasource\\'+listData.printFileName, "FileType": "pdf", "PrintColor": listData.PrintColor || "", "DblPrt": listData.printingFaces || "" } }) console.log(res) },2000) }, } } </script>
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 name = "" // 设备编号 let code = "" // 用户信息 let memberLoginVo = '' // 设备信息 let facility = ""; // 选中的文件 let selectedFile = []; // 打印的参数 let parameter = '' // 订单id let orderId = '' // 广告位 let advertisement = '' // 页面停留时间(秒) let tlTime = { djs: 10*60,//倒计时时间 mrT: 10*60,//默认时间 } let url = '' export default { url, inWebURL, baseURL, facility, selectedFile, parameter, orderId, code, memberLoginVo, name, advertisement, tlTime };
// 引用地址 let inWebURL = "ws://127.0.0.1:7000/"; let baseURL = "http://127.0.0.1"; // 记录首页名称 let name = "" // 设备编号 let code = "" // 用户信息 let memberLoginVo = '' // 设备信息 let facility = ""; // 选中的文件 let selectedFile = []; // 打印的参数 let parameter = '' // 订单id let orderId = '' // 广告位 let advertisement = '' // 页面停留时间(秒) let tlTime = { djs: 10*60,//倒计时时间 mrT: 10*60,//默认时间 } export default { inWebURL, baseURL, facility, selectedFile, parameter, orderId, code, memberLoginVo, name, advertisement, tlTime };
Ignore Space
Show notes
View
src/views/device.vue
<template> <div class="device"> <div class="box flex-between"> <div class="left"> <!-- 广告--> <div class="advertising icon1 flex-center" v-show="advertisement==''">广告位招租</div> <!-- 图片--> <div class="advertising icon1 flex-center" v-show="advertisement.type=='img'"> <img :src="advertisement.src" model="scaleToFill"/> </div> <!-- 视频--> <div class="advertising icon1 flex-center" v-show="advertisement.type=='video'"> <!-- controls--> <video autoplay loop muted :src="advertisement.src" style="width: 100%;height: 100%;"></video> </div> <!-- 功能--> <div class="feature flex-between"> <div class="main icon2 flex-start" @click="skip('operationGuide', 'U盘打印')" > <img src="../assets/demo2.png" /> <div>U盘打印</div> </div> <div class="main icon3 flex-start" @click="skip('operationGuide', '扫描打印')" > <img src="../assets/demo3.png" /> <div>扫描打印</div> </div> <div class="main icon4 flex-start" @click="skip('operationGuide', '身份证打印')" > <img src="../assets/demo4.png" /> <div>身份证打印</div> </div> </div> </div> <div class="right"> <div class="main4"> <span class="flex-center"> <!-- <img src="@/assets/ewm.jpg" alt="">--> <VueQr :logo-src="require('@/assets/logo.png')" :logoScale=".2" :logoMargin="0" logoBackgroundColor="white" :size="300" :margin="0" :auto-color="true" :dot-scale="1" :text="appSrc"></VueQr> </span> <span class="flex-center"> <div v-show="!src">支付宝小程序码</div> <VueQr v-show="src" :logo-src="require('@/assets/logo.png')" :logoScale=".2" :logoMargin="0" logoBackgroundColor="white" :size="300" :margin="0" :auto-color="true" :dot-scale="1" :text="src"></VueQr> </span> <div class="flex-center"> <img src="../assets/demo9.png" />扫一扫马上打印 </div> </div> </div> </div> <div class="box2 flex-between"> <!-- <div class="main2 flex-center" @click="skip('explain', '使用教程')">--> <!-- <img src="../assets/demo6.png" />使用教程--> <!-- </div>--> <div class="main2 flex-center" @click="skip('explain', '联系客服')"> <img src="../assets/demo7.png" />联系客服 </div> <div class="main2 flex-center" @click="skip('explain', '打印价格')"> <img src="../assets/demo5.png" />打印价格 </div> </div> </div> </template> <script> import VueQr from 'vue-qr' export default { name: "device", components: { VueQr }, data() { return { appSrc:'https://mps.xlmalls.com/web/'+this.cite.code, // advertisement: { // type: 'video', // src: 'https://cdn2.cheduoh.com/liCPtMuqo1P8NdHoM7VdTpY6Ffcz' // }, advertisement: this.cite.advertisement, src: '' }; }, methods: { skip(href, name) { // navigator.usb.requestDevice({ // filters: [{ // vendorId: 0xABCD, // classCode: 0xFF, // vendor-specific // protocolCode: 0x01 // }] // }).then(device => { // // 连接成功后进行通信操作 // // 执行数据传输操作 // console.log('连接成功后进行通信操作',device) // return device.open(); // }).catch(error => { // // 捕获异常 // console.log(error); // }); // if(this.cite.memberLoginVo=='') { // alert('请扫码登录再操作') // return // } this.$router.push({ name: href, params: { name: name, }, }); }, load() { if(this.src == '') { this.src = this.cite.url setTimeout(()=>{ this.load() },1000) } }, }, mounted() { this.load() } }; </script> <style scoped lang="less"> .device { margin: 2.5rem 4.13rem 0; .box { .left { width: 76.88rem; .advertising { width: 100%; height: 32.5rem; border-radius: 1.63rem; margin-bottom: 1.88rem; cursor: pointer; overflow: hidden; font-size: 8rem; font-weight: 400; color: #ffffff; line-height: 8rem; img { width: 100%; height: 100%; } } } .right { width: 33rem; } } .main { width: 32%; height: 10rem; border-radius: 1.63rem; font-size: 1.8rem; font-weight: 400; color: #ffffff; line-height: 1.8rem; margin-bottom: 1.88rem; cursor: pointer; img { width: 12rem; margin-top: -1rem; } } .icon1 { background: linear-gradient(359deg, #3dbf51 0%, #47d1a9 100%); box-shadow: 0rem 1.25rem 1.25rem 0.06rem rgba(120, 229, 217, 0.45); } .icon2 { background: linear-gradient(180deg, #f2c952 0%, #db572b 100%); box-shadow: 0rem 1.25rem 1.25rem 0.06rem rgba(255, 147, 128, 0.57); } .icon3 { background: linear-gradient(180deg, #84b2f7 0%, #8774d2 100%); box-shadow: 0rem 1.25rem 1.25rem 0.06rem rgba(150, 135, 232, 0.3); } .icon4 { background: linear-gradient(180deg, #5be7ff 0%, #309fd8 100%); box-shadow: 0rem 1.25rem 1.25rem 0.06rem rgba(104, 202, 253, 0.42); } .css1 { background: #ffffff; box-shadow: 0rem 0.63rem 1.25rem 0.06rem rgba(0, 0, 0, 0.14); border-radius: 1.63rem; cursor: pointer; } .main2 { width: 49%; height: 6.44rem; .css1(); font-size: 1.88rem; font-weight: bold; color: #323232; line-height: 2.63rem; img { width: 3.75rem; margin-right: 0.38rem; } } .main3 { width: 100%; height: 9.94rem; .css1(); font-size: 2.13rem; font-weight: bold; color: #323232; line-height: 3rem; img { width: 4.25rem; margin-right: 0.88rem; } } .main4 { display: inline-block; width: 100%; height: 44.38rem; .css1(); font-size: 1.88rem; font-weight: 400; color: #323232; line-height: 2rem; margin-bottom: 1.88rem; span { width: 18rem; height: 18rem; background: #ffffff; border: 0.06rem solid #707070; margin: 1rem auto 0; img { width: 100%; margin: 0; } } div { margin-top: 1rem; } img { width: 2.31rem; margin-right: 1.19rem; } } } </style>
<template> <div class="device"> <div class="box flex-between"> <div class="left"> <!-- 广告--> <div class="advertising icon1 flex-center" v-show="advertisement==''">广告位招租</div> <!-- 图片--> <div class="advertising icon1 flex-center" v-show="advertisement.type=='img'"> <img :src="advertisement.src" model="scaleToFill"/> </div> <!-- 视频--> <div class="advertising icon1 flex-center" v-show="advertisement.type=='video'"> <!-- controls--> <video autoplay loop muted :src="advertisement.src" style="width: 100%;height: 100%;"></video> </div> <!-- 功能--> <div class="feature flex-between"> <div class="main icon2 flex-start" @click="skip('operationGuide', 'U盘打印')" > <img src="../assets/demo2.png" /> <div>U盘打印</div> </div> <div class="main icon3 flex-start" @click="skip('operationGuide', '扫描打印')" > <img src="../assets/demo3.png" /> <div>扫描打印</div> </div> <div class="main icon4 flex-start" @click="skip('operationGuide', '身份证打印')" > <img src="../assets/demo4.png" /> <div>身份证打印</div> </div> </div> </div> <div class="right"> <div class="main4"> <span class="flex-center"> <!-- <img src="@/assets/ewm.jpg" alt="">--> <VueQr :logo-src="require('@/assets/logo.png')" :logoScale=".2" :logoMargin="0" logoBackgroundColor="white" :size="300" :margin="0" :auto-color="true" :dot-scale="1" :text="appSrc"></VueQr> </span> <span class="flex-center"> 支付宝小程序码 </span> <div class="flex-center"> <img src="../assets/demo9.png" />扫一扫马上打印 </div> </div> </div> </div> <div class="box2 flex-between"> <!-- <div class="main2 flex-center" @click="skip('explain', '使用教程')">--> <!-- <img src="../assets/demo6.png" />使用教程--> <!-- </div>--> <div class="main2 flex-center" @click="skip('explain', '联系客服')"> <img src="../assets/demo7.png" />联系客服 </div> <div class="main2 flex-center" @click="skip('explain', '打印价格')"> <img src="../assets/demo5.png" />打印价格 </div> </div> </div> </template> <script> import VueQr from 'vue-qr' export default { name: "device", components: { VueQr }, data() { return { appSrc:'https://mps.xlmalls.com/web/'+this.cite.code, // advertisement: { // type: 'video', // src: 'https://cdn2.cheduoh.com/liCPtMuqo1P8NdHoM7VdTpY6Ffcz' // }, advertisement: this.cite.advertisement }; }, methods: { skip(href, name) { // navigator.usb.requestDevice({ // filters: [{ // vendorId: 0xABCD, // classCode: 0xFF, // vendor-specific // protocolCode: 0x01 // }] // }).then(device => { // // 连接成功后进行通信操作 // // 执行数据传输操作 // console.log('连接成功后进行通信操作',device) // return device.open(); // }).catch(error => { // // 捕获异常 // console.log(error); // }); // if(this.cite.memberLoginVo=='') { // alert('请扫码登录再操作') // return // } this.$router.push({ name: href, params: { name: name, }, }); }, }, }; </script> <style scoped lang="less"> .device { margin: 2.5rem 4.13rem 0; .box { .left { width: 76.88rem; .advertising { width: 100%; height: 32.5rem; border-radius: 1.63rem; margin-bottom: 1.88rem; cursor: pointer; overflow: hidden; font-size: 8rem; font-weight: 400; color: #ffffff; line-height: 8rem; img { width: 100%; height: 100%; } } } .right { width: 33rem; } } .main { width: 32%; height: 10rem; border-radius: 1.63rem; font-size: 1.8rem; font-weight: 400; color: #ffffff; line-height: 1.8rem; margin-bottom: 1.88rem; cursor: pointer; img { width: 12rem; margin-top: -1rem; } } .icon1 { background: linear-gradient(359deg, #3dbf51 0%, #47d1a9 100%); box-shadow: 0rem 1.25rem 1.25rem 0.06rem rgba(120, 229, 217, 0.45); } .icon2 { background: linear-gradient(180deg, #f2c952 0%, #db572b 100%); box-shadow: 0rem 1.25rem 1.25rem 0.06rem rgba(255, 147, 128, 0.57); } .icon3 { background: linear-gradient(180deg, #84b2f7 0%, #8774d2 100%); box-shadow: 0rem 1.25rem 1.25rem 0.06rem rgba(150, 135, 232, 0.3); } .icon4 { background: linear-gradient(180deg, #5be7ff 0%, #309fd8 100%); box-shadow: 0rem 1.25rem 1.25rem 0.06rem rgba(104, 202, 253, 0.42); } .css1 { background: #ffffff; box-shadow: 0rem 0.63rem 1.25rem 0.06rem rgba(0, 0, 0, 0.14); border-radius: 1.63rem; cursor: pointer; } .main2 { width: 49%; height: 6.44rem; .css1(); font-size: 1.88rem; font-weight: bold; color: #323232; line-height: 2.63rem; img { width: 3.75rem; margin-right: 0.38rem; } } .main3 { width: 100%; height: 9.94rem; .css1(); font-size: 2.13rem; font-weight: bold; color: #323232; line-height: 3rem; img { width: 4.25rem; margin-right: 0.88rem; } } .main4 { display: inline-block; width: 100%; height: 44.38rem; .css1(); font-size: 1.88rem; font-weight: 400; color: #323232; line-height: 2rem; margin-bottom: 1.88rem; span { width: 18rem; height: 18rem; background: #ffffff; border: 0.06rem solid #707070; margin: 1rem auto 0; img { width: 100%; margin: 0; } } div { margin-top: 1rem; } img { width: 2.31rem; margin-right: 1.19rem; } } } </style>
Ignore Space
Show notes
View
src/views/expense.vue
<template> <!-- 费用支付--> <div class="expense"> <navbar :name="name"/> <div class="box flex-center"> <div class="left"> <div class="title">温馨提示</div> <div class="content">请在建议时限内尽快完成支付,如果操作超时本次打印业务可能需要重新提交。</div> </div> <div class="right"> <div class="code" @click="skip('complete',name)"> <VueQr :logo-src="require('@/assets/logo.png')" :logoScale=".2" :logoMargin="0" logoBackgroundColor="white" :size="300" :margin="0" :auto-color="true" :dot-scale="1" :text="appSrc"></VueQr> </div> <div class="flex-center tip">提示:请在 {{num}} 秒内完成扫码支付</div> </div> </div> </div> </template> <script> import navbar from '@/components/nav' import {getPayQrCode, downloadPDF, getPrintTask} from "../api/resultApi"; import VueQr from 'vue-qr' import bdRequest from "../utils/bdRequest"; export default { name: "expense", components: { navbar,VueQr }, provide() { return { title: '', type: this.name } }, data() { return { name: this.$route.params.name, appSrc: '', client: '', num: 120, selectedFile: this.cite.selectedFile, listData: { "code":"20240104231724631239-0", "copies":1, "printFileId":112, "printFileType":"PDF", "printingColor":"BW", "printingFaces":"SINGLE" } } }, methods: { skip(href,name) { this.$router.push({ name: href, params: { name: name } }) }, downloadPDF(id,name) { downloadPDF({id: id}).then(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(() => { }) }, async dayin() { let _this = this let {listData,selectedFile} = _this let i = '', deta='' selectedFile.forEach((item,index) => { if(listData.printFileId == item.id) { i=index deta = item } }) await this.downloadPDF(listData.printFileId,listData.printFileName) console.log('打印',deta,listData.copies) setTimeout(() =>{ _this.selectedFile.splice(i, 1) // 按份数循环打印 // for(let i=0;i<listData.copies;i++) { // } let res = bdRequest({ method: 'post', url: '/api/Printer/Print', post: '8080', data: { "PrinterName": "EPSON WF-C5890 Series", // "SourceFile": 'D:\\TZDYSHARE\\TEMPFILES\\'+listData.printFileName, "SourceFile": 'C:\\datasource\\'+listData.printFileName, "FileType": "pdf", "PrintColor": listData.printingColor || "", "DblPrt": listData.printingFaces || "" } }) console.log(res) setTimeout(()=>{ if(_this.selectedFile.length>0) { _this.getPrintTask() }else{ _this.cite.orderId = '' _this.skip('complete',_this.name) } },1000) },2000) }, async getPrintTask() { let _this = this if(_this.cite.orderId) { let res = await getPrintTask({orderId: _this.cite.orderId}) console.log(res,'getPrintTask数据') if(res) { _this.listData = res _this.dayin() }else{ setTimeout(()=>{ _this.getPrintTask() },1000) } } }, load() { let _this = this getPayQrCode({orderId: _this.cite.orderId}).then(res => { // console.log(res.data.qrCode) if(res.qrCode) { _this.appSrc = res.qrCode setTimeout(() =>{ // _this.dayin() _this.getPrintTask() },1000) } }) }, countDown(num) { if(num<1) { this.quit() return } setTimeout(()=>{ this.num = num-1 this.countDown(this.num) },1000) }, }, destroyed() { // 销毁监听 // clearTimeout() }, mounted() { this.countDown(120) this.load() } } </script> <style scoped lang="less"> .box { height: 42.13rem; .css1 { height: 100%; background: #FFFFFF; box-shadow: 0rem 0.31rem 0.63rem 0.06rem rgba(0,0,0,0.14); border-radius: 1.63rem; } .left { width: 46.44rem; margin-right: 1.88rem; .css1(); .title { font-size: 2.88rem; font-weight: bold; color: #D41212; line-height: 4.06rem; padding: 4.13rem 0 2.44rem; } .content { width: 37rem; font-size: 2.25rem; font-weight: bold; color: #323232; line-height: 3rem; margin: 0 auto; text-align: left; } } .right { width: 62.81rem; .css1(); font-size: 2.25rem; font-weight: bold; color: #323232; line-height: 3.13rem; .code { display: inline-block; width: 23.25rem; height: 22.88rem; background: #FFFFFF; //border: 0.06rem solid #707070; margin: 2.94rem auto 1.19rem; img { width: 100%; height: auto; } } } } </style>
<template> <!-- 费用支付--> <div class="expense"> <navbar :name="name"/> <div class="box flex-center"> <div class="left"> <div class="title">温馨提示</div> <div class="content">请在建议时限内尽快完成支付,如果操作超时本次打印业务可能需要重新提交。</div> </div> <div class="right"> <div class="code" @click="skip('complete',name)"> <VueQr :logo-src="require('@/assets/logo.png')" :logoScale=".2" :logoMargin="0" logoBackgroundColor="white" :size="300" :margin="0" :auto-color="true" :dot-scale="1" :text="appSrc"></VueQr> </div> <div class="flex-center tip">提示:请在 {{num}} 秒内完成扫码支付</div> </div> </div> </div> </template> <script> import navbar from '@/components/nav' import {getPayQrCode, downloadPDF, getPrintTask} from "../api/resultApi"; import VueQr from 'vue-qr' import bdRequest from "../utils/bdRequest"; export default { name: "expense", components: { navbar,VueQr }, provide() { return { title: '', type: this.name } }, data() { return { name: this.$route.params.name, appSrc: '', client: '', num: 120, selectedFile: this.cite.selectedFile, listData: { "code":"20240104231724631239-0", "copies":1, "printFileId":112, "printFileType":"PDF", "printingColor":"BW", "printingFaces":"SINGLE" } } }, methods: { skip(href,name) { this.$router.push({ name: href, params: { name: name } }) }, downloadPDF(id,name) { downloadPDF({id: id}).then(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(() => { }) }, async dayin() { let _this = this let {listData,selectedFile} = _this let i = '', deta='' selectedFile.forEach((item,index) => { if(listData.printFileId == item.id) { i=index deta = item } }) await this.downloadPDF(listData.printFileId,listData.printFileName) console.log('打印',deta,listData.copies) setTimeout(() =>{ _this.selectedFile.splice(i, 1) // 按份数循环打印 for(let i=0;i<listData.copies;i++) { let res = bdRequest({ method: 'post', url: '/api/Printer/Print', post: '8080', data: { "PrinterName": "EPSON WF-C5890 Series", // "SourceFile": 'D:\\TZDYSHARE\\TEMPFILES\\'+listData.printFileName, "SourceFile": 'C:\\datasource\\'+listData.printFileName, "FileType": "pdf", "PrintColor": listData.PrintColor || "", "DblPrt": listData.printingFaces || "" } }) console.log(res) } setTimeout(()=>{ if(_this.selectedFile.length>0) { _this.getPrintTask() }else{ _this.cite.orderId = '' _this.skip('complete',_this.name) } },1000) },2000) }, async getPrintTask() { let _this = this if(_this.cite.orderId) { let res = await getPrintTask({orderId: _this.cite.orderId}) console.log(res,'getPrintTask数据') if(res) { _this.listData = res _this.dayin() }else{ setTimeout(()=>{ _this.getPrintTask() },1000) } } }, load() { let _this = this getPayQrCode({orderId: _this.cite.orderId}).then(res => { // console.log(res.data.qrCode) if(res.qrCode) { _this.appSrc = res.qrCode setTimeout(() =>{ // _this.dayin() _this.getPrintTask() },1000) } }) }, countDown(num) { if(num<1) { this.quit() return } setTimeout(()=>{ this.num = num-1 this.countDown(this.num) },1000) }, }, destroyed() { // 销毁监听 // clearTimeout() }, mounted() { this.countDown(120) this.load() } } </script> <style scoped lang="less"> .box { height: 42.13rem; .css1 { height: 100%; background: #FFFFFF; box-shadow: 0rem 0.31rem 0.63rem 0.06rem rgba(0,0,0,0.14); border-radius: 1.63rem; } .left { width: 46.44rem; margin-right: 1.88rem; .css1(); .title { font-size: 2.88rem; font-weight: bold; color: #D41212; line-height: 4.06rem; padding: 4.13rem 0 2.44rem; } .content { width: 37rem; font-size: 2.25rem; font-weight: bold; color: #323232; line-height: 3rem; margin: 0 auto; text-align: left; } } .right { width: 62.81rem; .css1(); font-size: 2.25rem; font-weight: bold; color: #323232; line-height: 3.13rem; .code { display: inline-block; width: 23.25rem; height: 22.88rem; background: #FFFFFF; //border: 0.06rem solid #707070; margin: 2.94rem auto 1.19rem; img { width: 100%; height: auto; } } } } </style>
Ignore Space
Show notes
View
src/views/selectFile.vue
<template> <!-- 选取资料--> <div class="selectFile"> <navbar :name="name" /> <!-- U盘打印--> <div class="box flex-center" v-if="name == 'U盘打印'"> <div class="tip"> <div class="title">温馨提示</div> <div class="content">请在右侧文件浏览区,找到文件存放的目录/文件夹,然后点选您要打印的文件,之后按下“确认资料”按钮。</div> </div> <div class="file tip2"> <div class="main"> <div v-for="(item, index) in UpFile" v-bind:key="index" class="flex-between li"> <div class="name">{{ item.name }}</div> <span @click="onCancel(index, 'UpFile')">删除</span> </div> </div> <div class="flex-between but"> <div class="btn flex-center"> 选择文件 <input type="file" @change="handleFileChange" /> </div> <div class="btn flex-center" @click="skip('argument', name)">确认资料</div> </div> </div> </div> <!-- 扫描打印--> <div class="box flex-center" v-if="name == '扫描打印'"> <div class="file2"> <div class="title flex-between">已完成扫描的版面 <span :class="[{ act: smfyIndex == -1 }]" @click="onChange(-1, 'smfyIndex')">预览</span></div> <div class="main flex-between"> <div class="smfyData"> <div v-for="(item, index) in imgList" v-bind:key="index" :class="['flex-center', { act: smfyIndex == index }]" @click="onChange(index, 'smfyIndex')"> <div class="name">{{ index + 1 }}</div> <span @click="onCancel(index, 'imgList')">删除</span> </div> </div> <img v-show="smfyIndex!=-1" :src="imgList[smfyIndex]" alt="" style="width: 25rem; height: 100%" /> <img v-show="smfyIndex==-1" id="myCanvas" style="width: 25rem; height: 100%" /> </div> </div> <div class="tip tip2"> <div class="title">温馨提示</div> <div class="content"> 已经扫描好的页面显示在左边的列表中,您可以点击列表中的缩略图进行核对,有不满意的请点旁边的“X”进行移除并重新扫描。如果有文件需要继续扫描,请按要求放置好资料后,按“继续扫描”。 按照刚才的方法,重复扫描过程,直到完成了所有需要的页面。核对无误后,可以按“完成扫描”结束资料扫描过程。 </div> <div class="flex-between but"> <div class="btn flex-center" @click="paiz()">继续扫描</div> <div class="btn flex-center" @click="skip('argument', name)">完成扫描</div> </div> </div> </div> <!-- 身份证打印--> <div class="box flex-center" v-if="name == '身份证打印'"> <div class="file2 file3" style="margin-right: 20rem"> <div class="title">请核对您的信息</div> <div class="card" ref="captureArea" v-if="cardInfo!=''"> <div class="card-box"> <img src="../assets/card2.png" alt="身份证反面" /> <div class="card-name">{{ cardInfo.name }}</div> <div class="card-gender"> {{ cardInfo.xbmc }}<span>{{ cardInfo.mzmc }}</span> </div> <div class="card-birth"> {{ cardInfo.birthday | joinYear }} <span class="month">{{ cardInfo.birthday | joinMonth }}</span> <span class="day">{{ cardInfo.birthday | joinDay }}</span> </div> <div class="card-addr"> {{ cardInfo.address }} </div> <div class="card-id">{{ cardInfo.idNum }}</div> <div class="card-avatar"> <!-- <img :src="'data:image/png;base64,'+cardInfo.photo" alt="" />--> <img :src="photo" alt=""> </div> </div> <div class="card-box"> <img src="../assets/card1.png"/> <div class="card-sign">{{ cardInfo.issueOrg }}</div> <div class="card-date"> {{ cardInfo.effectDate | joinRq}} - {{ cardInfo.expireDate | joinRq}} </div> </div> </div> </div> <div class="tip"> <div class="title">温馨提示</div> <div class="content">身份证件信息读取成功,请您核对个人信息无误后,按“信息无误,继续”按钮进行后续操作。此时您可以取回您的身份证卡片并妥善保存。</div> <div class="btn flex-center" @click="skip('argument', name)">信息无误,继续</div> </div> </div> </div> </template> <script> import navbar from "@/components/nav"; import html2canvas from "html2canvas"; import bdRequest from "../utils/bdRequest"; import { upload2Pdf,changeIdPhotoBgc } from '@/api/resultApi' import parseCardWzxx from "../utils/mz"; export default { name: 'selectFile', components: { navbar }, provide() { return { title: this.tit, type: this.name } }, filters: { joinYear(val) { return val.substring(0, 4) }, joinMonth(val) { return val.substring(4, 6) }, joinDay(val) { return val.substring(6, 8) }, joinRq(val) { return val.substring(0, 4)+'.'+val.substring(4, 6)+'.'+val.substring(6, 8) } }, data() { return { tit: this.$route.params.name == 'U盘打印' ? '资料选取提交' : '资料扫描提交', name: this.$route.params.name, path: this.cite.inWebURL, socket: '', imgList: [], smfyIndex: -1, photo: '', UpFile: [], cardInfo: '', }; }, methods: { async uploadImg(data,sta) { let _this= this for (let i = 0; i < data.length; i++) { let formData = new FormData() let file = data[i] if(sta){ // let dataURL = file.toDataURL('image/png') let name = i+'.png' file = _this.dataURLtoFile(file, name) } formData.append('file', file) // 使用数组语法添加多个文件 let res = await upload2Pdf(formData) _this.cite.selectedFile.push(res) console.log('打印文件',this.cite.selectedFile,res) } }, async skip(href, name) { if(this.UpFile.length>0) { await this.uploadImg(this.UpFile,false) }else if(this.imgList.length>0) { await this.uploadImg(this.imgList,true) }else if(this.cardInfo) { await this.captureAndDownload() } this.$router.push({ name: href, params: { name: name } }) }, async captureAndDownload() { const captureArea = this.$refs.captureArea // 使用 html2canvas 将区域内容生成为图片 const canvas = await html2canvas(captureArea) // 将 canvas 转为图片 URL const dataURL = canvas.toDataURL('image/png') const name = 'sfz.png' const file = this.dataURLtoFile(dataURL, name) this.uploadImg([file],false) }, dataURLtoFile(dataURL, filename) { const arr = dataURL.split(',') const mime = arr[0].match(/:(.*?);/)[1] const bstr = atob(arr[1]) let n = bstr.length const u8arr = new Uint8Array(n) while (n--) { u8arr[n] = bstr.charCodeAt(n) } return new File([u8arr], filename, { type: mime }) }, onChange(index, name) { this[name] = index }, onCancel(index, name) { if(name == 'imgList') { this.smfyIndex = -1 } this[name].splice(index, 1) }, paiz() { this.socket.send('Capture@2') }, init: function () { if (typeof WebSocket === 'undefined') { alert('您的浏览器不支持socket') } else { // 实例化socket this.socket = new WebSocket(this.path) // 监听socket连接 this.socket.onopen = this.open // 监听socket错误信息 this.socket.onerror = this.error // 监听socket消息 this.socket.onmessage = this.getMessage } }, open: function () { // console.log("socket连接成功") this.socket.send('OpenIdCardEx@0') this.socket.send('OpenDevice@1') this.socket.send('SetResolution@2@2592@1944') this.socket.send('OpenVideo') this.socket.send('RotateRight') this.socket.send('Deskew') }, error: function () { console.log('连接错误') }, getMessage: function (msg) { if (typeof msg.data == 'string') { if (msg.data.indexOf('GetDevCount') == 0) { let s = msg.data.substring(12) if ('1' == s || '2' == s) { //如果是双摄像头 那就需要判断 s = 2;表示当前是连接了2个设备 alert('检测到已经连接上摄像头') } } else if (msg.data.indexOf('Capture') == 0) { let s = msg.data.substring(8) if (s) { this.imgList.push('data:image/jpeg;base64,' + s) } } else if (msg.data.indexOf('MoveDetectEvent') == 0) { this.socket.send('Capture@2') } else if (msg.data.indexOf('IdCardEvent') == 0) { this.socket.send('UnFaceDetect') } else if (msg.data.indexOf('ReadIdCard') == 0) { let s = msg.data.substring(11) if ('1' == s) { this.socket.send('GetIdCardResult@||') this.socket.send('GetIdCardImage@2') } } else if (msg.data.indexOf('GetIdCardResult') == 0) { let s = msg.data.substring(16) let info = document.getElementById('info') info.value = s } else if (msg.data.indexOf('GetBarcode') == 0) { // alert(msg.data); let s = msg.data.substring(11) let info = document.getElementById('info') info.value = s } else if (msg.data.indexOf('GetIdCardImage') == 0) { let s = msg.data.substring(15) let arr = s.split('#') let faceImg = arr[0] let myimg = document.getElementById('myCanvas3') myimg.src = 'data:image/jpeg;base64,' + faceImg } else if (msg.data.indexOf('GetBase64') == 0) { let s = msg.data.substring(10) let myimg = document.getElementById('myCanvas2') myimg.src = 'data:image/jpeg;base64,' + s alert(s) } else if (msg.data.indexOf('GetRecognitionFromFileName') == 0) { let s = msg.data.substring(27) let info = document.getElementById('info') info.value = s } else if (msg.data.indexOf('GetOcrFromFileName') == 0) { let s = msg.data.substring(19) let info = document.getElementById('info') info.value = s } else if (msg.data.indexOf('GetDogSN') == 0) { let s = msg.data.substring(11) let info = document.getElementById('info') info.value = s } } else { let reader = new FileReader() reader.onload = function (msg) { if (msg.target.readyState == FileReader.DONE) { let url = msg.target.result; document.getElementById('myCanvas').src = url; } } reader.readAsDataURL(msg.data) } }, close: function () { // console.log("socket已经关闭") this.socket.close() this.socket = '' }, handleFileChange(event) { let file = event.target.files[0] if (file) { this.UpFile.push(file) } }, // 获取身份证信息 async sfzCard() { let _this = this let res = await bdRequest({ method: 'get', url: '/api/readCard', post: '7846' }) if (res.errorMsg == 'OK') { // console.log(res.resultContent) _this.imgDeals(res.resultContent.photo) _this.cardInfo = parseCardWzxx(res.resultContent) }else{ setTimeout(() => { this.sfzCard() },1000) } }, // 图片处理 imgDeals(re) { let file = this.dataURLtoFile('data:image/png;base64,'+re, 'sfzTx.png') let formData = new FormData() formData.append('file', file) formData.append('colorEnum', 'CLEAR') changeIdPhotoBgc(formData).then((res)=>{ console.log(res) this.photo = res.previewPath }) }, }, destroyed() { // 销毁监听 if(this.socket) { this.close() } }, mounted() { this.cite.selectedFile = [] if (this.$route.params.name == "扫描打印") { this.init(); }else if(this.$route.params.name == "身份证打印") { this.sfzCard() } } } </script> <style scoped lang="less"> @font-face { font-family: 'STHeiti';//自定义字体名字 src: url('../assets/typeface/STHeiti.ttf') format('truetype');//定义好文件的相对地址 } .selectFile { .box { width: 114.06rem; height: 42.13rem; background: #ffffff; box-shadow: 0rem 0.31rem 0.63rem 0.06rem rgba(0, 0, 0, 0.14); border-radius: 1.63rem; margin: 0 auto; .tip { //margin-right: 15.31rem; width: 37rem; font-size: 2.25rem; font-weight: bold; color: #323232; line-height: 3rem; .title { font-size: 2.88rem; font-weight: bold; color: #d41212; line-height: 4.06rem; } .content { margin: 3rem auto 59px; text-align: center; } } .file { margin-left: 9.69rem; .main { width: 31.63rem; height: 26.56rem; background: #ffffff; border: 0.06rem solid #707070; margin: 0 auto 2.81rem; padding: 2rem 0; overflow-y: scroll; .li { width: 80%; margin: 0 auto; padding-bottom: 1rem; span { text-decoration: underline; cursor: pointer; } } } } .tip2 { width: 52rem; .but { .btn { width: 24.44rem; position: relative; input { position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; } } } } .file2 { margin-right: 9.69rem; .title { font-size: 2.13rem; font-weight: bold; color: #323232; line-height: 3rem; //text-align: left; span { text-decoration: underline; font-size: 1.5rem; font-weight: bold; color: #323232; line-height: 2rem; } .act { color: #52a39d; } } .main { width: 39.81rem; height: 31.31rem; background: #eeeeee; margin: 1.38rem auto 0; } .card { width: 42.81rem; height: 35.31rem; display: flex; flex-direction: column; justify-content: space-around; align-items: flex-end; font-family: 'STHeiti', Heiti, sans-serif;//使用自己自定义的名字 .card-box { width: 25rem; height: 15rem; margin-right: 5rem; position: relative; font-weight: bold; font-size: .9rem; line-height: 1rem; .card-title { padding: 1rem 0; } img { width: 25rem; } .card-sign { position: absolute; bottom: 2.6rem; left: 10.5rem; } .card-date { position: absolute; bottom: 0.5rem; left: 10.5rem; } .card-name { position: absolute; top: 2.2rem; left: 4.5rem; } .card-gender { position: absolute; top: 4.1rem; left: 4.5rem; //font-size: 0.7rem; span { margin-left: 5rem; } } .card-birth { position: absolute; top: 6.15rem; left: 4.5rem; //font-size: 0.7rem; .month { margin-left: 1.7rem; } .day { margin-left: 1.2rem; } } .card-addr { width: 10rem; position: absolute; top: 8.1rem; left: 4.5rem; //font-size: 0.7rem; text-align: left; } .card-id { position: absolute; bottom: .8rem; left: 8rem; letter-spacing: .2rem; } .card-avatar { position: absolute; top: 3.2rem; right: 2rem; width: 7rem; height: 9rem; img { width: 7rem; height: 9rem; background-size: contain; } } } } } .file3 { margin-right: 28.13rem; .main { width: 20.75rem; height: 28.88rem; border: 0.06rem solid #707070; margin: 1.06rem 0 0 13.38rem; } } .btn { width: 100%; height: 5.5rem; background: linear-gradient(132deg, #52a39d 0%, #a1c553 50%, #81d012 100%); border-radius: 1.25rem; font-size: 1.88rem; font-weight: 400; color: #ffffff; line-height: 2.63rem; cursor: pointer; } } .smfyData { height: 90%; width: 14.81rem; font-size: 1rem; font-weight: bold; color: #323232; line-height: 2rem; overflow: auto; cursor: pointer; .act { color: #52a39d; } .name { text-decoration: underline; } span { margin-left: 5rem; } } } </style>
<template> <!-- 选取资料--> <div class="selectFile"> <navbar :name="name" /> <!-- U盘打印--> <div class="box flex-center" v-if="name == 'U盘打印'"> <div class="tip"> <div class="title">温馨提示</div> <div class="content">请在右侧文件浏览区,找到文件存放的目录/文件夹,然后点选您要打印的文件,之后按下“确认资料”按钮。</div> </div> <div class="file tip2"> <div class="main"> <div v-for="(item, index) in UpFile" v-bind:key="index" class="flex-between li"> <div class="name">{{ item.name }}</div> <span @click="onCancel(index, 'UpFile')">删除</span> </div> </div> <div class="flex-between but"> <div class="btn flex-center"> 选择文件 <input type="file" @change="handleFileChange" /> </div> <div class="btn flex-center" @click="skip('argument', name)">确认资料</div> </div> </div> </div> <!-- 扫描打印--> <div class="box flex-center" v-if="name == '扫描打印'"> <div class="file2"> <div class="title flex-between">已完成扫描的版面 <span :class="[{ act: smfyIndex == -1 }]" @click="onChange(-1, 'smfyIndex')">预览</span></div> <div class="main flex-between"> <div class="smfyData"> <div v-for="(item, index) in imgList" v-bind:key="index" :class="['flex-center', { act: smfyIndex == index }]" @click="onChange(index, 'smfyIndex')"> <div class="name">{{ index + 1 }}</div> <span @click="onCancel(index, 'imgList')">删除</span> </div> </div> <img v-show="smfyIndex!=-1" :src="imgList[smfyIndex]" alt="" style="width: 25rem; height: 100%" /> <img v-show="smfyIndex==-1" id="myCanvas" style="width: 25rem; height: 100%" /> </div> </div> <div class="tip tip2"> <div class="title">温馨提示</div> <div class="content"> 已经扫描好的页面显示在左边的列表中,您可以点击列表中的缩略图进行核对,有不满意的请点旁边的“X”进行移除并重新扫描。如果有文件需要继续扫描,请按要求放置好资料后,按“继续扫描”。 按照刚才的方法,重复扫描过程,直到完成了所有需要的页面。核对无误后,可以按“完成扫描”结束资料扫描过程。 </div> <div class="flex-between but"> <div class="btn flex-center" @click="paiz()">继续扫描</div> <div class="btn flex-center" @click="skip('argument', name)">完成扫描</div> </div> </div> </div> <!-- 身份证打印--> <div class="box flex-center" v-if="name == '身份证打印'"> <div class="file2 file3" style="margin-right: 20rem"> <div class="title">请核对您的信息</div> <div class="card" ref="captureArea" v-if="cardInfo!=''"> <div class="card-box"> <img src="../assets/card2.png" alt="身份证反面" /> <div class="card-name">{{ cardInfo.name }}</div> <div class="card-gender"> {{ cardInfo.xbmc }}<span>{{ cardInfo.mzmc }}</span> </div> <div class="card-birth"> {{ cardInfo.birthday | joinYear }} <span class="month">{{ cardInfo.birthday | joinMonth }}</span> <span class="day">{{ cardInfo.birthday | joinDay }}</span> </div> <div class="card-addr"> {{ cardInfo.address }} </div> <div class="card-id">{{ cardInfo.idNum }}</div> <div class="card-avatar"> <!-- <img :src="'data:image/png;base64,'+cardInfo.photo" alt="" />--> <img :src="photo" alt=""> </div> </div> <div class="card-box"> <img src="../assets/card1.png"/> <div class="card-sign">{{ cardInfo.issueOrg }}</div> <div class="card-date"> {{ cardInfo.effectDate | joinRq}} - {{ cardInfo.expireDate | joinRq}} </div> </div> </div> </div> <div class="tip"> <div class="title">温馨提示</div> <div class="content">身份证件信息读取成功,请您核对个人信息无误后,按“信息无误,继续”按钮进行后续操作。此时您可以取回您的身份证卡片并妥善保存。</div> <div class="btn flex-center" @click="skip('argument', name)">信息无误,继续</div> </div> </div> </div> </template> <script> import navbar from "@/components/nav"; import html2canvas from "html2canvas"; import bdRequest from "../utils/bdRequest"; import { upload2Pdf,changeIdPhotoBgc } from '@/api/resultApi' import parseCardWzxx from "../utils/mz"; export default { name: 'selectFile', components: { navbar }, provide() { return { title: this.tit, type: this.name } }, filters: { joinYear(val) { return val.substring(0, 4) }, joinMonth(val) { return val.substring(4, 6) }, joinDay(val) { return val.substring(6, 8) }, joinRq(val) { return val.substring(0, 4)+'.'+val.substring(4, 6)+'.'+val.substring(6, 8) } }, data() { return { tit: this.$route.params.name == 'U盘打印' ? '资料选取提交' : '资料扫描提交', name: this.$route.params.name, path: this.cite.inWebURL, socket: '', imgList: [], smfyIndex: -1, photo: '', UpFile: [], cardInfo: '', }; }, methods: { async uploadImg(data,sta) { let _this= this for (let i = 0; i < data.length; i++) { let formData = new FormData() let file = data[i] if(sta){ // let dataURL = file.toDataURL('image/png') let name = i+'.png' file = _this.dataURLtoFile(file, name) } formData.append('file', file) // 使用数组语法添加多个文件 let res = await upload2Pdf(formData) _this.cite.selectedFile.push(res) console.log('打印文件',this.cite.selectedFile,res) } }, async skip(href, name) { if(this.UpFile.length>0) { await this.uploadImg(this.UpFile,false) }else if(this.imgList.length>0) { await this.uploadImg(this.imgList,true) }else if(this.cardInfo) { await this.captureAndDownload() } this.$router.push({ name: href, params: { name: name } }) }, async captureAndDownload() { const captureArea = this.$refs.captureArea // 使用 html2canvas 将区域内容生成为图片 const canvas = await html2canvas(captureArea) // 将 canvas 转为图片 URL const dataURL = canvas.toDataURL('image/png') const name = 'sfz.png' const file = this.dataURLtoFile(dataURL, name) this.uploadImg([file],false) }, dataURLtoFile(dataURL, filename) { const arr = dataURL.split(',') const mime = arr[0].match(/:(.*?);/)[1] const bstr = atob(arr[1]) let n = bstr.length const u8arr = new Uint8Array(n) while (n--) { u8arr[n] = bstr.charCodeAt(n) } return new File([u8arr], filename, { type: mime }) }, onChange(index, name) { this[name] = index }, onCancel(index, name) { if(name == 'imgList') { this.smfyIndex = -1 } this[name].splice(index, 1) }, paiz() { this.socket.send('Capture@2') }, init: function () { if (typeof WebSocket === 'undefined') { alert('您的浏览器不支持socket') } else { // 实例化socket this.socket = new WebSocket(this.path) // 监听socket连接 this.socket.onopen = this.open // 监听socket错误信息 this.socket.onerror = this.error // 监听socket消息 this.socket.onmessage = this.getMessage } }, open: function () { // console.log("socket连接成功") this.socket.send('OpenIdCardEx@0') this.socket.send('OpenDevice@1') this.socket.send('SetResolution@2@2592@1944') this.socket.send('OpenVideo') this.socket.send('RotateRight') this.socket.send('Deskew') }, error: function () { console.log('连接错误') }, getMessage: function (msg) { if (typeof msg.data == 'string') { if (msg.data.indexOf('GetDevCount') == 0) { let s = msg.data.substring(12) if ('1' == s || '2' == s) { //如果是双摄像头 那就需要判断 s = 2;表示当前是连接了2个设备 alert('检测到已经连接上摄像头') } } else if (msg.data.indexOf('Capture') == 0) { let s = msg.data.substring(8) if (s) { this.imgList.push('data:image/jpeg;base64,' + s) } } else if (msg.data.indexOf('MoveDetectEvent') == 0) { this.socket.send('Capture@2') } else if (msg.data.indexOf('IdCardEvent') == 0) { this.socket.send('UnFaceDetect') } else if (msg.data.indexOf('ReadIdCard') == 0) { let s = msg.data.substring(11) if ('1' == s) { this.socket.send('GetIdCardResult@||') this.socket.send('GetIdCardImage@2') } } else if (msg.data.indexOf('GetIdCardResult') == 0) { let s = msg.data.substring(16) let info = document.getElementById('info') info.value = s } else if (msg.data.indexOf('GetBarcode') == 0) { // alert(msg.data); let s = msg.data.substring(11) let info = document.getElementById('info') info.value = s } else if (msg.data.indexOf('GetIdCardImage') == 0) { let s = msg.data.substring(15) let arr = s.split('#') let faceImg = arr[0] let myimg = document.getElementById('myCanvas3') myimg.src = 'data:image/jpeg;base64,' + faceImg } else if (msg.data.indexOf('GetBase64') == 0) { let s = msg.data.substring(10) let myimg = document.getElementById('myCanvas2') myimg.src = 'data:image/jpeg;base64,' + s alert(s) } else if (msg.data.indexOf('GetRecognitionFromFileName') == 0) { let s = msg.data.substring(27) let info = document.getElementById('info') info.value = s } else if (msg.data.indexOf('GetOcrFromFileName') == 0) { let s = msg.data.substring(19) let info = document.getElementById('info') info.value = s } else if (msg.data.indexOf('GetDogSN') == 0) { let s = msg.data.substring(11) let info = document.getElementById('info') info.value = s } } else { let reader = new FileReader() reader.onload = function (msg) { if (msg.target.readyState == FileReader.DONE) { let url = msg.target.result; document.getElementById('myCanvas').src = url; } } reader.readAsDataURL(msg.data) } }, close: function () { // console.log("socket已经关闭") this.socket.close() this.socket = '' }, handleFileChange(event) { let file = event.target.files[0] if (file) { this.UpFile.push(file) } }, // 获取身份证信息 async sfzCard() { let _this = this let res = await bdRequest({ method: 'get', url: '/api/readCard', post: '7846' }) if (res.errorMsg == 'OK') { // console.log(res.resultContent) _this.imgDeals(res.resultContent.photo) _this.cardInfo = parseCardWzxx(res.resultContent) }else{ setTimeout(() => { this.sfzCard() },1000) } }, // 图片处理 imgDeals(re) { let file = this.dataURLtoFile('data:image/png;base64,'+re, 'sfzTx.png') let formData = new FormData() formData.append('file', file) formData.append('colorEnum', 'none') changeIdPhotoBgc(formData).then((res)=>{ console.log(res) this.photo = res.previewPath }) }, }, destroyed() { // 销毁监听 if(this.socket) { this.close() } }, mounted() { this.cite.selectedFile = [] if (this.$route.params.name == "扫描打印") { this.init(); }else if(this.$route.params.name == "身份证打印") { this.sfzCard() } } } </script> <style scoped lang="less"> @font-face { font-family: 'STHeiti';//自定义字体名字 src: url('../assets/typeface/STHeiti.ttf') format('truetype');//定义好文件的相对地址 } .selectFile { .box { width: 114.06rem; height: 42.13rem; background: #ffffff; box-shadow: 0rem 0.31rem 0.63rem 0.06rem rgba(0, 0, 0, 0.14); border-radius: 1.63rem; margin: 0 auto; .tip { //margin-right: 15.31rem; width: 37rem; font-size: 2.25rem; font-weight: bold; color: #323232; line-height: 3rem; .title { font-size: 2.88rem; font-weight: bold; color: #d41212; line-height: 4.06rem; } .content { margin: 3rem auto 59px; text-align: center; } } .file { margin-left: 9.69rem; .main { width: 31.63rem; height: 26.56rem; background: #ffffff; border: 0.06rem solid #707070; margin: 0 auto 2.81rem; padding: 2rem 0; overflow-y: scroll; .li { width: 80%; margin: 0 auto; padding-bottom: 1rem; span { text-decoration: underline; cursor: pointer; } } } } .tip2 { width: 52rem; .but { .btn { width: 24.44rem; position: relative; input { position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; } } } } .file2 { margin-right: 9.69rem; .title { font-size: 2.13rem; font-weight: bold; color: #323232; line-height: 3rem; //text-align: left; span { text-decoration: underline; font-size: 1.5rem; font-weight: bold; color: #323232; line-height: 2rem; } .act { color: #52a39d; } } .main { width: 39.81rem; height: 31.31rem; background: #eeeeee; margin: 1.38rem auto 0; } .card { width: 42.81rem; height: 35.31rem; display: flex; flex-direction: column; justify-content: space-around; align-items: flex-end; font-family: 'STHeiti', Heiti, sans-serif;//使用自己自定义的名字 .card-box { width: 25rem; height: 15rem; margin-right: 5rem; position: relative; font-weight: bold; font-size: .9rem; line-height: 1rem; .card-title { padding: 1rem 0; } img { width: 25rem; } .card-sign { position: absolute; bottom: 2.6rem; left: 10.5rem; } .card-date { position: absolute; bottom: 0.5rem; left: 10.5rem; } .card-name { position: absolute; top: 2.2rem; left: 4.5rem; } .card-gender { position: absolute; top: 4.1rem; left: 4.5rem; //font-size: 0.7rem; span { margin-left: 5rem; } } .card-birth { position: absolute; top: 6.15rem; left: 4.5rem; //font-size: 0.7rem; .month { margin-left: 1.7rem; } .day { margin-left: 1.2rem; } } .card-addr { width: 10rem; position: absolute; top: 8.1rem; left: 4.5rem; //font-size: 0.7rem; text-align: left; } .card-id { position: absolute; bottom: .8rem; left: 8rem; letter-spacing: .2rem; } .card-avatar { position: absolute; top: 3.2rem; right: 2rem; width: 7rem; height: 9rem; img { width: 7rem; height: 9rem; background-size: contain; } } } } } .file3 { margin-right: 28.13rem; .main { width: 20.75rem; height: 28.88rem; border: 0.06rem solid #707070; margin: 1.06rem 0 0 13.38rem; } } .btn { width: 100%; height: 5.5rem; background: linear-gradient(132deg, #52a39d 0%, #a1c553 50%, #81d012 100%); border-radius: 1.25rem; font-size: 1.88rem; font-weight: 400; color: #ffffff; line-height: 2.63rem; cursor: pointer; } } .smfyData { height: 90%; width: 14.81rem; font-size: 1rem; font-weight: bold; color: #323232; line-height: 2rem; overflow: auto; cursor: pointer; .act { color: #52a39d; } .name { text-decoration: underline; } span { margin-left: 5rem; } } } </style>
Show line notes below