qrcode_modal.html 4.0 KB

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