s-share-modal.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <!-- 全局分享弹框 -->
  2. <template>
  3. <view>
  4. <su-popup :show="state.showShareGuide" :showClose="false" @close="onCloseGuide" />
  5. <view v-if="state.showShareGuide" class="guide-wrap">
  6. <image class="guide-image" :src="sheep.$url.static('/static/img/shop/share/share_guide.png')" />
  7. </view>
  8. <su-popup :show="show" round="10" :showClose="false" @close="closeShareModal">
  9. <!-- 分享 tools -->
  10. <view class="share-box">
  11. <view class="share-list-box ss-flex">
  12. <!-- 操作 ①:发送给微信好友 -->
  13. <button v-if="shareConfig.methods.includes('forward')" class="share-item share-btn ss-flex-col ss-col-center"
  14. open-type="share" @tap="onShareByForward">
  15. <image class="share-img" :src="sheep.$url.static('/static/img/shop/share/share_wx.png')" mode="" />
  16. <text class="share-title">微信好友</text>
  17. </button>
  18. <!-- 操作 ②:生成海报图片 -->
  19. <button v-if="shareConfig.methods.includes('poster')" class="share-item share-btn ss-flex-col ss-col-center"
  20. @tap="onShareByPoster">
  21. <image class="share-img" :src="sheep.$url.static('/static/img/shop/share/share_poster.png')" mode="" />
  22. <text class="share-title">生成海报</text>
  23. </button>
  24. <!-- 操作 ③:生成链接 -->
  25. <button v-if="shareConfig.methods.includes('link')" class="share-item share-btn ss-flex-col ss-col-center"
  26. @tap="onShareByCopyLink">
  27. <image class="share-img" :src="sheep.$url.static('/static/img/shop/share/share_link.png')" mode="" />
  28. <text class="share-title">复制链接</text>
  29. </button>
  30. </view>
  31. <view class="share-foot ss-flex ss-row-center ss-col-center" @tap="closeShareModal">
  32. 取消
  33. </view>
  34. </view>
  35. </su-popup>
  36. <!-- 分享海报,对应操作 ② -->
  37. <canvas-poster ref="SharePosterRef" :show="state.showPosterModal" :shareInfo="shareInfo"
  38. @close="state.showPosterModal = false" />
  39. </view>
  40. </template>
  41. <script setup>
  42. /**
  43. * 分享弹窗
  44. */
  45. import { ref, unref, reactive, computed } from 'vue';
  46. import sheep from '@/sheep';
  47. import canvasPoster from './canvas-poster/index.vue';
  48. import { closeShareModal, showAuthModal } from '@/sheep/hooks/useModal';
  49. const show = computed(() => sheep.$store('modal').share);
  50. const shareConfig = computed(() => sheep.$store('app').platform.share);
  51. const SharePosterRef = ref('');
  52. const props = defineProps({
  53. shareInfo: {
  54. type: Object,
  55. default() { },
  56. },
  57. });
  58. const state = reactive({
  59. showShareGuide: false, // H5 的指引
  60. showPosterModal: false, // 海报弹窗
  61. });
  62. // 操作 ②:生成海报分享
  63. const onShareByPoster = () => {
  64. closeShareModal();
  65. if (!sheep.$store('user').isLogin) {
  66. showAuthModal();
  67. return;
  68. }
  69. unref(SharePosterRef).getPoster();
  70. state.showPosterModal = true;
  71. };
  72. // 操作 ①:直接转发分享
  73. const onShareByForward = () => {
  74. closeShareModal();
  75. // #ifdef H5
  76. if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) {
  77. state.showShareGuide = true;
  78. return;
  79. }
  80. // #endif
  81. // #ifdef APP-PLUS
  82. uni.share({
  83. provider: 'weixin',
  84. scene: 'WXSceneSession',
  85. type: 0,
  86. href: props.shareInfo.link,
  87. title: props.shareInfo.title,
  88. summary: props.shareInfo.desc,
  89. imageUrl: props.shareInfo.image,
  90. success: (res) => {
  91. console.log('success:' + JSON.stringify(res));
  92. },
  93. fail: (err) => {
  94. console.log('fail:' + JSON.stringify(err));
  95. },
  96. });
  97. // #endif
  98. };
  99. // 操作 ③:复制链接分享
  100. const onShareByCopyLink = () => {
  101. sheep.$helper.copyText(props.shareInfo.link);
  102. closeShareModal();
  103. };
  104. function onCloseGuide() {
  105. state.showShareGuide = false;
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .guide-image {
  110. right: 30rpx;
  111. top: 0;
  112. position: fixed;
  113. width: 580rpx;
  114. height: 430rpx;
  115. z-index: 10080;
  116. }
  117. // 分享tool
  118. .share-box {
  119. background: $white;
  120. width: 750rpx;
  121. border-radius: 30rpx 30rpx 0 0;
  122. padding-top: 30rpx;
  123. .share-foot {
  124. font-size: 24rpx;
  125. color: $gray-b;
  126. height: 80rpx;
  127. border-top: 1rpx solid $gray-e;
  128. }
  129. .share-list-box {
  130. .share-btn {
  131. background: none;
  132. border: none;
  133. line-height: 1;
  134. padding: 0;
  135. &::after {
  136. border: none;
  137. }
  138. }
  139. .share-item {
  140. flex: 1;
  141. padding-bottom: 20rpx;
  142. .share-img {
  143. width: 70rpx;
  144. height: 70rpx;
  145. background: $gray-f;
  146. border-radius: 50%;
  147. margin-bottom: 20rpx;
  148. }
  149. .share-title {
  150. font-size: 24rpx;
  151. color: $dark-6;
  152. }
  153. }
  154. }
  155. }
  156. </style>