ソースを参照

refactor: 重构活动分享逻辑,修正分享路径并更新开发配置

更新开发环境API接口地址从https://bpi.shuhi.com至https://bk.shuhi.com
修正多个页面的分享跳转路径,将原/pages/home/index调整为/pages/sell/index
抽离ActivityHost通用组件统一管理加价、减价分享活动逻辑
优化eventBus实现,支持绑定多个回调函数
重构小程序App、首页及售卖页的活动参数处理流程
ylong 2 日 前
コミット
eabd0edaac

+ 1 - 1
.env.dev.js

@@ -1,5 +1,5 @@
 export default {
     "NODE_ENV": 'development',
-    "apiUrl":"https://bpi.shuhi.com",
+    "apiUrl":"https://bk.shuhi.com",
     "apiUrlPrefix":"/api",
 };

+ 44 - 2
App.vue

@@ -84,13 +84,55 @@ export default {
 			this.slientLogin()
 		}
 	},
-	onShow() {
+	onShow(options) {
 		this.$updateCartBadge();
+		this.handleAppShowOptions(options);
 	},
 	onUnload() {
 		uni.removeStorageSync('loginType')
 	},
 	methods: {
+		parseEntryOptions(options = {}) {
+			let params = {};
+			if (!options || !options.query) return params;
+
+			if (options.query.scene) {
+				const decodeScene = decodeURIComponent(options.query.scene);
+				const paramPairs = decodeScene.split('&');
+				paramPairs.forEach((pair) => {
+					const [key, value] = pair.split('=');
+					params[key] = value;
+				});
+				return params;
+			}
+
+			return options.query || {};
+		},
+		cacheEntryParams(params = {}) {
+			if (params.upsellCode) {
+				uni.setStorageSync('upsellCode', params.upsellCode)
+			}
+			if (params.reduceCode) {
+				uni.setStorageSync('reduceCode', params.reduceCode)
+			}
+			if (params.isbn) {
+				uni.setStorageSync('scene_isbn', params.isbn);
+			}
+			if (params.bianhao) {
+				uni.setStorageSync('scene_bianhao', params.bianhao);
+			}
+		},
+		handleAppShowOptions(options = {}) {
+			const params = this.parseEntryOptions(options);
+			if (!Object.keys(params).length) return;
+
+			this.cacheEntryParams(params);
+			if (this.globalData.isColdLaunch) return;
+
+			if (params.upsellCode || params.reduceCode) {
+				eventBus.emit('appShowActivity', { params });
+			}
+		},
 		slientLogin(params = {}) {
 			let that = this;
 			uni.login({
@@ -227,4 +269,4 @@ uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
 	@extend .mallbtn;
 	background-color: $app-theme-buybtn-bg-color;
 }
-</style>
+</style>

+ 185 - 0
components/activity-host.vue

@@ -0,0 +1,185 @@
+<template>
+    <view>
+        <UpsellShare v-if="enableUpsell" ref="shareRef" @viewRules="emitViewRules" />
+        <ReduceShare v-if="enableReduce" ref="reduceShareRef" @viewRules="emitViewRules" />
+    </view>
+</template>
+
+<script>
+import UpsellShare from "@/pages/home/components/upsell-share.vue";
+import ReduceShare from "@/pages/home/components/reduce-share.vue";
+import { eventBus } from "@/utils/event-bus";
+
+export default {
+    name: "ActivityHost",
+    props: {
+        enableUpsell: {
+            type: Boolean,
+            default: true,
+        },
+        enableReduce: {
+            type: Boolean,
+            default: true,
+        },
+    },
+    components: {
+        UpsellShare,
+        ReduceShare,
+    },
+    data() {
+        return {
+            loginSuccessHandler: null,
+            appShowActivityHandler: null,
+        };
+    },
+    mounted() {
+        this.bindLoginSuccess();
+        this.bindAppShowActivity();
+        this.tryOpenPendingActivity();
+    },
+    beforeDestroy() {
+        this.unbindLoginSuccess();
+        this.unbindAppShowActivity();
+    },
+    methods: {
+        bindLoginSuccess() {
+            if (this.loginSuccessHandler) return;
+
+            this.loginSuccessHandler = (data) => {
+                this.openByLoginSuccess(data);
+                const app = getApp();
+                if (app && app.globalData) {
+                    app.globalData.isColdLaunch = false;
+                }
+            };
+            eventBus.on("loginSuccess", this.loginSuccessHandler);
+        },
+        bindAppShowActivity() {
+            if (this.appShowActivityHandler) return;
+
+            this.appShowActivityHandler = (data) => {
+                this.openByLoginSuccess(data);
+            };
+            eventBus.on("appShowActivity", this.appShowActivityHandler);
+        },
+        unbindLoginSuccess() {
+            if (!this.loginSuccessHandler) return;
+            eventBus.off("loginSuccess", this.loginSuccessHandler);
+            this.loginSuccessHandler = null;
+        },
+        unbindAppShowActivity() {
+            if (!this.appShowActivityHandler) return;
+            eventBus.off("appShowActivity", this.appShowActivityHandler);
+            this.appShowActivityHandler = null;
+        },
+        tryOpenPendingActivity() {
+            const token = uni.getStorageSync("token");
+            const upsellCode = uni.getStorageSync("upsellCode");
+            const reduceCode = uni.getStorageSync("reduceCode");
+            if (!token || (!upsellCode && !reduceCode)) return;
+
+            this.openByLoginSuccess();
+        },
+        openByLoginSuccess(data) {
+            const upsellCode = uni.getStorageSync("upsellCode") || data?.params?.upsellCode;
+            const reduceCode = uni.getStorageSync("reduceCode") || data?.params?.reduceCode;
+
+            if (this.enableUpsell && upsellCode) {
+                this.$refs.shareRef?.open(upsellCode);
+            }
+            if (this.enableReduce && reduceCode) {
+                this.$refs.reduceShareRef?.open(reduceCode);
+            }
+            this.$emit("refresh-order");
+        },
+        handlePageOptions(options = {}, isColdLaunch = false) {
+            if (isColdLaunch) return;
+
+            const params = this.parseEntryParams(options);
+            if (this.enableUpsell && params.upsellCode) {
+                this.$refs.shareRef?.open(params.upsellCode);
+                this.$emit("refresh-order");
+                return;
+            }
+            if (this.enableReduce && params.reduceCode) {
+                this.$refs.reduceShareRef?.open(params.reduceCode);
+                return;
+            }
+            this.$emit("refresh-order");
+        },
+        parseEntryParams(options = {}) {
+            if (!options.scene) return options;
+
+            const params = {};
+            const decodeScene = decodeURIComponent(options.scene);
+            const paramPairs = decodeScene.split("&");
+            paramPairs.forEach((pair) => {
+                const [key, value] = pair.split("=");
+                params[key] = value;
+            });
+            return params;
+        },
+        emitViewRules() {
+            this.$emit("view-rules");
+        },
+        getShareAppMessage(res) {
+            if (this.enableUpsell && res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "upsell") {
+                const upsellCode = uni.getStorageSync("upsellCodeShare");
+                uni.$u.http.get("/token/order/goToShare?upsellCode=" + upsellCode);
+                return {
+                    title: "书嗨",
+                    path: "/pages/home/index?upsellCode=" + upsellCode,
+                    imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
+                    desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
+                };
+            }
+
+            if (this.enableReduce && res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
+                const reduceCode = uni.getStorageSync("reduceCodeShare");
+                if (uni.$u && uni.$u.api && uni.$u.api.goToReduceShareAjax) {
+                    uni.$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/sell/index?reduceCode=" + reduceCode,
+                    imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
+                    desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
+                };
+            }
+
+            return null;
+        },
+        getShareTimeline(res) {
+            if (this.enableUpsell && res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "upsell") {
+                const upsellCode = uni.getStorageSync("upsellCodeShare");
+                uni.$u.http.get("/token/order/goToShare?upsellCode=" + upsellCode);
+                return {
+                    title: "书嗨",
+                    path: "/pages/home/index?upsellCode=" + upsellCode,
+                    imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
+                    desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
+                };
+            }
+
+            if (this.enableReduce && res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
+                const reduceCode = uni.getStorageSync("reduceCodeShare");
+                if (uni.$u && uni.$u.api && uni.$u.api.goToReduceShareAjax) {
+                    uni.$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/sell/index?reduceCode=" + reduceCode,
+                    imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
+                    desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
+                };
+            }
+
+            return null;
+        },
+    },
+};
+</script>

+ 2 - 2
pages-car/pages/index.vue

@@ -142,7 +142,7 @@
                 this.$u.api.goToReduceShareAjax({ reduceCode: reduceCode });
                 return {
                     title: "快来帮我减钱买书吧!",
-                    path: "/pages/home/index?reduceCode=" + reduceCode,
+                    path: "/pages/sell/index?reduceCode=" + reduceCode,
                     imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
                     desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
                 };
@@ -161,7 +161,7 @@
                 this.$u.api.goToReduceShareAjax({ reduceCode: reduceCode });
                 return {
                     title: "快来帮我减钱买书吧!",
-                    path: "/pages/home/index?reduceCode=" + reduceCode,
+                    path: "/pages/sell/index?reduceCode=" + reduceCode,
                     imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
                     desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
                 };

+ 1 - 1
pages-sell/pages/detail.vue

@@ -307,7 +307,7 @@ export default {
 
             return {
                 title: "快来帮我减钱买书吧!",
-                path: "/pages/home/index?reduceCode=" + reduceCode,
+                path: "/pages/sell/index?reduceCode=" + reduceCode,
                 imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
                 desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
             };

+ 1 - 1
pages-sell/pages/recommend.vue

@@ -77,7 +77,7 @@ export default {
 			}
 			return {
 				title: "快来帮我减钱买书吧!",
-				path: "/pages/home/index?reduceCode=" + reduceCode,
+				path: "/pages/sell/index?reduceCode=" + reduceCode,
 				imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
 				desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
 			};

+ 1 - 1
pages-sell/pages/search-result.vue

@@ -281,7 +281,7 @@ export default {
             }
             return {
                 title: "快来帮我减钱买书吧!",
-                path: "/pages/home/index?reduceCode=" + reduceCode,
+                path: "/pages/sell/index?reduceCode=" + reduceCode,
                 imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
                 desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
             };

+ 1 - 1
pages-sell/pages/topic.vue

@@ -141,7 +141,7 @@
 				}
 				return {
 					title: "快来帮我减钱买书吧!",
-					path: "/pages/home/index?reduceCode=" + reduceCode,
+					path: "/pages/sell/index?reduceCode=" + reduceCode,
 					imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
 					desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
 				};

+ 2 - 2
pages/cart/index.vue

@@ -49,7 +49,7 @@
 
                 return {
                     title: "快来帮我减钱买书吧!",
-                    path: "/pages/home/index?reduceCode=" + reduceCode,
+                    path: "/pages/sell/index?reduceCode=" + reduceCode,
                     imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
                     desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
                 };
@@ -74,7 +74,7 @@
                 }
                 return {
                     title: "快来帮我减钱买书吧!",
-                    path: "/pages/home/index?reduceCode=" + reduceCode,
+                    path: "/pages/sell/index?reduceCode=" + reduceCode,
                     imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
                     desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
                 };

+ 36 - 131
pages/home/index.vue

@@ -112,17 +112,13 @@
 
         <!-- 图书加价弹窗 -->
         <UpsellBook ref="upsellRef" @scan="handleScanCode" />
-
-        <!-- 加价分享弹窗 -->
-        <UpsellShare ref="shareRef" @viewRules="handleViewSellRules" />
         <!-- 加价二维码弹窗 -->
         <UpsellQrcode ref="upsellQrcodeRef" />
-
         <!-- 加价规则弹窗 -->
         <UpsellRules ref="upsellRulesRef" />
-        
-        <!-- 减价分享弹窗 -->
-        <ReduceShare ref="reduceShareRef" @viewRules="handleViewSellRules" />
+        <!-- 仅承接加价分享 -->
+        <ActivityHost ref="activityHost" :enable-reduce="false" @refresh-order="getLastOrder"
+            @view-rules="handleViewSellRules" />
     </view>
 </template>
 
@@ -137,11 +133,9 @@
     import FirstOrderFreePopup from "./components/FirstOrderFreePopup.vue";
     import UpsellBook from "./components/upsell-book.vue";
     import UpsellRules from "./components/upsell-rules.vue";
-    import UpsellShare from "./components/upsell-share.vue";
     import UpsellQrcode from "./components/upsell-qrcode.vue";
-import ReduceShare from "./components/reduce-share.vue";
+    import ActivityHost from "@/components/activity-host.vue";
     import FloatingDrag from "@/components/floating-drag.vue";
-    import { eventBus } from "@/utils/event-bus";
 
     const app = getApp();
 
@@ -157,9 +151,8 @@ export default {
         FirstOrderFreePopup,
         UpsellBook,
         UpsellRules,
-        UpsellShare,
         UpsellQrcode,
-        ReduceShare,
+        ActivityHost,
         FloatingDrag,
     },
     data() {
@@ -181,6 +174,7 @@ export default {
             },
             shareData: {},
             deleteBook: {},
+            pendingActivityOptions: {},
         };
     },
     computed: {
@@ -228,69 +222,18 @@ export default {
     },
     // 分享配置
     onShareAppMessage(res) {
-        if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "upsell") {
-            let upsellCode = uni.getStorageSync("upsellCodeShare");
-            console.log(upsellCode, "分享");
-            // 调用分享接口
-            uni.$u.http.get("/token/order/goToShare?upsellCode=" + upsellCode);
-            return {
-                title: "书嗨",
-                path: "/pages/home/index?upsellCode=" + upsellCode,
-                imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
-                desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
-            };
-        } else if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
-            let reduceCode = uni.getStorageSync("reduceCodeShare");
-            if (uni.$u && uni.$u.api && uni.$u.api.goToReduceShareAjax) {
-                uni.$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",
-            };
-        }
+        return this.$refs.activityHost?.getShareAppMessage(res) || {
+            title: "书嗨",
+            page: "/pages/home/index",
+        };
     },
 
     // 分享到朋友圈
     onShareTimeline(res) {
-        if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "upsell") {
-            let upsellCode = uni.getStorageSync("upsellCodeShare");
-            // 调用分享接口
-            uni.$u.http.get("/token/order/goToShare?upsellCode=" + upsellCode);
-            return {
-                title: "书嗨",
-                path: "/pages/home/index?upsellCode=" + upsellCode,
-                imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
-                desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
-            };
-        } else if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
-            let reduceCode = uni.getStorageSync("reduceCodeShare");
-            if (uni.$u && uni.$u.api && uni.$u.api.goToReduceShareAjax) {
-                uni.$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",
-            };
-        }
+        return this.$refs.activityHost?.getShareTimeline(res) || {
+            title: "书嗨",
+            page: "/pages/home/index",
+        };
     },
     onReady() {
         // 获取屏幕宽度和高度
@@ -300,53 +243,31 @@ export default {
                 this.screenHeight = res.windowHeight;
             },
         });
