qrcode_modal.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. {{define "qrcodeModal"}}
  2. <a-modal id="qrcode-modal" v-model="qrModal.visible" :title="qrModal.title"
  3. :closable="true"
  4. :class="themeSwitcher.darkCardClass"
  5. :footer="null"
  6. width="300px">
  7. <a-tag color="green" style="margin-bottom: 10px;display: block;text-align: center;">
  8. {{ i18n "pages.inbounds.clickOnQRcode" }}
  9. </a-tag>
  10. <canvas @click="copyToClipboard()" id="qrCode" style="width: 100%; height: 100%;"></canvas>
  11. </a-modal>
  12. <script>
  13. const qrModal = {
  14. title: '',
  15. content: '',
  16. inbound: new Inbound(),
  17. dbInbound: new DBInbound(),
  18. copyText: '',
  19. qrcode: null,
  20. clipboard: null,
  21. visible: false,
  22. show: function (title = '', content = '', dbInbound = new DBInbound(), copyText = '') {
  23. this.title = title;
  24. this.content = content;
  25. this.dbInbound = dbInbound;
  26. this.inbound = dbInbound.toInbound();
  27. if (ObjectUtil.isEmpty(copyText)) {
  28. this.copyText = content;
  29. } else {
  30. this.copyText = copyText;
  31. }
  32. this.visible = true;
  33. qrModalApp.$nextTick(() => {
  34. if (this.qrcode === null) {
  35. this.qrcode = new QRious({
  36. element: document.querySelector('#qrCode'),
  37. size: 260,
  38. value: content,
  39. });
  40. } else {
  41. this.qrcode.value = content;
  42. }
  43. });
  44. },
  45. close: function () {
  46. this.visible = false;
  47. },
  48. };
  49. const qrModalApp = new Vue({
  50. el: '#qrcode-modal',
  51. data: {
  52. qrModal: qrModal,
  53. },
  54. methods: {
  55. copyToClipboard() {
  56. this.qrModal.clipboard = new ClipboardJS('#qrCode', {
  57. text: () => this.qrModal.copyText,
  58. });
  59. this.qrModal.clipboard.on('success', () => {
  60. app.$message.success('{{ i18n "copied" }}')
  61. this.qrModal.clipboard.destroy();
  62. });
  63. }
  64. },
  65. });
  66. </script>
  67. {{end}}