s-share-modal.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. console.log(props.shareInfo);
  88. unref(SharePosterRef).getPoster();
  89. state.showPosterModal = true;
  90. };
  91. // 操作 ①:直接转发分享
  92. const onShareByForward = () => {
  93. closeShareModal();
  94. // #ifdef H5
  95. if (['WechatOfficialAccount', 'H5'].includes(sheep.$platform.name)) {
  96. state.showShareGuide = true;
  97. return;
  98. }
  99. // #endif
  100. // #ifdef APP-PLUS
  101. uni.share({
  102. provider: 'weixin',
  103. scene: 'WXSceneSession',
  104. type: 0,
  105. href: props.shareInfo.link,
  106. title: props.shareInfo.title,
  107. summary: props.shareInfo.desc,
  108. imageUrl: props.shareInfo.image,
  109. success: (res) => {
  110. console.log('success:' + JSON.stringify(res));
  111. },
  112. fail: (err) => {
  113. console.log('fail:' + JSON.stringify(err));
  114. },
  115. });
  116. // #endif
  117. };
  118. // 操作 ③:复制链接分享
  119. const onShareByCopyLink = () => {
  120. sheep.$helper.copyText(props.shareInfo.link);
  121. closeShareModal();
  122. };
  123. function onCloseGuide() {
  124. state.showShareGuide = false;
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .guide-image {
  129. right: 30rpx;
  130. top: 0;
  131. position: fixed;
  132. width: 580rpx;
  133. height: 430rpx;
  134. z-index: 10080;
  135. }
  136. // 分享tool
  137. .share-box {
  138. background: $white;
  139. width: 750rpx;
  140. border-radius: 30rpx 30rpx 0 0;
  141. padding-top: 30rpx;
  142. .share-foot {
  143. font-size: 24rpx;
  144. color: $gray-b;
  145. height: 80rpx;
  146. border-top: 1rpx solid $gray-e;
  147. }
  148. .share-list-box {
  149. .share-btn {
  150. background: none;
  151. border: none;
  152. line-height: 1;
  153. padding: 0;
  154. &::after {
  155. border: none;
  156. }
  157. }
  158. .share-item {
  159. flex: 1;
  160. padding-bottom: 20rpx;
  161. .share-img {
  162. width: 70rpx;
  163. height: 70rpx;
  164. background: $gray-f;
  165. border-radius: 50%;
  166. margin-bottom: 20rpx;
  167. }
  168. .share-title {
  169. font-size: 24rpx;
  170. color: $dark-6;
  171. }
  172. }
  173. }
  174. }
  175. </style>