index.vue 3.1 KB

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