From 16b59d6ab2b96a781fb55d387d2fa8f6edce0fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=98=89=E6=82=A6?= Date: Sun, 25 May 2025 10:44:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(store):=20:sparkles:=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=BC=B9=E6=A1=86=E7=8A=B6=E6=80=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LoginDialog/index.vue | 6 +++++- .../components/Header/components/LoginBtn.vue | 10 +++++++--- src/store/modules/user.ts | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/components/LoginDialog/index.vue b/src/components/LoginDialog/index.vue index 7bcb1ad..9dc6e7d 100644 --- a/src/components/LoginDialog/index.vue +++ b/src/components/LoginDialog/index.vue @@ -2,9 +2,12 @@ import { ref, watch } from 'vue'; import logoPng from '@/assets/images/logo.png'; import SvgIcon from '@/components/SvgIcon/index.vue'; +import { useUserStore } from '@/store'; import AccountPassword from './components/FormLogin/AccountPassword.vue'; import QrCodeLogin from './components/QrCodeLogin/index.vue'; +const userStore = useUserStore(); + // 使用 defineModel 定义双向绑定的 visible(需 Vue 3.4+) const visible = defineModel('visible'); const showMask = ref(false); // 控制遮罩层显示的独立状态 @@ -31,7 +34,8 @@ function toggleLoginMode() { // 点击遮罩层关闭对话框(触发过渡动画) function handleMaskClick() { - visible.value = false; // 触发离开动画 + // 触发离开动画 + userStore.closeLoginDialog(); } // 过渡动画结束回调 diff --git a/src/layouts/components/Header/components/LoginBtn.vue b/src/layouts/components/Header/components/LoginBtn.vue index 4d51858..87d714b 100644 --- a/src/layouts/components/Header/components/LoginBtn.vue +++ b/src/layouts/components/Header/components/LoginBtn.vue @@ -1,11 +1,15 @@ diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 3a9b777..731a74b 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -25,8 +25,21 @@ export const useUserStore = defineStore( const logout = async () => { // 如果需要调用接口,可以在这里调用 clearToken(); - router.replace({ name: 'login' }); clearUserInfo(); + router.replace({ name: 'chat' }); + }; + + // 新增:登录弹框状态 + const isLoginDialogVisible = ref(false); + + // 新增:打开弹框方法 + const openLoginDialog = () => { + isLoginDialogVisible.value = true; + }; + + // 新增:关闭弹框方法(可根据需求扩展) + const closeLoginDialog = () => { + isLoginDialogVisible.value = false; }; return { @@ -37,6 +50,10 @@ export const useUserStore = defineStore( setUserInfo, clearUserInfo, logout, + // 新增:暴露弹框状态和方法 + isLoginDialogVisible, + openLoginDialog, + closeLoginDialog, }; }, {