share.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template name="dever-share">
  2. <view>
  3. <dever-popup ref="popup" type="bottom">
  4. <view class="sharebtn">
  5. <view class="uni-share">
  6. <view class="uni-share-content">
  7. <view v-for="(v, k) in button" :key="k" class="uni-share-content-box" :style="v.type == 'copy' ? 'margin-right:0rpx;' : mr" @click='share(v.type)'>
  8. <view class="uni-share-content-image">
  9. <image :src="v.icon" class="content-image" />
  10. </view>
  11. <text class="uni-share-content-text">{{ v.text }}</text>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </dever-popup>
  17. </view>
  18. </template>
  19. <script>
  20. import deverPopup from "@/lib/dever/components/popup.vue";
  21. import copyText from "@/lib/clipboard.thorui.js";
  22. import wx from "@/lib/dever/components/jweixin.js";
  23. export default {
  24. data() {
  25. return {
  26. button: [{
  27. text: '微信',
  28. icon: '/static/dever/weixin.png',
  29. type: 'weixin'
  30. },
  31. {
  32. text: '朋友圈',
  33. icon: '/static/dever/pengyouquan.png',
  34. type: 'weixin_group'
  35. },
  36. {
  37. text: 'QQ',
  38. icon: '/static/dever/qq.png',
  39. type: 'qq'
  40. }
  41. ],
  42. }
  43. },
  44. props: {
  45. curid : 0,
  46. data : {},
  47. code : '',
  48. },
  49. created : function() {
  50. this.mr = 'margin-right:60rpx';
  51. if (this.data && this.data.poster) {
  52. this.mr = 'margin-right:40rpx';
  53. this.button.push({
  54. text: '海报',
  55. icon: '/static/dever/poster.png',
  56. type: 'poster'
  57. });
  58. }
  59. this.button.push({
  60. text: '复制',
  61. icon: '/static/dever/copy.png',
  62. type: 'copy'
  63. });
  64. if (this.code) {
  65. this.data.link = this.data.link + '?code=' + this.code;
  66. }
  67. this.init();
  68. },
  69. methods: {
  70. open : function() {
  71. this.$refs.popup.open();
  72. },
  73. init : function() {
  74. if (this.Dever.source == 'h5') {
  75. this.Dever.shareInit(wx, 1, false, this.data);
  76. }
  77. },
  78. share : function(type) {
  79. eval("this."+type+"()");
  80. },
  81. copy : function() {
  82. var self = this;
  83. var value = this.data.title;
  84. if (this.data.content) {
  85. value += "\r\n" + this.data.content;
  86. }
  87. if (this.data.link) {
  88. value += "\r\n" + this.data.link;
  89. }
  90. copyText.getClipboardData(value, function(res) {
  91. if (res) {
  92. self.Dever.alert('复制成功');
  93. } else {
  94. self.Dever.alert('复制失败');
  95. }
  96. });
  97. },
  98. weixin : function() {
  99. this.Dever.share('weixin', 'WXSceneSession', 0, this.data);
  100. },
  101. weixin_group : function() {
  102. this.Dever.share('weixin', 'WXSenceTimeline', 0, this.data);
  103. },
  104. qq : function() {
  105. this.Dever.share('qq', '', 1, this.data);
  106. },
  107. poster : function() {
  108. if (this.data.poster) {
  109. // 弹出海报
  110. } else {
  111. this.Dever.alert('没有海报素材');
  112. }
  113. }
  114. },
  115. components:{
  116. deverPopup
  117. }
  118. }
  119. </script>
  120. <style lang="scss">
  121. /* 底部分享 */
  122. .sharebtn {
  123. .uni-share {
  124. width: 690rpx;
  125. margin: 30rpx;
  126. border-radius: 30rpx;
  127. /* #ifndef APP-NVUE */
  128. display: flex;
  129. flex-direction: column;
  130. /* #endif */
  131. background-color: #fff;
  132. .uni-share-content {
  133. /* #ifndef APP-NVUE */
  134. display: flex;
  135. /* #endif */
  136. flex-direction: row;
  137. flex-wrap: nowrap;
  138. justify-content: center;
  139. overflow-x: scroll;
  140. padding: 15px 50rpx;
  141. .uni-share-content-box {
  142. /* #ifndef APP-NVUE */
  143. display: flex;
  144. /* #endif */
  145. flex-direction: column;
  146. align-items: center;
  147. // width: 25%;
  148. // justify-content: space-between;
  149. &:nth-last-child(1) {
  150. margin-right: 0;
  151. }
  152. .uni-share-content-image {
  153. /* #ifndef APP-NVUE */
  154. display: flex;
  155. /* #endif */
  156. flex-direction: row;
  157. justify-content: center;
  158. align-items: center;
  159. width: 90rpx;
  160. height: 90rpx;
  161. overflow: hidden;
  162. border-radius: 10rpx;
  163. .content-image {
  164. width: 90rpx;
  165. height: 90rpx;
  166. }
  167. }
  168. &:nth-last-child(1){
  169. .uni-share-content-image .content-image {
  170. width: 50rpx!important;
  171. height: 50rpx!important;
  172. }
  173. }
  174. .uni-share-content-text {
  175. font-size: 26rpx;
  176. color: #333;
  177. padding-top: 5px;
  178. padding-bottom: 10px;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. </style>