qrcode_modal.html 2.7 KB

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