Frag das Portal als schwebende Blase, Suchliste im Bild (0.65.0)
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Successful in 14m21s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 19m7s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 5m20s
CI / Build-Artefakte aktuell (pull_request) Successful in 5m46s
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Successful in 14m21s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 19m7s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 5m20s
CI / Build-Artefakte aktuell (pull_request) Successful in 5m46s
- AskBubble unten rechts (abschaltbar), Gespräch bleibt beim Seitenwechsel - Antwortanzeige als gemeinsame Komponente AskAnswer - Trefferliste der Kopfzeilen-Suche in der App-Oberfläche linksbündig - CI: optionale Kern-Plugins für Browser-Tests einschalten, Suchtest mit Demo-Inhalt Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
55c1d85ed7
commit
4d58364104
192 changed files with 717 additions and 507 deletions
|
|
@ -14,6 +14,8 @@ import { highlight } from '@/lib/highlight';
|
|||
*/
|
||||
const props = defineProps({
|
||||
initial: { type: String, default: '' },
|
||||
// Ausrichtung der Trefferliste: links, wenn das Feld links in der Kopfzeile steht (Mitarbeiter-App)
|
||||
align: { type: String, default: 'right' },
|
||||
});
|
||||
|
||||
const root = ref(null);
|
||||
|
|
@ -118,7 +120,8 @@ const showPanel = computed(() => open.value && query.value.trim().length >= 2);
|
|||
<div
|
||||
v-if="showPanel"
|
||||
id="global-search-results"
|
||||
class="absolute top-full right-0 z-50 mt-2 max-h-[min(70vh,560px)] w-[min(92vw,30rem)] overflow-y-auto rounded-lg border bg-popover text-popover-foreground shadow-lg"
|
||||
class="absolute top-full z-50 mt-2 max-h-[min(70vh,560px)] w-[min(92vw,30rem)] overflow-y-auto rounded-lg border bg-popover text-popover-foreground shadow-lg"
|
||||
:class="align === 'left' ? 'left-0' : 'right-0'"
|
||||
>
|
||||
<template v-if="groups.length">
|
||||
<section v-for="group in groups" :key="group.key" class="border-b last:border-b-0">
|
||||
|
|
@ -140,7 +143,7 @@ const showPanel = computed(() => open.value && query.value.trim().length >= 2);
|
|||
<span class="min-w-0 flex-1">
|
||||
<span class="block truncate text-sm font-medium" v-html="highlight(item.title, query)" />
|
||||
<span v-if="item.meta" class="block truncate text-xs text-muted-foreground">{{ item.meta }}</span>
|
||||
<span v-if="item.excerpt" class="mt-0.5 line-clamp-1 text-xs text-muted-foreground" v-html="highlight(item.excerpt, query)" />
|
||||
<span v-if="item.excerpt" class="mt-0.5 line-clamp-1 text-xs [overflow-wrap:anywhere] text-muted-foreground" v-html="highlight(item.excerpt, query)" />
|
||||
</span>
|
||||
</component>
|
||||
</li>
|
||||
|
|
|
|||
70
resources/js/components/ask/AskAnswer.vue
Normal file
70
resources/js/components/ask/AskAnswer.vue
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { ArrowUpRight, SearchX } from '@lucide/vue';
|
||||
import { answerBlocks } from '@/lib/ask';
|
||||
|
||||
// Antwort von „Frag das Portal“ mit Quellen – auf der Seite und in der schwebenden Blase
|
||||
const props = defineProps({
|
||||
result: { type: Object, required: true },
|
||||
// Kennung für Sprungmarken zu den Quellen (mehrere Antworten auf einer Seite)
|
||||
anchor: { type: String, default: 'quelle' },
|
||||
compact: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const blocks = computed(() => answerBlocks(props.result));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="result.found" class="grid min-w-0 grid-cols-1">
|
||||
<div class="grid grid-cols-1 leading-relaxed" :class="compact ? 'gap-2 text-sm' : 'gap-3 text-base'">
|
||||
<template v-for="(block, i) in blocks" :key="i">
|
||||
<p v-if="block.type === 'p'">
|
||||
<template v-for="(seg, j) in block.segments" :key="j">
|
||||
<a v-if="seg.cite" :href="`#${anchor}-${seg.cite}`" class="mx-0.5 align-super text-[0.7em] font-semibold text-brand-text hover:underline" :aria-label="`Quelle ${seg.cite}`">[{{ seg.cite }}]</a>
|
||||
<template v-else>{{ seg.text }}</template>
|
||||
</template>
|
||||
</p>
|
||||
<ul v-else class="grid list-disc gap-1.5 pl-5">
|
||||
<li v-for="(item, k) in block.items" :key="k">
|
||||
<template v-for="(seg, j) in item" :key="j">
|
||||
<a v-if="seg.cite" :href="`#${anchor}-${seg.cite}`" class="mx-0.5 align-super text-[0.7em] font-semibold text-brand-text hover:underline" :aria-label="`Quelle ${seg.cite}`">[{{ seg.cite }}]</a>
|
||||
<template v-else>{{ seg.text }}</template>
|
||||
</template>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<h3 class="mb-2 text-sm font-semibold" :class="compact ? 'mt-4' : 'mt-6'">Quellen</h3>
|
||||
<ol class="grid grid-cols-1" :class="compact ? 'gap-1.5' : 'gap-2'">
|
||||
<li v-for="source in result.sources" :id="`${anchor}-${source.n}`" :key="source.n" class="min-w-0">
|
||||
<a :href="source.url" class="group flex items-start gap-3 rounded-lg border bg-background hover:border-brand-300 hover:bg-accent" :class="compact ? 'px-2.5 py-2' : 'px-3 py-2.5'">
|
||||
<span class="grid size-6 shrink-0 place-items-center rounded-full bg-brand-soft text-xs font-semibold text-brand-text">{{ source.n }}</span>
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block font-medium group-hover:underline" :class="{ 'text-sm': compact }">{{ source.title }}</span>
|
||||
<span class="block truncate text-xs text-muted-foreground">{{ source.label }}<template v-if="source.meta"> · {{ source.meta }}</template></span>
|
||||
</span>
|
||||
<ArrowUpRight class="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||||
</a>
|
||||
</li>
|
||||
</ol>
|
||||
<p class="mt-3 text-xs text-muted-foreground">Automatisch zusammengefasst – im Zweifel gilt, was in den Quellen steht.</p>
|
||||
</div>
|
||||
|
||||
<div v-else class="grid min-w-0 grid-cols-1">
|
||||
<div class="flex items-start gap-3">
|
||||
<SearchX class="mt-0.5 size-5 shrink-0 text-muted-foreground" />
|
||||
<div class="grid gap-1">
|
||||
<p class="font-medium" :class="{ 'text-sm': compact }">{{ result.answer }}</p>
|
||||
<p class="text-sm text-muted-foreground">Versuchen Sie es mit anderen Worten – oder fragen Sie direkt Ihre Ansprechpersonen.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="result.suggestions?.length" class="mt-4 grid grid-cols-1 gap-2">
|
||||
<p class="text-sm font-medium">Vielleicht hilft Ihnen das weiter:</p>
|
||||
<a v-for="item in result.suggestions" :key="item.url" :href="item.url" class="flex items-center justify-between gap-3 rounded-lg border bg-background px-3 py-2 text-sm hover:bg-accent">
|
||||
<span class="min-w-0 truncate">{{ item.title }} <span class="text-muted-foreground">· {{ item.label }}</span></span>
|
||||
<ArrowUpRight class="size-4 shrink-0 text-muted-foreground" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
170
resources/js/components/ask/AskBubble.vue
Normal file
170
resources/js/components/ask/AskBubble.vue
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
<script setup>
|
||||
import { nextTick, ref, watch } from 'vue';
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { LoaderCircle, Maximize2, SendHorizontal, Sparkles, Trash2, X } from '@lucide/vue';
|
||||
import AskAnswer from '@/components/ask/AskAnswer.vue';
|
||||
import { askPortal } from '@/lib/ask';
|
||||
|
||||
// Schwebende Blase „Frag das Portal“ unten rechts. Der Rahmen bleibt beim Seitenwechsel
|
||||
// stehen – das Gespräch auch; beim Neuladen kommt es aus dem Sitzungsspeicher zurück.
|
||||
defineProps({
|
||||
// Am Handy steht unten die Menüleiste der Mitarbeiter-App – dann darüber
|
||||
aboveBottomNav: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const STORE = 'inhaus:frag-das-portal';
|
||||
const examples = ['Wie beantrage ich Urlaub?', 'Was mache ich bei einem Arbeitsunfall?', 'Wer ist in der Mitarbeitervertretung?'];
|
||||
|
||||
function restore() {
|
||||
try {
|
||||
const saved = JSON.parse(sessionStorage.getItem(STORE) ?? '[]');
|
||||
return Array.isArray(saved) ? saved : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
const open = ref(false);
|
||||
const messages = ref(restore()); // [{ question, result?, error? }]
|
||||
const input = ref('');
|
||||
const loading = ref(false);
|
||||
const field = ref(null);
|
||||
const list = ref(null);
|
||||
const trigger = ref(null);
|
||||
|
||||
watch(messages, (value) => {
|
||||
try {
|
||||
sessionStorage.setItem(STORE, JSON.stringify(value.slice(-10)));
|
||||
} catch {
|
||||
// Kein Speicher (privates Fenster) – das Gespräch gilt dann nur bis zum Neuladen
|
||||
}
|
||||
}, { deep: true });
|
||||
|
||||
function scrollDown() {
|
||||
nextTick(() => list.value?.scrollTo({ top: list.value.scrollHeight, behavior: 'smooth' }));
|
||||
}
|
||||
|
||||
function toggle() {
|
||||
open.value = !open.value;
|
||||
if (open.value) {
|
||||
nextTick(() => field.value?.focus());
|
||||
scrollDown();
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
open.value = false;
|
||||
nextTick(() => trigger.value?.focus());
|
||||
}
|
||||
|
||||
async function ask(question = input.value) {
|
||||
const text = question.trim();
|
||||
if (text.length < 3 || loading.value) return;
|
||||
|
||||
input.value = '';
|
||||
const message = { question: text, result: null, error: null };
|
||||
messages.value.push(message);
|
||||
loading.value = true;
|
||||
scrollDown();
|
||||
|
||||
try {
|
||||
messages.value[messages.value.length - 1].result = await askPortal(text);
|
||||
} catch (e) {
|
||||
messages.value[messages.value.length - 1].error = e.message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
scrollDown();
|
||||
nextTick(() => field.value?.focus());
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
messages.value = [];
|
||||
nextTick(() => field.value?.focus());
|
||||
}
|
||||
|
||||
const lastQuestion = () => messages.value.at(-1)?.question ?? '';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="print:hidden">
|
||||
<section
|
||||
v-if="open"
|
||||
id="frag-das-portal-blase"
|
||||
role="dialog"
|
||||
aria-labelledby="frag-das-portal-titel"
|
||||
class="fixed right-2 left-2 z-50 flex h-[min(36rem,calc(100dvh-13rem))] flex-col overflow-hidden rounded-2xl border bg-card shadow-2xl sm:left-auto sm:w-[26rem] sm:right-6"
|
||||
:class="aboveBottomNav ? 'bottom-36 lg:bottom-24' : 'bottom-20 sm:bottom-24'"
|
||||
@keydown.esc="close"
|
||||
>
|
||||
<header class="flex items-center gap-2 border-b bg-brand px-4 py-3 text-brand-foreground">
|
||||
<Sparkles class="size-5 shrink-0" />
|
||||
<h2 id="frag-das-portal-titel" class="flex-1 font-semibold">Frag das Portal</h2>
|
||||
<button v-if="messages.length" type="button" class="grid size-8 place-items-center rounded-full hover:bg-white/15" title="Gespräch leeren" aria-label="Gespräch leeren" @click="clear">
|
||||
<Trash2 class="size-4" />
|
||||
</button>
|
||||
<Link :href="lastQuestion() ? `/frag-das-portal?frage=${encodeURIComponent(lastQuestion())}` : '/frag-das-portal'" class="grid size-8 place-items-center rounded-full hover:bg-white/15" title="Groß öffnen" aria-label="Groß öffnen" @click="open = false">
|
||||
<Maximize2 class="size-4" />
|
||||
</Link>
|
||||
<button type="button" class="grid size-8 place-items-center rounded-full hover:bg-white/15" aria-label="Schließen" @click="close">
|
||||
<X class="size-4" />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div ref="list" class="grid flex-1 grid-cols-1 content-start gap-4 overflow-y-auto overscroll-contain p-4" aria-live="polite">
|
||||
<div v-if="!messages.length" class="grid gap-3 text-sm">
|
||||
<p>Stellen Sie eine Frage in eigenen Worten – ich suche die Antwort im Portal und nenne die Quellen.</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button v-for="example in examples" :key="example" type="button" class="rounded-pill border bg-background px-3 py-1.5 text-[13px] text-muted-foreground hover:bg-accent hover:text-foreground" @click="ask(example)">
|
||||
{{ example }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-for="(message, i) in messages" :key="i">
|
||||
<p class="ml-auto max-w-[85%] rounded-2xl rounded-br-md bg-brand-soft px-3.5 py-2 text-sm text-brand-text">{{ message.question }}</p>
|
||||
<div v-if="message.result" class="min-w-0 rounded-2xl rounded-bl-md border bg-background/60 p-3.5">
|
||||
<AskAnswer :result="message.result" :anchor="`blase-${i}`" compact />
|
||||
</div>
|
||||
<p v-else-if="message.error" class="rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive">{{ message.error }}</p>
|
||||
<p v-else-if="loading && i === messages.length - 1" class="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<LoaderCircle class="size-4 animate-spin text-brand" /> Ich suche im Portal …
|
||||
</p>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<form class="flex items-end gap-2 border-t p-2.5" @submit.prevent="ask()">
|
||||
<label for="frag-das-portal-feld" class="sr-only">Ihre Frage</label>
|
||||
<textarea
|
||||
id="frag-das-portal-feld"
|
||||
ref="field"
|
||||
v-model="input"
|
||||
rows="1"
|
||||
maxlength="300"
|
||||
placeholder="Ihre Frage …"
|
||||
class="max-h-28 min-h-10 min-w-0 flex-1 resize-none rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none [field-sizing:content] focus-visible:border-brand-400 focus-visible:ring-3 focus-visible:ring-ring/30"
|
||||
@keydown.enter.exact.prevent="ask()"
|
||||
/>
|
||||
<button type="submit" class="grid size-10 shrink-0 place-items-center rounded-full bg-brand text-brand-foreground hover:opacity-90 disabled:opacity-40" :disabled="loading || input.trim().length < 3" aria-label="Frage senden">
|
||||
<LoaderCircle v-if="loading" class="size-4 animate-spin" />
|
||||
<SendHorizontal v-else class="size-4" />
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<button
|
||||
ref="trigger"
|
||||
type="button"
|
||||
class="fixed right-4 z-50 flex h-14 items-center gap-2 rounded-full bg-brand px-4 text-brand-foreground shadow-lg transition hover:shadow-xl hover:brightness-110 focus-visible:ring-4 focus-visible:ring-ring/40 focus-visible:outline-none sm:right-6 sm:px-5"
|
||||
:class="aboveBottomNav ? 'bottom-20 lg:bottom-6' : 'bottom-4 sm:bottom-6'"
|
||||
:aria-expanded="open"
|
||||
aria-controls="frag-das-portal-blase"
|
||||
@click="toggle"
|
||||
>
|
||||
<X v-if="open" class="size-6" />
|
||||
<Sparkles v-else class="size-6" />
|
||||
<span class="hidden text-sm font-semibold sm:inline">{{ open ? 'Schließen' : 'Frag das Portal' }}</span>
|
||||
<span class="sr-only sm:hidden">{{ open ? 'Frag das Portal schließen' : 'Frag das Portal' }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -20,6 +20,7 @@ import AppLauncher from '@/components/apps/AppLauncher.vue';
|
|||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
import NavLink from '@/components/nav/NavLink.vue';
|
||||
import BottomNav from '@/components/nav/BottomNav.vue';
|
||||
import AskBubble from '@/components/ask/AskBubble.vue';
|
||||
import AppIcon from '@/components/AppIcon.vue';
|
||||
import GlobalSearchBox from '@/components/GlobalSearchBox.vue';
|
||||
import PageContent from '@/pagebuilder/PageContent.vue';
|
||||
|
|
@ -57,6 +58,10 @@ const embedded = computed(() => !!page.props.embedded);
|
|||
const navigation = computed(() => page.props.navigation);
|
||||
// Mitarbeiter-App am Handy: untere Menüleiste statt Burger-Menü (nicht eingebettet und nur angemeldet)
|
||||
const bottomNav = computed(() => isApp.value && !embedded.value && !!user.value);
|
||||
// „Frag das Portal“ als schwebende Blase – nicht auf der eigenen Seite und nicht bei
|
||||
// Seiten, die die ganze Höhe füllen (z. B. Nachrichten: dort liegt unten rechts das Eingabefeld)
|
||||
const askBubble = computed(() => !!page.props.ask?.bubble && !embedded.value && !!user.value
|
||||
&& frame.width !== 'app' && !page.url.startsWith('/frag-das-portal'));
|
||||
|
||||
// Was nicht in die Kopfzeile passt, kommt unter „Mehr“. Gemessen wird an einer
|
||||
// unsichtbaren Kopie der Menüpunkte – so passt es bei jeder Breite und Beschriftung.
|
||||
|
|
@ -194,7 +199,7 @@ const themeOptions = [
|
|||
<BrandLogo :inverted="headerStyle !== 'light'" compact />
|
||||
</Link>
|
||||
|
||||
<GlobalSearchBox v-if="isApp" :initial="searchQuery" class="hidden w-56 shrink-0 md:block xl:w-72" />
|
||||
<GlobalSearchBox v-if="isApp" :initial="searchQuery" align="left" class="hidden w-56 shrink-0 md:block xl:w-72" />
|
||||
|
||||
<nav ref="navBox" class="relative hidden h-full min-w-0 flex-1" :class="{ 'lg:block': !burgerOnDesktop }" aria-label="Hauptnavigation">
|
||||
<!-- Unsichtbare Kopie zum Messen der Breiten -->
|
||||
|
|
@ -372,5 +377,7 @@ const themeOptions = [
|
|||
</template>
|
||||
</div>
|
||||
|
||||
<Toaster position="bottom-right" />
|
||||
<AskBubble v-if="askBubble" :above-bottom-nav="bottomNav" />
|
||||
<!-- Meldungen über der Blase, damit sie sie nicht verdecken -->
|
||||
<Toaster position="bottom-right" :offset="askBubble ? { bottom: '6rem', right: '1.5rem' } : undefined" :mobile-offset="askBubble ? { bottom: bottomNav ? '9rem' : '5.5rem' } : undefined" />
|
||||
</template>
|
||||
|
|
|
|||
36
resources/js/lib/ask.js
Normal file
36
resources/js/lib/ask.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { http } from '@/lib/http';
|
||||
|
||||
/**
|
||||
* „Frag das Portal“: Frage stellen. Liefert { answer, found, sources, suggestions }
|
||||
* oder wirft einen Fehler mit verständlicher Meldung.
|
||||
*/
|
||||
export async function askPortal(question) {
|
||||
try {
|
||||
return await http.post('/frag-das-portal', { question });
|
||||
} catch (e) {
|
||||
throw new Error(e.status === 429 ? 'Sie haben gerade viele Fragen gestellt. Bitte einen Moment warten.' : (e.data?.errors?.question?.[0] ?? e.message));
|
||||
}
|
||||
}
|
||||
|
||||
/** Antworttext in Absätze und Listenpunkte; [2] wird zum Verweis auf Quelle 2 */
|
||||
export function answerBlocks(result) {
|
||||
if (!result?.found) return [];
|
||||
const known = new Set(result.sources.map((s) => s.n));
|
||||
const segments = (line) => line.split(/(\[\d+\])/).filter(Boolean).map((part) => {
|
||||
const cite = part.match(/^\[(\d+)\]$/);
|
||||
return cite && known.has(Number(cite[1])) ? { cite: Number(cite[1]) } : { text: part };
|
||||
});
|
||||
const out = [];
|
||||
for (const raw of result.answer.split('\n')) {
|
||||
const line = raw.trim();
|
||||
if (!line) continue;
|
||||
if (/^[-•*]\s+/.test(line)) {
|
||||
const last = out[out.length - 1];
|
||||
const item = segments(line.replace(/^[-•*]\s+/, ''));
|
||||
last?.type === 'list' ? last.items.push(item) : out.push({ type: 'list', items: [item] });
|
||||
} else {
|
||||
out.push({ type: 'p', segments: segments(line) });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
<script setup>
|
||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
||||
import { ArrowUpRight, LoaderCircle, MessageCircleQuestion, SearchX, Sparkles } from '@lucide/vue';
|
||||
import { nextTick, onMounted, ref } from 'vue';
|
||||
import { LoaderCircle, MessageCircleQuestion, Sparkles } from '@lucide/vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import PageHeader from '@/components/PageHeader.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { http } from '@/lib/http';
|
||||
import AskAnswer from '@/components/ask/AskAnswer.vue';
|
||||
import { askPortal } from '@/lib/ask';
|
||||
|
||||
const props = defineProps({
|
||||
question: { type: String, default: '' },
|
||||
|
|
@ -36,37 +37,14 @@ async function ask(question = input.value) {
|
|||
window.history.replaceState(window.history.state, '', `/frag-das-portal?frage=${encodeURIComponent(text)}`);
|
||||
|
||||
try {
|
||||
result.value = await http.post('/frag-das-portal', { question: text });
|
||||
result.value = await askPortal(text);
|
||||
} catch (e) {
|
||||
error.value = e.status === 429 ? 'Sie haben gerade viele Fragen gestellt. Bitte einen Moment warten.' : (e.data?.errors?.question?.[0] ?? e.message);
|
||||
error.value = e.message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Antwort als Absätze und Listenpunkte; [2] wird zum Verweis auf die Quelle
|
||||
const blocks = computed(() => {
|
||||
if (!result.value?.found) return [];
|
||||
const known = new Set(result.value.sources.map((s) => s.n));
|
||||
const segments = (line) => line.split(/(\[\d+\])/).filter(Boolean).map((part) => {
|
||||
const cite = part.match(/^\[(\d+)\]$/);
|
||||
return cite && known.has(Number(cite[1])) ? { cite: Number(cite[1]) } : { text: part };
|
||||
});
|
||||
const out = [];
|
||||
for (const raw of result.value.answer.split('\n')) {
|
||||
const line = raw.trim();
|
||||
if (!line) continue;
|
||||
if (/^[-•*]\s+/.test(line)) {
|
||||
const last = out[out.length - 1];
|
||||
const item = segments(line.replace(/^[-•*]\s+/, ''));
|
||||
last?.type === 'list' ? last.items.push(item) : out.push({ type: 'list', items: [item] });
|
||||
} else {
|
||||
out.push({ type: 'p', segments: segments(line) });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
if (props.question) ask(props.question);
|
||||
else nextTick(() => field.value?.focus());
|
||||
|
|
@ -122,61 +100,10 @@ onMounted(() => {
|
|||
|
||||
<p v-else-if="error" class="rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive">{{ error }}</p>
|
||||
|
||||
<template v-else-if="result">
|
||||
<Panel v-if="result.found">
|
||||
<p class="mb-3 text-sm font-medium text-muted-foreground">{{ asked }}</p>
|
||||
<div class="grid grid-cols-1 gap-3 text-base leading-relaxed">
|
||||
<template v-for="(block, i) in blocks" :key="i">
|
||||
<p v-if="block.type === 'p'">
|
||||
<template v-for="(seg, j) in block.segments" :key="j">
|
||||
<a v-if="seg.cite" :href="`#quelle-${seg.cite}`" class="mx-0.5 align-super text-xs font-semibold text-brand-text hover:underline" :aria-label="`Quelle ${seg.cite}`">[{{ seg.cite }}]</a>
|
||||
<template v-else>{{ seg.text }}</template>
|
||||
</template>
|
||||
</p>
|
||||
<ul v-else class="grid list-disc gap-1.5 pl-5">
|
||||
<li v-for="(item, k) in block.items" :key="k">
|
||||
<template v-for="(seg, j) in item" :key="j">
|
||||
<a v-if="seg.cite" :href="`#quelle-${seg.cite}`" class="mx-0.5 align-super text-xs font-semibold text-brand-text hover:underline" :aria-label="`Quelle ${seg.cite}`">[{{ seg.cite }}]</a>
|
||||
<template v-else>{{ seg.text }}</template>
|
||||
</template>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<h2 class="mt-6 mb-2 text-sm font-semibold">Quellen</h2>
|
||||
<ol class="grid grid-cols-1 gap-2">
|
||||
<li v-for="source in result.sources" :id="`quelle-${source.n}`" :key="source.n">
|
||||
<a :href="source.url" class="group flex items-start gap-3 rounded-lg border bg-background px-3 py-2.5 hover:border-brand-300 hover:bg-accent">
|
||||
<span class="grid size-6 shrink-0 place-items-center rounded-full bg-brand-soft text-xs font-semibold text-brand-text">{{ source.n }}</span>
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block font-medium group-hover:underline">{{ source.title }}</span>
|
||||
<span class="block truncate text-xs text-muted-foreground">{{ source.label }}<template v-if="source.meta"> · {{ source.meta }}</template></span>
|
||||
</span>
|
||||
<ArrowUpRight class="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||||
</a>
|
||||
</li>
|
||||
</ol>
|
||||
<p class="mt-4 text-xs text-muted-foreground">Automatisch zusammengefasst – im Zweifel gilt, was in den Quellen steht.</p>
|
||||
</Panel>
|
||||
|
||||
<Panel v-else>
|
||||
<div class="flex items-start gap-3">
|
||||
<SearchX class="mt-0.5 size-5 shrink-0 text-muted-foreground" />
|
||||
<div class="grid gap-1">
|
||||
<p class="font-medium">{{ result.answer }}</p>
|
||||
<p class="text-sm text-muted-foreground">Versuchen Sie es mit anderen Worten – oder fragen Sie direkt Ihre Ansprechpersonen.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="result.suggestions.length" class="mt-4 grid grid-cols-1 gap-2">
|
||||
<p class="text-sm font-medium">Vielleicht hilft Ihnen das weiter:</p>
|
||||
<a v-for="item in result.suggestions" :key="item.url" :href="item.url" class="flex items-center justify-between gap-3 rounded-lg border bg-background px-3 py-2 text-sm hover:bg-accent">
|
||||
<span class="min-w-0 truncate">{{ item.title }} <span class="text-muted-foreground">· {{ item.label }}</span></span>
|
||||
<ArrowUpRight class="size-4 shrink-0 text-muted-foreground" />
|
||||
</a>
|
||||
</div>
|
||||
</Panel>
|
||||
</template>
|
||||
<Panel v-else-if="result">
|
||||
<p class="mb-3 text-sm font-medium text-muted-foreground">{{ asked }}</p>
|
||||
<AskAnswer :result="result" />
|
||||
</Panel>
|
||||
</div>
|
||||
|
||||
<p class="flex items-start gap-2 text-xs text-muted-foreground">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue