front/src/components/NanaAssistant/NanaChatDialog.vue
zzh fd56dc4be9
All checks were successful
Build and Deploy Front / deploy (push) Successful in 15m46s
feat: 官网与助手共用 Nana 会话,完善下单与顶栏门户过渡
抽离 NanaChatDialog/NanaComposer;会话阅读流对齐 FAB;顶栏 Logo 虹膜回官网;账户下拉与下单页布局优化。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 10:02:06 +08:00

88 lines
2.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div
class="nana-chat-dialog ai-messages"
:class="{ 'is-active': active }"
role="log"
aria-live="polite"
>
<div
v-for="(msg, index) in normalized"
:key="index"
class="ai-msg-row"
:class="'ai-msg-row--' + msg.role"
>
<NanaAvatar
v-if="msg.role === 'assistant'"
size="sm"
:pulse="false"
class="ai-msg-nana"
/>
<div v-if="msg.role === 'assistant'" class="ai-msg-body">
<p v-if="msg.text" class="ai-msg-text">{{ msg.text }}</p>
<slot
name="assistant-extra"
:message="msg.raw"
:index="index"
:is-latest="isLatestAssistant(index)"
/>
</div>
<div v-else class="ai-msg-bubble">
<p v-if="msg.text" class="ai-msg-text">{{ msg.text }}</p>
</div>
</div>
<div v-if="typing" class="ai-msg-row ai-msg-row--assistant ai-msg-row--typing">
<NanaAvatar size="sm" pulse class="ai-msg-nana" />
<div class="ai-msg-body ai-msg-body--typing">
<span /><span /><span />
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import { computed } from 'vue';
import NanaAvatar from './NanaAvatar.vue';
export type NanaChatMessageInput = {
role: 'user' | 'assistant';
/** 官网会话字段 */
text?: string;
/** OMS 助手会话字段 */
content?: string;
[key: string]: unknown;
};
const props = withDefaults(
defineProps<{
messages: NanaChatMessageInput[];
typing?: boolean;
/** 是否展示会话流(对应 .ai-messages.is-active) */
active?: boolean;
}>(),
{
typing: false,
active: true,
},
);
const normalized = computed(() =>
props.messages.map((msg) => ({
role: msg.role,
text: String(msg.text ?? msg.content ?? '').trim(),
raw: msg,
})),
);
function isLatestAssistant(index: number) {
if (props.typing) return false;
const list = normalized.value;
if (!list[index] || list[index].role !== 'assistant') return false;
for (let i = list.length - 1; i >= 0; i -= 1) {
if (list[i].role === 'assistant') return i === index;
}
return false;
}
</script>
<style src="./nana-chat.css"></style>