index.vue 3.1 KB

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