搭建页面内容

This commit is contained in:
huangzhe
2025-07-28 10:17:29 +08:00
parent 77d8507d3b
commit dced4d6ca5
12 changed files with 1660 additions and 32 deletions

View File

@@ -31,4 +31,27 @@ export default [
title: '产品推荐',
},
},
{
path: '/productAssistant',
name: 'productAssistant',
component: () => import('@/views/AI-new/index.vue'),
meta: {
title: '产品助手',
},
},{
path: '/productKnowledge',
name: 'productKnowledge',
component: () => import('@/views/AI-new/views/productKnowledge/index.vue'),
meta: {
title: '产品知识助手',
},
},
{
path: '/productRecommend',
name: 'productRecommend',
component: () => import('@/views/AI-new/views/productRecommend/index.vue'),
meta: {
title: '产品推荐助手',
},
},
]

View File

@@ -0,0 +1,103 @@
<template>
<div class="hot-products">
<h4>你可以这样问我</h4>
<ul>
<li v-for="(product, index) in commendList" :key="index" :title="product.title"
@click="cellClick(product)">
<a href="javascript:void(0)">{{ product.title }}</a>
</li>
</ul>
</div>
</template>
<script>
import { Cell, CellGroup } from 'vant'
import { haslProducts } from '@/api/generatedApi'
export default {
name: 'HotProducts',
props: {
messagesList: {
type: Array,
default: () => [],
},
},
data() {
return {
hotProducts: [],
commendList: [{
title: '请为我推荐一款重疾险。',
action: () => {
console.log('请为我推荐一款重疾险。');
}
}, {
title: "60周岁以上可以投保保险产品吗",
action: () => {
console.log('60周岁以上可以投保保险产品吗');
}
}, {
title: "普通办公室职员适合投保的产品有哪些?",
action: () => {
console.log('普通办公室职员适合投保的产品有哪些?');
}
}],
showAll: false, // 控制是否展示全部数据
}
},
created() {
this.getHotProducts()
},
computed: {
displayedProducts() {
return this.showAll ? this.hotProducts : this.hotProducts.slice(0, 3)
},
},
methods: {
cellClick(item) {
this.$emit('cellClick', item)
},
toggleShowAll() {
this.showAll = !this.showAll
},
async getHotProducts() {
const res = await haslProducts()
this.hotProducts = res.content
this.$emit('getHotList', this.hotProducts)
},
},
components: {
[Cell.name]: Cell,
[CellGroup.name]: CellGroup,
},
}
</script>
<style scoped lang="scss">
.hot-products {
padding: 10px;
border-radius: 5px;
overflow: scroll;
h4 {
color: grey;
font-weight: normal;
margin-bottom: 10px;
}
ul {
list-style-type: none;
li {
width: fit-content;
padding: 5px 10px;
background: #fff;
border-radius: 10px;
cursor: pointer;
color: #2e5ca9;
margin: 10px 0;
}
}
}
</style>

View File

