mirror of
http://112.124.100.131/ebiz-ai/ebiz-base-ai.git
synced 2025-12-11 20:06:52 +08:00
feat(AI): 实现产品对比功能
- 在聊天组件中添加产品对比参数 - 在消息组件中支持 HTML 渲染 - 在 AI 入口组件中处理产品对比结果 - 在首页组件中清除产品对比结果 - 在对比表格组件中保存对比结果到 sessionStorage
This commit is contained in:
@@ -212,10 +212,10 @@ export default {
|
|||||||
think: '',
|
think: '',
|
||||||
isLike: false,
|
isLike: false,
|
||||||
isDisLike: false,
|
isDisLike: false,
|
||||||
}),
|
})
|
||||||
)
|
)
|
||||||
this.messages.push(this.currentMessage)
|
this.messages.push(this.currentMessage)
|
||||||
const params = {
|
let params = {
|
||||||
query: this.newMessage,
|
query: this.newMessage,
|
||||||
isDeep: this.isDeep ? 1 : 0,
|
isDeep: this.isDeep ? 1 : 0,
|
||||||
isOnline: this.isSearching ? 1 : 0,
|
isOnline: this.isSearching ? 1 : 0,
|
||||||
@@ -223,6 +223,11 @@ export default {
|
|||||||
conversationId: this.conversationId,
|
conversationId: this.conversationId,
|
||||||
productName: this.productName,
|
productName: this.productName,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.$route.query.compareId) {
|
||||||
|
params.compareResult = JSON.parse(sessionStorage.getItem('results'))
|
||||||
|
}
|
||||||
|
|
||||||
fetch(chat(), {
|
fetch(chat(), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -307,6 +312,8 @@ export default {
|
|||||||
sendMessage() {
|
sendMessage() {
|
||||||
if (this.messageStatus === 'send') return
|
if (this.messageStatus === 'send') return
|
||||||
if (this.newMessage.trim() === '') return
|
if (this.newMessage.trim() === '') return
|
||||||
|
// 防止xss
|
||||||
|
this.newMessage = this.newMessage.replace(/<[^>]+>/g, '')
|
||||||
this.messages.push({ type: 'user', text: this.newMessage })
|
this.messages.push({ type: 'user', text: this.newMessage })
|
||||||
this.$emit('update:messageStatus', 'send')
|
this.$emit('update:messageStatus', 'send')
|
||||||
// this.messageStatus = 'send'
|
// this.messageStatus = 'send'
|
||||||
@@ -315,10 +322,10 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.newMessage.includes('产品对比')) {
|
// if (this.newMessage.includes('产品对比')) {
|
||||||
// this.hasTreasureBox()
|
// // this.hasTreasureBox()
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
// this.autoScrollEnabled = true
|
// this.autoScrollEnabled = true
|
||||||
this.$emit('update:autoScrollEnabled', true)
|
this.$emit('update:autoScrollEnabled', true)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<div v-for="(message, index) in messagesList" :key="index" class="message-item">
|
<div v-for="(message, index) in messagesList" :key="index" class="message-item">
|
||||||
<!--用户消息-->
|
<!--用户消息-->
|
||||||
<div v-if="message.type === 'user'" class="user-message mb10">
|
<div v-if="message.type === 'user'" class="user-message mb10">
|
||||||
<p>{{ message.text }}</p>
|
<p v-html="message.text"></p>
|
||||||
</div>
|
</div>
|
||||||
<!--机器人消息-->
|
<!--机器人消息-->
|
||||||
<div v-else-if="message.type === 'bot'" class="bot-message mb10">
|
<div v-else-if="message.type === 'bot'" class="bot-message mb10">
|
||||||
|
|||||||
@@ -82,15 +82,25 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!compareId) {
|
if (!compareId) {
|
||||||
|
sessionStorage.removeItem('results')
|
||||||
this.messages.push({
|
this.messages.push({
|
||||||
type: 'bot',
|
type: 'bot',
|
||||||
text: '欢迎使用AI智能助手,请输入问题开始对话或输入关键词 "xxx工具箱","产品对比"。',
|
text: '欢迎使用AI智能助手,请输入问题开始对话或输入关键词 "xxx工具箱","产品对比"。',
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// 可以调用接口展示 名字 或者存在session里
|
// 可以调用接口展示 名字 或者存在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({
|
this.messages.push({
|
||||||
type: 'user',
|
type: 'user',
|
||||||
text: compareId,
|
text: other,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.getHotProducts()
|
this.getHotProducts()
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ export default {
|
|||||||
[Swipe.name]: Swipe,
|
[Swipe.name]: Swipe,
|
||||||
[SwipeItem.name]: SwipeItem,
|
[SwipeItem.name]: SwipeItem,
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
sessionStorage.removeItem('results')
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
navigationItems: [
|
navigationItems: [
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</el-table>
|
</el-table>
|
||||||
<div class="flex align-items-c justify-content-b">
|
<div class="flex align-items-c justify-content-b">
|
||||||
<van-button class="fs14 fw600" style="background: #fff; color: #000; flex: 1; border-radius: 8px" @click="emits">返回</van-button>
|
<van-button class="fs14 fw600" style="background: #fff; color: #000; flex: 1; border-radius: 8px" @click="emits">返回</van-button>
|
||||||
<!-- <van-button class="fs14 fw600" style="color: #fff; background: #1989fa; flex: 1; border-radius: 8px" @click="question">提问</van-button>-->
|
<van-button class="fs14 fw600" style="color: #fff; background: #1989fa; flex: 1; border-radius: 8px" @click="question">提问</van-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -83,7 +83,7 @@ export default {
|
|||||||
obj[item.productId] = item.knowledge[keys]
|
obj[item.productId] = item.knowledge[keys]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log(this.tableData)
|
sessionStorage.setItem('results', JSON.stringify(res.content))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user