index.vue 3.0 KB

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