index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. // #ifdef APP-PLUS
  61. setTimeout(e => {
  62. this.getVersion(0);
  63. }, 1500)
  64. // #endif
  65. // #ifndef APP-PLUS
  66. this.$util.Tips({
  67. title: err
  68. });
  69. // #endif
  70. })
  71. },
  72. // 微信分享;
  73. setOpenShare: function() {
  74. let that = this;
  75. getShare().then((res) => {
  76. let data = res.data;
  77. this.shareInfo = data;
  78. // #ifdef H5
  79. let url = location.href;
  80. if (this.$store.state.app.uid) {
  81. url =
  82. url.indexOf("?") === -1 ?
  83. url + "?spread=" + this.$store.state.app.uid :
  84. url + "&spread=" + this.$store.state.app.uid;
  85. }
  86. if (that.$wechat.isWeixin()) {
  87. let configAppMessage = {
  88. desc: data.synopsis,
  89. title: data.title,
  90. link: url,
  91. imgUrl: data.img,
  92. };
  93. that.$wechat.wechatEvevt(
  94. ["updateAppMessageShareData", "updateTimelineShareData"],
  95. configAppMessage
  96. );
  97. }
  98. // #endif
  99. });
  100. },
  101. },
  102. onReachBottom: function() {
  103. if (this.isDiy) {
  104. this.$refs.diy.onsollBotton()
  105. }
  106. },
  107. // 滚动监听
  108. onPageScroll(e) {
  109. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  110. uni.$emit('scroll');
  111. },
  112. // #ifdef MP
  113. //发送给朋友
  114. onShareAppMessage(res) {
  115. // 此处的distSource为分享者的部分信息,需要传递给其他人
  116. let that = this;
  117. return {
  118. title: this.shareInfo.title,
  119. path: "/pages/index/index?spid=" + this.$store.state.app.uid || 0,
  120. imageUrl: this.shareInfo.img,
  121. };
  122. },
  123. //分享到朋友圈
  124. onShareTimeline() {
  125. return {
  126. title: this.shareInfo.title,
  127. query: {
  128. spid: this.$store.state.app.uid || 0
  129. },
  130. imageUrl: this.shareInfo.img,
  131. };
  132. },
  133. // #endif
  134. }
  135. </script>
  136. <style>
  137. </style>