qrcode_modal.html 3.4 KB

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