1
0

qrcode_modal.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. <canvas id="qrCode" style="width: 100%; height: 100%;"></canvas>
  7. </a-modal>
  8. <script>
  9. const qrModal = {
  10. title: '',
  11. content: '',
  12. inbound: new Inbound(),
  13. dbInbound: new DBInbound(),
  14. okText: '',
  15. copyText: '',
  16. qrcode: null,
  17. clipboard: null,
  18. visible: false,
  19. show: function (title='', content='', dbInbound=new DBInbound(),okText='{{ i18n "copy" }}', copyText='') {
  20. this.title = title;
  21. this.content = content;
  22. this.dbInbound = dbInbound;
  23. this.inbound = dbInbound.toInbound();
  24. this.okText = okText;
  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.clipboard === null) {
  33. this.clipboard = new ClipboardJS('#qr-modal-ok-btn', {
  34. text: () => this.copyText,
  35. });
  36. this.clipboard.on('success', () => app.$message.success('{{ i18n "copied" }}'));
  37. }
  38. if (this.qrcode === null) {
  39. this.qrcode = new QRious({
  40. element: document.querySelector('#qrCode'),
  41. size: 260,
  42. value: content,
  43. });
  44. } else {
  45. this.qrcode.value = content;
  46. }
  47. });
  48. },
  49. close: function () {
  50. this.visible = false;
  51. },
  52. };
  53. const qrModalApp = new Vue({
  54. el: '#qrcode-modal',
  55. data: {
  56. qrModal: qrModal,
  57. },
  58. });
  59. </script>
  60. {{end}}