智慧农业后台管理页面
guoshilong
2022-11-08 082613d446e29e4ec1c16bfaa52345106a498b23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
  <div>
    <el-dialog
      title="补打印"
      :modal-append-to-body="false"
      :append-to-body="true"
      :close-on-click-modal="false"
      @close="close"
      width="40%"
      :visible.sync="visible"
      center
    >
      <div style="color:#FF9947;text-align: center;height:60px">为了保证每一个溯源码的唯一性,已经打印过的溯源码请勿重复打印。</div>
      <div class="dialog-code">
        <div class="sym">
          {{code}}
        </div>
      </div>
      <div style="text-align: center">
        <el-button type="success" plain @click="exporter">导出链接</el-button>
        <el-button type="success" plain @click="download">下载二维码</el-button>
        <el-button type="success" @click="printer">打 印</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { mapGetters } from "vuex";
import { getQrCodeBase64 } from "@/api/qrcode/qrcode";
export default {
  data() {
    return {
      code: null,
      visible: false,
    };
  },
  computed: {
    ...mapGetters(["permission", "userInfo"]),
  },
  mounted() {},
  methods: {
    //初始化
    init(row) {
      this.code = row.code;
      this.visible = true;
    },
    //下载
    download(){
      var that = this;
      //获取二维码图片
      getQrCodeBase64(this.code).then((res)=>{
        // res.data 就是base64
        var base64 = res.data.toString(); 
        var byteCharacters = atob(
          base64.replace(/^data:image\/(png|jpeg|jpg);base64,/, "")
        );
        var byteNumbers = new Array(byteCharacters.length);
        for (var i = 0; i < byteCharacters.length; i++) {
          byteNumbers[i] = byteCharacters.charCodeAt(i);
        }
        var byteArray = new Uint8Array(byteNumbers);
        var blob = new Blob([byteArray], {
          type: undefined,
        });
        var aLink = document.createElement("a");
        //这里写保存时的图片名称
        aLink.download = that.code + ".jpg"; 
        aLink.href = URL.createObjectURL(blob);
        aLink.click();
      })
      
    }
  },
};
</script>
 
<style>
.dialog-code{
  height: 100px;
  margin-left:30px;
}
.sym{
  width: 150px;
  height: 60px;
  line-height: 60px;
  border: 1px solid #f1f1f1;
  text-align: center;
  border-radius: 6px;
}
</style>