index.vue 2.0 KB

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