index.vue 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="share-pg">
  3. <GoBack class="goback abs" style="z-index: 100" @click="router.go(-1)" />
  4. <div class="will-copy" ref="src">
  5. <div class="copy-img">
  6. <img src="/images/share.jpg" alt="" />
  7. </div>
  8. <div class="content txt">
  9. <div class="name">{{ user.nickname || "朋友" }}</div>
  10. <div style="line-height: 1.6em">
  11. 您是第{{user.num}}位“紫金草行动”参与者。播撒紫金草种子,让和平之花开满全城。
  12. </div>
  13. </div>
  14. </div>
  15. <img class="img-target" :src="imgData" v-if="imgData" alt="" />
  16. <PageLoading class="rendering" v-else :loading="true" text="正在生成..." />
  17. </div>
  18. </template>
  19. <script setup>
  20. import { onMounted,watch, ref } from "vue";
  21. import html2canvas from "html2canvas";
  22. import { useModel } from "@zjxpcyc/vue-tiny-store";
  23. import { useRouter } from "vue-router";
  24. import GoBack from "@/components/GoBack.vue";
  25. import PageLoading from "@/components/PageLoading.vue";
  26. const router = useRouter();
  27. const { user } = useModel("user");
  28. const imgData = ref();
  29. const src = ref();
  30. onMounted(() => {
  31. const t = setTimeout(()=>{
  32. html2canvas(src.value).then((canvas) => {
  33. imgData.value = canvas.toDataURL("image/jpg", 0.8);
  34. });
  35. clearTimeout(t);
  36. }, 200);
  37. });
  38. </script>
  39. <style lang="less" scoped>
  40. .share-pg {
  41. position: relative;
  42. overflow: hidden;
  43. height: 100%;
  44. .rendering {
  45. position: fixed;
  46. z-index: 1000;
  47. width: 100%;
  48. height: 100%;
  49. top: 0;
  50. left: 0;
  51. }
  52. .goback{
  53. z-index: 100;
  54. left: 10px;
  55. top: 10px;
  56. }
  57. .will-copy {
  58. position: absolute;
  59. z-index: 1;
  60. width: 100vw;
  61. height: 100vh;
  62. left: -200vw;
  63. top: 0;
  64. .copy-img {
  65. width: 100%;
  66. height: 100%;
  67. position: relative;
  68. img {
  69. width: 100%;
  70. position: absolute;
  71. left: 0;
  72. bottom: 0;
  73. }
  74. }
  75. }
  76. .content {
  77. position: absolute;
  78. top: 50vh;
  79. left: 30vw;
  80. text-align: left;
  81. width: 56vw;
  82. padding-bottom: 20px;
  83. .name {
  84. font-size: 18px;
  85. }
  86. }
  87. .img-target {
  88. position: absolute;
  89. z-index: 20;
  90. width: 100vw;
  91. height: 100vh;
  92. top: 0;
  93. left: 0;
  94. }
  95. }
  96. </style>