index.vue 3.7 KB

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