| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <template>
- <view>
- <cart-container ref="cartContainer"></cart-container>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- }
- },
- onShow() {
- // 每次显示页面时,更新购物车角标并调用子组件的刷新方法
- this.$updateCartBadge();
- this.$nextTick(() => {
- if (this.$refs.cartContainer) {
- this.$refs.cartContainer.loadData();
- }
- });
- },
- onPullDownRefresh() {
- // 更新购物车角标并调用子组件的刷新方法
- this.$updateCartBadge();
- if (this.$refs.cartContainer) {
- // 如果 cartContainer 的 loadData 返回 Promise,可以通过 await 等待结束后停止下拉刷新,这里暂直接调用并停止
- this.$refs.cartContainer.loadData();
- }
- setTimeout(() => {
- uni.stopPullDownRefresh();
- }, 1000);
- },
- // 分享配置
- onShareAppMessage(res) {
- console.log(res, '分享');
- if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
- let reduceCode = uni.getStorageSync("reduceCodeShare");
- // 调用分享接口
- // 使用 uni.$u 确保可用性,避免 this.$u 在某些上下文不可用
- if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
- this.$u.api.goToReduceShareAjax({
- reduceCode: reduceCode
- });
- } else {
- // 降级尝试
- uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
- }
- return {
- title: "快来帮我减钱买书吧!",
- path: "/pages/home/index?reduceCode=" + reduceCode,
- imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
- desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
- };
- } else {
- return {
- title: "书嗨",
- page: "/pages/home/index",
- };
- }
- },
- // 分享到朋友圈
- onShareTimeline(res) {
- if (res.from === "button") {
- let reduceCode = uni.getStorageSync("reduceCodeShare");
- // 调用分享接口
- if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
- this.$u.api.goToReduceShareAjax({
- reduceCode: reduceCode
- });
- } else {
- uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
- }
- return {
- title: "快来帮我减钱买书吧!",
- path: "/pages/home/index?reduceCode=" + reduceCode,
- imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
- desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
- };
- } else {
- return {
- title: "书嗨",
- page: "/pages/home/index",
- };
- }
- },
- methods: {
- }
- }
- </script>
- <style>
- /* Empty style as content is in the component */
- </style>
|