diff --git a/frontend/dist/index.html b/frontend/dist/index.html index 83f5014b..bf02cf0d 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -10,8 +10,8 @@ AI工作台 - - + +
diff --git a/frontend/src/config.ts b/frontend/src/config.ts index c490db68..b7c14562 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -1,10 +1,10 @@ -export const config = { +export const config = { appTitle: 'AI工作台', auth: { // Login mode switch: // - 'casdoor': submit username/password to backend Casdoor password-login API. // - 'password': submit to legacy local /api/user/login. - loginMode: 'casdoor', + loginMode: 'password', casdoor: { enabled: true, authorizeApi: '/api/user/casdoor/authorize-url', diff --git a/frontend/src/views/ChatView.vue b/frontend/src/views/ChatView.vue index 2ec110b3..59b2a1c9 100644 --- a/frontend/src/views/ChatView.vue +++ b/frontend/src/views/ChatView.vue @@ -69,6 +69,10 @@ const handleLogout = () => { router.push('/'); }; +const handleVoiceFeatureClick = () => { + showMessageDialog('info', '该功能正在开发中'); +}; + const stripReasoningPrelude = (text: string) => { if (!text) return ''; let cleaned = text @@ -1008,7 +1012,7 @@ const showChatRating = ref(false); -
+
@@ -1018,7 +1022,7 @@ const showChatRating = ref(false);
-
+
{{ (currentUser?.username || 'I').charAt(0).toUpperCase() }}
@@ -1030,7 +1034,7 @@ const showChatRating = ref(false);
-
+
- - - + + +
{{ $t('chat.thinking') }}
@@ -1496,7 +1500,12 @@ const showChatRating = ref(false);
-
@@ -1504,7 +1513,7 @@ const showChatRating = ref(false); @click="showKbDropdown = !showKbDropdown" class="flex items-center gap-1 rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-medium text-slate-600 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800" > - + {{ selectedKb }}
{{ option }} @@ -1527,14 +1536,17 @@ const showChatRating = ref(false); @click="toggleBrowserPanel" class="flex items-center gap-1 rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-medium text-slate-600 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800" > - + {{ browserPanelOpen ? '收起浏览器' : '打开浏览器' }}
@@ -1560,7 +1572,7 @@ const showChatRating = ref(false); >
@@ -1571,7 +1583,7 @@ const showChatRating = ref(false); >
- + 浏览器
@@ -1618,7 +1630,7 @@ const showChatRating = ref(false); v-if="!browserCurrentUrl" class="flex h-full flex-col items-center justify-center gap-3 px-8 text-center text-sm text-slate-500 dark:text-slate-400" > - +
在这里直接打开网页,边聊天边查看内容。
支持输入 `https://`、`localhost` 或内网 IP 地址。
diff --git a/frontend/src/views/WorkspaceView.vue b/frontend/src/views/WorkspaceView.vue index 360abc1b..2049a073 100644 --- a/frontend/src/views/WorkspaceView.vue +++ b/frontend/src/views/WorkspaceView.vue @@ -4,10 +4,12 @@ * 文件用途:用户工作台,支持自定义布局、收藏、嵌入 Agent * 引用文件:vue, vue-router, lucide-vue-next, 后端 /api/user 接口 */ -import { ref, onMounted, onBeforeUnmount, computed, watch } from 'vue'; +import { ref, onMounted, computed, watch, nextTick } from 'vue'; import { useRouter } from 'vue-router'; import { useI18n } from 'vue-i18n'; import { config } from '../config'; +import { useTheme } from '../composables/useTheme'; +import type { ThemePreference } from '../composables/useTheme'; import ThemeToggleButton from '../components/ThemeToggleButton.vue'; import DeleteConfirmDialog from '../components/DeleteConfirmDialog.vue'; import GeneralFeedbackDialog from '../components/GeneralFeedbackDialog.vue'; @@ -33,7 +35,13 @@ import { Bot, Lock, User, + Mail, + Building, + CreditCard, + Globe, LogOut, + Save, + Palette, Megaphone, X, ChevronDown, @@ -43,6 +51,7 @@ import { const { t, locale } = useI18n(); const { showMessageDialog } = useGlobalMessageDialog(); const router = useRouter(); +const { setThemePreference } = useTheme(); const loadLanguagePreference = () => { const storedLang = localStorage.getItem('hxops_lang'); @@ -104,6 +113,19 @@ interface WecomBindPromptState { error: string; } +interface ProfileForm { + id: number; + username: string; + real_name: string; + email: string; + phone_number: string; + department: string; + role: string; + employee_id: string; + language: string; + theme_preference: ThemePreference; +} + // State const isLoading = ref(true); const currentUser = ref<{ id: number; username: string; role: string; default_agent_id?: number | null } | null>(null); @@ -696,20 +718,53 @@ const handleRegister = async () => { } }; -// Header Dropdown State -const showUserDropdown = ref(false); -const userMenuRef = ref(null); +const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates'>('applications'); +const isProfileLoading = ref(false); +const isProfileSaving = ref(false); +const isProfileEditing = ref(false); +const showPasswordModal = ref(false); +const profileUser = ref({ + id: 0, + username: '', + real_name: '', + email: '', + phone_number: '', + department: '', + role: '', + employee_id: '', + language: 'zh-CN', + theme_preference: 'system' as ThemePreference, +}); +const originalProfile = ref(null); +const passwordForm = ref({ + current: '', + new: '', + confirm: '', +}); -const handleDocumentPointerDown = (event: MouseEvent | TouchEvent) => { - if (!showUserDropdown.value) return; - const target = event.target as Node | null; - if (!target) return; - if (userMenuRef.value?.contains(target)) return; - showUserDropdown.value = false; -}; +const themeOptions: Array<{ value: ThemePreference; label: () => string }> = [ + { value: 'light', label: () => t('theme.light') || 'Light' }, + { value: 'dark', label: () => t('theme.dark') || 'Dark' }, + { value: 'system', label: () => t('theme.system') || 'Follow System' }, +]; + +const hasProfileUnsavedChanges = computed(() => { + if (!originalProfile.value) return false; + return ( + profileUser.value.real_name !== originalProfile.value.real_name || + profileUser.value.phone_number !== originalProfile.value.phone_number || + profileUser.value.language !== originalProfile.value.language || + profileUser.value.theme_preference !== originalProfile.value.theme_preference || + profileUser.value.email !== originalProfile.value.email || + profileUser.value.employee_id !== originalProfile.value.employee_id || + profileUser.value.department !== originalProfile.value.department + ); +}); const handleLogout = () => { localStorage.removeItem('hxops_user'); + sessionStorage.removeItem('hxops_user'); + sessionStorage.removeItem('hxops_wecom_state'); currentUser.value = null; agents.value = []; quickQuestions.value = []; @@ -720,8 +775,171 @@ const handleLogout = () => { router.push('/'); }; -const navigateToProfile = () => { - router.push('/profile'); +const captureOriginalProfile = () => { + originalProfile.value = { ...profileUser.value }; +}; + +const parseErrorMessage = async (res: Response) => { + try { + const data = await res.json(); + return data?.error || data?.message || ''; + } catch { + try { + return await res.text(); + } catch { + return ''; + } + } +}; + +const fetchProfile = async () => { + isProfileLoading.value = true; + try { + const res = await fetch('/api/user/profile', { headers: getAuthHeaders() }); + if (!res.ok) { + showMessageDialog('error', '加载个人中心失败'); + return; + } + const data = await res.json(); + profileUser.value = { ...profileUser.value, ...data }; + if (data.language) locale.value = data.language; + if (data.theme_preference) setThemePreference(data.theme_preference); + captureOriginalProfile(); + isProfileEditing.value = false; + } catch (e) { + console.error(e); + showMessageDialog('error', '加载个人中心失败'); + } finally { + isProfileLoading.value = false; + } +}; + +const navigateToProfile = async () => { + activeSidebarItem.value = 'profile'; + if (!profileUser.value.id) { + await fetchProfile(); + } +}; + +const startProfileEditing = () => { + isProfileEditing.value = true; +}; + +const cancelProfileEditing = () => { + if (originalProfile.value) { + profileUser.value = { ...originalProfile.value }; + locale.value = profileUser.value.language; + setThemePreference(profileUser.value.theme_preference); + } + isProfileEditing.value = false; +}; + +const saveProfile = async () => { + if (!hasProfileUnsavedChanges.value) { + isProfileEditing.value = false; + return; + } + + const payload = { + real_name: profileUser.value.real_name, + phone_number: profileUser.value.phone_number, + language: profileUser.value.language, + theme_preference: profileUser.value.theme_preference, + email: profileUser.value.email, + employee_id: profileUser.value.employee_id, + department: profileUser.value.department, + }; + + locale.value = profileUser.value.language; + setThemePreference(profileUser.value.theme_preference); + + try { + isProfileSaving.value = true; + const res = await fetch('/api/user/profile', { + method: 'PUT', + headers: { 'Content-Type': 'application/json', ...getAuthHeaders() }, + body: JSON.stringify(payload), + }); + + if (!res.ok) { + const message = await parseErrorMessage(res); + showMessageDialog('error', message || '保存个人资料失败'); + return; + } + + showMessageDialog('success', '个人资料已保存'); + captureOriginalProfile(); + isProfileEditing.value = false; + } catch (e) { + console.error(e); + showMessageDialog('error', '保存个人资料失败'); + } finally { + isProfileSaving.value = false; + } +}; + +const handleChangePassword = async () => { + if (passwordForm.value.new !== passwordForm.value.confirm) { + showMessageDialog('warning', t('profile.passwordMismatch') || 'Passwords do not match'); + return; + } + + try { + const res = await fetch('/api/user/change-password', { + method: 'POST', + headers: { 'Content-Type': 'application/json', ...getAuthHeaders() }, + body: JSON.stringify({ + current_password: passwordForm.value.current, + new_password: passwordForm.value.new, + }), + }); + + const data = await res.json(); + if (!res.ok) { + showMessageDialog('error', data.error || '修改密码失败'); + return; + } + + showMessageDialog('success', t('profile.passwordChanged') || 'Password changed successfully'); + passwordForm.value = { current: '', new: '', confirm: '' }; + showPasswordModal.value = false; + } catch (e) { + console.error(e); + showMessageDialog('error', '修改密码失败'); + } +}; + +const openGeneralFeedback = () => { + activeSidebarItem.value = 'feedback'; + showGeneralFeedbackDialog.value = true; +}; + +const openWorkspaceSection = async ( + sectionId: 'announcements' | 'favorites' | 'all_agents', + sidebarItem: 'applications' | 'updates', +) => { + activeSidebarItem.value = sidebarItem; + const targetSection = layoutSections.value.find((section) => section.id === sectionId); + if (targetSection) { + targetSection.collapsed = false; + } + await nextTick(); + document.getElementById(`workspace-section-${sectionId}`)?.scrollIntoView({ + behavior: 'smooth', + block: 'start', + }); +}; + +const navigateToApplications = () => openWorkspaceSection('favorites', 'applications'); + +const navigateToUpdates = () => openWorkspaceSection('announcements', 'updates'); + +const navigateToGeneralChat = () => { + router.push(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`); +}; + +const openAdminPanel = () => { + window.location.assign('http://localhost:8881/admin'); }; const navigateToChat = (id: number) => { @@ -915,8 +1133,6 @@ const openAnnouncement = (ann: Announcement) => { }; onMounted(async () => { - document.addEventListener('mousedown', handleDocumentPointerDown); - document.addEventListener('touchstart', handleDocumentPointerDown, { passive: true }); loadLanguagePreference(); fetchAnnouncements(); const handledCasdoor = await tryCasdoorCallbackLogin(); @@ -936,11 +1152,6 @@ onMounted(async () => { isLoading.value = false; } }); - -onBeforeUnmount(() => { - document.removeEventListener('mousedown', handleDocumentPointerDown); - document.removeEventListener('touchstart', handleDocumentPointerDown); -});