117 lines
3.8 KiB
Vue
117 lines
3.8 KiB
Vue
/**
|
|
* features/chat/components/ChatBrowserPanel.vue
|
|
* 内置浏览器侧栏 UI:移动端遮罩、拖拽分隔条与 iframe 预览区。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { ExternalLink, Globe, RotateCw, X } from 'lucide-vue-next';
|
|
|
|
const open = defineModel<boolean>('open', { required: true });
|
|
const draftUrl = defineModel<string>('draftUrl', { required: true });
|
|
|
|
defineProps<{
|
|
currentUrl: string;
|
|
frameKey: number;
|
|
panelStyle: { width: string } | undefined;
|
|
isResizing: boolean;
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
load: [];
|
|
refresh: [];
|
|
'open-new-tab': [];
|
|
'url-enter': [event: KeyboardEvent];
|
|
'start-resize': [event: MouseEvent];
|
|
close: [];
|
|
}>();
|
|
</script>
|
|
|
|
<template>
|
|
<template v-if="open">
|
|
<div
|
|
class="fixed inset-0 z-40 bg-overlay backdrop-blur-sm lg:hidden"
|
|
@click="emit('close')"
|
|
/>
|
|
|
|
<div
|
|
class="relative z-10 hidden w-2 shrink-0 cursor-col-resize bg-transparent lg:block"
|
|
@mousedown="emit('start-resize', $event)"
|
|
>
|
|
<div
|
|
class="absolute inset-y-0 left-1/2 w-px -translate-x-1/2 transition-colors"
|
|
:class="isResizing ? 'bg-brand-500' : 'bg-slate-200'"
|
|
/>
|
|
</div>
|
|
|
|
<aside
|
|
class="fixed inset-y-0 right-0 z-50 flex w-full max-w-[100vw] flex-col border-l border-default bg-surface shadow-2xl sm:w-[420px] lg:static lg:z-0 lg:w-[420px] lg:shadow-none"
|
|
:style="panelStyle"
|
|
>
|
|
<div class="flex items-center justify-between border-b border-default px-4 py-3">
|
|
<div class="flex items-center gap-2 text-sm font-semibold text-secondary">
|
|
<Globe class="h-4 w-4 text-brand-500" />
|
|
{{ $t('chat.browser') }}
|
|
</div>
|
|
<button
|
|
type="button"
|
|
class="rounded-md p-1.5 text-muted transition-colors hover-surface-soft hover:text-secondary"
|
|
:title="$t('chat.closeBrowser')"
|
|
@click="emit('close')"
|
|
>
|
|
<X class="h-4 w-4" />
|
|
</button>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-2 border-b border-default px-3 py-3">
|
|
<input
|
|
v-model="draftUrl"
|
|
type="text"
|
|
:placeholder="$t('chat.browserInputPlaceholder')"
|
|
class="flex-1 rounded-xl border border-default bg-surface-soft px-3 py-2 text-sm text-primary outline-none transition focus:border-brand-400 focus:bg-surface"
|
|
@keydown="emit('url-enter', $event)"
|
|
/>
|
|
<button
|
|
type="button"
|
|
class="rounded-xl bg-brand-600 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-brand-500"
|
|
@click="emit('load')"
|
|
>
|
|
{{ $t('chat.open') }}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="rounded-xl border border-default p-2 text-muted transition-colors hover:bg-surface-soft hover:text-secondary"
|
|
:title="$t('chat.refresh')"
|
|
@click="emit('refresh')"
|
|
>
|
|
<RotateCw class="h-4 w-4" />
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="rounded-xl border border-default p-2 text-muted transition-colors hover:bg-surface-soft hover:text-secondary"
|
|
:title="$t('chat.openInNewTab')"
|
|
@click="emit('open-new-tab')"
|
|
>
|
|
<ExternalLink class="h-4 w-4" />
|
|
</button>
|
|
</div>
|
|
|
|
<div class="min-h-0 flex-1 bg-slate-100">
|
|
<div
|
|
v-if="!currentUrl"
|
|
class="flex h-full flex-col items-center justify-center gap-3 px-8 text-center text-sm text-muted"
|
|
>
|
|
<Globe class="h-8 w-8 text-brand-500" />
|
|
<div>{{ $t('chat.browserHint1') }}</div>
|
|
<div class="text-xs">{{ $t('chat.browserHint2') }}</div>
|
|
</div>
|
|
<iframe
|
|
v-else
|
|
:key="frameKey"
|
|
:src="currentUrl"
|
|
class="h-full w-full border-0 bg-surface"
|
|
allow="clipboard-read; clipboard-write"
|
|
/>
|
|
</div>
|
|
</aside>
|
|
</template>
|
|
</template>
|