qrcode_modal.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. <canvas @click="copyToClipboard('qrCode-sub',genSubLink(qrModal.client.subId))" id="qrCode-sub" style="width: 100%; height: 100%;"></canvas>
  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. <canvas @click="copyToClipboard('qrCode-'+index, row.link)" :id="'qrCode-'+index" style="width: 100%; height: 100%;"></canvas>
  18. </template>
  19. </a-modal>
  20. <script>
  21. const qrModal = {
  22. title: '',
  23. clientIndex: 0,
  24. inbound: new Inbound(),
  25. dbInbound: new DBInbound(),
  26. client: null,
  27. qrcodes: [],
  28. clipboard: null,
  29. visible: false,
  30. subId: '',
  31. show: function (title = '', dbInbound = new DBInbound(), clientIndex = 0) {
  32. this.title = title;
  33. this.clientIndex = clientIndex;
  34. this.dbInbound = dbInbound;
  35. this.inbound = dbInbound.toInbound();
  36. settings = JSON.parse(this.inbound.settings);
  37. this.client = settings.clients[clientIndex];
  38. remark = [this.dbInbound.remark, ( this.client ? this.client.email : '')].filter(Boolean).join('-');
  39. address = this.dbInbound.address;
  40. this.subId = '';
  41. this.qrcodes = [];
  42. if (this.inbound.tls && !ObjectUtil.isArrEmpty(this.inbound.stream.tls.settings.domains)) {
  43. this.inbound.stream.tls.settings.domains.forEach((domain) => {
  44. remarkText = [remark, domain.remark].filter(Boolean).join('-');
  45. this.qrcodes.push({
  46. remark: remarkText,
  47. link: this.inbound.genLink(domain.domain, remarkText, clientIndex)
  48. });
  49. });
  50. } else {
  51. this.qrcodes.push({
  52. remark: remark,
  53. link: this.inbound.genLink(address, remark, clientIndex)
  54. });
  55. }
  56. this.visible = true;
  57. },
  58. close: function () {
  59. this.visible = false;
  60. },
  61. };
  62. const qrModalApp = new Vue({
  63. delimiters: ['[[', ']]'],
  64. el: '#qrcode-modal',
  65. data: {
  66. qrModal: qrModal,
  67. },
  68. methods: {
  69. copyToClipboard(elmentId, content) {
  70. this.qrModal.clipboard = new ClipboardJS('#' + elmentId, {
  71. text: () => content,
  72. });
  73. this.qrModal.clipboard.on('success', () => {
  74. app.$message.success('{{ i18n "copied" }}')
  75. this.qrModal.clipboard.destroy();
  76. });
  77. },
  78. setQrCode(elmentId, content) {
  79. new QRious({
  80. element: document.querySelector('#' + elmentId),
  81. size: 260,
  82. value: content,
  83. });
  84. },
  85. genSubLink(subID) {
  86. const { domain: host, port, tls: isTLS, path: base } = app.subSettings;
  87. return buildURL({ host, port, isTLS, base, path: subID+'?name='+remark });
  88. }
  89. },
  90. updated() {
  91. if (qrModal.client && qrModal.client.subId) {
  92. qrModal.subId = qrModal.client.subId;
  93. this.setQrCode("qrCode-sub", this.genSubLink(qrModal.subId));
  94. }
  95. qrModal.qrcodes.forEach((element, index) => {
  96. this.setQrCode("qrCode-" + index, element.link);
  97. });
  98. }
  99. });
  100. </script>
  101. {{end}}