qrcode_modal.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.email;
  39. address = this.dbInbound.address;
  40. this.qrcodes = [];
  41. if (this.inbound.tls && !ObjectUtil.isArrEmpty(this.inbound.stream.tls.settings.domains)) {
  42. this.inbound.stream.tls.settings.domains.forEach((domain) => {
  43. this.qrcodes.push({
  44. remark: remark + "-" + domain.remark,
  45. link: this.inbound.genLink(domain.domain, remark + "-" + domain.remark, clientIndex)
  46. });
  47. });
  48. } else {
  49. this.qrcodes.push({
  50. remark: remark,
  51. link: this.inbound.genLink(address, remark, clientIndex)
  52. });
  53. }
  54. this.visible = true;
  55. },
  56. close: function () {
  57. this.visible = false;
  58. },
  59. };
  60. const qrModalApp = new Vue({
  61. delimiters: ['[[', ']]'],
  62. el: '#qrcode-modal',
  63. data: {
  64. qrModal: qrModal,
  65. },
  66. methods: {
  67. copyToClipboard(elmentId,content) {
  68. this.qrModal.clipboard = new ClipboardJS('#'+elmentId, {
  69. text: () => content,
  70. });
  71. this.qrModal.clipboard.on('success', () => {
  72. app.$message.success('{{ i18n "copied" }}')
  73. this.qrModal.clipboard.destroy();
  74. });
  75. },
  76. setQrCode(elmentId,content) {
  77. new QRious({
  78. element: document.querySelector('#'+elmentId),
  79. size: 260,
  80. value: content,
  81. });
  82. },
  83. genSubLink(subID) {
  84. protocol = app.subSettings.tls ? "https://" : "http://";
  85. hostName = app.subSettings.domain === "" ? window.location.hostname : app.subSettings.domain;
  86. subPort = app.subSettings.port;
  87. port = (subPort === 443 && app.subSettings.tls) || (subPort === 80 && !app.subSettings.tls) ? "" : ":" + String(subPort);
  88. subPath = app.subSettings.path;
  89. return protocol + hostName + port + subPath + subID;
  90. }
  91. },
  92. updated() {
  93. if (qrModal.client.subId){
  94. qrModal.subId = qrModal.client.subId;
  95. this.setQrCode("qrCode-sub",this.genSubLink(this.subId));
  96. }
  97. qrModal.qrcodes.forEach((element,index) => {
  98. this.setQrCode("qrCode-"+index, element.link);
  99. });
  100. }
  101. });
  102. </script>
  103. {{end}}