qrcode_modal.html 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. if (this.clipboard === null) {
  34. this.clipboard = new ClipboardJS('#qr-modal-ok-btn', {
  35. text: () => this.copyText,
  36. });
  37. this.clipboard.on('success', () => {
  38. app.$message.success('{{ i18n "copied" }}')
  39. this.clipboard.destroy();
  40. });
  41. }
  42. if (this.qrcode === null) {
  43. this.qrcode = new QRious({
  44. element: document.querySelector('#qrCode'),
  45. size: 260,
  46. value: content,
  47. });
  48. } else {
  49. this.qrcode.value = content;
  50. }
  51. });
  52. },
  53. close: function () {
  54. this.visible = false;
  55. },
  56. };
  57. const qrModalApp = new Vue({
  58. el: '#qrcode-modal',
  59. data: {
  60. qrModal: qrModal,
  61. },
  62. methods: {
  63. copyToClipboard() {
  64. this.qrModal.clipboard = new ClipboardJS('#qrCode', {
  65. text: () => this.qrModal.copyText,
  66. });
  67. this.qrModal.clipboard.on('success', () => {
  68. app.$message.success('{{ i18n "copied" }}')
  69. this.qrModal.clipboard.destroy();
  70. });
  71. }
  72. },
  73. });
  74. </script>
  75. {{end}}