qrcode_modal.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. {{define "qrcodeModal"}}
  2. <a-modal id="qrcode-modal" v-model="qrModal.visible" :title="qrModal.title"
  3. :closable="true"
  4. :class="themeSwitcher.darkCardClass"
  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="orange" style="margin-top: 10px;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 : '');
  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. this.qrcodes.push({
  45. remark: remark + "-" + domain.remark,
  46. link: this.inbound.genLink(domain.domain, remark + "-" + domain.remark, clientIndex)
  47. });
  48. });
  49. } else {
  50. this.qrcodes.push({
  51. remark: remark,
  52. link: this.inbound.genLink(address, remark, clientIndex)
  53. });
  54. }
  55. this.visible = true;
  56. },
  57. close: function () {
  58. this.visible = false;
  59. },
  60. };
  61. const qrModalApp = new Vue({
  62. delimiters: ['[[', ']]'],
  63. el: '#qrcode-modal',
  64. data: {
  65. qrModal: qrModal,
  66. },
  67. methods: {
  68. copyToClipboard(elmentId, content) {
  69. this.qrModal.clipboard = new ClipboardJS('#' + elmentId, {
  70. text: () => content,
  71. });
  72. this.qrModal.clipboard.on('success', () => {
  73. app.$message.success('{{ i18n "copied" }}')
  74. this.qrModal.clipboard.destroy();
  75. });
  76. },
  77. setQrCode(elmentId, content) {
  78. new QRious({
  79. element: document.querySelector('#' + elmentId),
  80. size: 260,
  81. value: content,
  82. });
  83. },
  84. genSubLink(subID) {
  85. const { domain: host, port, tls: isTLS, path: base } = app.subSettings;
  86. return buildURL({ host, port, isTLS, base, path: subID+'?name='+subID });
  87. }
  88. },
  89. updated() {
  90. if (qrModal.client && qrModal.client.subId) {
  91. qrModal.subId = qrModal.client.subId;
  92. this.setQrCode("qrCode-sub", this.genSubLink(qrModal.subId));
  93. }
  94. qrModal.qrcodes.forEach((element, index) => {
  95. this.setQrCode("qrCode-" + index, element.link);
  96. });
  97. }
  98. });
  99. </script>
  100. {{end}}