qrcode_modal.html 4.0 KB

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