+        this.$nextTick(() => {
+            if (this.hasActivityEntryOptions(this.pendingActivityOptions)) {
+                this.$refs.activityHost?.handlePageOptions(this.pendingActivityOptions, app.globalData.isColdLaunch);
+            }
+            this.pendingActivityOptions = {};
+        });
     },
     onShow() {
         this.$updateCartBadge();
         if (!app.globalData.isColdLaunch) {
+            if (this.hasActivityEntryOptions(this.pendingActivityOptions)) {
+                return
+            }
             let token = uni.getStorageSync("token");
             if (token) {
                 this.getLastOrder();
             }
             return
         }
-        eventBus.on("loginSuccess", (data) => {
-            console.log(data, "登录成功loginSuccess");
-            this.loginSuccess(data);
-            app.globalData.isColdLaunch = false;
-        });;
     },
 
         //针对多次扫码的热启动场景,需要判断是否是冷启动
         onLoad(options) {
             console.log(options, app.globalData.isColdLaunch, "onLoad");
-            if (app.globalData.isColdLaunch) return
-
-            if (options.scene) {
-                let params = {};
-                // 对 scene 进行解码
-                const decodeScene = decodeURIComponent(options.scene);
-                // 拆分参数
-                const paramPairs = decodeScene.split('&');
-                paramPairs.forEach((pair) => {
-                    const [key, value] = pair.split('=');
-                    params[key] = value;
-                });
-
-            if (params.upsellCode) {
-                this.$refs.shareRef?.open(params.upsellCode);
-                this.getLastOrder();
-            }
-            if (params.reduceCode) {
-                this.$refs.reduceShareRef?.open(params.reduceCode);
-            }
-        } else if (options.upsellCode) {
-            this.$refs.shareRef?.open(options.upsellCode);
-        } else if (options.reduceCode) {
-            this.$refs.reduceShareRef?.open(options.reduceCode);
-        } else {
-            this.getLastOrder();
-        }
+            this.pendingActivityOptions = options || {};
     },
     // #ifdef MP-ALIPAY
     onPullDownRefresh() {
@@ -354,30 +275,21 @@ export default {
     },
     // #endif
 
-        //卸载loginSuccess事件
+        // 清理活动缓存
         onUnload() {
             uni.removeStorageSync("upsellCode");
             uni.removeStorageSync("reduceCode");
-            eventBus.off("loginSuccess");
         },
 
     methods: {
-        // 登录成功之后
-        loginSuccess(data) {
-            let upsellCode = uni.getStorageSync("upsellCode");
-            if (upsellCode) {
-                console.log(upsellCode, "登录成功之后助力的 code值:", upsellCode);
-                this.$refs.shareRef?.open(upsellCode);
-            }
-            // 仿照加价助力:优先读取缓存,兼容扫码冷启动参数丢失场景
-            let reduceCode = uni.getStorageSync("reduceCode") || data?.params?.reduceCode;
-            if (reduceCode) {
-                console.log(reduceCode, "登录成功之后助力的 code值:", reduceCode);
-                this.$refs.reduceShareRef?.open(reduceCode);
-            }
-            this.getLastOrder();
-        },
-
+            //扫码助力
+            handleScanCode(data = {}) {
+                this.$refs.upsellQrcodeRef.open(data);
+            },
+            //查看活动规则
+            handleViewSellRules() {
+                this.$refs.upsellRulesRef.open();
+            },
             //删除书籍
             handleDeleteBook(book) {
                 this.deleteBook = book;
@@ -404,16 +316,6 @@ export default {
                     });
             },
 
-            //扫码助力
-            handleScanCode(data = {}) {
-                this.$refs.upsellQrcodeRef.open(data);
-            },
-
-            //查看活动规则
-            handleViewSellRules() {
-                this.$refs.upsellRulesRef.open();
-            },
-
             handleStart() {
                 this.showPopup = true;
             },
@@ -433,6 +335,9 @@ export default {
                     this.onNext();
                 }
             },
