index.vue 2.9 KB

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