index.vue 1.7 KB

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