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