@@ -0,0 +1,601 @@
<template>
<div>
<div class="new-session">
<button @click="startNewConversation" class="active">
<svg-icon icon-class="add" class-name="chat-icon" style="color: #000;"></svg-icon>
开启新会话
</button>
</div>
<div v-if="isVoiceMode && newMessage" class="isVoiceModeText">
<textarea class="textarea" placeholder="请输入内容" v-model="newMessage"></textarea>
</div>
<footer class="chat-footer">
<!-- 输入框 or 按住说话提示 -->
<div class="input-wrapper ml10">
<input v-if="!isVoiceMode" type="text" v-model="newMessage" placeholder="请简短描述您的问题"
@keyup.enter="sendMessage" />
<div v-else class="voice-hint-container" :class="{ disabled: messageStatus === 'send' }"
@mousedown="startRecording" @selectstart="() => false" @mouseup="stopRecording" @mouseleave="stopRecording"
@touchend="stopRecording" @touchstart="startRecording">
<div class="waveform" :class="{ active: isRecording }">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</div>
<!-- <div class="hint-text" v-if='!isRecording'>按住说话</div>-->
</div>
</div>
<!-- 语音按钮按住说话 -->
<button @click="isVoiceMode = !isVoiceMode" class="mic-button ml10 mr10">
<!-- <svg-icon v-if="!isVoiceMode" icon-class="voice" class-name="chat-icon ml10 wh25"></svg-icon>
<span v-else class="ml15 mr5 input-icon"></span> -->
</button>
<!-- 发送按钮 -->
<button @click="sendMessage" :disabled="messageStatus === 'send'" :class="{ disabled: messageStatus === 'send' }"
class="mr10 fs16">发送</button>
</footer>
<section class="section pb10">
<!-- <button @click="searchInternet" :class="{ active: isSearching }" class="ml10">
<svg-icon icon-class="earth" class-name="chat-icon"></svg-icon>
联网搜索
</button> -->
<button @click="deepInternet" :class="{ active: isDeep }">
<svg-icon icon-class="think" class-name="chat-icon"></svg-icon>
深度思考
</button>
<!-- <button @click="startNewConversation" class="active">
<svg-icon icon-class="add" class-name="chat-icon"></svg-icon>
新建会话
</button> -->
</section>
</div>
</template>
<script>
import SvgIcon from '@/components/svg-icon/index.vue'
import { audioToText, chat, chatProduct } from '@/api/generatedApi'
export default {
components: {
SvgIcon,
},
props: {
messages: {
type: Array,
default: () => [],
},
messageStatus: {
type: String,
default: 'stop',
},
isDeep: {
type: Boolean,
default: false,
},
isSearching: {
type: Boolean,
default: false,
},
conversationId: {
type: String,
default: '',
},
productName: {
type: String,
default: '',
},
autoScrollEnabled: {
type: Boolean,
default: false,
},
chatData: {
type: Object,
default: () => ({}),
},
},
data() {
return {
isThink: false,
newMessage: '',
isRecording: false,
mediaRecorder: null,
audioChunks: [],
isRecognizing: false,
isVoiceMode: false,
answerMap: '',
currentMessage: null,
// 打字机相关
typingText: '',
typingQueue: [],
typingQueueText: [],
isTyping: false,
typingSpeed: 30,
typingTimeout: null,
}
},
methods: {
deepInternet() {
this.$emit('update:isDeep', !this.isDeep)
},
searchInternet() {
this.$emit('update:isSearching', !this.isSearching)
},
startNewConversation() {
this.$emit('update:messages', [])
this.$emit('update:conversationId', '')
this.$emit('update:productName', '')
},
async startRecording() {
if (this.messageStatus === 'send') return
if (this.isRecognizing) return
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
this.mediaRecorder = new MediaRecorder(stream)
this.audioChunks = []
this.mediaRecorder.ondataavailable = (event) => {
if (event.data.size > 0) {
this.audioChunks.push(event.data)
}
}
this.mediaRecorder.onstop = () => {
this.handleStopRecording()
}
this.mediaRecorder.start()
this.isRecording = true
} catch (err) {
alert('无法访问麦克风,请检查权限')
console.error(err)
}
},
hasTreasureBox() {
chatProduct({ query: this.newMessage })
.then((res) => {
if (res) {
this.messageStatus = 'stop'
this.messages.push({ type: 'box', text: this.newMessage, detail: res.content })
this.newMessage = ''
}
})
.catch(() => {
this.messageStatus = 'stop'
})
},
stopRecording() {
if (this.mediaRecorder && this.isRecording) {
this.mediaRecorder.stop()
this.isRecording = false
}
},
async handleStopRecording() {
this.isRecognizing = true
const blob = new Blob(this.audioChunks, { type: 'audio/webm' })
try {
const text = await this.callVoiceRecognitionAPI(blob)
if (text) {
this.newMessage = text
this.$emit('update:messageStatus', 'stop')
}
} catch (error) {
console.error('语音识别失败:', error)
this.newMessage = ''
} finally {
this.isRecognizing = false
}
},
callVoiceRecognitionAPI(blob) {
return new Promise((resolve, reject) => {
const formData = new FormData()
formData.append('file', blob)
formData.append('appType', 'haslBigHelper')
formData.append('user', 'chenyuda')
audioToText(formData)
.then((res) => {
if (res) {
resolve(res.content)
}
})
.catch((err) => {
reject(err)
})
})
},
axiosGetAiChat() {
const abortController = new AbortController()
this.currentMessage = JSON.parse(
JSON.stringify({
type: 'bot',
text: '',
isThink: this.isDeep,
showThink: true,
think: '',
isLike: false,
isDisLike: false,
})
)
this.messages.push(this.currentMessage)
let params = {
query: this.newMessage,
isDeep: this.isDeep ? 1 : 0,
isOnline: this.isSearching ? 1 : 0,
user: 'chenyuda',
conversationId: this.conversationId,
productName: this.productName,
}
// 如果有自定义参数
if (this.chatData) {
for (let k in this.chatData) {
params[k] = this.chatData[k]
}
}
if (this.$route.query.compareId) {
params.compareResult = JSON.parse(sessionStorage.getItem('results'))
}
fetch(chat(), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
signal: abortController.signal,
body: JSON.stringify(params),
})
.then(async (res) => {
this.newMessage = ''
await this.processStreamResponse(res)
})
.catch((err) => {
this.$emit('update:messageStatus', 'stop')
})
},
async processStreamResponse(response) {
if (!response.ok) throw new Error(`HTTP错误: ${response.status}`)
if (!response.body) {
console.error('响应体不存在:', response)
return
}
const reader = response.body.getReader()
let buffer = ''
while (true) {
try {
const { done, value } = await reader.read()
if (done) break
buffer += new TextDecoder().decode(value)
const lines = buffer.split('\n')
lines.slice(0, -1).forEach((line) => {
const parsed = this.parseStreamLine(line)
if (parsed) this.updateMessageContent(parsed)
})
buffer = lines[lines.length - 1] || ''
} catch (error) {
console.error('读取流数据时发生错误:', error)
break
}
}
},
parseStreamLine(line) {
try {
const cleanLine = line.replace(/^data:\s*/, '')
if (!cleanLine) return null
const data = JSON.parse(cleanLine)
if (data.answer) {
this.answerMap += data.answer
}
return this.updateConversationState(data)
} catch (error) {
console.error('流数据解析失败:', error)
return null
}
},
updateConversationState(data) {
this.$emit('update:conversationId', data.conversation_id || '')
if (data.answer && data.answer.indexOf('<think>') !== -1) {
data.isThink = true
this.isThink = true
this.$emit('getIsThink', true)
}
if (data.answer && data.answer.indexOf('</think>') !== -1) {
data.isThink = true
this.isThink = false
this.$emit('getIsThink', false)
}
if (data.answer && this.isThink) {
data.isThink = true
}
if (data.answer && !this.isThink) {
data.isThink = false
}
return data
},
updateMessageContent(parse) {
let { event, answer, isThink } = parse
if (event === 'message_end') {
this.$emit('update:messageStatus', 'stop')
}
if (!this.currentMessage || !answer) return
const mode = isThink ? 'think' : 'text'
const chars = {
answer: answer,
isThink: isThink,
}
this.typingQueue.push(chars)
if (!this.isTyping) {
this.startTypingAnimation(mode)
}
},
startTypingAnimation() {
this.isTyping = true
const typeNextChar = () => {
if (this.typingQueue.length === 0) {
this.isTyping = false
return
}
// 取出一个完整文本块
const chunk = this.typingQueue.shift()
const chars = chunk.answer.split('')
const isThink = chunk.isThink
// 内部递归函数,用于逐字输出当前块
const outputChar = () => {
if (chars.length === 0) {
// 当前块输出完毕,继续处理下一个
setTimeout(typeNextChar, 10)
return
}
const char = chars.shift()
this.currentMessage[isThink ? 'think' : 'text'] += char
const delay = this.getTypingDelay(char)
setTimeout(outputChar, delay)
}
outputChar()
}
typeNextChar()
},
getTypingDelay(char) {
if (['。', '', '', '', '\n'].includes(char)) {
return this.typingSpeed * 3
}
return this.typingSpeed
},
sendMessage() {
if (this.messageStatus === 'send') return
if (this.newMessage.trim() === '') return
this.newMessage = this.newMessage.replace(/<[^>]+>/g, '')
this.messages.push({ type: 'user', text: this.newMessage })
this.$emit('update:messageStatus', 'send')
if (this.newMessage.includes('工具箱')) {
this.hasTreasureBox()
return
}
this.$emit('update:autoScrollEnabled', true)
this.axiosGetAiChat()
},
cellClick(item) {
console.log(item);
const productName = item.title
this.messages.push({ type: 'user', text: productName })
this.$emit('update:messageStatus', 'send')
this.$emit('update:autoScrollEnabled', true)
this.axiosGetAiChat()
}
}
}
</script>
<style lang="scss" scoped>
$primary-color: #2e5ca9;
$primary-text-color: #f6aa21;
$primary-trans-color: rgba(135, 162, 208, 0.5);
.input-icon {
font-size: 20px;
color: #707070;
}
.wh25 {
width: 25px;
height: 25px;
}
.isVoiceModeText {
display: flex;
textarea {
flex: 1;
max-height: 80px;
resize: none;
background: #fff;
outline: none;
overflow-y: auto;
padding: 10px;
border: none;
}
}
.section {
font-size: 13px;
display: flex;
align-items: center;
padding: 10px 10px 0 10px;
background-color: #fff;
gap: 10px;
button {
padding: 4px 8px;
border: none;
background-color: $primary-trans-color;
color: #fff;
font-weight: 600;
border-radius: 20px;
cursor: pointer;
}
}
.new-session {
position: absolute;
width: fit-content;
background-color: transparent;
left: 50%;
transform: translateX(-50%);
bottom: 80px;
button{
border-radius: 10px;
border: 1px solid #090909;
margin-bottom: 15px;
padding: 5px 10px;
}
}
.chat-footer {
display: flex;
align-items: center;
padding: 10px 10px 0 10px;
//padding-bottom: constant(safe-area-inset-bottom);
//padding-bottom: env(safe-area-inset-bottom);
background-color: #fff;
.input-wrapper {
flex: 1;
margin-right: 10px;
input {
width: 100%;
padding: 10px;
border: none;
background: #f5f5f5;
border-radius: 5px;
font-size: 14px;
}
.voice-hint-container {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 10px;
background-color: #f5f5f5;
border-radius: 5px;
color: #888;
font-size: 14px;
//-webkit-user-select: none;
//-moz-user-select: none;
//-ms-user-select: none;
//user-select: none;
&:active {
background-color: #eaeaea;
}
.waveform {
display: flex;
align-items: flex-end;
align-items: center;
//height: 30px;
//width: 60px;
gap: 2px;
&.disabled {
cursor: not-allowed;
background: red;
}
&.active .bar {
animation: wave-animation 1s infinite ease-in-out;
}
.bar {
width: 4px;
background-color: $primary-color;
margin: 0 1px;
&:nth-child(1) {
height: 10px;
animation-delay: 0s;
}
&:nth-child(2) {
height: 16px;
animation-delay: 0.1s;
}
&:nth-child(3) {
height: 12px;
animation-delay: 0.2s;
}
&:nth-child(4) {
height: 18px;
animation-delay: 0.3s;
}
&:nth-child(5) {
height: 14px;
animation-delay: 0.4s;
}
}
}
.hint-text {
margin-top: 4px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
}
}
.mic-button {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
border: none;
background: transparent;
color: $primary-color;
cursor: pointer;
font-size: 12px;
margin-left: 5px;
&:active {
color: #e6454a;
/* 按下变红 */
}
}
button {
border: none;
outline: none;
color: $primary-text-color;
border-radius: 5px;
background: transparent;
font-weight: 600;
cursor: pointer;
}
.disabled {
pointer-events: none;
opacity: 0.5;
}
}
@keyframes wave-animation {
0%,
100% {
transform: scaleY(1);
}
50% {
transform: scaleY(1.5);
}
}
</style>

View File

@@ -0,0 +1,3 @@
let currentSenderActionType = 'product_recommend'
const senderActionType = ['product_recommend', 'chat', 'normal_chat']

View File

@@ -0,0 +1,268 @@
<template>
<section>
<div v-for="(message, index) in messagesList" :key="index" class="message-item">
<!--用户消息-->
<div v-if="message.type === 'user'" class="user-message mb10">
<p v-html="message.text"></p>
</div>
<!--机器人消息-->
<div v-else-if="message.type === 'bot'" class="bot-message mb10">
<span v-if="message.isThink" style="width: 100%">
<!-- loading-->
<span class="speakLoadingToast pv10">
<van-loading type="spinner" color="#2e5ca9" size="20px" v-if="!message.text" />
<span class="loading-text">{{ message.text ? '思考完成' : '思考中...' }}</span>
<van-icon name="arrow-up" :class="message.showThink ? 'rate360' : 'rate180'" @click="showThink(message)"
v-if="message.think" />
</span>
<!--开启思考-->
<p v-html="md.render(message.think)" v-if="message.think && message.showThink" class="thinkText" />
</span>
<div style="width: 100%">
<p v-html="md.render(message.text)" v-if="message.text"></p>
<span class="speakLoadingToast pv10" v-else-if="!message.text && !thinkOk && !message.isThink">
<van-loading type="spinner" color="#2e5ca9" size="20px" v-if="!message.text" />
</span>
<div class="text-right fs12 mb5 mr10" style="font-size: 10px; color: #f6aa21">
<!-- 新增点赞和踩按钮 -->
<div class="reaction-buttons mb10" v-if="message.type !== 'user'">
<button @click="handleReaction(message, 'like')" class="like">
<svg-icon :icon-class="message.isLike ? 'fillLike' : 'like'" class-name="chat-icon"></svg-icon>
</button>
<button @click="handleReaction(message, 'dislike')" class="dislike">
<svg-icon :icon-class="message.isDisLike ? 'fillDislike' : 'dislike'" class-name="wh15"></svg-icon>
</button>
</div>
</div>
</div>
</div>
<!--百宝箱-->
<div v-else class="mb10">
<treasure-box :item="message" @setProductName="setProductName"></treasure-box>
</div>
</div>
</section>
</template>
<script>
// icon
import { Icon } from 'vant'
import TreasureBox from '@/views/AI/components/treasureBox.vue'
import MarkdownIt from 'markdown-it'
import markdownItKatex from 'markdown-it-katex'
const md = new MarkdownIt({
html: true,
linkify: true,
typographer: true,
}).use(markdownItKatex)
export default {
name: 'message',
components: { TreasureBox, [Icon.name]: Icon },
props: {
messagesList: {
type: Array,
default: () => [],
},
thinkOk: {
type: Boolean,
default: false,
},
isDeep: {
type: Boolean,
default: false,
},
},
data() {
return {
md,
}
},
methods: {
setProductName(e) {
this.$emit('setProductName', e)
},
showThink(message) {
this.$set(message, 'showThink', !message.showThink)
console.log(message.showThink)
},
// 处理点赞和踩的逻辑
handleReaction(message, type) {
if (type === 'like') {
this.$set(message, 'isLike', !message.isLike)
this.$set(message, 'isDisLike', false)
} else if (type === 'dislike') {
this.$set(message, 'isDisLike', !message.isDisLike)
this.$set(message, 'isLike', false)
}
// 触发父组件的更新事件
this.$emit('update-message', { ...message })
},
},
}
</script>
<style scoped lang="scss">
// 主题颜色定义
$primary-color: #2e5ca9; // 修复了 SCSS 变量的定义方式
$primary-text-color: #f6aa21; // 修复了 SCSS 变量的定义方式
$primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色透明度为0.8
.wh15 {
width: 15px;
height: 15px;
}
.message-item {
p {
line-height: 2;
}
// 清除所有样式
//all: unset;
::v-deep ol,
::v-deep ul {
margin: unset !important;
padding: 5px 10px;
list-style: unset;
li {
margin: unset;
padding: unset;
list-style: unset;
}
}
}
.message-item {
all: initial;
margin-bottom: 10px;
width: 100%;
font-size: unset;
.user-message,
.bot-message {
display: flex;
align-items: center;
img {
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 10px;
}
p {
background-color: $primary-color;
color: #fff;
border-radius: 5px;
padding: 10px;
//max-width: 70%;
//max-width: 80%;
}
}
.user-message {
justify-content: end;
max-width: 80%;
margin-left: 20%;
}
.bot-message {
justify-content: start;
background-color: #fff;
border-radius: 5px;
max-width: calc(80% + 20px);
display: flex;
flex-wrap: wrap;
line-height: 20px;
.bot-avatar {
margin-left: 10px;
margin-right: 0;
}
.thinkText {
color: $primary-trans-color;
padding-top: 0;
}
.speakLoadingToast {
display: flex;
align-items: center;
gap: 10px;
color: $primary-text-color;
margin-left: 10px;
.loading-text {
color: $primary-trans-color;
}
}
p {
background-color: #fff;
padding: 10px 10px 2px 10px;
color: $primary-color;
}
}
// 新增样式:点赞和踩按钮
.reaction-buttons {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 5px;
button {
display: flex;
align-items: center;
background: #fff;
border: none;
cursor: pointer;
font-size: 11px;
padding: 2px 3px;
border-radius: 5px;
color: $primary-color;
}
.dislike {
color: $primary-text-color;
}
}
}
.rate360 {
animation-duration: 0.5s;
animation-fill-mode: both;
animation-name: rate360;
}
.rate180 {
animation-duration: 0.5s;
animation-fill-mode: both;
animation-name: rate180;
}
@keyframes rate360 {
0% {
transform: rotate(180deg);
}
100% {
transform: rotate(0deg);
}
}
@keyframes rate180 {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(180deg);
}
}
</style>

