index.vue 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view>
  3. <cart-container ref="cartContainer"></cart-container>
  4. <policy-consent-host />
  5. </view>
  6. </template>
  7. <script>
  8. import PolicyConsentHost from '@/components/policy-consent-host.vue'
  9. import tabbarBlockMixin from '@/utils/tabbar-block-mixin.js'
  10. import { eventBus } from '@/utils/event-bus.js'
  11. export default {
  12. mixins: [tabbarBlockMixin],
  13. components: {
  14. PolicyConsentHost,
  15. },
  16. data() {
  17. return {
  18. }
  19. },
  20. onShow() {
  21. // 每次显示页面时更新角标;通过事件通知子组件刷新,避免访问 $refs 触发小程序占位组件报错
  22. this.$updateCartBadge();
  23. eventBus.emit('cartPageRefresh');
  24. },
  25. onPullDownRefresh() {
  26. this.$updateCartBadge();
  27. eventBus.emit('cartPageRefresh');
  28. setTimeout(() => {
  29. uni.stopPullDownRefresh();
  30. }, 1000);
  31. },
  32. // 分享配置
  33. onShareAppMessage(res) {
  34. console.log(res, '分享');
  35. if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
  36. let reduceCode = uni.getStorageSync("reduceCodeShare");
  37. // 调用分享接口
  38. // 使用 uni.$u 确保可用性,避免 this.$u 在某些上下文不可用
  39. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  40. this.$u.api.goToReduceShareAjax({
  41. reduceCode: reduceCode
  42. });
  43. } else {
  44. // 降级尝试
  45. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  46. }
  47. return {
  48. title: "快来帮我减钱买书吧!",
  49. path: "/pages/sell/index?reduceCode=" + reduceCode,
  50. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  51. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  52. };
  53. } else {
  54. return {
  55. title: "书嗨",
  56. page: "/pages/home/index",
  57. };
  58. }
  59. },
  60. // 分享到朋友圈
  61. onShareTimeline(res) {
  62. if (res.from === "button") {
  63. let reduceCode = uni.getStorageSync("reduceCodeShare");
  64. // 调用分享接口
  65. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  66. this.$u.api.goToReduceShareAjax({
  67. reduceCode: reduceCode
  68. });
  69. } else {
  70. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  71. }
  72. return {
  73. title: "快来帮我减钱买书吧!",
  74. path: "/pages/sell/index?reduceCode=" + reduceCode,
  75. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  76. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  77. };
  78. } else {
  79. return {
  80. title: "书嗨",
  81. page: "/pages/home/index",
  82. };
  83. }
  84. },
  85. methods: {
  86. }
  87. }
  88. </script>
  89. <style>
  90. /* Empty style as content is in the component */
  91. </style>