poster.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="poster" id="posterBox">
  3. <view class="img-box">
  4. <u--image width="100%" height="1110rpx" :src="posterImg" :fade="false" mode="aspectFit"></u--image>
  5. </view>
  6. <u-toast ref="createPosterLoading"></u-toast>
  7. <view class="common-btn ml10 mr10" @click="downloadPoster">下载海报</view>
  8. <!-- 海报生成器 -->
  9. <l-painter v-if="posterImgBg && wxGodeImg" ref="painter" isCanvasToTempFilePath @success="successHandler"
  10. css="width: 750rpx;" hidden>
  11. <l-painter-view css="position: relative; height: 1110rpx;">
  12. <l-painter-image :src="posterImgBg" css="object-fit: contain; width: 100%; height: 100%;" />
  13. <l-painter-image :src="wxGodeImg"
  14. css="width: 180rpx; height: 180rpx;position: absolute;bottom: 50rpx;right: 70rpx" />
  15. </l-painter-view>
  16. <l-painter-view
  17. css="display: flex; align-items: center; justify-content: space-between; padding-top: 38rpx;">
  18. </l-painter-view>
  19. </l-painter>
  20. </view>
  21. </template>
  22. <script>
  23. import {
  24. getBanner
  25. } from "@/common/api/home.js";
  26. const RADIO = 721
  27. export default {
  28. data() {
  29. return {
  30. posterImg: '',
  31. posterImgBg: '',
  32. wxGodeImg: '',
  33. };
  34. },
  35. onLoad() {
  36. this.getPoster()
  37. this.getWxCode()
  38. this.handlePoster()
  39. },
  40. methods: {
  41. successHandler(event) {
  42. this.posterImg = event
  43. this.$refs.createPosterLoading.hide()
  44. },
  45. getWxCode() {
  46. let userInfo = uni.getStorageSync('userInfo')
  47. console.log(33333, userInfo)
  48. userInfo = userInfo && JSON.parse(userInfo)
  49. const sendData = {
  50. path: '/pages/home/dashboard/index?id=' + userInfo.id,
  51. // path: '/pages/home/dashboard/index?id=5',
  52. type: 'file'
  53. }
  54. this.$api.getQRCode(sendData).then(res => {
  55. this.wxGodeImg = res.data.url
  56. })
  57. },
  58. getPoster() {
  59. const configs = uni.getStorageSync("configs");
  60. console.log("getConfigzj=>", configs);
  61. if (configs) {
  62. this.posterImgBg = configs.shop_adimg
  63. } else {
  64. getBanner().then(res => {
  65. this.posterImgBg = res.data.shop_adimg
  66. })
  67. }
  68. },
  69. downloadPoster() {
  70. // console.log(222, this.posterImgSrc)
  71. // uni.saveImageToPhotosAlbum({
  72. // filePath: this.posterImgSrc,
  73. // complete:() => {
  74. // this.showPoster = false
  75. // }
  76. // })
  77. let _this = this
  78. this.$refs.painter.canvasToTempFilePathSync({
  79. fileType: "jpg",
  80. // 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
  81. pathType: 'url',
  82. quality: 1,
  83. success: (res) => {
  84. console.log(res.tempFilePath);
  85. // 非H5 保存到相册
  86. // H5 提示用户长按图另存
  87. uni.saveImageToPhotosAlbum({
  88. filePath: res.tempFilePath,
  89. success: function() {
  90. uni.showToast({
  91. title: '保存成功'
  92. })
  93. // _this.showPoster = false
  94. }
  95. });
  96. },
  97. })
  98. },
  99. handlePoster() {
  100. this.$refs.createPosterLoading.show({
  101. type: 'loading',
  102. message: "海报生成中...",
  103. duration: 30000,
  104. complete: () => {
  105. // this.showPoster = showPoster;
  106. }
  107. })
  108. return
  109. },
  110. }
  111. };
  112. </script>
  113. <style lang="scss" scoped>
  114. .poster {
  115. height: 100vh;
  116. width: 100%;
  117. display: flex;
  118. flex-direction: column;
  119. .img-box {
  120. flex-shrink: 0;
  121. width: 100%;
  122. height: 1110rpx;
  123. position: relative;
  124. }
  125. .info-wrap {
  126. position: absolute;
  127. bottom: 50rpx;
  128. right: left;
  129. width: 100%;
  130. z-index: 100;
  131. display: flex;
  132. box-sizing: border-box;
  133. padding: 0 50rpx;
  134. justify-content: flex-end;
  135. }
  136. }
  137. </style>