index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!-- 海报弹窗 -->
  2. <template>
  3. <su-popup :show="show" round="10" @close="onClosePoster" type="center" class="popup-box">
  4. <view class="ss-flex-col ss-col-center ss-row-center">
  5. <template v-if="poster.views.length > 0">
  6. <l-painter :board="poster" />
  7. </template>
  8. </view>
  9. </su-popup>
  10. </template>
  11. <script setup>
  12. import { getCurrentInstance, reactive } from 'vue';
  13. import sheep from '@/sheep';
  14. import { getPosterData } from '@/sheep/components/s-share-modal/canvas-poster/poster';
  15. const props = defineProps({
  16. show: {
  17. type: Boolean,
  18. default: false,
  19. },
  20. shareInfo: {
  21. type: Object,
  22. default() {
  23. },
  24. },
  25. });
  26. const poster = reactive({
  27. css: {
  28. // 根节点若无尺寸,自动获取父级节点
  29. width: sheep.$platform.device.windowWidth * 0.9,
  30. height: 600,
  31. },
  32. views: [],
  33. });
  34. const emits = defineEmits(['success', 'close']);
  35. const vm = getCurrentInstance();
  36. const onClosePoster = () => {
  37. emits('close');
  38. };
  39. // 保存海报图片
  40. const onSavePoster = () => {
  41. if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) {
  42. sheep.$helper.toast('请长按图片保存');
  43. return;
  44. }
  45. uni.saveImageToPhotosAlbum({
  46. filePath: poster.src,
  47. success: (res) => {
  48. onClosePoster();
  49. sheep.$helper.toast('保存成功');
  50. },
  51. fail: (err) => {
  52. sheep.$helper.toast('保存失败');
  53. console.log('图片保存失败:', err);
  54. },
  55. });
  56. };
  57. // 使用 canvas 生成海报
  58. async function getPoster(params) {
  59. let drawer = await getPosterData({
  60. width: sheep.$platform.device.windowWidth * 0.9,
  61. shareInfo: props.shareInfo,
  62. });
  63. poster.views = drawer;
  64. }
  65. defineExpose({
  66. getPoster,
  67. });
  68. </script>
  69. <style lang="scss" scoped>
  70. .popup-box {
  71. position: relative;
  72. }
  73. .poster-title {
  74. color: #999;
  75. }
  76. // 分享海报
  77. .poster-btn-box {
  78. width: 600rpx;
  79. position: absolute;
  80. left: 50%;
  81. transform: translateX(-50%);
  82. bottom: -80rpx;
  83. .cancel-btn {
  84. width: 240rpx;
  85. height: 70rpx;
  86. line-height: 70rpx;
  87. background: $white;
  88. border-radius: 35rpx;
  89. font-size: 28rpx;
  90. font-weight: 500;
  91. color: $dark-9;
  92. }
  93. .save-btn {
  94. width: 240rpx;
  95. height: 70rpx;
  96. line-height: 70rpx;
  97. border-radius: 35rpx;
  98. font-size: 28rpx;
  99. font-weight: 500;
  100. }
  101. }
  102. .poster-img {
  103. border-radius: 20rpx;
  104. }
  105. .hideCanvas {
  106. position: fixed;
  107. top: -99999rpx;
  108. left: -99999rpx;
  109. z-index: -99999;
  110. }
  111. </style>