From d9f814ccfbb168c96ad2ef580570ab41a9c868c8 Mon Sep 17 00:00:00 2001 From: LingandRX Date: Wed, 1 Jan 2025 17:33:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E5=AE=9E=E7=8E=B0=E9=80=80?= =?UTF-8?q?=E5=87=BA=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=99=BB=E5=BD=95=E7=8A=B6=E6=80=81=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 DefaultLayout 组件中添加退出登录按钮 - 实现 logout 函数,用于清除 token 并重定向到登录页 - 修改路由配置,增加 requiresAuth 元数据用于权限控制 - 优化 auth.js 中的 TokenKey 名称 - 移除 CustomCard、AboutView 和 TestApi 组件中的冗余样式 --- src/components/CustomCard.vue | 37 +--------------------------------- src/components/CustomLogin.vue | 5 +++-- src/components/TestApi.vue | 2 +- src/layouts/DefaultLayout.vue | 19 +++++++++++++++++ src/router/index.js | 17 +++++++++++++++- src/utils/auth.js | 2 +- src/utils/time.js | 4 ++-- src/views/AboutView.vue | 9 +-------- 8 files changed, 44 insertions(+), 51 deletions(-) diff --git a/src/components/CustomCard.vue b/src/components/CustomCard.vue index d9a3646..b09fb35 100644 --- a/src/components/CustomCard.vue +++ b/src/components/CustomCard.vue @@ -28,39 +28,4 @@ defineProps({ - + diff --git a/src/components/CustomLogin.vue b/src/components/CustomLogin.vue index 45b8051..dceb389 100644 --- a/src/components/CustomLogin.vue +++ b/src/components/CustomLogin.vue @@ -2,6 +2,7 @@ import { UserOutlined, LockOutlined } from '@ant-design/icons-vue' import { computed, reactive } from 'vue' import router from '@/router/index.js' +import { setToken } from '@/utils/auth.js' const formState = reactive({ account: '', @@ -22,8 +23,8 @@ const onfinish = async () => { }) if (response.ok) { - const data = await response.json() - console.log(data) + console.log(`formState.account:${formState.account}`) + setToken(formState.account) await router.push('/') } else { console.error('Login failed', response.statusText) diff --git a/src/components/TestApi.vue b/src/components/TestApi.vue index 89e2c23..80d6b89 100644 --- a/src/components/TestApi.vue +++ b/src/components/TestApi.vue @@ -22,7 +22,7 @@ export default defineComponent({