114 lines
3.8 KiB
Vue
114 lines
3.8 KiB
Vue
/**
|
|
* features/chat/components/ChatMobileHeader.vue
|
|
* 移动端顶栏:Agent 名称、学习之窗与 Agent 切换弹层。合同付款预警可隐藏历史入口。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
|
import { BookOpen, History, LayoutGrid } from 'lucide-vue-next';
|
|
import AgentCategoryList from '@/shared/components/AgentCategoryList.vue';
|
|
import type { AgentWithCategory } from '@/shared/utils/agent-category.utils';
|
|
|
|
export interface ChatMobileHeaderAgent extends AgentWithCategory {}
|
|
|
|
defineProps<{
|
|
agentName: string;
|
|
activeAgentId: number;
|
|
hasAgentGuides: boolean;
|
|
userAgents: ChatMobileHeaderAgent[];
|
|
hideHistory?: boolean;
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
'open-guide': [];
|
|
'go-history': [];
|
|
'open-agent-popover': [];
|
|
'switch-agent': [agent: ChatMobileHeaderAgent];
|
|
}>();
|
|
|
|
const showAgentPopover = ref(false);
|
|
const popoverRef = ref<HTMLElement | null>(null);
|
|
|
|
const toggleAgentPopover = () => {
|
|
showAgentPopover.value = !showAgentPopover.value;
|
|
if (showAgentPopover.value) {
|
|
emit('open-agent-popover');
|
|
}
|
|
};
|
|
|
|
const handleClickOutside = (event: MouseEvent | TouchEvent) => {
|
|
const target = event.target as Node | null;
|
|
if (!target) return;
|
|
if (showAgentPopover.value && popoverRef.value && !popoverRef.value.contains(target)) {
|
|
showAgentPopover.value = false;
|
|
}
|
|
};
|
|
|
|
const onSwitchAgent = (agent: ChatMobileHeaderAgent) => {
|
|
showAgentPopover.value = false;
|
|
emit('switch-agent', agent);
|
|
};
|
|
|
|
onMounted(() => {
|
|
document.addEventListener('mousedown', handleClickOutside);
|
|
document.addEventListener('touchstart', handleClickOutside, { passive: true });
|
|
});
|
|
|
|
onBeforeUnmount(() => {
|
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
document.removeEventListener('touchstart', handleClickOutside);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<header class="relative flex items-center justify-between border-b border-default bg-surface px-4 py-2.5">
|
|
<div class="flex items-center gap-2">
|
|
<div class="flex h-7 w-7 items-center justify-center rounded-lg bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-xs font-bold text-white shadow-sm shadow-brand-500/20">
|
|
AI
|
|
</div>
|
|
<span class="text-sm font-semibold text-primary">{{ agentName }}</span>
|
|
<button
|
|
v-if="hasAgentGuides"
|
|
type="button"
|
|
class="ml-1 flex items-center gap-1.5 rounded-lg border border-brand-300 bg-brand-100 px-3 py-1.5 text-xs font-bold text-brand-700 shadow-sm transition-all hover:border-brand-400 hover:bg-brand-200"
|
|
@click="emit('open-guide')"
|
|
>
|
|
<BookOpen class="h-4 w-4" />
|
|
学习之窗
|
|
</button>
|
|
</div>
|
|
<div class="flex items-center gap-1">
|
|
<button
|
|
type="button"
|
|
class="flex h-9 w-9 items-center justify-center rounded-full text-muted transition-colors hover-surface-soft"
|
|
:title="$t('chat.agents')"
|
|
@click="toggleAgentPopover"
|
|
>
|
|
<LayoutGrid class="h-5 w-5" />
|
|
</button>
|
|
<button
|
|
v-if="!hideHistory"
|
|
type="button"
|
|
class="flex h-9 w-9 items-center justify-center rounded-full text-muted transition-colors hover-surface-soft"
|
|
:title="$t('chat.history')"
|
|
@click="emit('go-history')"
|
|
>
|
|
<History class="h-5 w-5" />
|
|
</button>
|
|
</div>
|
|
<div
|
|
v-if="showAgentPopover"
|
|
ref="popoverRef"
|
|
class="absolute right-4 top-12 z-50 w-72 rounded-2xl border border-default bg-surface p-3 shadow-xl"
|
|
>
|
|
<div class="mb-2 text-xs font-medium text-muted">{{ $t('chat.agents') }}</div>
|
|
<AgentCategoryList
|
|
v-if="userAgents.length > 0"
|
|
:agents="userAgents"
|
|
:active-agent-id="activeAgentId"
|
|
@select="onSwitchAgent"
|
|
/>
|
|
<div v-else class="py-3 text-center text-xs text-muted">{{ $t('chat.noOtherAgents') }}</div>
|
|
</div>
|
|
</header>
|
|
</template>
|