sharePoster.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view class="share-poster-wrap" :catchtouchmove="false">
  3. <div v-if="showSlot" @click.stop="handleCreatePoster">
  4. <slot></slot>
  5. </div>
  6. <image @click.stop="handleCreatePoster" :style="style" class="share-icon" src="@/static/share-poster-icon.png" mode="aspectFill" v-else/>
  7. <view class="poster-mask" v-if="show||showPoster" @click.stop="showPoster=false"></view>
  8. <view class="loading-box" v-if="show">
  9. <image class="load-img" src="../../static/loading.png" mode="aspectFill" />
  10. <view>海报生成中...</view>
  11. </view>
  12. <image v-if="showPoster" class="poster-img" :src="posterImg" mode="widthFix" show-menu-by-longpress />
  13. </view>
  14. </template>
  15. <script>
  16. import {apiGetPoster} from '@/api/common'
  17. export default {
  18. // shareData.type 分享页面:
  19. //activity_detail(活动详情) activity_list(活动列表) special_column_list(专栏列表) special_column_detail(专栏详情)
  20. //report_list(报告列表) report_detail(报告详情) chart_list(图库列表) chart_detail(图库详情) voice_detail(语音详情)
  21. props:{
  22. style:null,
  23. shareData:null,
  24. showSlot:{//是否用插槽显示
  25. default:false
  26. }
  27. },
  28. data () {
  29. return {
  30. loading:false,
  31. show:false,
  32. posterImg:'',
  33. showPoster:false
  34. }
  35. },
  36. methods: {
  37. async handleCreatePoster(){
  38. this.show=true
  39. const res=await apiGetPoster({
  40. code_page:this.shareData.code_page,
  41. code_scene:this.shareData.code_scene,
  42. source:this.shareData.type,
  43. pars:JSON.stringify(this.shareData.data)
  44. })
  45. if(res.code==200){
  46. this.posterImg=res.data
  47. this.show=false
  48. this.showPoster=true
  49. }else{
  50. this.show=false
  51. }
  52. }
  53. }
  54. }
  55. </script>
  56. <style lang="scss" scoped>
  57. .share-poster-wrap{
  58. .share-icon{
  59. position: fixed;
  60. bottom: 100rpx;
  61. right: 34rpx;
  62. z-index: 50;
  63. width: 76rpx;
  64. height: 76rpx;
  65. }
  66. .poster-mask{
  67. position: fixed;
  68. left: 0;
  69. top: 0;
  70. right: 0;
  71. bottom: 0;
  72. background: rgba(0, 0, 0, 0.4);
  73. z-index: 998;
  74. }
  75. .loading-box{
  76. background-color: #fff;
  77. position: fixed;
  78. left: 50%;
  79. top: 50%;
  80. z-index: 999;
  81. transform: translate(-50%,-50%);
  82. width: 417rpx;
  83. height: 261rpx;
  84. text-align: center;
  85. padding-top: 80rpx;
  86. font-size: 32rpx;
  87. font-weight: bold;
  88. .load-img{
  89. width: 91rpx;
  90. height: 91rpx;
  91. animation: circle 1s linear infinite;
  92. }
  93. @keyframes circle {
  94. 0%{
  95. transform: rotateZ(0);
  96. }
  97. 100%{
  98. transform: rotateZ(360deg);
  99. }
  100. }
  101. }
  102. .poster-img{
  103. width: 90vw;
  104. display: block;
  105. position: fixed;
  106. left: 50%;
  107. top: 50%;
  108. z-index: 999;
  109. transform: translate(-50%,-50%);
  110. border-radius: 16rpx;
  111. }
  112. }
  113. </style>