refactor(frontend): 重构前端第二版
This commit is contained in:
1 parent
2631f78b00
commit
4b562cfa82
205 files changed
+15399
-12015
No files matched your search
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* 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';
|
||||
|
||||
export interface ChatMobileHeaderAgent {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
defineProps<{
|
||||
agentName: string;
|
||||
hasAgentGuides: boolean;
|
||||
userAgents: ChatMobileHeaderAgent[];
|
||||
}>();
|
||||
|
||||
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
|
||||
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>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<button
|
||||
v-for="agent in userAgents"
|
||||
:key="agent.id"
|
||||
type="button"
|
||||
class="flex flex-col items-center gap-1.5 rounded-xl px-2 py-3 text-center transition-colors hover-surface-soft"
|
||||
@click="onSwitchAgent(agent)"
|
||||
>
|
||||
<div class="flex h-9 w-9 items-center justify-center rounded-lg bg-brand-50 text-sm font-bold text-brand-600">
|
||||
{{ agent.name.charAt(0) }}
|
||||
</div>
|
||||
<span class="w-full truncate text-xs font-medium text-secondary">{{ agent.name }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="userAgents.length === 0" class="py-3 text-center text-xs text-muted">{{ $t('chat.noOtherAgents') }}</div>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
Reference in new issue
Block a user