qrcode_modal.html 5.7 KB

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