Files
ebiz-base-ai/src/views/customer/index.vue
陈昱达 990d600c56 feat(AI): 实现产品对比功能并优化页面结构
- 在 sticky 组件中添加 conversationId属性,用于记录对话 ID
- 在 AI 页面中添加导航栏,提升用户体验
- 新增产品对比页面,展示对比结果
-优化对比表格样式,增加返回按钮
- 在客服页面中添加导航栏,与 AI 页面保持一致
2025-06-13 15:31:13 +08:00

157 lines
3.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="chat-page">
<van-nav-bar title="客服助手" left-text="返回" left-arrow @click-left="$router.history.go(-1)" />
<main class="chat-main">
<div class="chat-content">
<div class="message-area" ref="messageArea" @scroll="handleScroll">
<!-- -->
<messageComponent
:messagesList="messages"
:is-deep="isDeep"
:is-search="isSearching"
:think-ok="isThink"
@setProductName="setProductName"
></messageComponent>
</div>
</div>
<!-- 滚动到顶部按钮 -->
<div class="button-container" style="background: #fff">
<van-icon name="upgrade" size="2em" @click="scrollToTop" />
</div>
</main>
<chatMessage
:messages.sync="messages"
:messageStatus.sync="messageStatus"
:is-deep.sync="isDeep"
:conversation-id.sync="conversationId"
:is-searching.sync="isSearching"
:product-name.sync="productName"
:autoScrollEnabled.sync="autoScrollEnabled"
@getIsThink="getIsThink"
></chatMessage>
</div>
</template>
<script>
import { Icon, NavBar } from 'vant'
import SvgIcon from '@/components/svg-icon/index.vue'
import HotProducts from '@/views/AI/components/HotProducts.vue'
import chatMessage from '@/views/AI/components/chat.vue'
import messageComponent from '@/views/AI/components/message.vue'
export default {
components: {
SvgIcon,
messageComponent,
[Icon.name]: Icon,
[NavBar.name]: NavBar,
HotProducts,
chatMessage,
},
data() {
return {
hotList: [],
productName: '',
conversationId: '',
messageStatus: 'stop',
isThink: null,
messages: [
{
type: 'bot',
text: '欢迎使用AI客服助手请输入问题开始对话。',
},
],
isSearching: false,
isDeep: false,
autoScrollEnabled: true,
scrollPosition: 0,
}
},
methods: {
getIsThink(e) {
this.isThink = e
},
getHotProducts(e) {
console.log(e)
this.hotList = e
},
scrollToTop() {
const messageArea = this.$refs.messageArea
if (messageArea) {
messageArea.scrollTop = 0
}
},
scrollToBottom() {
if (!this.autoScrollEnabled) return
this.$nextTick(() => {
const messageArea = this.$refs.messageArea
if (messageArea) {
messageArea.scrollTop = messageArea.scrollHeight
}
})
},
setProductName(e) {
this.productName = e
},
handleScroll() {
const messageArea = this.$refs.messageArea
if (!messageArea) return
const threshold = 10
const isAtBottom = messageArea.scrollHeight - messageArea.clientHeight <= messageArea.scrollTop + threshold
this.autoScrollEnabled = isAtBottom
this.scrollPosition = messageArea.scrollTop
},
},
watch: {
messages: {
handler() {
this.$nextTick(() => this.scrollToBottom())
},
deep: true,
},
},
}
</script>
<style lang="scss" scoped>
$primary-color: #2e5ca9;
$primary-text-color: #f6aa21;
$primary-trans-color: rgba(135, 162, 208, 0.5);
.chat-page {
display: flex;
flex-direction: column;
height: 100vh;
//-webkit-user-select: none;
//-moz-user-select: none;
//-ms-user-select: none;
//user-select: none;
.chat-main {
flex: 1;
overflow-y: auto;
padding: 10px;
background: #f7f8fa;
position: relative;
.button-container {
position: fixed;
bottom: 150px;
right: 10px;
border-radius: 50%;
}
.chat-content {
height: 100%;
.message-area {
height: 100%;
overflow-y: auto;
transition: all 0.2s ease-in-out;
}
}
}
}
</style>