index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <diy ref="diy" v-if="isDiy"></diy>
  3. <visualization v-else></visualization>
  4. </template>
  5. <script>
  6. import diy from './diy'
  7. import visualization from './visualization'
  8. import Cache from '@/utils/cache';
  9. import {
  10. getShare
  11. } from "@/api/public.js";
  12. let app = getApp();
  13. export default {
  14. data() {
  15. return {
  16. isDiy: uni.getStorageSync('is_diy'),
  17. shareInfo: {}
  18. }
  19. },
  20. components: {
  21. diy,
  22. visualization
  23. },
  24. onShow() {
  25. uni.hideTabBar()
  26. uni.$on('is_diy', (data) => {
  27. this.isDiy = data
  28. })
  29. this.setOpenShare();
  30. },
  31. onHide() {
  32. // this.isDiy = -1
  33. },
  34. methods: {
  35. // 微信分享;
  36. setOpenShare: function() {
  37. let that = this;
  38. getShare().then((res) => {
  39. let data = res.data;
  40. this.shareInfo = data;
  41. // #ifdef H5
  42. let url = location.href;
  43. if (this.$store.state.app.uid) {
  44. url =
  45. url.indexOf("?") === -1 ?
  46. url + "?spread=" + this.$store.state.app.uid :
  47. url + "&spread=" + this.$store.state.app.uid;
  48. }
  49. if (that.$wechat.isWeixin()) {
  50. let configAppMessage = {
  51. desc: data.synopsis,
  52. title: data.title,
  53. link: url,
  54. imgUrl: data.img,
  55. };
  56. that.$wechat.wechatEvevt(
  57. ["updateAppMessageShareData", "updateTimelineShareData"],
  58. configAppMessage
  59. );
  60. }
  61. // #endif
  62. });
  63. },
  64. },
  65. onReachBottom: function() {
  66. if (this.isDiy) {
  67. this.$refs.diy.onsollBotton()
  68. }
  69. },
  70. // 滚动监听
  71. onPageScroll(e) {
  72. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  73. uni.$emit('scroll');
  74. },
  75. // #ifdef MP
  76. //发送给朋友
  77. onShareAppMessage(res) {
  78. // 此处的distSource为分享者的部分信息,需要传递给其他人
  79. let that = this;
  80. return {
  81. title: this.shareInfo.title,
  82. path: "/pages/index/index?spid=" + this.$store.state.app.uid || 0,
  83. imageUrl: this.shareInfo.img,
  84. };
  85. },
  86. //分享到朋友圈
  87. onShareTimeline() {
  88. return {
  89. title: this.shareInfo.title,
  90. query: {
  91. spid: this.$store.state.app.uid || 0
  92. },
  93. imageUrl: this.shareInfo.img,
  94. };
  95. },
  96. // #endif
  97. }
  98. </script>
  99. <style>
  100. </style>