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

13
model/ChatModel.js Normal file
View File

@@ -0,0 +1,13 @@
export const MessageRole = {
AI: "AI",
ME: "ME",
OTHER: "OTHER"
}
export const MessageType = {
TEXT: 'TEXT',
IMAGE: 'IMAGE'
}

View File

@@ -1,35 +0,0 @@
export enum MessageRole {
AI = "AI",
ME = "ME",
OTHER = "OTHER"
}
export enum MessageType {
TEXT = 'TEXT',
IMAGE = 'IMAGE'
}
export interface TextContent {
type: MessageType;
text: string;
}
export interface ImageContent {
type: MessageType;
url: string;
}
export type MessageContent = TextContent | ImageContent;
export interface ChatModel {
msgId: string;
msgType: MessageRole;
msg: string;
msgContent?: MessageContent;
}

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>
</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,
@@ -178,13 +200,15 @@
// 短暂指向最新消息的ID触发滚动
lastMsgId.value = `${chatMsgList.value[chatMsgList.value.length - 1].msgId}`;
// 等待DOM更新后切回底部锚点确保下次能继续滚动到底
nextTick(() => {
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);
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>

View File

@@ -1,76 +1,54 @@
<template>
<view class="container">
<view class="mk-title">
<text class="title">避世放松 能量调节</text>
<image class="wave" src="@/static/wave_icon.png" mode="widthFix"/>
</view>
<view class="container-scroll">
<view class="mk-card-item" v-for="(item, index) in 8" :key="index">
<image src="/static/test/mk_img_1.png"></image>
<text>#森系环境 #出工人必备-{{item}}</text>
</view>
</view>
<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
:duration="duration">
<swiper-item>
<view class="swiper-item uni-bg-red">A</view>
</swiper-item>
<swiper-item>
<view class="swiper-item uni-bg-green">B</view>
</swiper-item>
<swiper-item>
<view class="swiper-item uni-bg-blue">C</view>
</swiper-item>
</swiper>
</view>
</template>
<script setup>
<script>
</script>
<style lang="scss" scoped>
<style scoped lang="scss">
.container {
.mk-title {
padding: 4px 0;
display: inline-block;
position: relative;
.title {
font-weight: 400;
font-size: 16px;
color: #000000;
z-index: 2;
position: relative;
}
.wave {
position: absolute;
bottom: 2px;
left: 0;
.uni-margin-wrap {
width: 690rpx;
width: 100%;
z-index: 1;
}
.swiper {
height: 300rpx;
border-radius: 8px;
}
.container-scroll {
display: flex;
flex-direction: row;
overflow-x: auto;
margin-top: 4px;
/* 隐藏滚动条 */
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.mk-card-item {
display: flex;
flex-direction: column;
width: 188px;
height: 154px;
background-color: #ffffff;
border-radius: 10px;
margin-right: 8px;
image {
width: 188px;
height: 112px;
}
text {
padding: 12px;
.swiper-item {
display: block;
height: 300rpx;
line-height: 300rpx;
text-align: center;
font-weight: 500;
font-size: 12px;
color: #333333;
}
.uni-bg-red {
background-color: red;
}
.uni-bg-green {
background-color: green;
}
.uni-bg-blue {
background-color: blue;
}
}
</style>

View File

@@ -0,0 +1,76 @@
<template>
<view class="container">
<view class="mk-title">
<text class="title">避世放松 能量调节</text>
<image class="wave" src="@/static/wave_icon.png" mode="widthFix"/>
</view>
<view class="container-scroll">
<view class="mk-card-item" v-for="(item, index) in 8" :key="index">
<image src="/static/test/mk_img_1.png"></image>
<text>#森系环境 #出工人必备-{{item}}</text>
</view>
</view>
</view>
</template>
<script setup>
</script>
<style lang="scss" scoped>
.container {
.mk-title {
padding: 4px 0;
display: inline-block;
position: relative;
.title {
font-weight: 400;
font-size: 16px;
color: #000000;
z-index: 2;
position: relative;
}
.wave {
position: absolute;
bottom: 2px;
left: 0;
width: 100%;
z-index: 1;
}
}
.container-scroll {
display: flex;
flex-direction: row;
overflow-x: auto;
margin-top: 4px;
/* 隐藏滚动条 */
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.mk-card-item {
display: flex;
flex-direction: column;
width: 188px;
height: 154px;
background-color: #ffffff;
border-radius: 10px;
margin-right: 8px;
image {
width: 188px;
height: 112px;
}
text {
padding: 12px;
text-align: center;
font-weight: 500;
font-size: 12px;
color: #333333;
}
}
}
}
</style>

View File

@@ -0,0 +1,7 @@
import request from "../base/request";
function mainPageData() {
return request.post('/mainScene/mainPageData');
}
export { mainPageData }

View File

@@ -0,0 +1,7 @@
import request from "../base/request";
function quickBookingComponent() {
return request.post('/mainScene/quickBookingComponent');
}
export { quickBookingComponent }