index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!-- 公共二维码dialog组件
  2. 1.引入方式
  3. <qr-code-dialog v-if="qrCodeDialogType" :qrCodeDialogData="qrCodeDialogData"></qr-code-dialog>
  4. import qrCodeDialog from "@/components/qrCodeDialog/index.vue"
  5. components: {
  6. qrCodeDialog
  7. },
  8. 2.必要参数
  9. qrCodeDialogType:false,
  10. qrCodeDialogData:{},
  11. 3.必要方法
  12. //二维码组件开关
  13. qrCodeDialogButton(type,id,name){
  14. if(type == 1){
  15. this.$set(this,'qrCodeDialogData',{
  16. type:'chemicalsCabinet', //二维码类型 用于区分二维码功能类型
  17. parameter:id, //二维码参数
  18. name:name, //二维码名称用于下载时命名
  19. });
  20. this.$set(this,'qrCodeDialogType',true);
  21. }else{
  22. this.$set(this,'qrCodeDialogType',false);
  23. }
  24. },
  25. -->
  26. <template>
  27. <div>
  28. <!--添加/编辑弹窗-->
  29. <el-dialog class="trainingCourseAddDialog" title=' 1'
  30. :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false"
  31. :visible.sync="dialogType" v-if="dialogType" width="394px">
  32. <div class="trainingCourseAddDialog-title-box">
  33. <p></p>
  34. <p class="el-icon-close" @click="buttonClick"></p>
  35. </div>
  36. <vue-qr v-if="vueQrImgType" ref="vueQr" class="trainingCourseAddDialog-vue-qr" :text="vueQrCodeData" :size="200"></vue-qr>
  37. <p class="trainingCourseAddDialog-button-p" @click="buttonClick(1)">下载二维码</p>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <script>
  42. import vueQr from 'vue-qr'
  43. export default {
  44. name: 'qrCodeDialog',
  45. components: {
  46. vueQr
  47. },
  48. props:{
  49. qrCodeDialogData:{},
  50. },
  51. data(){
  52. return{
  53. dialogType:true,
  54. vueQrCodeData:null,
  55. vueQrImgType:false,
  56. identification: localStorage.getItem('codeOnlineAdd'), //二维码规则 服务器域名,需与微信后台开发配置内一致.
  57. }
  58. },
  59. created(){
  60. },
  61. mounted(){
  62. this.initialize();
  63. },
  64. methods:{
  65. //初始化
  66. initialize(){
  67. this.$set(this,'vueQrCodeData', this.identification+'?code='+this.qrCodeDialogData.parameter+'&type='+this.qrCodeDialogData.type);
  68. this.$set(this,'vueQrImgType',true);
  69. },
  70. buttonClick(type){
  71. if(type == 1){
  72. let base64Str = this.$refs.vueQr.imgUrl;
  73. let aLink = document.createElement("a");
  74. aLink.style.display = "none";
  75. aLink.href = base64Str;
  76. aLink.download = this.qrCodeDialogData.name+"-二维码.png";
  77. document.body.appendChild(aLink);
  78. aLink.click();
  79. document.body.removeChild(aLink);
  80. }else{
  81. this.$parent.qrCodeDialogButton();
  82. }
  83. },
  84. },
  85. }
  86. </script>
  87. <style scoped lang="scss">
  88. .trainingCourseAddDialog{
  89. font-weight:500;
  90. .trainingCourseAddDialog-title-box{
  91. display: flex;
  92. p:nth-child(1){
  93. flex:1;
  94. }
  95. p:nth-child(2){
  96. font-size:18px;
  97. width:60px;
  98. height:60px;
  99. text-align: center;
  100. line-height:60px;
  101. color:#999;
  102. cursor: pointer;
  103. }
  104. }
  105. .trainingCourseAddDialog-vue-qr{
  106. display: block!important;
  107. height:200px;
  108. width:200px;
  109. margin:20px auto 27px;
  110. }
  111. .trainingCourseAddDialog-button-p{
  112. width:150px;
  113. height:40px;
  114. line-height:40px;
  115. margin:0 auto 30px;
  116. color:#fff;
  117. background:#0045AF;
  118. border-radius:10px;
  119. text-align: center;
  120. cursor: pointer;
  121. }
  122. ::v-deep .el-dialog__header{
  123. display: none;
  124. }
  125. ::v-deep .el-dialog__body{
  126. padding:0;
  127. }
  128. }
  129. </style>