s-share-modal.vue 5.2 KB

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