index.vue 3.0 KB

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