qrcode_modal.html 2.0 KB

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