share.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. id : 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. this.Dever.shareInit(wx, 1, 1, this.data);
  75. },
  76. share : function(type) {
  77. eval("this."+type+"()");
  78. },
  79. copy : function() {
  80. var self = this;
  81. var value = this.data.title;
  82. if (this.data.content) {
  83. value += "\r\n" + this.data.content;
  84. }
  85. if (this.data.link) {
  86. value += "\r\n" + this.data.link;
  87. }
  88. copyText.getClipboardData(value, function(res) {
  89. if (res) {
  90. self.Dever.alert('复制成功');
  91. } else {
  92. self.Dever.alert('复制失败');
  93. }
  94. });
  95. },
  96. weixin : function() {
  97. this.Dever.share('weixin', 'WXSceneSession', 0, this.data);
  98. },
  99. weixin_group : function() {
  100. this.Dever.share('weixin', 'WXSenceTimeline', 0, this.data);
  101. },
  102. qq : function() {
  103. this.Dever.share('qq', '', 1, this.data);
  104. },
  105. poster : function() {
  106. if (this.data.poster) {
  107. // 弹出海报
  108. } else {
  109. this.Dever.alert('没有海报素材');
  110. }
  111. }
  112. },
  113. components:{
  114. deverPopup
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. /* 底部分享 */
  120. .sharebtn {
  121. .uni-share {
  122. width: 690rpx;
  123. margin: 30rpx;
  124. border-radius: 30rpx;
  125. /* #ifndef APP-NVUE */
  126. display: flex;
  127. flex-direction: column;
  128. /* #endif */
  129. background-color: #fff;
  130. .uni-share-content {
  131. /* #ifndef APP-NVUE */
  132. display: flex;
  133. /* #endif */
  134. flex-direction: row;
  135. flex-wrap: nowrap;
  136. justify-content: center;
  137. overflow-x: scroll;
  138. padding: 15px 50rpx;
  139. .uni-share-content-box {
  140. /* #ifndef APP-NVUE */
  141. display: flex;
  142. /* #endif */
  143. flex-direction: column;
  144. align-items: center;
  145. // width: 25%;
  146. // justify-content: space-between;
  147. &:nth-last-child(1) {
  148. margin-right: 0;
  149. }
  150. .uni-share-content-image {
  151. /* #ifndef APP-NVUE */
  152. display: flex;
  153. /* #endif */
  154. flex-direction: row;
  155. justify-content: center;
  156. align-items: center;
  157. width: 90rpx;
  158. height: 90rpx;
  159. overflow: hidden;
  160. border-radius: 10rpx;
  161. .content-image {
  162. width: 90rpx;
  163. height: 90rpx;
  164. }
  165. }
  166. &:nth-last-child(1){
  167. .uni-share-content-image .content-image {
  168. width: 50rpx!important;
  169. height: 50rpx!important;
  170. }
  171. }
  172. .uni-share-content-text {
  173. font-size: 26rpx;
  174. color: #333;
  175. padding-top: 5px;
  176. padding-bottom: 10px;
  177. }
  178. }
  179. }
  180. }
  181. }
  182. </style>