|
@@ -1,101 +1,379 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <main class="conversation-panel">
|
|
|
|
|
- <header>
|
|
|
|
|
- <div>
|
|
|
|
|
- <h1>对话入口</h1>
|
|
|
|
|
- <p>系统会识别意图并进入对应流程</p>
|
|
|
|
|
|
|
+ <main class="chat-area">
|
|
|
|
|
+ <div class="chat-header" :class="{ disconnected: store.connectionStatus === 'disconnected' }">
|
|
|
|
|
+ <span class="chat-header-title">空海医院医疗助手 · Web Demo · 门诊大厅 · 联调演示</span>
|
|
|
|
|
+ <span class="chat-header-status">
|
|
|
|
|
+ <span :class="store.connectionStatus === 'disconnected' ? 'status-dot-err' : 'status-dot'" />
|
|
|
|
|
+ {{ store.connectionStatus === 'disconnected' ? '连接异常' : '在线' }}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="chat-messages" ref="messagesEl">
|
|
|
|
|
+ <!-- Disconnected overlay -->
|
|
|
|
|
+ <div v-if="store.connectionStatus === 'disconnected'" class="disconnected-overlay">
|
|
|
|
|
+ <div class="disc-icon">
|
|
|
|
|
+ <svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
|
|
|
|
|
+ <path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z" />
|
|
|
|
|
+ <line x1="12" y1="9" x2="12" y2="13" />
|
|
|
|
|
+ <line x1="12" y1="17" x2="12.01" y2="17" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <p class="disc-title">连接异常</p>
|
|
|
|
|
+ <p class="disc-desc">请检查网络连接或联系现场工作人员。</p>
|
|
|
|
|
+ <div class="disc-btns">
|
|
|
|
|
+ <button class="btn-accent">重新连接</button>
|
|
|
|
|
+ <button class="btn-outline">联系工作人员</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Empty state -->
|
|
|
|
|
+ <div v-else-if="store.messages.length === 0 && !store.sending" class="chat-empty">
|
|
|
|
|
+ <div class="chat-empty-icon">
|
|
|
|
|
+ <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6">
|
|
|
|
|
+ <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <p class="chat-empty-text">您好,我是门诊助手</p>
|
|
|
|
|
+ <p class="chat-empty-hint">请说出您的就诊需求,例如:我头疼三天,想挂号</p>
|
|
|
</div>
|
|
</div>
|
|
|
- <span v-if="store.task" class="task-pill">{{ store.task.taskType }}</span>
|
|
|
|
|
- </header>
|
|
|
|
|
|
|
|
|
|
- <section class="messages" aria-label="对话消息">
|
|
|
|
|
- <MessageBubble v-for="message in store.messages" :key="message.id" :message="message" />
|
|
|
|
|
- </section>
|
|
|
|
|
|
|
+ <!-- Loading skeleton -->
|
|
|
|
|
+ <div v-if="store.sending && store.messages.length === 0" class="loading-block">
|
|
|
|
|
+ <div class="skeleton-line w60" />
|
|
|
|
|
+ <div class="skeleton-line w80" />
|
|
|
|
|
+ <div class="skeleton-line w40" />
|
|
|
|
|
+ <p class="loading-text">正在分析症状并匹配科室…</p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Messages -->
|
|
|
|
|
+ <template v-for="msg in store.messages" :key="msg.id">
|
|
|
|
|
+ <div v-if="msg.role !== 'system'" :class="['msg', msg.role === 'user' ? 'msg-user' : 'msg-ai']">
|
|
|
|
|
+ {{ msg.content }}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </template>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Mini card previews -->
|
|
|
|
|
+ <div
|
|
|
|
|
+ v-for="preview in store.cardPreviews"
|
|
|
|
|
+ :key="preview.id"
|
|
|
|
|
+ :class="['chat-card', { active: isPreviewActive(preview.id) }]"
|
|
|
|
|
+ @click="store.viewCard(isPreviewActive(preview.id) ? null : preview.id)"
|
|
|
|
|
+ >
|
|
|
|
|
+ <div class="cc-title">{{ preview.title }}</div>
|
|
|
|
|
+ <div class="cc-choice">{{ preview.subtitle }}</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
|
|
|
- <ChatInput @submit="handleSubmit" />
|
|
|
|
|
|
|
+ <ChatInput :disabled="store.sending" @submit="handleSubmit" />
|
|
|
</main>
|
|
</main>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
-import { demoCards } from '../api/demoFixtures';
|
|
|
|
|
|
|
+import { watch, ref, nextTick } from 'vue';
|
|
|
import ChatInput from './ChatInput.vue';
|
|
import ChatInput from './ChatInput.vue';
|
|
|
-import MessageBubble from './MessageBubble.vue';
|
|
|
|
|
import { useTerminalStore } from '../state/terminalStore';
|
|
import { useTerminalStore } from '../state/terminalStore';
|
|
|
|
|
|
|
|
const store = useTerminalStore();
|
|
const store = useTerminalStore();
|
|
|
|
|
+const messagesEl = ref<HTMLElement | null>(null);
|
|
|
|
|
|
|
|
-if (store.messages.length === 0) {
|
|
|
|
|
- store.addMessage({
|
|
|
|
|
- id: 'welcome',
|
|
|
|
|
- role: 'assistant',
|
|
|
|
|
- content: '请直接告诉我你想办理什么,也可以描述症状。'
|
|
|
|
|
- });
|
|
|
|
|
|
|
+function isPreviewActive(previewId: string): boolean {
|
|
|
|
|
+ // Active when viewing a historical card, or when this is the latest card and not viewing history
|
|
|
|
|
+ if (store.viewingCardId) {
|
|
|
|
|
+ return store.viewingCardId === previewId;
|
|
|
|
|
+ }
|
|
|
|
|
+ return store.activeCard?.cardInstanceId === previewId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function handleSubmit(text: string) {
|
|
|
|
|
- store.addMessage({ id: crypto.randomUUID(), role: 'user', content: text });
|
|
|
|
|
- store.setTask({
|
|
|
|
|
- taskId: 'task_demo_registration',
|
|
|
|
|
- taskType: 'REGISTRATION',
|
|
|
|
|
- currentStep: 'TRIAGE_RECOMMEND_DEPARTMENT',
|
|
|
|
|
- status: 'ACTIVE'
|
|
|
|
|
- });
|
|
|
|
|
- store.addMessage({
|
|
|
|
|
- id: crypto.randomUUID(),
|
|
|
|
|
- role: 'assistant',
|
|
|
|
|
- content: '已识别为挂号需求。根据描述,建议优先选择神经内科。'
|
|
|
|
|
|
|
+async function handleSubmit(text: string) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await store.sendMessage(text);
|
|
|
|
|
+ scrollToBottom();
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // error already set in store
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function scrollToBottom() {
|
|
|
|
|
+ nextTick(() => {
|
|
|
|
|
+ if (messagesEl.value) {
|
|
|
|
|
+ messagesEl.value.scrollTop = messagesEl.value.scrollHeight;
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
- store.setActiveCard(demoCards.card_department);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+watch(() => store.messages.length, () => scrollToBottom());
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|
|
|
-.conversation-panel {
|
|
|
|
|
|
|
+.chat-area {
|
|
|
display: flex;
|
|
display: flex;
|
|
|
- min-height: 0;
|
|
|
|
|
flex-direction: column;
|
|
flex-direction: column;
|
|
|
- overflow: hidden;
|
|
|
|
|
- border: 1px solid var(--border);
|
|
|
|
|
- border-radius: var(--radius-panel);
|
|
|
|
|
- background: var(--surface);
|
|
|
|
|
|
|
+ height: 100vh;
|
|
|
|
|
+ background: var(--bg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-header {
|
|
|
|
|
|
|
+.chat-header {
|
|
|
|
|
+ padding: 14px 24px;
|
|
|
|
|
+ background: var(--surface);
|
|
|
|
|
+ border-bottom: 1px solid var(--border);
|
|
|
display: flex;
|
|
display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
|
- padding: 16px;
|
|
|
|
|
- border-bottom: 1px solid #edf1f7;
|
|
|
|
|
|
|
+ flex-shrink: 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-h1 {
|
|
|
|
|
- margin: 0;
|
|
|
|
|
- font-size: 22px;
|
|
|
|
|
|
|
+.chat-header-title {
|
|
|
|
|
+ font-size: var(--fs-sm);
|
|
|
|
|
+ color: var(--muted);
|
|
|
|
|
+ font-weight: 500;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-p {
|
|
|
|
|
- margin: 4px 0 0;
|
|
|
|
|
- color: var(--text-secondary);
|
|
|
|
|
- font-size: 13px;
|
|
|
|
|
|
|
+.chat-header-status {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ gap: 6px;
|
|
|
|
|
+ font-size: var(--fs-xs);
|
|
|
|
|
+ color: var(--accent-light);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-.task-pill {
|
|
|
|
|
- align-self: flex-start;
|
|
|
|
|
- padding: 7px 11px;
|
|
|
|
|
- border-radius: 999px;
|
|
|
|
|
- background: #f1f0ff;
|
|
|
|
|
- color: var(--brand-primary);
|
|
|
|
|
- font-size: 12px;
|
|
|
|
|
- font-weight: 800;
|
|
|
|
|
|
|
+.status-dot {
|
|
|
|
|
+ width: 8px;
|
|
|
|
|
+ height: 8px;
|
|
|
|
|
+ border-radius: 50%;
|
|
|
|
|
+ background: var(--accent-light);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.status-dot-err {
|
|
|
|
|
+ width: 8px;
|
|
|
|
|
+ height: 8px;
|
|
|
|
|
+ border-radius: 50%;
|
|
|
|
|
+ background: var(--danger);
|
|
|
|
|
+ animation: blink 1s ease-in-out infinite;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@keyframes blink {
|
|
|
|
|
+ 0%, 100% { opacity: 1; }
|
|
|
|
|
+ 50% { opacity: 0.3; }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-.messages {
|
|
|
|
|
|
|
+.chat-messages {
|
|
|
|
|
+ flex: 1;
|
|
|
|
|
+ overflow-y: auto;
|
|
|
|
|
+ padding: 24px;
|
|
|
display: flex;
|
|
display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ gap: 14px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* ─── Empty state ─── */
|
|
|
|
|
+.chat-empty {
|
|
|
flex: 1;
|
|
flex: 1;
|
|
|
- min-height: 0;
|
|
|
|
|
|
|
+ display: flex;
|
|
|
flex-direction: column;
|
|
flex-direction: column;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: center;
|
|
|
gap: 12px;
|
|
gap: 12px;
|
|
|
- overflow-y: auto;
|
|
|
|
|
|
|
+ color: var(--muted);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.chat-empty-icon {
|
|
|
|
|
+ width: 64px;
|
|
|
|
|
+ height: 64px;
|
|
|
|
|
+ border-radius: 50%;
|
|
|
|
|
+ background: var(--accent-soft);
|
|
|
|
|
+ display: grid;
|
|
|
|
|
+ place-items: center;
|
|
|
|
|
+ font-size: 28px;
|
|
|
|
|
+ color: var(--accent);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.chat-empty-text {
|
|
|
|
|
+ font-family: var(--font-display);
|
|
|
|
|
+ font-size: var(--fs-h2);
|
|
|
|
|
+ font-weight: 500;
|
|
|
|
|
+ color: var(--fg);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.chat-empty-hint {
|
|
|
|
|
+ font-size: var(--fs-sm);
|
|
|
|
|
+ color: var(--muted);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* ─── Messages ─── */
|
|
|
|
|
+.msg {
|
|
|
|
|
+ max-width: 78%;
|
|
|
|
|
+ padding: 12px 16px;
|
|
|
|
|
+ border-radius: var(--radius-lg);
|
|
|
|
|
+ font-size: var(--fs-body);
|
|
|
|
|
+ line-height: 1.6;
|
|
|
|
|
+ animation: msgIn 0.3s ease-out both;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@keyframes msgIn {
|
|
|
|
|
+ from {
|
|
|
|
|
+ opacity: 0;
|
|
|
|
|
+ transform: translateY(8px);
|
|
|
|
|
+ }
|
|
|
|
|
+ to {
|
|
|
|
|
+ opacity: 1;
|
|
|
|
|
+ transform: translateY(0);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.msg-user {
|
|
|
|
|
+ align-self: flex-end;
|
|
|
|
|
+ background: var(--accent);
|
|
|
|
|
+ color: var(--surface);
|
|
|
|
|
+ border-bottom-right-radius: 4px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.msg-ai {
|
|
|
|
|
+ align-self: flex-start;
|
|
|
|
|
+ background: var(--surface);
|
|
|
|
|
+ border: 1px solid var(--border);
|
|
|
|
|
+ border-bottom-left-radius: 4px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* ─── Mini chat cards ─── */
|
|
|
|
|
+.chat-card {
|
|
|
|
|
+ align-self: flex-start;
|
|
|
|
|
+ margin-top: -4px;
|
|
|
|
|
+ padding: 12px 16px;
|
|
|
|
|
+ background: var(--surface);
|
|
|
|
|
+ border: 1px solid var(--border);
|
|
|
|
|
+ border-left: 4px solid var(--accent);
|
|
|
|
|
+ border-radius: var(--radius-md);
|
|
|
|
|
+ cursor: pointer;
|
|
|
|
|
+ transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ gap: 4px;
|
|
|
|
|
+ max-width: 300px;
|
|
|
|
|
+ font-size: var(--fs-sm);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.chat-card:hover {
|
|
|
|
|
+ border-color: var(--accent);
|
|
|
|
|
+ box-shadow: 0 2px 10px rgba(43, 31, 153, 0.1);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.chat-card.active {
|
|
|
|
|
+ border-color: var(--accent);
|
|
|
|
|
+ background: var(--accent-faint);
|
|
|
|
|
+ box-shadow: 0 2px 12px rgba(43, 31, 153, 0.08);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.cc-title {
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ font-size: var(--fs-sm);
|
|
|
|
|
+ color: var(--fg);
|
|
|
|
|
+ line-height: 1.3;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.cc-choice {
|
|
|
|
|
+ font-size: var(--fs-xs);
|
|
|
|
|
+ color: var(--muted);
|
|
|
|
|
+ line-height: 1.4;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* ─── Loading skeleton ─── */
|
|
|
|
|
+.loading-block {
|
|
|
|
|
+ align-self: flex-start;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ gap: 10px;
|
|
|
|
|
+ width: 70%;
|
|
|
padding: 16px;
|
|
padding: 16px;
|
|
|
- background: #fbfdff;
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.skeleton-line {
|
|
|
|
|
+ height: 14px;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+ background: linear-gradient(90deg, var(--border) 25%, color-mix(in oklch, var(--accent) 5%, transparent) 50%, var(--border) 75%);
|
|
|
|
|
+ background-size: 200% 100%;
|
|
|
|
|
+ animation: shimmer 1.5s ease-in-out infinite;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.skeleton-line.w60 { width: 60%; }
|
|
|
|
|
+.skeleton-line.w80 { width: 80%; }
|
|
|
|
|
+.skeleton-line.w40 { width: 40%; }
|
|
|
|
|
+
|
|
|
|
|
+@keyframes shimmer {
|
|
|
|
|
+ 0% { background-position: 200% 0; }
|
|
|
|
|
+ 100% { background-position: -200% 0; }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.loading-text {
|
|
|
|
|
+ margin-top: 6px;
|
|
|
|
|
+ font-size: var(--fs-sm);
|
|
|
|
|
+ color: var(--muted);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* ─── Disconnected overlay ─── */
|
|
|
|
|
+.disconnected-overlay {
|
|
|
|
|
+ flex: 1;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ gap: 12px;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.disc-icon {
|
|
|
|
|
+ width: 72px;
|
|
|
|
|
+ height: 72px;
|
|
|
|
|
+ border-radius: 50%;
|
|
|
|
|
+ background: color-mix(in oklch, var(--danger) 10%, transparent);
|
|
|
|
|
+ display: grid;
|
|
|
|
|
+ place-items: center;
|
|
|
|
|
+ color: var(--danger);
|
|
|
|
|
+ margin-bottom: 4px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.disc-title {
|
|
|
|
|
+ font-family: var(--font-display);
|
|
|
|
|
+ font-size: var(--fs-h2);
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.disc-desc {
|
|
|
|
|
+ font-size: var(--fs-sm);
|
|
|
|
|
+ color: var(--muted);
|
|
|
|
|
+ max-width: 280px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.disc-btns {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ gap: 10px;
|
|
|
|
|
+ margin-top: 8px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.btn-accent {
|
|
|
|
|
+ padding: 10px 24px;
|
|
|
|
|
+ background: var(--accent);
|
|
|
|
|
+ color: var(--surface);
|
|
|
|
|
+ border-radius: var(--radius-sm);
|
|
|
|
|
+ font-size: var(--fs-body);
|
|
|
|
|
+ font-weight: 500;
|
|
|
|
|
+ transition: background 0.15s ease;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.btn-accent:hover {
|
|
|
|
|
+ background: color-mix(in oklch, var(--accent) 85%, black);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.btn-outline {
|
|
|
|
|
+ padding: 10px 24px;
|
|
|
|
|
+ border: 1px solid var(--border);
|
|
|
|
|
+ border-radius: var(--radius-sm);
|
|
|
|
|
+ font-size: var(--fs-body);
|
|
|
|
|
+ color: var(--muted);
|
|
|
|
|
+ background: transparent;
|
|
|
|
|
+ transition: background 0.15s ease;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.btn-outline:hover {
|
|
|
|
|
+ background: var(--bg);
|
|
|
}
|
|
}
|
|
|
</style>
|
|
</style>
|