All checks were successful
Build and Deploy Front / deploy (push) Successful in 15m46s
抽离 NanaChatDialog/NanaComposer;会话阅读流对齐 FAB;顶栏 Logo 虹膜回官网;账户下拉与下单页布局优化。 Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
2.2 KiB
Vue
88 lines
2.2 KiB
Vue
<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>
|