feat(AI): 添加产品名称同步和错误处理优化

- 在 message 组件中添加 setProductName 方法,并在 treasureBox 组件中触发该事件
- 在 AI index 组件中实现 setProductName 方法,用于更新产品名称
- 优化错误处理,在产品详情请求失败时更新消息状态
- 在聊天记录中添加产品名称参数,以便在请求中传递
This commit is contained in:
陈昱达
2025-06-06 11:44:46 +08:00
parent 03b469840b
commit e8ddb69215
3 changed files with 22 additions and 4 deletions

View File

@@ -26,7 +26,7 @@
</div>
<!--百宝箱-->
<div v-else class='mb10'>
<treasure-box :item="message"></treasure-box>
<treasure-box :item="message" @setProductName='setProductName'></treasure-box>
</div>
<!-- 新增点赞和踩按钮 -->
<div class="reaction-buttons mb10" v-if="message.type !== 'user'">
@@ -76,6 +76,10 @@ export default {
}
},
methods: {
setProductName(e){
this.$emit('setProductName',e)
},
showThink(message) {
this.$set(message, 'showThink', !message.showThink)

View File

@@ -51,7 +51,11 @@ export default {
this.getTreasureBox()
} else {
this.setList(this.item.detail)
this.$emit('setProductName',this.item.detail.productName)
}
},
immediate: true,
},
@@ -86,6 +90,7 @@ export default {
productDetail({ productName: this.item.text }).then((res) => {
if(res){
this.$set(this.item,'detail',res.content)
this.$emit('setProductName',res.content.productName)
this.setList()
}
})

View File

@@ -4,7 +4,7 @@
<div class="chat-content">
<div class="message-area" ref="messageArea" @scroll="handleScroll">
<HotProducts class="mb10" :messagesList.sync="messages"></HotProducts>
<messageComponent :messagesList="messages" :is-deep="isDeep" :is-search="isSearching" :think-ok='isThink'></messageComponent>
<messageComponent :messagesList="messages" :is-deep="isDeep" :is-search="isSearching" :think-ok='isThink' @setProductName='setProductName'></messageComponent>
</div>
</div>
@@ -53,6 +53,7 @@ export default {
data() {
return {
productName:'',
answerMap:'',
timer:null,
answerIndex:0,
@@ -79,6 +80,7 @@ export default {
startNewConversation() {
this.messages = []
this.conversationId = ''
this.productName = ''
},
hasTreasureBox() {
@@ -88,6 +90,8 @@ export default {
this.messages.push({ type: 'box', text: this.newMessage,detail:res.content })
this.newMessage = ''
}
}).catch(()=>{
this.messageStatus = 'stop'
})
},
@@ -136,7 +140,9 @@ export default {
}
})
},
setProductName(e){
console.log(e)
},
handleScroll() {
const messageArea = this.$refs.messageArea
if (!messageArea) return
@@ -169,6 +175,7 @@ export default {
isOnline: this.isSearching ? 1 : 0,
user: 'chenyuda',
conversationId: this.conversationId,
productName:this.productName,
}
fetch(chat(), {
@@ -181,7 +188,9 @@ export default {
this.newMessage = ''
await this.processStreamResponse(res)
})
.catch((err) => console.error('请求错误:', err))
.catch((err) => {
this.messageStatus = 'stop'
})
},
async processStreamResponse(response) {