| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <template>
- <ele-modal
- title="二维码"
- :visible.sync="QRvisible"
- v-if="QRvisible"
- width="800px"
- :modal="false"
- >
- <div id="printSection">
- <div
- v-for="(item, index) in codeList"
- :key="index"
- style="
- display: flex;
- padding-left: 20px;
- align-items: center;
- justify-content: center;
- margin: auto;
- "
- >
- <div style="width: 250px; height: 240px">
- <img
- :src="item.qrcode"
- alt="QR Code"
- style="width: 240px; height: 240px"
- />
- </div>
- <div
- style="
- width: 440px;
- height: 240px;
- display: flex;
- flex-direction: column;
- flex-wrap: wrap;
- justify-content: center;
- "
- >
- <div style="text-align: left; font-size: 20px">
- <span style="display: inline-block; width: 100px">编码:</span>
- <span style="color: #000">{{ item.code }}</span>
- </div>
- <div style="text-align: left; font-size: 20px">
- <span style="display: inline-block; width: 100px">名称:</span>
- <span style="color: #000">{{ item.name }}</span>
- </div>
- </div>
- </div>
- </div>
- <div slot="footer">
- <el-button @click="print">打印预览</el-button>
- <el-button @click="close">关闭</el-button>
- </div>
- </ele-modal>
- </template>
- <script>
- import QRCode from 'qrcode';
- export default {
- name: 'print',
- data() {
- return {
- QRvisible: false,
- codeList: []
- };
- },
- methods: {
- open(data) {
- this.codeList = data;
- this.QRvisible = true;
- this.$nextTick(() => {
- this.generateQRCodes();
- });
- // queryPrint({ ids }).then(res => {
- // this.codeList = res;
- // this.QRvisible = true
- // this.$nextTick(() => {
- // this.generateQRCodes()
- // })
- // })
- },
- generateQRCodes() {
- this.codeList.forEach((item) => {
- QRCode.toDataURL(item.code)
- .then((url) => {
- item.qrcode = url;
- this.$forceUpdate();
- })
- .catch((err) => {
- console.error(err);
- });
- });
- },
- close() {
- this.QRvisible = false;
- },
- print() {
- const printSection = document.getElementById('printSection');
- // 创建打印任务
- const printWindow = window.open('', '_blank');
- printWindow.document.open();
- printWindow.document.write('<html><head><title>打印预览</title>');
- printWindow.document.write(
- '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
- );
- printWindow.document.write('</head><body>');
- printWindow.document.write(printSection.innerHTML);
- printWindow.document.write('</body></html>');
- printWindow.document.close();
- printWindow.onload = function () {
- printWindow.print();
- };
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @media print {
- #printSection {
- font-size: 34px;
- span {
- font-size: 34px;
- }
- }
- }
- </style>
|