Files
syops/frontend/src/features/chat/components/ChatGuideModal.vue
T

115 lines
4.9 KiB
Vue

/**
* features/chat/components/ChatGuideModal.vue
* Agent 学习之窗:指南目录与视频 / PDF / 图片预览。
*/
<script setup lang="ts">
import { BookOpen, FileText, Image as ImageIcon, PanelLeftClose, PanelLeftOpen, Play, X } from 'lucide-vue-next';
import type { AgentGuide } from '../composables/useChatGuides';
const open = defineModel<boolean>('open', { required: true });
const activeGuideId = defineModel<number | null>('activeGuideId', { required: true });
const showSidebar = defineModel<boolean>('showSidebar', { required: true });
defineProps<{
agentName: string;
guides: AgentGuide[];
activeGuide: AgentGuide | undefined;
}>();
</script>
<template>
<Teleport to="body">
<div
v-if="open"
class="fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 p-4 backdrop-blur-sm"
>
<div class="flex h-[85vh] w-full max-w-4xl flex-col overflow-hidden rounded-2xl bg-surface shadow-xl">
<div class="flex shrink-0 items-center justify-between border-b border-default bg-surface px-6 py-4">
<h3 class="flex items-center gap-2 text-lg font-bold text-primary">
<BookOpen class="h-5 w-5 text-brand-600" />
{{ agentName }} - 学习之窗
</h3>
<div class="flex items-center gap-3">
<button
type="button"
class="flex items-center gap-1.5 rounded-lg border border-transparent px-3 py-1.5 text-sm font-medium text-brand-600 transition-colors hover:border-brand-100 hover:bg-brand-50 hover:text-brand-700"
@click="showSidebar = !showSidebar"
>
<component :is="showSidebar ? PanelLeftClose : PanelLeftOpen" class="h-4 w-4" />
{{ showSidebar ? '收起目录' : '展开目录' }}
</button>
<div class="h-5 w-px bg-default" />
<button
type="button"
class="rounded-lg p-1 text-muted transition-colors hover:bg-surface-soft hover:text-primary"
@click="open = false"
>
<X class="h-6 w-6" />
</button>
</div>
</div>
<div class="relative flex min-h-0 flex-1 overflow-hidden">
<div
v-show="showSidebar"
class="absolute z-10 h-full w-64 shrink-0 space-y-2 overflow-y-auto border-r border-default bg-surface-soft p-4 shadow-xl transition-transform duration-300 md:relative md:shadow-none"
:class="showSidebar ? 'translate-x-0' : '-translate-x-full absolute'"
>
<button
v-for="guide in guides"
:key="guide.id"
type="button"
class="w-full rounded-xl border px-4 py-3 text-left transition-all"
:class="activeGuideId === guide.id ? 'border-brand-200 bg-brand-50 text-brand-700 shadow-sm' : 'border-transparent bg-surface hover:border-default hover:shadow-sm'"
@click="activeGuideId = guide.id"
>
<div class="mb-1 flex items-center gap-2">
<component
:is="guide.file_type === 'video' ? Play : (guide.file_type === 'pdf' ? FileText : ImageIcon)"
class="h-4 w-4 shrink-0"
/>
<span class="truncate text-sm font-medium">{{ guide.file_name }}</span>
</div>
<p
v-if="guide.remark"
class="truncate text-xs opacity-70"
:class="activeGuideId === guide.id ? 'text-brand-600' : 'text-muted'"
>
{{ guide.remark }}
</p>
</button>
</div>
<div class="relative flex flex-1 items-center justify-center overflow-hidden bg-[#ebedf0] dark:bg-gray-900">
<template v-if="activeGuide">
<video
v-if="activeGuide.file_type === 'video'"
:key="'video-' + activeGuide.id"
:src="activeGuide.file_url || activeGuide.file_path"
controls
class="h-full w-full bg-black object-contain"
/>
<iframe
v-else-if="activeGuide.file_type === 'pdf'"
:key="'pdf-' + activeGuide.id"
:src="activeGuide.file_url || activeGuide.file_path"
class="h-full w-full border-none bg-surface"
/>
<img
v-else
:key="'img-' + activeGuide.id"
:src="activeGuide.file_url || activeGuide.file_path"
class="max-h-full max-w-full object-contain"
/>
</template>
<div v-else class="flex flex-col items-center gap-3 text-muted">
<BookOpen class="h-12 w-12 opacity-20" />
<p class="text-sm">请选择左侧指南进行查阅</p>
</div>
</div>
</div>
</div>
</div>
</Teleport>
</template>