qrcode_modal.html 3.6 KB

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