fa-share.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view>
  3. <u-popup v-model="value" :popup="false" mode="bottom" @close="hide" @open="open">
  4. <!-- #ifndef MP-WEIXIN -->
  5. <u-grid :col="3" :border="false">
  6. <u-grid-item v-for="(item, index) in list" :key="index" @click="share(index, item)">
  7. <u-icon :name="item.icon" :color="item.color" :size="item.size"></u-icon>
  8. <view class="grid-text u-m-t-10" v-text="item.name"></view>
  9. </u-grid-item>
  10. </u-grid>
  11. <!-- #endif -->
  12. <!-- #ifdef MP-WEIXIN -->
  13. <u-grid :col="3" :border="false">
  14. <u-grid-item v-for="(item, index) in list" :key="index" @click="share(index, item)">
  15. <button class="u-text-center share-btn" :open-type="index==1?'share':''">
  16. <u-icon :name="item.icon" :color="item.color" :size="item.size"></u-icon>
  17. <view class="grid-text u-m-t-10" v-text="item.name"></view>
  18. </button>
  19. </u-grid-item>
  20. </u-grid>
  21. <!-- #endif -->
  22. <u-gap height="3" bg-color="rgb(244, 246, 248)"></u-gap>
  23. <view class="u-text-center u-p-30" @click="hide">取消</view>
  24. </u-popup>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. isWeiXinBrowser
  30. } from '@/common/util.js';
  31. export default {
  32. name: 'fa-app-share',
  33. props: {
  34. value: {
  35. type: Boolean,
  36. default: false
  37. },
  38. goodsId: {
  39. type: [Number, String],
  40. default: ''
  41. },
  42. title: {
  43. type: String,
  44. default: ''
  45. },
  46. summary: {
  47. type: String,
  48. default: ''
  49. },
  50. href: {
  51. type: String,
  52. default: ''
  53. },
  54. imageUrl: {
  55. type: String,
  56. default: ''
  57. }
  58. },
  59. data() {
  60. let list = [];
  61. // #ifdef H5
  62. list = list.concat([
  63. // {
  64. // name: '生成海报',
  65. // icon: 'photo',
  66. // size: 60,
  67. // color: '#2979ff',
  68. // type: 0, //图文
  69. // provider: 'poster'
  70. // },
  71. {
  72. name: '复制链接',
  73. icon: 'attach',
  74. size: 60,
  75. color: '#44b549',
  76. type: 0, //图文
  77. provider: 'copylink'
  78. }
  79. ]);
  80. // #endif
  81. // #ifdef MP-WEIXIN
  82. list = [{
  83. name: '生成海报',
  84. icon: 'photo',
  85. size: 60,
  86. color: '#2979ff',
  87. type: 0, //图文
  88. provider: 'weixin'
  89. },
  90. {
  91. name: '分享好友',
  92. icon: 'weixin-circle-fill',
  93. size: 60,
  94. color: '#44b549',
  95. type: 0, //图文
  96. provider: 'weixin'
  97. }
  98. ];
  99. // #endif
  100. // #ifdef APP-PLUS
  101. list = [{
  102. name: '微信好友',
  103. icon: 'weixin-circle-fill',
  104. size: 60,
  105. color: '#44b549',
  106. type: 0, //图文
  107. provider: 'weixin'
  108. },
  109. {
  110. name: '微信朋友圈',
  111. icon: 'moments-circel-fill',
  112. size: 60,
  113. color: '#44b549',
  114. type: 0, //图文
  115. provider: 'weixin'
  116. },
  117. {
  118. name: '微信收藏',
  119. icon: 'star-fill',
  120. size: 60,
  121. color: '#ff9100',
  122. type: 0, //图文
  123. provider: 'weixin'
  124. },
  125. {
  126. name: 'QQ好友',
  127. icon: 'qq-circle-fill',
  128. size: 60,
  129. color: '#388BFF',
  130. type: 2, //图
  131. provider: 'qq'
  132. },
  133. {
  134. name: '新浪微博',
  135. icon: 'weibo-circle-fill',
  136. size: 60,
  137. color: '#BE3E3F',
  138. type: 0, //图文
  139. provider: 'sinaweibo '
  140. }
  141. ];
  142. // #endif
  143. return {
  144. list: list
  145. };
  146. },
  147. methods: {
  148. open(){
  149. // #ifdef H5
  150. if(isWeiXinBrowser()){
  151. this.$u.toast('请点击右上角的•••进行分享');
  152. }
  153. // #endif
  154. },
  155. hide() {
  156. this.$emit('input', false);
  157. },
  158. // #ifdef H5
  159. share(index, item) {
  160. if (item.provider === 'poster') {
  161. this.$emit('shares')
  162. return;
  163. } else if (item.provider === 'copylink') {
  164. this.$util.uniCopy({
  165. content: window.location.href,
  166. success: () => {
  167. this.$u.toast('复制成功,请去粘贴发送给好友吧');
  168. this.hide()
  169. },
  170. error: () => {
  171. console.error('复制失败!');
  172. }
  173. });
  174. }
  175. },
  176. // #endif
  177. // #ifdef MP-WEIXIN
  178. share(index, item) {
  179. if (!index) {
  180. this.$emit('shares')
  181. return;
  182. }
  183. },
  184. // #endif
  185. // #ifdef APP-PLUS
  186. share(index, item) {
  187. let data = {
  188. provider: item.provider,
  189. type: item.type,
  190. href: this.href,
  191. title: this.title,
  192. summary: this.summary,
  193. imageUrl: this.imageUrl,
  194. success: res => {
  195. this.hide();
  196. this.$u.toast('分享成功!');
  197. },
  198. fail: err => {
  199. console.log(JSON.stringify(err));
  200. this.$u.toast('分享失败!');
  201. }
  202. };
  203. if (index == 0) {
  204. data.scene = 'WXSceneSession';
  205. }
  206. if (index == 1) {
  207. data.scene = 'WXSenceTimeline';
  208. }
  209. if (index == 2) {
  210. data.scene = 'WXSceneFavorite';
  211. }
  212. console.log(JSON.stringify(data));
  213. uni.share(data);
  214. }
  215. // #endif
  216. }
  217. };
  218. </script>
  219. <style lang="scss" scoped>
  220. </style>