qrcode_modal.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. 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. this.inbound.genAllLinks(this.dbInbound.remark, app.remarkModel, client).forEach(l => {
  37. this.qrcodes.push({
  38. remark: l.remark,
  39. link: l.link
  40. });
  41. });
  42. this.visible = true;
  43. },
  44. close: function () {
  45. this.visible = false;
  46. },
  47. };
  48. const qrModalApp = new Vue({
  49. delimiters: ['[[', ']]'],
  50. el: '#qrcode-modal',
  51. data: {
  52. qrModal: qrModal,
  53. },
  54. methods: {
  55. copyToClipboard(elmentId, content) {
  56. this.qrModal.clipboard = new ClipboardJS('#' + elmentId, {
  57. text: () => content,
  58. });
  59. this.qrModal.clipboard.on('success', () => {
  60. app.$message.success('{{ i18n "copied" }}')
  61. this.qrModal.clipboard.destroy();
  62. });
  63. },
  64. setQrCode(elmentId, content) {
  65. new QRious({
  66. element: document.querySelector('#' + elmentId),
  67. size: 260,
  68. value: content,
  69. });
  70. },
  71. genSubLink(subID) {
  72. return app.subSettings.subURI+subID;
  73. }
  74. },
  75. updated() {
  76. if (qrModal.client && qrModal.client.subId) {
  77. qrModal.subId = qrModal.client.subId;
  78. this.setQrCode("qrCode-sub", this.genSubLink(qrModal.subId));
  79. }
  80. qrModal.qrcodes.forEach((element, index) => {
  81. this.setQrCode("qrCode-" + index, element.link);
  82. });
  83. }
  84. });
  85. </script>
  86. {{end}}