1
0

qrcode_modal.html 2.2 KB

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