From 1922787df71340589dd1d47b41d7ce7f755d6191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Wed, 29 Oct 2025 20:30:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=BC=B9=E5=87=BA=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=8A=A0=E5=85=A5=E5=AF=B9=E9=A6=96=E9=A1=B5=E6=B8=B8?= =?UTF-8?q?=E5=AE=A2=E7=99=BB=E5=BD=95=E7=9A=84=E4=BA=8B=E4=BB=B6=E7=9B=91?= =?UTF-8?q?=E5=90=AC=EF=BC=9B=E9=A6=96=E9=A1=B5=E6=B8=B8=E5=AE=A2=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=88=90=E5=8A=9F=E5=90=8E=EF=BC=8C=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=A1=B5=E9=9D=A2=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/login-prompt.vue | 5 +++++ pages/home/home.vue | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) 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)