190
src/views/AI-new/index.vue Normal file
View File

@@ -0,0 +1,190 @@
<template>
<div class="chat-page">
<van-nav-bar title="产品助手" left-text="返回" left-arrow @click-left="$router.history.go(-1)" />
<sticky :hotList="hotList" :productName="productName" :messagesList.sync="messages"
:autoScrollEnabled.sync="autoScrollEnabled" @setProductName="setProductName"
:isDisabled="messageStatus === 'send'" :conversationId="conversationId"></sticky>
<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"
v-if="messages.length > 1"
></messageComponent>
<div class="mb20" v-else>
HI我是长生产品助手可以为你推荐产品答疑解惑请点击以下功能体检
</div>
<HotProducts class="mb10" :messagesList.sync="messages" @getHotList="getHotProducts" @cellClick="cellClick">
</HotProducts>
</div>
</div>
<!-- 滚动到顶部按钮 -->
<div class="button-container" style="background: #fff">
<van-icon name="upgrade" size="2em" @click="scrollToTop" />
</div>
</main>
<chatMessage ref="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 messageComponent from '@/views/AI-new/components/message.vue'
import SvgIcon from '@/components/svg-icon/index.vue'
import HotProducts from '@/views/AI-new/components/HotProducts.vue'
import sticky from '@/views/AI/components/sticky.vue'
import chatMessage from '@/views/AI-new/components/chat-new.vue'
export default {
components: {
SvgIcon,
[Icon.name]: Icon,
[NavBar.name]: NavBar,
messageComponent,
HotProducts,
chatMessage,
sticky,
},
data() {
return {
hotList: [],
productName: '',
conversationId: '',
messageStatus: 'stop',
isThink: null,
messages: [],
isSearching: false,
isDeep: false,
autoScrollEnabled: true,
scrollPosition: 0,
}
},
created() {
let { compareId, conversationId } = this.$route.query
if (conversationId) {
this.conversationId = conversationId
}
if (!compareId) {
sessionStorage.removeItem('results')
// this.messages.push({
// type: 'bot',
// text: 'HI我是长生产品助手可以为你推荐产品、答疑解惑请点击以下功能体检。',
// })
} else {
// 可以调用接口展示 名字 或者存在session里
let sesstions = JSON.parse(sessionStorage.getItem('results')).productResults
console.log(sesstions)
let text = sesstions.map((item) => {
return item.productName + '<br/>'
})
console.log(text)
let other = '对比产品 <br/>' + text.join('')
this.messages.push({
type: 'user',
text: other,
})
}
this.getHotProducts()
},
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
},
cellClick(item) {
this.$refs.chatMessage.cellClick(item)
}
},
watch: {
messages: {
handler() {
console.log(this.messages, 'messages');
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: #fafafa;
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>

View File

@@ -0,0 +1,188 @@
<template>
<div class="chat-page">
<van-nav-bar title="产品知识助手" left-text="返回" left-arrow @click-left="$router.history.go(-1)" />
<sticky :hotList="hotList" :productName="productName" :messagesList.sync="messages"
:autoScrollEnabled.sync="autoScrollEnabled" @setProductName="setProductName"
:isDisabled="messageStatus === 'send'" :conversationId="conversationId"></sticky>
<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>
<!-- <HotProducts class="mb10" :messagesList.sync="messages" @getHotList="getHotProducts"></HotProducts> -->
</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 messageComponent from '@/views/AI/components/message.vue'
import SvgIcon from '@/components/svg-icon/index.vue'
import HotProducts from '@/views/AI-new/components/HotProducts.vue'
import sticky from '@/views/AI/components/sticky.vue'
import chatMessage from '@/views/AI-new/components/chat-new.vue'
export default {
components: {
SvgIcon,
[Icon.name]: Icon,
[NavBar.name]: NavBar,
messageComponent,
HotProducts,
chatMessage,
sticky,
},
data() {
return {
hotList: [],
productName: '',
conversationId: '',
messageStatus: 'stop',
isThink: null,
messages: [],
isSearching: false,
isDeep: false,
autoScrollEnabled: true,
scrollPosition: 0,
}
},
created() {
let { compareId, conversationId } = this.$route.query
if (conversationId) {
this.conversationId = conversationId
}
if (!compareId) {
sessionStorage.removeItem('results')
this.messages.push({
type: 'bot',
text: `
这里是产品知识小助手,请告诉我您想要了解哪个产品?也可以输入以下信息,我帮您进行精准查询:
1.投保规则
2.保障责任
3.增值服务
您可以直接向我提问~
`,
})
} else {
// 可以调用接口展示 名字 或者存在session里
let sesstions = JSON.parse(sessionStorage.getItem('results')).productResults
console.log(sesstions)
let text = sesstions.map((item) => {
return item.productName + '<br/>'
})
console.log(text)
let other = '对比产品 <br/>' + text.join('')
this.messages.push({
type: 'user',
text: other,
})
}
this.getHotProducts()
},
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() {
console.log(this.messages, 'messages');
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>

View File

@@ -0,0 +1,194 @@
<template>
<div class="chat-page">
<van-nav-bar title="产品推荐助手" left-text="返回" left-arrow @click-left="$router.history.go(-1)" />
<sticky :hotList="hotList" :productName="productName" :messagesList.sync="messages"
:autoScrollEnabled.sync="autoScrollEnabled" @setProductName="setProductName"
:isDisabled="messageStatus === 'send'" :conversationId="conversationId"></sticky>
<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>
<!-- <HotProducts class="mb10" :messagesList.sync="messages" @getHotList="getHotProducts"></HotProducts> -->
</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 messageComponent from '@/views/AI/components/message.vue'
import SvgIcon from '@/components/svg-icon/index.vue'
import HotProducts from '@/views/AI-new/components/HotProducts.vue'
import sticky from '@/views/AI/components/sticky.vue'
import chatMessage from '@/views/AI-new/components/chat-new.vue'
export default {
components: {
SvgIcon,
[Icon.name]: Icon,
[NavBar.name]: NavBar,
messageComponent,
HotProducts,
chatMessage,
sticky,
},
data() {
return {
hotList: [],
productName: '',
conversationId: '',
messageStatus: 'stop',
isThink: null,
messages: [],
isSearching: false,
isDeep: false,
autoScrollEnabled: true,
scrollPosition: 0,
}
},
created() {
let { compareId, conversationId } = this.$route.query
if (conversationId) {
this.conversationId = conversationId
}
if (!compareId) {
sessionStorage.removeItem('results')
this.messages.push({
type: 'bot',
text: `
这里是产品推荐小助手,请告诉我以下客户的信息, 我帮您精准推荐:
1.如果您需要推荐保障类产品,您可以告诉我以下信息:
• 客户需要哪类保障?(重疾/医疗/意外)
• 客户的年龄、性别、有无既往病症
• 客户的保障场景(住院医疗/百万医疗/出行意外/综合意外/
交通意外)
2.如果您需要推荐理财储蓄类产品,您可以告诉我以下信息:
• 客户主要目标是什么?(财富升值/子女教育/资产传承/养老保障)
• 客户的年龄、性别、年收入、风险承受能力
`,
})
} else {
// 可以调用接口展示 名字 或者存在session里
let sesstions = JSON.parse(sessionStorage.getItem('results')).productResults
console.log(sesstions)
let text = sesstions.map((item) => {
return item.productName + '<br/>'
})
console.log(text)
let other = '对比产品 <br/>' + text.join('')
this.messages.push({
type: 'user',
text: other,
})
}
this.getHotProducts()
},
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: #000;
$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>

View File

@@ -12,7 +12,8 @@
<span class="speakLoadingToast pv10">
<van-loading type="spinner" color="#2e5ca9" size="20px" v-if="!message.text" />
<span class="loading-text">{{ message.text ? '思考完成' : '思考中...' }}</span>
<van-icon name="arrow-up" :class="message.showThink ? 'rate360' : 'rate180'" @click="showThink(message)" v-if="message.think" />
<van-icon name="arrow-up" :class="message.showThink ? 'rate360' : 'rate180'" @click="showThink(message)"
v-if="message.think" />
</span>
<!--开启思考-->
<p v-html="md.render(message.think)" v-if="message.think && message.showThink" class="thinkText" />
@@ -22,22 +23,24 @@
<span class="speakLoadingToast pv10" v-else-if="!message.text && !thinkOk && !message.isThink">
<van-loading type="spinner" color="#2e5ca9" size="20px" v-if="!message.text" />
</span>
<div class="text-right fs12 mb5 mr10" style="font-size: 10px; color: #f6aa21">此内容由AI生成</div>
<div class="text-right fs12 mb5 mr10" style="font-size: 10px; color: #f6aa21">
<!-- 新增点赞和踩按钮 -->
<div class="reaction-buttons mb10" v-if="message.type !== 'user'">
<button @click="handleReaction(message, 'like')" class="like">
<svg-icon :icon-class="message.isLike ? 'fillLike' : 'like'" class-name="chat-icon"></svg-icon>
</button>
<button @click="handleReaction(message, 'dislike')" class="dislike">
<svg-icon :icon-class="message.isDisLike ? 'fillDislike' : 'dislike'" class-name="wh15"></svg-icon>
</button>
</div>
</div>
</div>
</div>
<!--百宝箱-->
<div v-else class="mb10">
<treasure-box :item="message" @setProductName="setProductName"></treasure-box>
</div>
<!-- 新增点赞和踩按钮 -->
<div class="reaction-buttons mb10" v-if="message.type !== 'user'">
<button @click="handleReaction(message, 'like')" class="like">
<svg-icon :icon-class="message.isLike ? 'fillLike' : 'like'" class-name="chat-icon"></svg-icon> 有用
</button>
<button @click="handleReaction(message, 'dislike')" class="dislike">
<svg-icon :icon-class="message.isDisLike ? 'fillDislike' : 'dislike'" class-name="wh15"></svg-icon>无用
</button>
</div>
</div>
</section>
</template>
@@ -103,7 +106,7 @@ export default {
<style scoped lang="scss">
// 主题颜色定义
$primary-color: #2e5ca9; // 修复了 SCSS 变量的定义方式
$primary-color: #000; // 修复了 SCSS 变量的定义方式
$primary-text-color: #f6aa21; // 修复了 SCSS 变量的定义方式
$primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色透明度为0.8
@@ -111,10 +114,12 @@ $primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色
width: 15px;
height: 15px;
}
.message-item {
p {
line-height: 2;
}
// 清除所有样式
//all: unset;
::v-deep ol,
@@ -130,6 +135,7 @@ $primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色
}
}
}
.message-item {
all: initial;
margin-bottom: 10px;
@@ -149,7 +155,7 @@ $primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色
}
p {
background-color: $primary-color;
background-color: #57a6fc;
color: #fff;
border-radius: 5px;
padding: 10px;
@@ -163,6 +169,7 @@ $primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色
max-width: 80%;
margin-left: 20%;
}
.bot-message {
justify-content: start;
background-color: #fff;
@@ -181,12 +188,14 @@ $primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色
color: $primary-trans-color;
padding-top: 0;
}
.speakLoadingToast {
display: flex;
align-items: center;
gap: 10px;
color: $primary-text-color;
margin-left: 10px;
.loading-text {
color: $primary-trans-color;
}
@@ -203,6 +212,7 @@ $primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色
// 新增样式:点赞和踩按钮
.reaction-buttons {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 5px;
@@ -223,11 +233,13 @@ $primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色
}
}
}
.rate360 {
animation-duration: 0.5s;
animation-fill-mode: both;
animation-name: rate360;
}
.rate180 {
animation-duration: 0.5s;
animation-fill-mode: both;
@@ -238,14 +250,17 @@ $primary-trans-color: rgba(135, 162, 208, 0.5); // 使用rgba定义颜色
0% {
transform: rotate(180deg);
}
100% {
transform: rotate(0deg);
}
}
@keyframes rate180 {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(180deg);
}

View File

@@ -47,6 +47,11 @@ export default {
data() {
return {
swiper: [
[
{ title: "产品助手", icon: 'product', path: '/productAssistant' },
{ title: "产品知识助手", icon: 'product', path: '/productKnowledge' },
{ title: "产品推荐助手", icon: 'product', path: '/productRecommend' },
],
[
{ title: 'AI智能助手', icon: 'product', path: '/chatPage' },
{ title: '产品对比', icon: 'earth', path: '/comparison' },

View File

@@ -0,0 +1,28 @@
<script lang="ts">
export default {
name: "recommendTips",
props: {
list: {
type: Array,
default: () => []
}
},
methods: {
handleActiveItem(item) {
this.$emit('activeItem', item.action)
}
}
}
</script>
<template>
<div>
<ul>
<li v-for="item in list" :key="item.id" @click="handleActiveItem(item)">
<a href="javascript:void(0)">{{ item.title }}</a>
</li>
</ul>
</div>
</template>
<style lang="scss" scoped></style>

View File

@@ -5,13 +5,9 @@
<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>
<messageComponent :messagesList="messages" :is-deep="isDeep" :is-search="isSearching" :think-ok="isThink"
@setProductName="setProductName"></messageComponent>
</div>
</div>
<!-- 滚动到顶部按钮 -->
@@ -20,16 +16,9 @@
</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>
<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>
@@ -39,10 +28,11 @@ 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'
import RecommendTips from "./components/RecommendTips.vue"
export default {
components: {
SvgIcon,
RecommendTips,
messageComponent,
[Icon.name]: Icon,
[NavBar.name]: NavBar,
@@ -52,6 +42,22 @@ export default {
data() {
return {
hotList: [],
commendList: [{
title: '请为我推荐一款重疾险。',
action: () => {
console.log('请为我推荐一款重疾险。');
}
}, {
title: "60周岁以上可以投保保险产品吗",
action: () => {
console.log('60周岁以上可以投保保险产品吗');
}
}, {
title: "60周岁以上可以投保保险产品吗",
action: () => {
console.log('60周岁以上可以投保保险产品吗');
}
}],
productName: '',
conversationId: '',
messageStatus: 'stop',
@@ -59,7 +65,7 @@ export default {
messages: [
{
type: 'bot',
text: '欢迎使用AI客服助手请输入问题开始对话。',
text: 'HI我是长生产品助手可以为你推荐产品、答疑解惑请点击以下功能体检。',
},
],
isSearching: false,
@@ -69,6 +75,9 @@ export default {
}
},
methods: {
handleActiveItem(cb) {
cb()
},
getIsThink(e) {
this.isThink = e
},
@@ -145,6 +154,7 @@ $primary-trans-color: rgba(135, 162, 208, 0.5);
.chat-content {
height: 100%;
.message-area {
height: 100%;
overflow-y: auto;