feat: 来对话列表的处理
This commit is contained in:
@@ -116,6 +116,8 @@
|
|||||||
|
|
||||||
// 会话进行中标志
|
// 会话进行中标志
|
||||||
let isSessionActive = false;
|
let isSessionActive = false;
|
||||||
|
/// 指令
|
||||||
|
let commonType = ''
|
||||||
|
|
||||||
|
|
||||||
// 打开抽屉
|
// 打开抽屉
|
||||||
@@ -167,8 +169,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// 是发送指令
|
/// 是发送指令
|
||||||
const handleReplyInstruct = (text) => {
|
const handleReplyInstruct = (item) => {
|
||||||
sendMessage(text, true)
|
if(item.type === 'MyOrder') {
|
||||||
|
/// 订单
|
||||||
|
return
|
||||||
|
}
|
||||||
|
commonType = item.type
|
||||||
|
sendMessage(item.title, true)
|
||||||
setTimeoutScrollToBottom()
|
setTimeoutScrollToBottom()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +278,7 @@
|
|||||||
conversationId: conversationId.value,
|
conversationId: conversationId.value,
|
||||||
agentId: agentId.value,
|
agentId: agentId.value,
|
||||||
messageType: isInstruct ? 1 : 0,
|
messageType: isInstruct ? 1 : 0,
|
||||||
messageContent: message
|
messageContent: isInstruct ? commonType : message
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入AI消息
|
// 插入AI消息
|
||||||
@@ -305,9 +312,10 @@
|
|||||||
// 流式接收内容
|
// 流式接收内容
|
||||||
agentChatStream(args, (chunk) => {
|
agentChatStream(args, (chunk) => {
|
||||||
console.log('分段内容:', chunk)
|
console.log('分段内容:', chunk)
|
||||||
if (chunk.error) {
|
if (chunk && chunk.error) {
|
||||||
chatMsgList.value[aiMsgIndex].msg = '请求错误,请重试';
|
chatMsgList.value[aiMsgIndex].msg = '请求错误,请重试';
|
||||||
clearInterval(finishInterval);
|
clearInterval(loadingTimer);
|
||||||
|
loadingTimer = null;
|
||||||
isTyping = false;
|
isTyping = false;
|
||||||
typeWriterTimer = null;
|
typeWriterTimer = null;
|
||||||
isSessionActive = false; // 出错也允许再次发送
|
isSessionActive = false; // 出错也允许再次发送
|
||||||
@@ -334,10 +342,20 @@
|
|||||||
if (chunk && chunk.finish) {
|
if (chunk && chunk.finish) {
|
||||||
// 结尾处理:确保剩余内容全部输出
|
// 结尾处理:确保剩余内容全部输出
|
||||||
const finishInterval = setInterval(() => {
|
const finishInterval = setInterval(() => {
|
||||||
|
console.log('aiMsgBuffer.length:', aiMsgBuffer.length)
|
||||||
if (aiMsgBuffer.length === 0) {
|
if (aiMsgBuffer.length === 0) {
|
||||||
clearInterval(finishInterval);
|
clearInterval(finishInterval);
|
||||||
|
clearInterval(loadingTimer);
|
||||||
|
loadingTimer = null;
|
||||||
isTyping = false;
|
isTyping = false;
|
||||||
isSessionActive = false; // 会话结束,允许再次发送
|
typeWriterTimer = null;
|
||||||
|
// 补全:如果消息内容还停留在'加载中.'或为空,则给出友好提示
|
||||||
|
const msg = chatMsgList.value[aiMsgIndex].msg;
|
||||||
|
console.log('msg:', msg)
|
||||||
|
if (!msg || msg === '加载中.' || msg.startsWith('加载中')) {
|
||||||
|
chatMsgList.value[aiMsgIndex].msg = '未获取到内容,请重试';
|
||||||
|
}
|
||||||
|
isSessionActive = false;
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="quick-access">
|
<view class="quick-access">
|
||||||
<view class="quick-access-scroll">
|
<view class="quick-access-scroll">
|
||||||
<view class="quick-access-item" v-for="(item, index) in itemList" :key="index" @click="sendReply(item.title)">
|
<view class="quick-access-item" v-for="(item, index) in itemList" :key="index" @click="sendReply(item)">
|
||||||
<image class="quick-access-item-bg" src="/static/quick/quick_icon_bg.png" mode="aspectFill"></image>
|
<image class="quick-access-item-bg" src="/static/quick/quick_icon_bg.png" mode="aspectFill"></image>
|
||||||
<view class="quick-access-item-title">
|
<view class="quick-access-item-title">
|
||||||
<image :src="item.icon"></image>
|
<image :src="item.icon"></image>
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
const emits = defineEmits(['replySent']);
|
const emits = defineEmits(['replySent']);
|
||||||
|
|
||||||
const sendReply = (text) => {
|
const sendReply = (item) => {
|
||||||
emits('replySent', text); // 向父组件传递数据
|
emits('replySent', item); // 向父组件传递数据
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -33,21 +33,25 @@
|
|||||||
icon: '/static/quick/quick_icon_yuding.png',
|
icon: '/static/quick/quick_icon_yuding.png',
|
||||||
title: '预定门票',
|
title: '预定门票',
|
||||||
content: '快速预定天沐温泉门票',
|
content: '快速预定天沐温泉门票',
|
||||||
|
type: 'Command.quickBooking'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: '/static/quick/quick_icon_find.png',
|
icon: '/static/quick/quick_icon_find.png',
|
||||||
title: '探索发现',
|
title: '探索发现',
|
||||||
content: '亲子、团建等更多玩法',
|
content: '亲子、团建等更多玩法',
|
||||||
|
type: 'Command.discovery'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: '/static/quick/quick_icon_call.png',
|
icon: '/static/quick/quick_icon_call.png',
|
||||||
title: '呼叫服务',
|
title: '呼叫服务',
|
||||||
content: '加床、订麻将机...',
|
content: '加床、订麻将机...',
|
||||||
|
type: 'Command.createWorkOrder'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: '/static/quick/quick_icon_order.png',
|
icon: '/static/quick/quick_icon_order.png',
|
||||||
title: '我的订单',
|
title: '我的订单',
|
||||||
content: '快速查看订单',
|
content: '快速查看订单',
|
||||||
|
type: 'MyOrder'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<!-- :style="backgroundStyle" -->
|
<!-- :style="backgroundStyle" -->
|
||||||
<view class="top-item1-left">
|
<view class="top-item1-left">
|
||||||
<image :src="initPageImages.welcomeImageUrl"></image>
|
<image :src="initPageImages.welcomeImageUrl"></image>
|
||||||
<text>{{ currentDate }} 多云 -3~6℃ gg </text>
|
<text>{{ currentDate }} 多云 -3~6℃ ff </text>
|
||||||
</view>
|
</view>
|
||||||
<view class="top-item1-right">
|
<view class="top-item1-right">
|
||||||
<image :src="initPageImages.logoImageUrl"></image>
|
<image :src="initPageImages.logoImageUrl"></image>
|
||||||
@@ -23,8 +23,8 @@
|
|||||||
type: Object,
|
type: Object,
|
||||||
default: {
|
default: {
|
||||||
backgroundImageUrl: '',
|
backgroundImageUrl: '',
|
||||||
logoImageUrl: '/static/hello_banner_icon@2x.png',
|
logoImageUrl: '',
|
||||||
welcomeImageUrl: '/static/hello_banner_bg@2x.png'
|
welcomeImageUrl: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
welcomeContent: {
|
welcomeContent: {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const API = '/agent/assistant/chat';
|
|||||||
function agentChatStream(params, onChunk) {
|
function agentChatStream(params, onChunk) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const token = uni.getStorageSync('token');
|
const token = uni.getStorageSync('token');
|
||||||
|
let hasError = false;
|
||||||
|
|
||||||
console.log("发送请求内容: ", params)
|
console.log("发送请求内容: ", params)
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
@@ -34,7 +35,7 @@ function agentChatStream(params, onChunk) {
|
|||||||
reject(err);
|
reject(err);
|
||||||
},
|
},
|
||||||
complete(res) {
|
complete(res) {
|
||||||
if(res.statusCode === 500) {
|
if(res.statusCode !== 200) {
|
||||||
console.log("====> ", JSON.stringify(res))
|
console.log("====> ", JSON.stringify(res))
|
||||||
|
|
||||||
if (onChunk) {
|
if (onChunk) {
|
||||||
@@ -47,9 +48,18 @@ function agentChatStream(params, onChunk) {
|
|||||||
|
|
||||||
requestTask.onHeadersReceived(res => {
|
requestTask.onHeadersReceived(res => {
|
||||||
console.log('onHeadersReceived', res);
|
console.log('onHeadersReceived', res);
|
||||||
|
const status = res.statusCode || (res.header && res.header.statusCode);
|
||||||
|
if (status && status !== 200) {
|
||||||
|
hasError = true;
|
||||||
|
if (onChunk) {
|
||||||
|
onChunk({ error: true, message: `服务器错误(${status})`, detail: res });
|
||||||
|
}
|
||||||
|
requestTask.abort && requestTask.abort();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
requestTask.onChunkReceived(res => {
|
requestTask.onChunkReceived(res => {
|
||||||
|
if (hasError) return;
|
||||||
const base64 = uni.arrayBufferToBase64(res.data);
|
const base64 = uni.arrayBufferToBase64(res.data);
|
||||||
let data = '';
|
let data = '';
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user