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

@@ -20,7 +20,7 @@
<style lang="scss" scoped>
.chat-ai {
margin: 6px 12px;
padding: 0 16px;
padding: 0 12px;
min-width: 80px;
background: rgba(255,255,255,0.4);

View File

@@ -17,14 +17,12 @@
<style lang="scss" scoped>
.chat-other {
margin: 6px 0;
padding: 0 12px;
display: flex;
justify-content: center;
background-color: white;
margin: 6px 12px;
padding: 8px 24px;
border-radius: 4px;
font-size: 14px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
flex-direction: column;
max-width: 100%; // ✅ 限制最大宽度
overflow-x: hidden; // ✅ 防止横向撑开
text {
font-family: PingFang SC, PingFang SC;

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 {
// 等待新内容到来,不结束

View File

@@ -13,7 +13,9 @@
default: ''
}
})
</script>
<style>
<style scoped>
</style>

View File

@@ -2,51 +2,35 @@
<view class="more-tips">
<view class="more-tips-scroll">
<view class="more-tips-item" v-for="(item, index) in itemList" :key="index">
<text class="more-tips-item-title" @click="sendReply(item.title)">{{ item.title }}</text>
<text class="more-tips-item-title" @click="sendReply(item)">{{ item }}</text>
</view>
</view>
</view>
</template>
<script setup>
import { onMounted, ref } from 'vue';
const itemList = ref([])
import { defineProps } from "vue";
const emits = defineEmits(['replySent']);
defineProps({
itemList: {
type: [],
default: [
'定温泉票',
'定酒店',
'优惠套餐',
'亲子玩法',
'了解交通',
'看看酒店',
'看看美食'
]
}
})
const sendReply = (text) => {
emits('replySent', text); // 向父组件传递数据
}
onMounted(() => {
initData()
})
const initData = () => {
itemList.value = [
{
title: '定温泉票',
},
{
title: '定酒店',
},
{
title: '优惠套餐',
},
{
title: '亲子玩法',
},
{
title: '了解交通',
},
{
title: '看看酒店',
},
{
title: '看看美食',
}
]
}
</script>
<style lang="scss" scoped>