s-share-modal.vue 4.5 KB

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