index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. export default {
  11. mixins: [tabbarBlockMixin],
  12. components: {
  13. PolicyConsentHost,
  14. },
  15. data() {
  16. return {
  17. }
  18. },
  19. onShow() {
  20. // 每次显示页面时,更新购物车角标并调用子组件的刷新方法
  21. this.$updateCartBadge();
  22. this.$nextTick(() => {
  23. if (this.$refs.cartContainer) {
  24. this.$refs.cartContainer.loadData();
  25. }
  26. });
  27. },
  28. onPullDownRefresh() {
  29. // 更新购物车角标并调用子组件的刷新方法
  30. this.$updateCartBadge();
  31. if (this.$refs.cartContainer) {
  32. // 如果 cartContainer 的 loadData 返回 Promise,可以通过 await 等待结束后停止下拉刷新,这里暂直接调用并停止
  33. this.$refs.cartContainer.loadData();
  34. }
  35. setTimeout(() => {
  36. uni.stopPullDownRefresh();
  37. }, 1000);
  38. },
  39. // 分享配置
  40. onShareAppMessage(res) {
  41. console.log(res, '分享');
  42. if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
  43. let reduceCode = uni.getStorageSync("reduceCodeShare");
  44. // 调用分享接口
  45. // 使用 uni.$u 确保可用性,避免 this.$u 在某些上下文不可用
  46. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  47. this.$u.api.goToReduceShareAjax({
  48. reduceCode: reduceCode
  49. });
  50. } else {
  51. // 降级尝试
  52. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  53. }
  54. return {
  55. title: "快来帮我减钱买书吧!",
  56. path: "/pages/sell/index?reduceCode=" + reduceCode,
  57. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  58. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  59. };
  60. } else {
  61. return {
  62. title: "书嗨",
  63. page: "/pages/home/index",
  64. };
  65. }
  66. },
  67. // 分享到朋友圈
  68. onShareTimeline(res) {
  69. if (res.from === "button") {
  70. let reduceCode = uni.getStorageSync("reduceCodeShare");
  71. // 调用分享接口
  72. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  73. this.$u.api.goToReduceShareAjax({
  74. reduceCode: reduceCode
  75. });
  76. } else {
  77. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  78. }
  79. return {
  80. title: "快来帮我减钱买书吧!",
  81. path: "/pages/sell/index?reduceCode=" + reduceCode,
  82. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  83. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  84. };
  85. } else {
  86. return {
  87. title: "书嗨",
  88. page: "/pages/home/index",
  89. };
  90. }
  91. },
  92. methods: {
  93. }
  94. }
  95. </script>
  96. <style>
  97. /* Empty style as content is in the component */
  98. </style>