s-share-modal.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. console.log(props.shareInfo, 44444)
  102. sheep.$helper.copyText(props.shareInfo.link);
  103. closeShareModal();
  104. };
  105. function onCloseGuide() {
  106. state.showShareGuide = false;
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. .guide-image {
  111. right: 30rpx;
  112. top: 0;
  113. position: fixed;
  114. width: 580rpx;
  115. height: 430rpx;
  116. z-index: 10080;
  117. }
  118. // 分享tool
  119. .share-box {
  120. background: $white;
  121. width: 750rpx;
  122. border-radius: 30rpx 30rpx 0 0;
  123. padding-top: 30rpx;
  124. .share-foot {
  125. font-size: 24rpx;
  126. color: $gray-b;
  127. height: 80rpx;
  128. border-top: 1rpx solid $gray-e;
  129. }
  130. .share-list-box {
  131. .share-btn {
  132. background: none;
  133. border: none;
  134. line-height: 1;
  135. padding: 0;
  136. &::after {
  137. border: none;
  138. }
  139. }
  140. .share-item {
  141. flex: 1;
  142. padding-bottom: 20rpx;
  143. .share-img {
  144. width: 70rpx;
  145. height: 70rpx;
  146. background: $gray-f;
  147. border-radius: 50%;
  148. margin-bottom: 20rpx;
  149. }
  150. .share-title {
  151. font-size: 24rpx;
  152. color: $dark-6;
  153. }
  154. }
  155. }
  156. }
  157. </style>