index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div>
  3. <el-dialog :visible.sync="dialogTableVisible" :width="width + 'px'">
  4. <!--<vue-qr
  5. ref="qrCode"
  6. :text="qrUrl"
  7. :size="width"
  8. :correct-level="3"
  9. :margin="5"
  10. :callback="qrCodeCallback"
  11. />-->
  12. <div class="qrCode">
  13. <el-image :src="itemObj.qrCodeImage" style="width: 200px;" />
  14. <div class="btn">
  15. <el-button type="primary" @click="downLoad">下载</el-button>
  16. <el-button @click="dialogTableVisible = false">关闭</el-button>
  17. </div>
  18. </div>
  19. </el-dialog>
  20. </div>
  21. </template>
  22. <script>
  23. // import VueQr from 'vue-qr'
  24. import serviceMixin from '../../mixin/index'
  25. export default {
  26. components: {
  27. // VueQr
  28. },
  29. mixins: [serviceMixin],
  30. props: {
  31. showQrCode: {
  32. type: Boolean,
  33. default: () => false
  34. },
  35. width: {
  36. type: Number,
  37. default: () => 300
  38. },
  39. itemObj: {
  40. type: Object,
  41. default: () => ({})
  42. }
  43. },
  44. data() {
  45. return {
  46. dialogTableVisible: false,
  47. dataUrl: ''
  48. }
  49. },
  50. watch: {
  51. showQrCode(val) {
  52. if (val) {
  53. this.dialogTableVisible = true
  54. }
  55. },
  56. dialogTableVisible(val) {
  57. if (!val) {
  58. this.$emit('showQrCode')
  59. }
  60. }
  61. },
  62. methods: {
  63. // qrCodeCallback(val) {
  64. // console.log(val)
  65. // this.dataUrl = val
  66. // },
  67. downLoad() {
  68. this.$confirm('是否下载二维码?', '提示', {
  69. confirmButtonText: '确定',
  70. cancelButtonText: '取消',
  71. type: 'warning'
  72. }).then(async() => {
  73. this.isLoading = true
  74. // 使用a链接下载
  75. const downUrl = `${process.env.VUE_APP_BASE_API}/providers/download/image?ids=${this.itemObj.id}&type=1`
  76. this.downloadWithUrl(downUrl, this.itemObj.name)
  77. .catch((err) => {
  78. console.log(err)
  79. this.$message.error(`下载${this.itemObj.name}二维码失败`)
  80. })
  81. .finally(() => {
  82. this.$message({
  83. message: '下载成功',
  84. type: 'success'
  85. })
  86. this.dialogTableVisible = false
  87. })
  88. })
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .qrCode {
  95. width: 100%;
  96. display: flex;
  97. flex-direction: column;
  98. align-items: center;
  99. .btn {
  100. width: 100%;
  101. display: flex;
  102. justify-content: space-around;
  103. margin-top: 30px;
  104. }
  105. }
  106. </style>