s-share-modal.vue 5.0 KB

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