share.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="content">
  3. <!-- <button type="primary" @tap="shareInfo">分享</button> -->
  4. </view>
  5. </template>
  6. <script>
  7. import $config from './../../config/global.config';
  8. import share from '@/common/share.js';
  9. export default {
  10. props: {},
  11. data() {
  12. return {
  13. title: 'Hello',
  14. avatarUrl: '',
  15. invitationCode: '',
  16. username: '',
  17. imgUrl: this.$mConfig.staticUrl
  18. };
  19. },
  20. onLoad() {},
  21. onShow() {},
  22. onBackPress() {
  23. //监听back键,关闭弹出菜单
  24. if (this.shareObj.shareMenu.isVisible()) {
  25. this.shareObj.shareMenu.hide();
  26. this.shareObj.alphaBg.hide();
  27. return true;
  28. }
  29. },
  30. methods: {
  31. //noHome 代表非首页,即自定义页面
  32. shareInfo(params, url, title, des, images, noHome = false) {
  33. // return this.$mUtil.toast('暂无法使用分享功能')
  34. console.log('params', params, url);
  35. let shareList = [{
  36. icon: '/static/czd/wx.png',
  37. text: '微信好友'
  38. },
  39. {
  40. icon: '/static/czd/pyq.png',
  41. text: '朋友圈'
  42. }
  43. ];
  44. let shareInfo = {
  45. href: $config.hostUrl,
  46. title: title || '"宜格服务"懂宜昌,更懂你!',
  47. summary: des || '打造宜昌政务、医疗、交通、旅游、教育、生活等综合城市服务平台!',
  48. imgUrl: images || '/logo.png'
  49. };
  50. /* if (!noHome) {
  51. let options = params.split('/?')[1].split('&');
  52. let pageType = options[0].split('=')[1];
  53. let type = options[1].split('=')[1];
  54. let model_id = options[2].split('=')[1];
  55. let model_type = null;
  56. if (pageType == 3) {
  57. model_type = 0;
  58. }
  59. if (pageType == 2) {
  60. model_type = 1;
  61. }
  62. if (pageType == 1) {
  63. if (type == 1 || type == 5) {
  64. model_type = 2;
  65. }
  66. if (type == 2) {
  67. model_type = 5;
  68. }
  69. if (type == 3) {
  70. model_type = 6;
  71. }
  72. if (type == 4) {
  73. model_type = 3;
  74. }
  75. }
  76. } */
  77. this.shareObj = share(shareInfo, shareList, index => {
  78. console.log('点击按钮的序号: ' + index);
  79. console.log('分享信息' + shareInfo.href, shareInfo.title, shareInfo.summary);
  80. if (index == 0) {
  81. uni.share({
  82. provider: 'weixin',
  83. scene: 'WXSceneSession',
  84. type: 0,
  85. href: shareInfo.href,
  86. title: shareInfo.title,
  87. summary: shareInfo.summary,
  88. imageUrl: shareInfo.imgUrl,
  89. success: res => {
  90. this.shareObj.shareMenu.hide();
  91. this.shareObj.alphaBg.hide();
  92. // this.cacheBbs(model_type, model_id);
  93. // this.$mUtil.toast('分享成功')
  94. },
  95. fail: (err) => {
  96. this.shareObj.shareMenu.hide();
  97. this.shareObj.alphaBg.hide();
  98. }
  99. });
  100. } else if (index == 1) {
  101. uni.share({
  102. provider: 'weixin',
  103. scene: 'WXSenceTimeline',
  104. type: 0,
  105. href: shareInfo.href,
  106. title: shareInfo.title,
  107. summary: shareInfo.summary,
  108. imageUrl: shareInfo.imgUrl,
  109. success: res => {
  110. this.shareObj.shareMenu.hide();
  111. this.shareObj.alphaBg.hide();
  112. // this.cacheBbs(model_type, model_id);
  113. },
  114. fail: (err) => {
  115. this.shareObj.shareMenu.hide();
  116. this.shareObj.alphaBg.hide();
  117. }
  118. });
  119. } else {
  120. this.shareObj.shareMenu.hide();
  121. this.shareObj.alphaBg.hide();
  122. }
  123. });
  124. this.$nextTick(() => {
  125. this.shareObj.alphaBg.show();
  126. this.shareObj.shareMenu.show();
  127. });
  128. },
  129. cacheBbs(model_type, model_id) {
  130. console.log('参数为' + model_type, model_id);
  131. this.$http
  132. .post(`/opus/cache-bbs`, {
  133. bbs_type: 2,
  134. model_type: model_type,
  135. model_id: model_id
  136. })
  137. .then(res => {});
  138. }
  139. }
  140. };
  141. </script>
  142. <style>
  143. .content {
  144. text-align: center;
  145. height: 400upx;
  146. }
  147. .logo {
  148. height: 200upx;
  149. width: 200upx;
  150. margin-top: 200upx;
  151. }
  152. .title {
  153. font-size: 36upx;
  154. color: #8f8f94;
  155. }
  156. </style>