share-btn.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="sharebtn">
  3. <view class="uni-share">
  4. <view class="uni-share-content">
  5. <view v-for="(item, index) in bottomData" :key="index" style="position: relative;" class="uni-share-content-box" >
  6. <view class="uni-share-content-image">
  7. <image :src="item.icon" class="content-image" />
  8. </view>
  9. <text class="uni-share-content-text">{{ item.text }}</text>
  10. <button open-type="share" style="position: absolute; background: none; width: 100%; height: 100%;" @click='btnShare(item.text)'></button>
  11. </view>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. bottomData: [
  21. // #ifdef H5
  22. {
  23. text: '复制',
  24. icon: '/static/index/copy.png',
  25. name: 'copy'
  26. }
  27. // #endif
  28. // #ifdef APP-PLUS || MP-WEIXIN
  29. {
  30. text: '微信',
  31. icon: '/static/index/weixin.png',
  32. name: 'wx'
  33. },
  34. {
  35. text: '朋友圈',
  36. icon: '/static/index/pengyouquan.png',
  37. name: 'copy'
  38. }
  39. // #endif
  40. ],
  41. // sharedataTemp: {
  42. // type: 0,
  43. // strShareUrl: "https://uniapp.dcloud.io",
  44. // strShareTitle: "分享标题",
  45. // strShareSummary: "分享总结",
  46. // strShareImageUrl: "/static/sharemenu/copyurl.png"
  47. // }
  48. }
  49. },
  50. props: ["sharedataTemp"],
  51. // onLoad() {
  52. // console.log('sharedataTemp',this.sharedataTemp);
  53. // },
  54. methods: {
  55. btnShare(ind) {
  56. console.log(ind);
  57. var strProvider = "",
  58. strScene = "",
  59. mytype = '';
  60. switch (ind) {
  61. case '复制':
  62. uni.setClipboardData({
  63. data: this.sharedataTemp.strShareUrl,
  64. complete() {
  65. uni.showToast({
  66. title: "已复制到剪贴板"
  67. })
  68. }
  69. })
  70. break;
  71. case '微信':
  72. strProvider = "weixin"
  73. strScene = "WXSceneSession"
  74. mytype = 0
  75. break;
  76. case '朋友圈':
  77. strProvider = "weixin"
  78. strScene = "WXSenceTimeline"
  79. mytype = 0
  80. break;
  81. }
  82. if (strProvider != "") { //点击了0-3序号的这4个按钮
  83. uni.share({
  84. provider: strProvider,
  85. scene: strScene,
  86. type: mytype,
  87. href: this.sharedataTemp.strShareUrl,
  88. title: this.sharedataTemp.strShareTitle,
  89. summary: this.sharedataTemp.strShareSummary,
  90. imageUrl: this.sharedataTemp.strShareImageUrl,
  91. success: function(res) {
  92. console.log("success:" + JSON.stringify(res));
  93. },
  94. fail: function(err) {
  95. console.log("fail:" + JSON.stringify(err));
  96. }
  97. })
  98. }
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. /* 底部分享 */
  105. .sharebtn {
  106. .uni-share {
  107. width: 690rpx;
  108. margin: 30rpx;
  109. border-radius: 30rpx;
  110. /* #ifndef APP-NVUE */
  111. display: flex;
  112. flex-direction: column;
  113. /* #endif */
  114. background-color: #fff;
  115. .uni-share-content {
  116. /* #ifndef APP-NVUE */
  117. display: flex;
  118. /* #endif */
  119. flex-direction: row;
  120. flex-wrap: nowrap;
  121. justify-content: center;
  122. overflow-x: scroll;
  123. padding: 15px 50rpx;
  124. .uni-share-content-box {
  125. /* #ifndef APP-NVUE */
  126. display: flex;
  127. /* #endif */
  128. flex-direction: column;
  129. align-items: center;
  130. // width: 25%;
  131. // justify-content: space-between;
  132. margin-right: 60rpx;
  133. &:nth-last-child(1) {
  134. margin-right: 0;
  135. }
  136. .uni-share-content-image {
  137. /* #ifndef APP-NVUE */
  138. display: flex;
  139. /* #endif */
  140. flex-direction: row;
  141. justify-content: center;
  142. align-items: center;
  143. width: 90rpx;
  144. height: 90rpx;
  145. overflow: hidden;
  146. border-radius: 10rpx;
  147. .content-image {
  148. width: 90rpx;
  149. height: 90rpx;
  150. }
  151. }
  152. &:nth-last-child(1){
  153. .uni-share-content-image .content-image {
  154. width: 50rpx!important;
  155. height: 50rpx!important;
  156. }
  157. }
  158. .uni-share-content-text {
  159. font-size: 26rpx;
  160. color: #333;
  161. padding-top: 5px;
  162. padding-bottom: 10px;
  163. }
  164. }
  165. }
  166. }
  167. }
  168. </style>