index.vue 1.8 KB

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