index.vue 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view>
  3. <cart-container ref="cartContainer"></cart-container>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. }
  11. },
  12. onShow() {
  13. // 每次显示页面时,更新购物车角标并调用子组件的刷新方法
  14. this.$updateCartBadge();
  15. this.$nextTick(() => {
  16. if (this.$refs.cartContainer) {
  17. this.$refs.cartContainer.loadData();
  18. }
  19. });
  20. },
  21. // 分享配置
  22. onShareAppMessage(res) {
  23. console.log(res, '分享');
  24. if (res.from === "button") {
  25. let reduceCode = uni.getStorageSync("reduceCodeShare");
  26. // 调用分享接口
  27. // 使用 uni.$u 确保可用性,避免 this.$u 在某些上下文不可用
  28. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  29. this.$u.api.goToReduceShareAjax({
  30. reduceCode: reduceCode
  31. });
  32. } else {
  33. // 降级尝试
  34. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  35. }
  36. return {
  37. title: "快来帮我减钱买书吧!",
  38. path: "/pages/home/index?reduceCode=" + reduceCode,
  39. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  40. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  41. };
  42. } else {
  43. return {
  44. title: "书嗨",
  45. page: "/pages/home/index",
  46. };
  47. }
  48. },
  49. // 分享到朋友圈
  50. onShareTimeline(res) {
  51. if (res.from === "button") {
  52. let reduceCode = uni.getStorageSync("reduceCodeShare");
  53. // 调用分享接口
  54. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  55. this.$u.api.goToReduceShareAjax({
  56. reduceCode: reduceCode
  57. });
  58. } else {
  59. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  60. }
  61. return {
  62. title: "快来帮我减钱买书吧!",
  63. path: "/pages/home/index?reduceCode=" + reduceCode,
  64. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  65. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  66. };
  67. } else {
  68. return {
  69. title: "书嗨",
  70. page: "/pages/home/index",
  71. };
  72. }
  73. },
  74. methods: {
  75. }
  76. }
  77. </script>
  78. <style>
  79. /* Empty style as content is in the component */
  80. </style>