feat: 首页数据

This commit is contained in:
2025-07-26 18:16:14 +08:00
parent cb22c0531c
commit 84b6d1c063
11 changed files with 214 additions and 157 deletions

View File

@@ -22,9 +22,10 @@
<ChatTopBanner class="chat-container-top-bannar"></ChatTopBanner>
<view class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId">
<template v-if="item.msgType === MessageRole.AI">
<ChatCardAI class="message-item-ai" :text="item.msg">
<image v-if="item.msgContent && item.msgContent.type === MessageType.IMAGE" src="/static/logo.png" style="width: 100px;height: 100px;"></image>
<ChatCardAI class="message-item-ai" :text="item.msg">
</ChatCardAI>
</template>
@@ -33,7 +34,10 @@
</ChatCardMine>
</template>
<template v-else>
<ChatCardOther class="message-item-other" :text="item.msg"></ChatCardOther>
<ChatCardOther class="message-item-other" :text="item.msg">
<OneFeelMK001/>
<OneFeelMK002/>
</ChatCardOther>
</template>
</view>
@@ -43,7 +47,7 @@
<!-- 输入框区域 -->
<view class="footer-area">
<ChatMoreTips @replySent="handleReply"></ChatMoreTips>
<ChatMoreTips @replySent="handleReply" :itemList="guideWords"></ChatMoreTips>
<ChatQuickAccess @replySent="handleReply"></ChatQuickAccess>
<ChatInputArea
v-model:inputMessage="inputMessage"
@@ -56,7 +60,7 @@
</view>
</template>
<script setup lang="ts">
<script setup >
import { onMounted, getCurrentInstance, nextTick } from 'vue'
import { ref } from 'vue'
import { defineEmits } from 'vue'
@@ -75,8 +79,10 @@
import { MessageRole, ChatModel, MessageType } from '../../model/ChatModel';
import OneFeelMK001 from '../module/OneFeelMK001.vue';
import OneFeelMK002 from '../module/OneFeelMK002.vue';
import request from '../../request/base/request';
import { agentChatStream } from '../../request/api/AgentChatStream';
import { mainPageData } from '../../request/api/MainPageData';
// 导航栏相关
const statusBarHeight = ref(20);
@@ -85,9 +91,12 @@
const holdKeyboard = ref(false) // focus时点击页面的时候不收起键盘
const holdKeyboardFlag = ref(true) // 是否在键盘弹出,点击界面时关闭键盘
const chatMsgList = ref<ChatModel[]>([])
const chatMsgList = ref([])
const inputMessage = ref('')
const mainPageDataModel = ref({})
const guideWords = ref([])
// 锚点ID控制滚动位置
const lastMsgId = ref('anchor-bottom');
@@ -99,7 +108,7 @@
console.log('=============打开抽屉')
}
const handleReply = (text: string) => {
const handleReply = (text) => {
loadMessage(text)
scrollToBottom()
};
@@ -113,16 +122,29 @@
});
onMounted(() => {
// getMainPageData()
initData()
})
const getMainPageData = async() => {
mainPageDataModel.value = await mainPageData()
guideWords.value = mainPageDataModel.value.guideWords
}
const initData = () => {
const msg: ChatModel = {
const msg = {
msgId: `msg_${0}`,
msgType: MessageRole.AI,
msg: '查信息、预定下单、探索玩法、呼叫服务、我通通可以满足,快试试问我问题吧!',
}
chatMsgList.value.push(msg)
const msg1 = {
msgId: `msg_${1}`,
msgType: MessageRole.OTHER,
msg: '',
}
chatMsgList.value.push(msg1)
}
const handleTouchEnd = () => {
@@ -147,7 +169,7 @@
}
// 发送消息
const sendMessage = (message: string) => {
const sendMessage = (message) => {
console.log("inputMessage list:", message)
if (!message.trim()) return;
handleNoHideKeyboard()
@@ -157,8 +179,8 @@
scrollToBottom()
}
const loadMessage = (text: string) => {
const newMsg: ChatModel = {
const loadMessage = (text) => {
const newMsg = {
msgId: `msg_${chatMsgList.value.length}`,
msgType: MessageRole.ME,
msg: text,
@@ -179,12 +201,14 @@
lastMsgId.value = `${chatMsgList.value[chatMsgList.value.length - 1].msgId}`;
// 等待DOM更新后切回底部锚点确保下次能继续滚动到底
nextTick(() => {
lastMsgId.value = 'anchor-bottom';
nextTick(() => {
lastMsgId.value = 'anchor-bottom';
});
});
}
let loadingTimer: any = null;
let typeWriterTimer: any = null;
let loadingTimer = null;
let typeWriterTimer = null;
let aiMsgBuffer = ''; // 全局缓冲区
let isTyping = false; // 是否正在打字
@@ -199,7 +223,7 @@
}
// 1. 插入AI消息
const aiMsg: ChatModel = {
const aiMsg = {
msgId: `msg_${chatMsgList.value.length}`,
msgType: MessageRole.AI,
msg: '加载中.',
@@ -262,7 +286,10 @@
if (aiMsgBuffer.length > 0) {
chatMsgList.value[aiMsgIndex].msg += aiMsgBuffer[0];
aiMsgBuffer = aiMsgBuffer.slice(1);
scrollToBottom();
nextTick(() => {
scrollToBottom();
});
typeWriterTimer = setTimeout(typeWriter, 30);
} else {
// 等待新内容到来,不结束