index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <el-dialog class="share-popup" v-model="show" title="分享" append-to-body>
  3. <p>请使用手机扫描二维码或 复制分享链接</p>
  4. <vue-qrcode
  5. :value="url"
  6. :width="isMobile ? 150 : 180"
  7. class="share-popup__qrcode"
  8. :color="{}"
  9. type="image/jpeg"
  10. />
  11. <div class="share-popup-tools">
  12. <div class="share-popup__btn" @click="copyUrl">复制分享链接</div>
  13. <div v-if="isMobile" class="share-popup__btn" @click="saveQRCode">保存二维码</div>
  14. </div>
  15. </el-dialog>
  16. </template>
  17. <script setup lang="ts">
  18. import { computed, ref, watch } from 'vue';
  19. import VueQrcode from 'vue-qrcode';
  20. import clipboard from 'clipboard';
  21. import { storeToRefs } from 'pinia';
  22. import useBaseStore from '@/store/module/base';
  23. const baseStore = useBaseStore();
  24. const { manageJsLoaded } = storeToRefs(baseStore);
  25. const url = window.location.href;
  26. const isMobile = ref(false);
  27. const props = defineProps<{
  28. visible: boolean;
  29. }>();
  30. const emits = defineEmits(['update:visible']);
  31. const show = computed({
  32. get() {
  33. return props.visible;
  34. },
  35. set(v) {
  36. emits('update:visible', v);
  37. },
  38. });
  39. const copyUrl = () => {
  40. clipboard.copy(url);
  41. ElNotification({
  42. title: '提示',
  43. type: 'success',
  44. message: '链接已复制',
  45. position: 'bottom-right',
  46. });
  47. };
  48. const saveQRCode = () => {
  49. const img = document.getElementsByClassName('share-popup__qrcode');
  50. if (img && img.length) {
  51. const a = document.createElement('a');
  52. // @ts-ignore
  53. a.href = img[0].src;
  54. a.download = '三亚家园.jpg';
  55. a.click();
  56. }
  57. };
  58. watch(manageJsLoaded, (v) => {
  59. if (v) {
  60. isMobile.value = window.browser.isMobile();
  61. }
  62. });
  63. </script>
  64. <style lang="scss">
  65. .share-popup {
  66. --el-dialog-width: 420px;
  67. --el-dialog-border-radius: 0;
  68. --el-dialog-title-font-size: 24px;
  69. height: 580px;
  70. background: rgba(0, 0, 0, 0.7);
  71. backdrop-filter: blur(4px);
  72. .el-dialog__header {
  73. padding: 50px 40px;
  74. }
  75. .el-dialog__title {
  76. color: white;
  77. font-weight: 700;
  78. }
  79. .el-dialog__body {
  80. padding: 0 60px;
  81. display: flex;
  82. flex-direction: column;
  83. align-items: center;
  84. justify-content: center;
  85. p {
  86. width: 220px;
  87. color: white;
  88. font-size: 20px;
  89. text-align: center;
  90. }
  91. }
  92. .el-dialog__headerbtn {
  93. --el-color-info: white;
  94. top: 35px;
  95. right: 20px;
  96. font-size: 26px;
  97. }
  98. &__qrcode {
  99. margin: 25px 0 40px;
  100. overflow: hidden;
  101. border-radius: 10px;
  102. }
  103. &__btn {
  104. flex: 1;
  105. height: 50px;
  106. line-height: 50px;
  107. text-align: center;
  108. color: white;
  109. font-size: 20px;
  110. background: var(--el-color-primary);
  111. border-radius: 100px;
  112. cursor: pointer;
  113. }
  114. &-tools {
  115. display: flex;
  116. align-items: center;
  117. gap: 12px;
  118. width: 100%;
  119. }
  120. }
  121. @media only screen and (max-width: 600px) {
  122. .share-popup {
  123. --el-dialog-width: 314px;
  124. --el-dialog-border-radius: 0;
  125. --el-dialog-title-font-size: 16px;
  126. height: 433px;
  127. .el-dialog__header {
  128. padding: 10px 30px 30px;
  129. }
  130. .el-dialog__body {
  131. padding: 0 30px;
  132. p {
  133. width: 160px;
  134. font-size: 16px;
  135. }
  136. }
  137. .el-dialog__headerbtn {
  138. top: 15px;
  139. right: 6px;
  140. font-size: 23px;
  141. }
  142. &__qrcode {
  143. margin: 18px 0 37px;
  144. border-radius: 3px;
  145. }
  146. &__btn {
  147. height: 43px;
  148. line-height: 43px;
  149. font-size: 16px;
  150. }
  151. }
  152. }
  153. </style>