s-share-modal.vue 5.0 KB

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