index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <diy ref="diy" v-if="isDiy"></diy>
  3. <visualization v-else></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. } from "@/api/public.js";
  12. let app = getApp();
  13. export default {
  14. data() {
  15. return {
  16. isDiy: uni.getStorageSync('is_diy'),
  17. shareInfo: {}
  18. }
  19. },
  20. components: {
  21. diy,
  22. visualization
  23. },
  24. onShow() {
  25. uni.hideTabBar()
  26. uni.$on('is_diy', (data) => {
  27. this.isDiy = data
  28. })
  29. this.setOpenShare();
  30. },
  31. onHide() {
  32. // this.isDiy = -1
  33. },
  34. methods: {
  35. // 微信分享;
  36. setOpenShare: function() {
  37. let that = this;
  38. getShare().then((res) => {
  39. let data = res.data;
  40. this.shareInfo = data;
  41. // #ifdef H5
  42. let url = location.href;
  43. if (this.$store.state.app.uid) {
  44. url =
  45. url.indexOf("?") === -1 ?
  46. url + "?spread=" + this.$store.state.app.uid :
  47. url + "&spread=" + this.$store.state.app.uid;
  48. }
  49. if (that.$wechat.isWeixin()) {
  50. let configAppMessage = {
  51. desc: data.synopsis,
  52. title: data.title,
  53. link: url,
  54. imgUrl: data.img,
  55. };
  56. that.$wechat.wechatEvevt(
  57. ["updateAppMessageShareData", "updateTimelineShareData"],
  58. configAppMessage
  59. );
  60. }
  61. // #endif
  62. });
  63. },
  64. },
  65. onReachBottom: function() {
  66. if (this.isDiy) {
  67. this.$refs.diy.onsollBotton()
  68. }
  69. },
  70. // #ifdef MP
  71. //发送给朋友
  72. onShareAppMessage(res) {
  73. // 此处的distSource为分享者的部分信息,需要传递给其他人
  74. let that = this;
  75. return {
  76. title: this.shareInfo.title,
  77. path: "/pages/index/index?spid=" + this.$store.state.app.uid || 0,
  78. imageUrl: this.shareInfo.img,
  79. };
  80. },
  81. //分享到朋友圈
  82. onShareTimeline() {
  83. return {
  84. title: this.shareInfo.title,
  85. query: {
  86. spid: this.$store.state.app.uid || 0
  87. },
  88. imageUrl: this.shareInfo.img,
  89. };
  90. },
  91. // #endif
  92. }
  93. </script>
  94. <style>
  95. </style>