qrcode_modal.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. {{define "qrcodeModal"}}
  2. <a-modal id="qrcode-modal" v-model="qrModal.visible" :title="qrModal.title"
  3. :dialog-style="{ top: '20px' }"
  4. :closable="true"
  5. :class="themeSwitcher.currentTheme"
  6. :footer="null"
  7. width="300px">
  8. <a-tag color="green" style="margin-bottom: 10px;display: block;text-align: center;">
  9. {{ i18n "pages.inbounds.clickOnQRcode" }}
  10. </a-tag>
  11. <template v-if="app.subSettings.enable && qrModal.subId">
  12. <a-divider>{{ i18n "pages.settings.subSettings"}}</a-divider>
  13. <canvas @click="copyToClipboard('qrCode-sub',genSubLink(qrModal.client.subId))"
  14. id="qrCode-sub"
  15. class="qr-bg">
  16. </canvas>
  17. <a-divider>{{ i18n "pages.settings.subSettings"}} Json</a-divider>
  18. <canvas @click="copyToClipboard('qrCode-subJson',genSubJsonLink(qrModal.client.subId))"
  19. id="qrCode-subJson"
  20. style="width: 100%; height: 100%; display: flex; border-radius: 1rem;">
  21. </canvas>
  22. </template>
  23. <a-divider>{{ i18n "pages.inbounds.client" }}</a-divider>
  24. <template v-for="(row, index) in qrModal.qrcodes">
  25. <a-tag color="green" style="margin: 10px 0; display: block; text-align: center;">[[ row.remark ]]</a-tag>
  26. <canvas @click="copyToClipboard('qrCode-'+index, row.link)"
  27. :id="'qrCode-'+index"
  28. class="qr-bg"></canvas>
  29. </template>
  30. </a-modal>
  31. <script>
  32. const qrModal = {
  33. title: '',
  34. dbInbound: new DBInbound(),
  35. client: null,
  36. qrcodes: [],
  37. clipboard: null,
  38. visible: false,
  39. subId: '',
  40. show: function (title = '', dbInbound, client) {
  41. this.title = title;
  42. this.dbInbound = dbInbound;
  43. this.inbound = dbInbound.toInbound();
  44. this.client = client;
  45. this.subId = '';
  46. this.qrcodes = [];
  47. if (this.inbound.protocol == Protocols.WIREGUARD){
  48. this.inbound.genInboundLinks(dbInbound.remark).split('\r\n').forEach((l,index) =>{
  49. this.qrcodes.push({
  50. remark: "Peer " + (index+1),
  51. link: l
  52. });
  53. });
  54. } else {
  55. this.inbound.genAllLinks(this.dbInbound.remark, app.remarkModel, client).forEach(l => {
  56. this.qrcodes.push({
  57. remark: l.remark,
  58. link: l.link
  59. });
  60. });
  61. }
  62. this.visible = true;
  63. },
  64. close: function () {
  65. this.visible = false;
  66. },
  67. };
  68. const qrModalApp = new Vue({
  69. delimiters: ['[[', ']]'],
  70. el: '#qrcode-modal',
  71. data: {
  72. qrModal: qrModal,
  73. },
  74. methods: {
  75. copyToClipboard(elmentId, content) {
  76. this.qrModal.clipboard = new ClipboardJS('#' + elmentId, {
  77. text: () => content,
  78. });
  79. this.qrModal.clipboard.on('success', () => {
  80. app.$message.success('{{ i18n "copied" }}')
  81. this.qrModal.clipboard.destroy();
  82. });
  83. },
  84. setQrCode(elmentId, content) {
  85. new QRious({
  86. element: document.querySelector('#' + elmentId),
  87. size: 260,
  88. value: content,
  89. });
  90. },
  91. genSubLink(subID) {
  92. return app.subSettings.subURI+subID;
  93. },
  94. genSubJsonLink(subID) {
  95. return app.subSettings.subJsonURI+subID;
  96. }
  97. },
  98. updated() {
  99. if (qrModal.client && qrModal.client.subId) {
  100. qrModal.subId = qrModal.client.subId;
  101. this.setQrCode("qrCode-sub", this.genSubLink(qrModal.subId));
  102. this.setQrCode("qrCode-subJson", this.genSubJsonLink(qrModal.subId));
  103. }
  104. qrModal.qrcodes.forEach((element, index) => {
  105. this.setQrCode("qrCode-" + index, element.link);
  106. });
  107. }
  108. });
  109. </script>
  110. {{end}}