refactor(chat + workspace): chat和workspace重构,子路由、懒加载等

This commit is contained in:
sophie committed 2026-06-10 16:39:05 +08:00
1 parent 0a647a0b79
commit 1f1f7236b0
57 files changed
+4356 -3798

No files matched your search

@@ -0,0 +1,129 @@
<script setup lang="ts">
/**
* features/workspace/components/WorkspaceModals.vue
* 工作台弹窗:公告详情、修改密码、快捷问题删除、意见反馈。
*/
import { inject } from 'vue';
import { X } from 'lucide-vue-next';
import DeleteConfirmDialog from '@/components/DeleteConfirmDialog.vue';
import GeneralFeedbackDialog from '@/components/GeneralFeedbackDialog.vue';
import { getAuthHeaders } from '@/utils/auth';
import { WORKSPACE_KEY } from '../composables/workspace.context';
const ws = inject(WORKSPACE_KEY)! as any;
</script>
<template>
<div>
<div
v-if="ws.showAnnouncementModal && ws.selectedAnnouncement"
class="dialog-overlay z-50 items-center animate-fade-in"
@click.self="ws.showAnnouncementModal = false"
>
<div class="dialog-panel max-w-2xl max-h-[85vh] animate-slide-up">
<div class="dialog-header">
<div class="min-w-0">
<span class="inline-flex rounded-full bg-brand-50 px-2 py-1 text-xs font-bold text-brand-600">{{ new Date(ws.selectedAnnouncement.created_at).toLocaleDateString() }}</span>
<h3 class="mt-2 text-2xl font-bold text-primary">{{ ws.selectedAnnouncement.title }}</h3>
</div>
<button type="button" class="btn-icon-ds shrink-0" :aria-label="$t('admin.close')" @click="ws.showAnnouncementModal = false">
<X class="w-5 h-5" />
</button>
</div>
<div class="dialog-body">
<p class="whitespace-pre-wrap leading-relaxed text-secondary">{{ ws.selectedAnnouncement.content }}</p>
</div>
<div class="dialog-footer">
<button type="button" @click="ws.showAnnouncementModal = false" class="btn-primary">
{{ $t('admin.close') }}
</button>
</div>
</div>
</div>
<div
v-if="ws.CHANGE_PASSWORD_ENABLED && ws.showPasswordModal"
class="dialog-overlay z-50 items-center"
>
<div class="dialog-panel max-w-md">
<div class="dialog-header">
<h3 class="section-title">{{ $t('profile.changePassword') || 'Change Password' }}</h3>
<button
type="button"
class="btn-icon-ds"
:aria-label="$t('admin.close')"
:disabled="ws.isChangingPassword"
@click="ws.showPasswordModal = false"
>
<X class="w-5 h-5" />
</button>
</div>
<form @submit.prevent="ws.handleChangePassword">
<div class="dialog-body">
<div>
<label class="label-field">{{ $t('profile.currentPassword') || 'Current Password' }}</label>
<input
v-model="ws.passwordForm.current"
type="password"
class="input-field mt-1"
:disabled="ws.isChangingPassword"
required
/>
</div>
<div>
<label class="label-field">{{ $t('profile.newPassword') || 'New Password' }}</label>
<input
v-model="ws.passwordForm.new"
type="password"
class="input-field mt-1"
:disabled="ws.isChangingPassword"
required
/>
</div>
<div>
<label class="label-field">{{ $t('profile.confirmPassword') || 'Confirm Password' }}</label>
<input
v-model="ws.passwordForm.confirm"
type="password"
class="input-field mt-1"
:disabled="ws.isChangingPassword"
required
/>
</div>
</div>
<div class="dialog-footer">
<button
type="button"
:disabled="ws.isChangingPassword"
@click="ws.showPasswordModal = false"
class="btn-secondary flex-1 disabled:opacity-50 disabled:cursor-not-allowed"
>
{{ $t('profile.cancel') || 'Cancel' }}
</button>
<button
type="submit"
:disabled="ws.isChangingPassword"
class="btn-primary flex-1 disabled:opacity-50 disabled:cursor-not-allowed"
>
{{ ws.isChangingPassword ? $t('profile.changingPassword') : ($t('profile.changePassword') || 'Update') }}
</button>
</div>
</form>
</div>
</div>
<DeleteConfirmDialog
v-model="ws.showDeleteQuickQuestionDialog"
:title="$t('workspace.quickQuestions.deleteDialog.title')"
:message="$t('workspace.quickQuestions.deleteDialog.message')"
@confirm="ws.confirmRemoveQuickQuestion"
@cancel="ws.cancelRemoveQuickQuestion"
/>
<GeneralFeedbackDialog
v-model="ws.showGeneralFeedbackDialog"
:auth-headers="getAuthHeaders()"
source-page="workspace"
@submitted="ws.msg.success('反馈提交成功')"
/>
</div>
</template>
@@ -0,0 +1,86 @@
<script setup lang="ts">
/**
* features/workspace/components/WorkspaceSidebar.vue
* 工作台左侧导航:子路由链接、返回聊天与退出登录。
*/
import { inject } from 'vue';
import { useRoute } from 'vue-router';
import {
LayoutGrid, Bot, FileText, User, LogOut, Edit, Megaphone, Clock, Package,
} from 'lucide-vue-next';
import { WORKSPACE_PATHS } from '../constants/routes';
import { WORKSPACE_KEY } from '../composables/workspace.context';
const ws = inject(WORKSPACE_KEY)! as any;
const route = useRoute();
const linkItems = [
{ path: WORKSPACE_PATHS.profile, labelKey: 'workspace.nav.profile', icon: User, match: ['workspace-profile'] },
{ path: WORKSPACE_PATHS.applications, labelKey: 'workspace.nav.applications', icon: LayoutGrid, match: ['workspace-applications'] },
{ path: WORKSPACE_PATHS.scheduleRuns, labelKey: 'workspace.nav.scheduleRuns', icon: Clock, match: ['workspace-schedule-runs'] },
{ path: WORKSPACE_PATHS.shippingNotice, labelKey: 'workspace.nav.shippingNotice', icon: Package, match: ['workspace-shipping-notice'] },
{ path: WORKSPACE_PATHS.feedback, labelKey: 'workspace.nav.feedback', icon: Edit, match: ['workspace-feedback'] },
{ path: WORKSPACE_PATHS.updates, labelKey: 'workspace.nav.updates', icon: Megaphone, match: ['workspace-updates'] },
] as const;
function isActive(match: readonly string[]) {
return match.includes(String(route.name || ''));
}
</script>
<template>
<aside class="lg:sticky lg:top-0 lg:h-screen">
<div class="flex h-full flex-col border-r border-default bg-surface px-5 py-6 shadow-sm">
<div class="border-b border-subtle pb-6">
<div class="flex items-center gap-3">
<div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-purple-600 text-white shadow-lg shadow-brand-500/25">
<Bot class="h-6 w-6" />
</div>
<div class="min-w-0">
<div class="text-2xl font-extrabold tracking-tight text-primary">{{ $t('workspace.brandTitle') }}</div>
<div class="truncate text-xs font-medium text-muted">
{{ ws.currentUser?.username }} / {{ ws.currentUser?.role }}
</div>
</div>
</div>
</div>
<div class="flex-1 py-6">
<nav class="space-y-2">
<RouterLink
v-for="item in linkItems"
:key="item.path"
:to="item.path"
class="ws-nav-btn"
:class="{ 'ws-nav-btn--active': isActive(item.match) }"
>
<component :is="item.icon" class="h-4 w-4" />
<span>{{ $t(item.labelKey) }}</span>
</RouterLink>
<button
type="button"
class="ws-nav-btn w-full"
:class="{ 'ws-nav-btn--active': isActive(['workspace-knowledge-base']) }"
@click="ws.navigateToKnowledgeBase"
>
<FileText class="h-4 w-4" />
<span>{{ $t('workspace.nav.knowledgeBase') }}</span>
</button>
</nav>
</div>
<div class="border-t border-subtle pt-6">
<div class="space-y-2">
<button type="button" @click="ws.navigateToGeneralChat" class="ws-nav-btn">
<Bot class="h-4 w-4" />
<span>{{ $t('workspace.nav.backToChat') }}</span>
</button>
<button type="button" @click="ws.handleLogout" class="ws-nav-btn ws-nav-btn--danger">
<LogOut class="h-4 w-4" />
<span>{{ $t('workspace.nav.logout') }}</span>
</button>
</div>
</div>
</div>
</aside>
</template>