index.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <van-dialog class="app-qrcode" v-model:show="showDialog" :show-confirm-button="showConfirmButton"
  3. confirm-button-text="保存" show-cancel-button @confirm="onConfirm">
  4. <vue-qr ref="qrRef" :size="400" :logoSrc="require('@mobile/assets/logo.svg')" :text="content" />
  5. </van-dialog>
  6. </template>
  7. <script lang="ts" setup>
  8. import { computed, shallowRef } from 'vue'
  9. import { Dialog } from 'vant'
  10. import plus from '@/utils/h5plus'
  11. import VueQr from 'vue-qr/src/packages/vue-qr.vue'
  12. const props = defineProps({
  13. show: {
  14. type: Boolean,
  15. default: false
  16. },
  17. content: String,
  18. fileName: String
  19. })
  20. const VanDialog = Dialog.Component
  21. const emit = defineEmits(['update:show'])
  22. const showConfirmButton = shallowRef(false)
  23. const qrRef = shallowRef()
  24. const showDialog = computed({
  25. get: () => props.show,
  26. set: (val) => emit('update:show', val)
  27. })
  28. // 保存二维码
  29. const onConfirm = () => {
  30. plus.saveImage(qrRef.value.imgUrl, 'thj_' + (props.fileName ?? new Date().getTime()))
  31. }
  32. plus.onPlusReady(() => {
  33. showConfirmButton.value = true
  34. })
  35. </script>
  36. <style lang="less">
  37. @import './index.less';
  38. </style>