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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<template>
  <div class="encoding viewWrap">
    <a ref="download" style="display: none" />
    <h2>编码管理</h2>
    <!-- 数据功能按钮区 -->
    <el-button type="primary" icon="el-icon-download" style="width: 100px;" @click="handleExport">导出</el-button>
    <!-- 数据表格区 -->
    <el-table stripe :data="tableData" height="0" style="margin-top: 20px;">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="name" label="名称"> </el-table-column>
      <el-table-column prop="code" label="编码"> </el-table-column>
      <el-table-column label="二维码" width="120">
        <template slot-scope="scope">
          <el-button @click.native.prevent="handleShowCode(scope.row)" type="text" size="small">
            <i class="iconfont icon-erweima" style="font-size: 12px;"></i>
            查看二维码
          </el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <!-- 二维码 -->
    <div class="codeWrap" v-show="showCode" @click="handleCloseCode">
      <transition name="el-zoom-in-center">
        <img v-show="showCode" :src="imgBase64">
      </transition>
      <div class="codeMessage">点击屏幕关闭二维码</div>
    </div>
  </div>
</template>
 
<style lang="less" scoped>
.encoding {
  padding: 20px;
}
</style>
 
<script>
export default {
  name: "encoding",
  components: {},
  data() {
    return {
      tableData: [],
      showCode: false,
      codeObj: null,
      imgBase64: null,
    };
  },
  computed: {},
  mounted() {
    this.onGetTableData()
  },
  methods: {
    // 获取表格数据
    onGetTableData: function () {
      var that = this;
      that
        .$axiosAdmin({
          method: "get",
          url: "base/markQrCode/show",
        })
        .then((res) => {
          if (res.success == true) {
            that.tableData = res.content;
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 生成二维码
    handleShowCode: function (row) {
      this.imgBase64 = row.imgBase64
      this.showCode = true;
    },
    // 关闭二维码
    handleCloseCode: function () {
      this.imgBase64 = null
      this.showCode = false;
    },
    // 导出
    handleExport: function () {
      var that = this;
      that
        .$axiosAdmin({
          method: "get",
          responseType: "blob",
          url: "base/markQrCode/download",
        })
        .then((res) => {
          const blob = res;
          that.$refs.download.href = window.URL.createObjectURL(new Blob([blob], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));
          that.$refs.download.download = `标识类二维码.xlsx`;
          that.$refs.download.click();
        })
        .catch((err) => {
          console.log(err);
        });
    }
  },
};
</script>