260323 function add report chat and front
This commit is contained in:
1 parent
605317c2b2
commit
5e8ea03b6c
16 files changed
+2351
-100
No files matched your search
@@ -4,7 +4,7 @@
|
||||
* 文件用途:用户工作台,支持自定义布局、收藏、嵌入 Agent
|
||||
* 引用文件:vue, vue-router, lucide-vue-next, 后端 /api/user 接口
|
||||
*/
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { ref, onMounted, computed, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { config } from '../config';
|
||||
@@ -29,6 +29,21 @@ import {
|
||||
const { t, locale } = useI18n();
|
||||
const router = useRouter();
|
||||
|
||||
const loadLanguagePreference = () => {
|
||||
const storedLang = localStorage.getItem('hxops_lang');
|
||||
if (storedLang) {
|
||||
locale.value = storedLang;
|
||||
}
|
||||
};
|
||||
|
||||
const saveLanguagePreference = (lang: string) => {
|
||||
localStorage.setItem('hxops_lang', lang);
|
||||
};
|
||||
|
||||
watch(locale, (newLang) => {
|
||||
saveLanguagePreference(newLang);
|
||||
});
|
||||
|
||||
// Interfaces
|
||||
interface Agent {
|
||||
id: number;
|
||||
@@ -73,10 +88,18 @@ const announcements = ref<Announcement[]>([]);
|
||||
const quickQuestions = ref<QuickQuestion[]>([]);
|
||||
const favoriteAgentIds = ref<number[]>([]);
|
||||
const embeddedAgents = ref<EmbeddedAgent[]>([]);
|
||||
const SECTION_TITLE_KEY_MAP: Record<string, string> = {
|
||||
announcements: 'workspace.announcements.title',
|
||||
favorites: 'workspace.favorites',
|
||||
quick_questions: 'workspace.quickQuestions.title',
|
||||
embedded: 'workspace.embedded.title',
|
||||
all_agents: 'workspace.availableAgents',
|
||||
};
|
||||
const layoutSections = ref<LayoutSection[]>([
|
||||
{ id: 'announcements', visible: true, collapsed: false, title: 'workspace.announcements.title' },
|
||||
{ id: 'favorites', visible: true, collapsed: false, title: 'workspace.favorites' },
|
||||
{ id: 'quick_questions', visible: true, collapsed: false, title: 'workspace.quickQuestions.title' },
|
||||
{ id: 'embedded', visible: true, collapsed: false, title: 'workspace.embedded' },
|
||||
{ id: 'embedded', visible: true, collapsed: false, title: 'workspace.embedded.title' },
|
||||
{ id: 'all_agents', visible: true, collapsed: false, title: 'workspace.availableAgents' },
|
||||
]);
|
||||
|
||||
@@ -162,6 +185,16 @@ const filteredQuickQuestions = computed(() => {
|
||||
);
|
||||
});
|
||||
|
||||
const normalizeSectionId = (id: string) => {
|
||||
if (id === 'quice_questions' || id === 'quickQuestions') return 'quick_questions';
|
||||
if (id === 'allAgents') return 'all_agents';
|
||||
return id;
|
||||
};
|
||||
|
||||
const getSectionTitleKey = (sectionId: string) => {
|
||||
return SECTION_TITLE_KEY_MAP[normalizeSectionId(sectionId)] || normalizeSectionId(sectionId);
|
||||
};
|
||||
|
||||
// Methods
|
||||
const getAuthHeaders = () => {
|
||||
let stored = localStorage.getItem('hxops_user');
|
||||
@@ -206,24 +239,28 @@ const fetchHome = async () => {
|
||||
embeddedAgents.value = data.embedded_agents || [];
|
||||
|
||||
if (data.layout && data.layout.sections) {
|
||||
const backendSections = data.layout.sections as LayoutSection[];
|
||||
const backendSections = (data.layout.sections as LayoutSection[]).map((s) => ({
|
||||
...s,
|
||||
id: normalizeSectionId(s.id),
|
||||
}));
|
||||
const defaultSections = [
|
||||
{ id: 'favorites', visible: true },
|
||||
{ id: 'quick_questions', visible: true },
|
||||
{ id: 'embedded', visible: true },
|
||||
{ id: 'all_agents', visible: true },
|
||||
{ id: 'announcements', visible: true, title: getSectionTitleKey('announcements') },
|
||||
{ id: 'favorites', visible: true, title: getSectionTitleKey('favorites') },
|
||||
{ id: 'quick_questions', visible: true, title: getSectionTitleKey('quick_questions') },
|
||||
{ id: 'embedded', visible: true, title: getSectionTitleKey('embedded') },
|
||||
{ id: 'all_agents', visible: true, title: getSectionTitleKey('all_agents') },
|
||||
];
|
||||
|
||||
const merged: LayoutSection[] = [];
|
||||
const backendIds = new Set(backendSections.map(s => s.id));
|
||||
const mapKey = (id: string) => (id === 'quick_questions' ? 'quickQuestions' : id === 'all_agents' ? 'allAgents' : id);
|
||||
const mapKey = (id: string) => (normalizeSectionId(id) === 'quick_questions' ? 'quickQuestions' : normalizeSectionId(id) === 'all_agents' ? 'allAgents' : normalizeSectionId(id));
|
||||
|
||||
backendSections.forEach(s => {
|
||||
const def = defaultSections.find(d => d.id === s.id);
|
||||
if (config.workspace.modules[mapKey(s.id) as keyof typeof config.workspace.modules] === false) {
|
||||
return;
|
||||
}
|
||||
merged.push({ ...def, ...s });
|
||||
merged.push({ ...def, ...s, title: getSectionTitleKey(s.id) });
|
||||
});
|
||||
|
||||
defaultSections.forEach(d => {
|
||||
@@ -248,10 +285,11 @@ const fetchHome = async () => {
|
||||
} else {
|
||||
// Fallback for no layout data
|
||||
const defaultSections = [
|
||||
{ id: 'favorites', visible: true, collapsed: false },
|
||||
{ id: 'quick_questions', visible: true, collapsed: false },
|
||||
{ id: 'embedded', visible: true, collapsed: false },
|
||||
{ id: 'all_agents', visible: true, collapsed: false },
|
||||
{ id: 'announcements', visible: true, collapsed: false, title: getSectionTitleKey('announcements') },
|
||||
{ id: 'favorites', visible: true, collapsed: false, title: getSectionTitleKey('favorites') },
|
||||
{ id: 'quick_questions', visible: true, collapsed: false, title: getSectionTitleKey('quick_questions') },
|
||||
{ id: 'embedded', visible: true, collapsed: false, title: getSectionTitleKey('embedded') },
|
||||
{ id: 'all_agents', visible: true, collapsed: false, title: getSectionTitleKey('all_agents') },
|
||||
];
|
||||
|
||||
layoutSections.value = defaultSections.filter(s => {
|
||||
@@ -363,9 +401,13 @@ const handleLogin = async () => {
|
||||
// Store in localStorage with 30 days expiry
|
||||
const expiry = new Date().getTime() + 30 * 24 * 60 * 60 * 1000;
|
||||
localStorage.setItem('hxops_user', JSON.stringify({ user, expiry }));
|
||||
// Avoid stale session user overriding current login.
|
||||
sessionStorage.removeItem('hxops_user');
|
||||
} else {
|
||||
// Store in sessionStorage (cleared when tab closed)
|
||||
sessionStorage.setItem('hxops_user', JSON.stringify({ user }));
|
||||
// Avoid stale remembered user overriding current login.
|
||||
localStorage.removeItem('hxops_user');
|
||||
}
|
||||
|
||||
await fetchHome();
|
||||
@@ -570,6 +612,7 @@ const openAnnouncement = (ann: Announcement) => {
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
loadLanguagePreference();
|
||||
loadAuthUser();
|
||||
fetchAnnouncements();
|
||||
if (currentUser.value && currentUser.value.role !== 'guest') {
|
||||
@@ -798,14 +841,15 @@ onMounted(async () => {
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h2 class="text-xl font-bold text-slate-800 flex items-center gap-2.5 cursor-pointer select-none" @click="toggleSectionCollapse(section)">
|
||||
<div class="p-2 rounded-lg" :class="{
|
||||
'bg-emerald-50 text-emerald-600': section.id === 'announcements',
|
||||
'bg-yellow-50 text-yellow-600': section.id === 'favorites',
|
||||
'bg-brand-50 text-brand-600': section.id === 'quick_questions',
|
||||
'bg-purple-50 text-purple-600': section.id === 'embedded',
|
||||
'bg-slate-100 text-slate-600': section.id === 'all_agents'
|
||||
}">
|
||||
<component :is="section.id === 'favorites' ? Star : (section.id === 'embedded' ? Bot : LayoutGrid)" class="w-5 h-5" />
|
||||
<component :is="section.id === 'announcements' ? Megaphone : (section.id === 'favorites' ? Star : (section.id === 'embedded' ? Bot : LayoutGrid))" class="w-5 h-5" />
|
||||
</div>
|
||||
{{ $t(section.title || section.id) }}
|
||||
{{ $t(getSectionTitleKey(section.id)) }}
|
||||
<component :is="section.collapsed ? ChevronDown : ChevronUp" class="w-4 h-4 text-slate-400" />
|
||||
</h2>
|
||||
<!-- Actions for Quick Questions -->
|
||||
@@ -815,6 +859,25 @@ onMounted(async () => {
|
||||
</div>
|
||||
|
||||
<div v-show="!section.collapsed" class="animate-fade-in">
|
||||
<!-- Content: Announcements -->
|
||||
<div v-if="section.id === 'announcements'">
|
||||
<div v-if="announcements.length === 0" class="text-slate-400 text-sm italic py-8 text-center bg-slate-50 rounded-xl border border-dashed border-slate-200">{{ $t('workspace.announcements.noData') }}</div>
|
||||
<div v-else class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
|
||||
<div
|
||||
v-for="ann in announcements"
|
||||
:key="ann.id"
|
||||
class="group border border-slate-200 rounded-2xl bg-white p-5 hover:border-emerald-300 hover:shadow-md transition-all cursor-pointer"
|
||||
@click="openAnnouncement(ann)"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3 mb-2">
|
||||
<h4 class="font-bold text-slate-900 line-clamp-2 group-hover:text-emerald-700 transition-colors">{{ ann.title }}</h4>
|
||||
<span class="text-[10px] font-semibold text-emerald-700 bg-emerald-50 px-2 py-0.5 rounded-full whitespace-nowrap">{{ new Date(ann.created_at).toLocaleDateString() }}</span>
|
||||
</div>
|
||||
<p class="text-sm text-slate-600 line-clamp-3">{{ ann.content }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content: Favorites -->
|
||||
<div v-if="section.id === 'favorites'">
|
||||
<div v-if="favoriteAgents.length === 0" class="text-slate-400 text-sm italic py-4 bg-slate-50 rounded-xl text-center border border-dashed border-slate-200">{{ $t('workspace.noFavorites') }}</div>
|
||||
|
||||
Reference in new issue
Block a user