index.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <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. </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 emit = defineEmits(['update:show'])
  21. const showConfirmButton = shallowRef(false)
  22. const qrRef = shallowRef()
  23. const showDialog = computed({
  24. get: () => props.show,
  25. set: (val) => emit('update:show', val)
  26. })
  27. // 保存二维码
  28. const onConfirm = () => {
  29. plus.saveImage(qrRef.value.imgUrl, 'thj_' + (props.fileName ?? new Date().getTime()))
  30. }
  31. plus.onPlusReady(() => {
  32. showConfirmButton.value = true
  33. })
  34. </script>
  35. <style lang="less">
  36. @import './index.less';
  37. </style>