diff --git a/components/login-prompt.vue b/components/login-prompt.vue index 4d302be..0b9af30 100644 --- a/components/login-prompt.vue +++ b/components/login-prompt.vue @@ -85,6 +85,11 @@ const continueAsVisitor = async () => { if (res.code === 200) { userStore.setUserInfo(res.data); hide(); + + // 发送游客登录成功事件,通知首页重新加载 + uni.$emit('visitorLoginSuccess', { + userInfo: res.data + }); } }; diff --git a/pages/home/home.vue b/pages/home/home.vue index a095310..466b9b0 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -369,6 +369,9 @@ export default { // 初始化TCP连接监听器 this.initTcpListeners() + // 监听游客登录成功事件 + uni.$on('visitorLoginSuccess', this.handleVisitorLoginSuccess) + // 页面渲染完成后自动连接两个TCP连接 this.$nextTick(() => { console.log('页面渲染完成,开始自动连接TCP服务器...') @@ -421,9 +424,36 @@ export default { // 移除TCP监听器,防止内存泄漏 this.removeTcpListeners() + + // 移除游客登录成功事件监听器 + uni.$off('visitorLoginSuccess', this.handleVisitorLoginSuccess) }, methods: { + // 处理游客登录成功事件 + handleVisitorLoginSuccess(data) { + console.log('收到游客登录成功事件:', data) + // 重新加载页面数据 + this.reloadPageData() + }, + + // 重新加载页面数据 + reloadPageData() { + console.log('重新加载页面数据...') + + // 更新用户信息store + this.userStore = useUserStore() + + // 根据新的用户状态加载相应的数据 + if (this.userStore.userInfo && this.userStore.userInfo.isVisitor) { + console.log('游客登录成功,加载默认自选股') + this.loadGuestDefaultStocks() + } else if (this.userStore.userInfo && !this.userStore.userInfo.isVisitor) { + console.log('用户登录,加载自选股数据') + this.loadMySelectionsData() + } + }, + // 防抖函数 debounce(fn, delay = 300) { if (this.debounceTimer) clearTimeout(this.debounceTimer)