index.vue 3.8 KB

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