From a5be5b1fdcf919b43c7d7850449511266cf8fbc0 Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Sun, 12 Apr 2026 17:48:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src/App.vue | 465 +--------- dashboard/src/components/AppSidebar.vue | 118 +++ dashboard/src/components/BaseButton.vue | 50 + dashboard/src/composables/index.js | 5 + dashboard/src/composables/useAuth.js | 77 ++ dashboard/src/views/AuthView.vue | 750 ++------------- dashboard/src/views/ConversationsView.vue | 940 ++----------------- dashboard/src/views/HomeView.vue | 857 ++--------------- dashboard/src/views/ToolsView.vue | 1027 ++------------------- 9 files changed, 564 insertions(+), 3725 deletions(-) create mode 100644 dashboard/src/components/AppSidebar.vue create mode 100644 dashboard/src/components/BaseButton.vue create mode 100644 dashboard/src/composables/index.js create mode 100644 dashboard/src/composables/useAuth.js diff --git a/dashboard/src/App.vue b/dashboard/src/App.vue index 91c8deb..3b91f0f 100644 --- a/dashboard/src/App.vue +++ b/dashboard/src/App.vue @@ -1,469 +1,26 @@ diff --git a/dashboard/src/components/AppSidebar.vue b/dashboard/src/components/AppSidebar.vue new file mode 100644 index 0000000..2424ea5 --- /dev/null +++ b/dashboard/src/components/AppSidebar.vue @@ -0,0 +1,118 @@ + + + + + diff --git a/dashboard/src/components/BaseButton.vue b/dashboard/src/components/BaseButton.vue new file mode 100644 index 0000000..dd5020f --- /dev/null +++ b/dashboard/src/components/BaseButton.vue @@ -0,0 +1,50 @@ + + + + + diff --git a/dashboard/src/composables/index.js b/dashboard/src/composables/index.js new file mode 100644 index 0000000..b883f31 --- /dev/null +++ b/dashboard/src/composables/index.js @@ -0,0 +1,5 @@ +// 导出所有组合式函数 +export { useAuth } from './useAuth.js' +export { useApi, usePagination, useForm } from './useApi.js' +export { formatDate, formatNumber, truncate } from './useFormatters.js' +export { debounce, throttle, storage, copyToClipboard } from './useUtils.js' diff --git a/dashboard/src/composables/useAuth.js b/dashboard/src/composables/useAuth.js new file mode 100644 index 0000000..040810e --- /dev/null +++ b/dashboard/src/composables/useAuth.js @@ -0,0 +1,77 @@ +/** + * 认证状态管理组合式函数 + */ +import { ref, onMounted, onUnmounted } from 'vue' + +export function useAuth() { + const isLoggedIn = ref(false) + const user = ref(null) + const loading = ref(true) + + // 检查登录状态 + const checkAuth = () => { + isLoggedIn.value = !!localStorage.getItem('access_token') + if (isLoggedIn.value) { + const userData = localStorage.getItem('user') + if (userData) { + try { + user.value = JSON.parse(userData) + } catch { + user.value = null + } + } + } else { + user.value = null + } + } + + // 登录 + const login = (token, userData) => { + localStorage.setItem('access_token', token) + localStorage.setItem('user', JSON.stringify(userData)) + isLoggedIn.value = true + user.value = userData + window.dispatchEvent(new CustomEvent('auth-change')) + } + + // 登出 + const logout = async (api) => { + try { + if (api) await api.logout() + } catch (e) { + console.error('登出失败:', e) + } + localStorage.removeItem('access_token') + localStorage.removeItem('user') + isLoggedIn.value = false + user.value = null + window.dispatchEvent(new CustomEvent('auth-change')) + } + + // 获取 Token + const getToken = () => localStorage.getItem('access_token') + + // 监听认证变化 + const handleAuthChange = () => { + checkAuth() + } + + onMounted(() => { + checkAuth() + window.addEventListener('auth-change', handleAuthChange) + }) + + onUnmounted(() => { + window.removeEventListener('auth-change', handleAuthChange) + }) + + return { + isLoggedIn, + user, + loading, + checkAuth, + login, + logout, + getToken + } +} diff --git a/dashboard/src/views/AuthView.vue b/dashboard/src/views/AuthView.vue index 13151ba..7bcda4b 100644 --- a/dashboard/src/views/AuthView.vue +++ b/dashboard/src/views/AuthView.vue @@ -1,335 +1,94 @@ diff --git a/dashboard/src/views/ConversationsView.vue b/dashboard/src/views/ConversationsView.vue index bf526c4..ceda75e 100644 --- a/dashboard/src/views/ConversationsView.vue +++ b/dashboard/src/views/ConversationsView.vue @@ -1,201 +1,38 @@