From 875072bb68a149f7c94c30b17e7a1f83ab5364e1 Mon Sep 17 00:00:00 2001 From: jinhhanhan <1683105490@qq.com> Date: Sat, 14 Mar 2026 10:53:55 +0800 Subject: [PATCH] =?UTF-8?q?chore=EF=BC=9A=E5=95=86=E5=93=81=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=88=86=E4=BA=AB=E7=BB=99=E6=99=BA=E8=83=BD=E5=AE=A2?= =?UTF-8?q?=E6=9C=8D=E8=BF=9B=E8=A1=8C=E8=A7=A3=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components-diy/diy-category-item.vue | 51 +++++++ pages_tool/ai-chat/ai-chat-message.vue | 180 +------------------------ pages_tool/ai-chat/index.vue | 28 ++++ 3 files changed, 83 insertions(+), 176 deletions(-) diff --git a/components-diy/diy-category-item.vue b/components-diy/diy-category-item.vue index f6515cb..bb8795d 100644 --- a/components-diy/diy-category-item.vue +++ b/components-diy/diy-category-item.vue @@ -120,6 +120,10 @@ {{ showMarketPrice(item) }} + + 🤖 + 更多详情 + - - - - - - - {{ message.title }} - ¥{{ message.price }} - {{ message.description }} - - - - + @@ -182,9 +169,6 @@ - @@ -282,50 +266,6 @@ - - - - - - 选择商品 - - - - - - {{ category.category_name }} - - - - - 加载商品中... - - - 该分类下暂无商品 - - - - - {{ product.goods_name }} - ¥{{ product.price }} - - - - - - - @@ -463,12 +403,7 @@ export default { defaultNickname: '我', // 默认昵称 showNicknameEditor: false, // 昵称编辑弹窗控制 tempNickname: '', // 昵称编辑临时值 - // 商品选择相关 - showProductSelector: false, // 商品选择弹窗控制 - productCategories: [], // 商品分类列表 - selectedCategoryIndex: 0, // 当前选中的分类索引 - selectedCategoryProducts: [], // 当前分类下的商品列表 - loadingProducts: false, // 商品加载状态 + // Dify API相关 currentConversationId: null, isAIServiceAvailable: true, @@ -1320,11 +1255,7 @@ export default { this.$emit('link-open', message) }, - // 查看商品 - viewProduct(message) { - this.$emit('product-view', message) - }, - + // 处理操作 handleAction(action, message) { // 处理重试操作 @@ -1519,110 +1450,7 @@ export default { }) }, - // 选择商品 - selectProduct() { - this.hideToolsPanel() - this.showProductSelector = true - this.loadProductCategories() - }, - - // 关闭商品选择弹窗 - closeProductSelector() { - this.showProductSelector = false - }, - - // 加载商品分类 - loadProductCategories() { - uni.showLoading({ title: '加载商品分类中...' }) - - this.$api.sendRequest({ - url: '/api/goodscategory/tree', - data: { - level: 2 - }, - success: (res) => { - uni.hideLoading() - - if (res.code == 0 && res.data) { - this.productCategories = res.data - if (res.data.length > 0) { - this.selectCategory(0) - } - } else { - uni.showToast({ - title: '获取商品分类失败', - icon: 'none' - }) - this.closeProductSelector() - } - }, - fail: () => { - uni.hideLoading() - uni.showToast({ - title: '网络错误,请稍后重试', - icon: 'none' - }) - this.closeProductSelector() - } - }) - }, - - // 选择分类 - selectCategory(index) { - this.selectedCategoryIndex = index - const category = this.productCategories[index] - if (category) { - this.loadCategoryProducts(category.id) - } - }, - - // 加载分类商品 - loadCategoryProducts(categoryId) { - this.loadingProducts = true - this.selectedCategoryProducts = [] - - this.$api.sendRequest({ - url: '/api/goods/list', - data: { - category_id: categoryId, - page: 1, - limit: 50 - }, - success: (res) => { - this.loadingProducts = false - - if (res.code == 0 && res.data && res.data.list) { - this.selectedCategoryProducts = res.data.list - } else { - this.selectedCategoryProducts = [] - } - }, - fail: () => { - this.loadingProducts = false - this.selectedCategoryProducts = [] - } - }) - }, - - // 选择商品 - selectProductItem(product) { - // 构建商品消息 - const productMessage = { - id: ++this.messageId, - role: 'user', - type: 'text', - content: `我想了解以下商品的信息:\n商品名称:${product.goods_name}\n价格:¥${product.price}\n商品ID:${product.id}`, - timestamp: Date.now(), - product: product - } - - this.messages.push(productMessage) - this.closeProductSelector() - this.$emit('product-selected', productMessage) - - // 触发AI回复 - this.sendMessageWithContent(productMessage.content) - }, + // 清空聊天记录 clearMessages() { diff --git a/pages_tool/ai-chat/index.vue b/pages_tool/ai-chat/index.vue index 62be17b..9002f06 100644 --- a/pages_tool/ai-chat/index.vue +++ b/pages_tool/ai-chat/index.vue @@ -257,6 +257,20 @@ export default { // ========== 初始化页面 ========== initChat() { console.log('AI聊天页面初始化'); + + // 检查是否有从商品分类传递过来的商品信息 + const selectedProduct = uni.getStorageSync('selectedProduct') + if (selectedProduct) { + console.log('检测到选择的商品:', selectedProduct) + + // 清除存储的商品信息,避免重复发送 + uni.removeStorageSync('selectedProduct') + + // 延迟发送商品信息,确保聊天组件已经初始化 + setTimeout(() => { + this.sendProductToAI(selectedProduct) + }, 500) + } }, async initNavigation() { @@ -482,6 +496,20 @@ export default { onVideoPause(message) { console.log('视频暂停:', message); }, + + sendProductToAI(product) { + if (!this.$refs.chat) { + console.error('聊天组件未初始化') + return + } + + const productContent = `我想了解以下商品的详细信息:\n商品名称:${product.goods_name}\n价格:¥${product.price}\n商品ID:${product.goods_id}` + + console.log('商品信息已发送到AI客服:', productContent) + + // 使用sendMessageWithContent方法发送商品信息 + this.$refs.chat.sendMessageWithContent(productContent) + }, onLinkOpen(message) { uni.showModal({