qrcode_modal.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. <a-tag color="green" style="margin-bottom: 10px;display: block;text-align: center;" >click on QR Code to Copy</a-tag>
  6. <canvas v-if="qrModal.inbound.protocol != Protocols.VMESS && qrModal.inbound.protocol != Protocols.VLESS" id="qrCode" style="width: 100%; height: 100%;"></canvas>
  7. <template v-if="qrModal.inbound.protocol === Protocols.VMESS" v-for="(vmess, index) in qrModal.inbound.settings.vmesses">
  8. <a-tag color="red" style="margin-bottom: 10px;display: block;text-align: center;" v-text="vmess.email"></a-tag>
  9. <canvas @click="copyTextToClipboard(`qrCode-vmess-${vmess.id}`,index)" :id="`qrCode-vmess-${vmess.id}`" style="width: 100%; height: 100%;"></canvas>
  10. <a-divider style="height: 2px; background-color: #7e7e7e" />
  11. </template>
  12. <template v-if="qrModal.inbound.protocol === Protocols.VLESS" v-for="(vless, index) in qrModal.inbound.settings.vlesses">
  13. <a-tag color="red" style="margin-bottom: 10px;display: block;text-align: center;" v-text="vless.email"></a-tag>
  14. <canvas @click="copyTextToClipboard(`qrCode-vless-${vless.id}`,index)" :id="`qrCode-vless-${vless.id}`" style="width: 100%; height: 100%;"></canvas>
  15. <a-divider style="height: 2px; background-color: #7e7e7e" />
  16. </template>
  17. </a-modal>
  18. <script>
  19. const qrModal = {
  20. title: '',
  21. content: '',
  22. inbound: new Inbound(),
  23. dbInbound: new DBInbound(),
  24. okText: '',
  25. copyText: '',
  26. qrcode: null,
  27. clipboard: null,
  28. visible: false,
  29. show: function (title='', content='', dbInbound=new DBInbound(),okText='{{ i18n "copy" }}', copyText='') {
  30. this.title = title;
  31. this.content = content;
  32. this.dbInbound = dbInbound;
  33. this.inbound = dbInbound.toInbound();
  34. this.okText = okText;
  35. if (ObjectUtil.isEmpty(copyText)) {
  36. this.copyText = content;
  37. } else {
  38. this.copyText = copyText;
  39. }
  40. this.visible = true;
  41. qrModalApp.$nextTick(() => {
  42. if (this.clipboard === null) {
  43. this.clipboard = new ClipboardJS('#qr-modal-ok-btn', {
  44. text: () => this.copyText,
  45. });
  46. this.clipboard.on('success', () => app.$message.success('{{ i18n "copied" }}'));
  47. }
  48. if (this.qrcode === null) {
  49. this.qrcode = new QRious({
  50. element: document.querySelector('#qrCode'),
  51. size: 260,
  52. value: content,
  53. });
  54. } else {
  55. this.qrcode.value = content;
  56. }
  57. });
  58. },
  59. close: function () {
  60. this.visible = false;
  61. },
  62. };
  63. const qrModalApp = new Vue({
  64. el: '#qrcode-modal',
  65. data: {
  66. qrModal: qrModal,
  67. },
  68. methods: {
  69. setQrCode(elmentId,index) {
  70. content = qrModal.inbound.genLink(qrModal.dbInbound.address,qrModal.dbInbound.remark,index)
  71. new QRious({
  72. element: document.querySelector('#'+elmentId),
  73. size: 260,
  74. value: content,
  75. });
  76. },
  77. copyTextToClipboard(elmentId,index) {
  78. link = qrModal.inbound.genLink(qrModal.dbInbound.address,qrModal.dbInbound.remark,index)
  79. this.qrModal.copyText = link
  80. this.qrModal.clipboard = new ClipboardJS('#' + elmentId, {
  81. text: () => link,
  82. });
  83. this.qrModal.clipboard.on('success', () => {
  84. app.$message.success('{{ i18n "copied" }}')
  85. this.qrModal.clipboard.destroy();
  86. });
  87. }
  88. },
  89. updated() {
  90. switch (qrModal.inbound.protocol) {
  91. case Protocols.VMESS:
  92. vmesses = qrModal.inbound.settings.vmesses
  93. for (const index in vmesses) {
  94. this.setQrCode("qrCode-vmess-" + vmesses[index].id ,index)
  95. }
  96. break;
  97. case Protocols.VLESS:
  98. vlesses = qrModal.inbound.settings.vlesses
  99. for (const index in vlesses) {
  100. this.setQrCode("qrCode-vless-" + vlesses[index].id ,index)
  101. }
  102. break;
  103. default: return null;
  104. }
  105. }
  106. });
  107. </script>
  108. {{end}}