+            hasActivityEntryOptions(options = {}) {
+                return !!(options.scene || options.upsellCode || options.reduceCode);
+            },
 
             //提交
             onNext() {

+ 32 - 4
pages/sell/index.vue

@@ -1,22 +1,48 @@
 <template>
 	<view>
 		<sell-container ref="sellContainer"></sell-container>
+		<ActivityHost ref="activityHost" :enable-upsell="false"></ActivityHost>
 	</view>
 </template>
 
 <script>
+import ActivityHost from "@/components/activity-host.vue";
+
 export default {
+	components: {
+		ActivityHost
+	},
 	data() {
 		return {
-			
+			pendingActivityOptions: {}
 		}
 	},
-	onLoad() {
-		
+	onLoad(options) {
+		this.pendingActivityOptions = options || {};
+	},
+	onReady() {
+		this.$nextTick(() => {
+			if (this.hasActivityEntryOptions(this.pendingActivityOptions)) {
+				this.$refs.activityHost?.handlePageOptions(this.pendingActivityOptions);
+			}
+			this.pendingActivityOptions = {};
+		});
 	},
 	onShow() {
 		this.$updateCartBadge();
 	},
+	onShareAppMessage(res) {
+		return this.$refs.activityHost?.getShareAppMessage(res) || {
+			title: "书嗨",
+			path: "/pages/sell/index",
+		};
+	},
+	onShareTimeline(res) {
+		return this.$refs.activityHost?.getShareTimeline(res) || {
+			title: "书嗨",
+			path: "/pages/sell/index",
+		};
+	},
 	onPullDownRefresh() {
 		if (this.$refs.sellContainer) {
 			this.$refs.sellContainer.hasShareList();
@@ -32,7 +58,9 @@ export default {
 		comp.scrollTop = e.scrollTop;
 	},
 	methods: {
-		
+		hasActivityEntryOptions(options = {}) {
+			return !!(options.scene || options.reduceCode || options.upsellCode);
+		}
 	}
 }
 </script>

+ 21 - 6
utils/event-bus.js

@@ -3,20 +3,35 @@ export const eventBus = {
 
     // 注册事件监听
     on(eventName, callback) {
-        this.events[eventName] = callback;
+        if (!this.events[eventName]) {
+            this.events[eventName] = [];
+        }
+        this.events[eventName].push(callback);
     },
 
     // 触发事件
     emit(eventName, data) {
-        if (typeof this.events[eventName] === 'function') {
-            this.events[eventName](data);
-        }
+        const callbacks = this.events[eventName] || [];
+        callbacks.forEach((callback) => {
+            if (typeof callback === "function") {
+                callback(data);
+            }
+        });
     },
 
     // 移除事件监听
     off(eventName, callback) {
-        if (this.events[eventName] === callback) {
+        const callbacks = this.events[eventName];
+        if (!callbacks) return;
+
+        if (!callback) {
+            delete this.events[eventName];
+            return;
+        }
+
+        this.events[eventName] = callbacks.filter((item) => item !== callback);
+        if (!this.events[eventName].length) {
             delete this.events[eventName];
         }
     }
-};
+};