|
@@ -11,16 +11,16 @@
|
|
},
|
|
},
|
|
|
|
|
|
2.必要参数
|
|
2.必要参数
|
|
-
|
|
|
|
|
|
+ codeList:[],
|
|
batchQrCodeDialogData:{},
|
|
batchQrCodeDialogData:{},
|
|
|
|
|
|
3.必要方法
|
|
3.必要方法
|
|
|
|
|
|
//二维码组件开关
|
|
//二维码组件开关
|
|
open(type,id,name){
|
|
open(type,id,name){
|
|
- if(this.checkSubList.length>0){
|
|
|
|
|
|
+ if(this.codeList.length>0){
|
|
let list = [];
|
|
let list = [];
|
|
- this.checkSubList.forEach((item)=>{
|
|
|
|
|
|
+ this.codeList.forEach((item)=>{
|
|
list.push({
|
|
list.push({
|
|
code:item.subId, //参数
|
|
code:item.subId, //参数
|
|
name:item.subName //名称
|
|
name:item.subName //名称
|
|
@@ -44,11 +44,10 @@
|
|
<template>
|
|
<template>
|
|
<div>
|
|
<div>
|
|
<!--添加/编辑弹窗-->
|
|
<!--添加/编辑弹窗-->
|
|
- <el-dialog class="batch-qr-code-dialog" title=' '
|
|
|
|
|
|
+ <el-dialog class="batch-qr-code-dialog" :title="batchQrCodeDialogData.title?batchQrCodeDialogData.title:'二维码批量下载'"
|
|
:modal-append-to-body="false"
|
|
:modal-append-to-body="false"
|
|
:show-close="false" :close-on-click-modal="false" :close-on-press-escape="false"
|
|
:show-close="false" :close-on-click-modal="false" :close-on-press-escape="false"
|
|
:visible.sync="dialogType" v-if="dialogType" width="1210px">
|
|
:visible.sync="dialogType" v-if="dialogType" width="1210px">
|
|
- <p class="title-p">{{batchQrCodeDialogData.title?batchQrCodeDialogData.title:'二维码'}}</p>
|
|
|
|
<div class="for-code-max-box scrollbar-box">
|
|
<div class="for-code-max-box scrollbar-box">
|
|
<div class="for-code-box" v-for="(item,index) in codeList" :key="item.code">
|
|
<div class="for-code-box" v-for="(item,index) in codeList" :key="item.code">
|
|
<vue-qr v-if="dialogType" :ref="'qr'+item.code" class="batch-qr-code-dialog-vue-qr" :text="item.parameter"
|
|
<vue-qr v-if="dialogType" :ref="'qr'+item.code" class="batch-qr-code-dialog-vue-qr" :text="item.parameter"
|
|
@@ -57,11 +56,11 @@
|
|
:height="item.codeName?240:200"></canvas>
|
|
:height="item.codeName?240:200"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
- <div class="button-bottom-box">
|
|
|
|
- <p class="null-p"></p>
|
|
|
|
- <p class="out-p" @click="buttonClick(2)">取消</p>
|
|
|
|
- <p class="batch-qr-code-dialog-button-p" @click="buttonClick(1)">批量下载</p>
|
|
|
|
- <p class="null-p"></p>
|
|
|
|
|
|
+ <div slot="footer" class="dialog-footer dialog-footer-box">
|
|
|
|
+ <p class="dialog-footer-button-null"></p>
|
|
|
|
+ <p class="dialog-footer-button-info" @click="buttonClick(2)">取消</p>
|
|
|
|
+ <p class="dialog-footer-button-primary" @click="buttonClick(1)">批量下载</p>
|
|
|
|
+ <p class="dialog-footer-button-null"></p>
|
|
</div>
|
|
</div>
|
|
</el-dialog>
|
|
</el-dialog>
|
|
</div>
|
|
</div>
|
|
@@ -69,6 +68,8 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
import vueQr from 'vue-qr'
|
|
import vueQr from 'vue-qr'
|
|
|
|
+ import saveAs from 'file-saver'
|
|
|
|
+ import JSZip from 'jszip'
|
|
|
|
|
|
export default {
|
|
export default {
|
|
name: 'batchQrCodeDialog',
|
|
name: 'batchQrCodeDialog',
|
|
@@ -135,16 +136,32 @@
|
|
},
|
|
},
|
|
buttonClick(type) {
|
|
buttonClick(type) {
|
|
if (type == 1) {
|
|
if (type == 1) {
|
|
- this.codeList.forEach((item) => {
|
|
|
|
- let canvas = this.$refs['canvas'+item.code]
|
|
|
|
|
|
+ // 初始化一个zip打包对象
|
|
|
|
+ let zip = new JSZip()
|
|
|
|
+ this.codeList.forEach((item,index) => {
|
|
|
|
+ let canvas = this.$refs['canvas' + item.code][0];
|
|
const base64Img = canvas.toDataURL('image/png')
|
|
const base64Img = canvas.toDataURL('image/png')
|
|
- console.log('base64Img',base64Img)
|
|
|
|
- var a = document.createElement('a') // 生成一个a元素
|
|
|
|
- var event = new MouseEvent('click') // 创建一个单击事件
|
|
|
|
- a.download = this.batchQrCodeDialogData.codeName // 设置图片名称
|
|
|
|
- a.href = base64Img // 将生成的URL设置为a.href属性
|
|
|
|
- a.dispatchEvent(event)
|
|
|
|
|
|
+ // 这个images文件目录中创建一个base64数据为imgData的图像,图像名是index序号 + item.codeName实验室名称 + '.gif'
|
|
|
|
+ zip.file((index+1)+'_'+item.codeName+'.gif', base64Img.replace(/^data:image\/(png|jpg);base64,/, ""), { base64: true })
|
|
|
|
+ })
|
|
|
|
+ // 把打包内容异步转成blob二进制格式
|
|
|
|
+ zip.generateAsync({ type: 'blob' }).then(function(content) {
|
|
|
|
+ // content就是blob数据,这里以 实验室二维码.zip 名称下载
|
|
|
|
+ // 使用了FileSaver.js
|
|
|
|
+ saveAs(content, '实验室二维码.zip')
|
|
})
|
|
})
|
|
|
|
+ this.msgSuccess('操作成功')
|
|
|
|
+ this.$set(this, 'dialogType', false)
|
|
|
|
+ if(this.$parent.$refs['table-box']){
|
|
|
|
+ this.$parent.$refs['table-box'].clearSelection();
|
|
|
|
+ this.$parent.codeList = [];
|
|
|
|
+ }else if(this.$parent.$parent.$refs['table-box']){
|
|
|
|
+ this.$parent.$parent.$refs['table-box'].clearSelection();
|
|
|
|
+ this.$parent.$parent.codeList = [];
|
|
|
|
+ }else if(this.$parent.$parent.$parent.$refs['table-box']){
|
|
|
|
+ this.$parent.$parent.$parent.$refs['table-box'].clearSelection();
|
|
|
|
+ this.$parent.$parent.$parent.codeList = [];
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
this.$set(this, 'dialogType', false)
|
|
this.$set(this, 'dialogType', false)
|
|
}
|
|
}
|
|
@@ -157,27 +174,6 @@
|
|
.batch-qr-code-dialog {
|
|
.batch-qr-code-dialog {
|
|
z-index: 10000;
|
|
z-index: 10000;
|
|
font-weight: 500;
|
|
font-weight: 500;
|
|
- .batch-qr-code-dialog-title-box {
|
|
|
|
- display: flex;
|
|
|
|
- p:nth-child(1) {
|
|
|
|
- flex: 1;
|
|
|
|
- }
|
|
|
|
- p:nth-child(2) {
|
|
|
|
- font-size: 18px;
|
|
|
|
- width: 60px;
|
|
|
|
- height: 60px;
|
|
|
|
- text-align: center;
|
|
|
|
- line-height: 60px;
|
|
|
|
- color: #999;
|
|
|
|
- cursor: pointer;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- .title-p {
|
|
|
|
- text-align: center;
|
|
|
|
- margin-top: 40px;
|
|
|
|
- font-size: 16px;
|
|
|
|
- font-weight: 700;
|
|
|
|
- }
|
|
|
|
.for-code-max-box {
|
|
.for-code-max-box {
|
|
max-height: 500px;
|
|
max-height: 500px;
|
|
.for-code-box {
|
|
.for-code-box {
|
|
@@ -196,38 +192,6 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- .button-bottom-box {
|
|
|
|
- display: flex;
|
|
|
|
- margin: 0 auto 30px;
|
|
|
|
- .null-p {
|
|
|
|
- flex: 1;
|
|
|
|
- }
|
|
|
|
- .out-p {
|
|
|
|
- width: 100px;
|
|
|
|
- height: 40px;
|
|
|
|
- line-height: 40px;
|
|
|
|
- color: #A9A9A9;
|
|
|
|
- background: #fff;
|
|
|
|
- border: 1px solid #A9A9A9;
|
|
|
|
- border-radius: 4px;
|
|
|
|
- text-align: center;
|
|
|
|
- cursor: pointer;
|
|
|
|
- }
|
|
|
|
- .batch-qr-code-dialog-button-p {
|
|
|
|
- margin-left: 20px;
|
|
|
|
- width: 100px;
|
|
|
|
- height: 40px;
|
|
|
|
- line-height: 40px;
|
|
|
|
- color: #fff;
|
|
|
|
- background: #0045AF;
|
|
|
|
- border-radius: 4px;
|
|
|
|
- text-align: center;
|
|
|
|
- cursor: pointer;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- ::v-deep .el-dialog__header {
|
|
|
|
- display: none;
|
|
|
|
- }
|
|
|
|
::v-deep .el-dialog__body {
|
|
::v-deep .el-dialog__body {
|
|
padding: 0;
|
|
padding: 0;
|
|
}
|
|
}
|