wujingjing
2025-01-07 baba739c537b153b9426746374691afcd90a8c47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<template>
    <div class="message-list">
        <div v-for="(item, msgIndex) of msgList" :key="`${item.historyId}_${item.role}`">
            <UserMsg
                :msg="item"
                @shareClick="shareClick"
                @setCommonQuestion="setCommonQuestionClick"
                v-if="item.role === RoleEnum.user"
            ></UserMsg>
 
            <AssistantMsg
                v-else
                :msg="item"
                :msgList="msgList"
                :isLast="msgIndex === msgList.length - 1"
                @sendChatMessage="sendChatMessage"
                @shareMsg="shareClick"
                @stopGenClick="stopGenClick"
                :isTalking="isTalking"
            />
        </div>
        <div v-if="showAskMore" class="ml-4 mt-5 pb-10">
            <div class="text-gray-600 mb-5">你可以继续问我:</div>
            <div class="space-y-2 inline-flex flex-col">
                <div
                    v-for="item in msgList.at(-1).content.askMoreList"
                    :key="item.history_id"
                    class="bg-white p-3 hover:bg-[#c5e0ff] hover:text-[#1c86ff] cursor-pointer rounded-lg"
                    @click="askMoreClick(item)"
                >
                    {{ item.question }}
                </div>
            </div>
        </div>
    </div>
</template>
 
<script setup lang="ts" name="MessageList">
import { computed, defineProps, type PropType } from 'vue';
import AssistantMsg from '../assistant/index.vue';
import type { ChatContent, ChatMessage, ContextHistory } from '../model/types';
import { RoleEnum } from '../model/types';
import UserMsg from '../user/index.vue';
import { isSharePage } from '/@/stores/chatRoom';
 
const props = defineProps({
    msgList: {
        type: Array as PropType<ChatMessage[]>,
    },
    isTalking: {
        type: Boolean,
        default: false,
    },
});
 
const emit = defineEmits({
    shareClick: (msg: ChatMessage) => true,
    setCommonQuestionClick: (msg: ChatMessage) => true,
    sendChatMessage: (msg: ChatContent) => true,
    askMoreClick: (msg: ContextHistory) => true,
    stopGenClick: () => true,
});
const showAskMore = computed(() => {
    if (!props.msgList || props.msgList.length === 0) return false;
    const last = props.msgList.at(-1);
    const isShow = last?.role === RoleEnum.assistant && last?.content?.values && last.content?.askMoreList?.length > 0;
    const result = isShow && !isSharePage.value;
    return result;
});
const shareClick = (msg: ChatMessage) => {
    emit('shareClick', msg);
};
 
const setCommonQuestionClick = (msg: ChatMessage) => {
    emit('setCommonQuestionClick', msg);
};
 
const sendChatMessage = (msg: ChatContent) => {
    emit('sendChatMessage', msg);
};
 
const askMoreClick = (msg: ContextHistory) => {
    emit('askMoreClick', msg);
};
 
const stopGenClick = () => {
    emit('stopGenClick');
};
</script>
<style scoped lang="scss"></style>