Compare commits
No commits in common. "539d9ca5b3349ea602e5d306a282e5f1296d8bae" and "8f2ce34669a93fed2656f117da6a97af6811bc38" have entirely different histories.
539d9ca5b3
...
8f2ce34669
@ -116,8 +116,6 @@
|
|||||||
|
|
||||||
// 会话进行中标志
|
// 会话进行中标志
|
||||||
let isSessionActive = false;
|
let isSessionActive = false;
|
||||||
/// 指令
|
|
||||||
let commonType = ''
|
|
||||||
|
|
||||||
|
|
||||||
// 打开抽屉
|
// 打开抽屉
|
||||||
@ -169,13 +167,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// 是发送指令
|
/// 是发送指令
|
||||||
const handleReplyInstruct = (item) => {
|
const handleReplyInstruct = (text) => {
|
||||||
if(item.type === 'MyOrder') {
|
sendMessage(text, true)
|
||||||
/// 订单
|
|
||||||
return
|
|
||||||
}
|
|
||||||
commonType = item.type
|
|
||||||
sendMessage(item.title, true)
|
|
||||||
setTimeoutScrollToBottom()
|
setTimeoutScrollToBottom()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +271,7 @@
|
|||||||
conversationId: conversationId.value,
|
conversationId: conversationId.value,
|
||||||
agentId: agentId.value,
|
agentId: agentId.value,
|
||||||
messageType: isInstruct ? 1 : 0,
|
messageType: isInstruct ? 1 : 0,
|
||||||
messageContent: isInstruct ? commonType : message
|
messageContent: message
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入AI消息
|
// 插入AI消息
|
||||||
@ -312,10 +305,9 @@
|
|||||||
// 流式接收内容
|
// 流式接收内容
|
||||||
agentChatStream(args, (chunk) => {
|
agentChatStream(args, (chunk) => {
|
||||||
console.log('分段内容:', chunk)
|
console.log('分段内容:', chunk)
|
||||||
if (chunk && chunk.error) {
|
if (chunk.error) {
|
||||||
chatMsgList.value[aiMsgIndex].msg = '请求错误,请重试';
|
chatMsgList.value[aiMsgIndex].msg = '请求错误,请重试';
|
||||||
clearInterval(loadingTimer);
|
clearInterval(finishInterval);
|
||||||
loadingTimer = null;
|
|
||||||
isTyping = false;
|
isTyping = false;
|
||||||
typeWriterTimer = null;
|
typeWriterTimer = null;
|
||||||
isSessionActive = false; // 出错也允许再次发送
|
isSessionActive = false; // 出错也允许再次发送
|
||||||
@ -342,20 +334,10 @@
|
|||||||
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;
|
||||||
typeWriterTimer = null;
|
isSessionActive = false; // 会话结束,允许再次发送
|
||||||
// 补全:如果消息内容还停留在'加载中.'或为空,则给出友好提示
|
|
||||||
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)">
|
<view class="quick-access-item" v-for="(item, index) in itemList" :key="index" @click="sendReply(item.title)">
|
||||||
<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 = (item) => {
|
const sendReply = (text) => {
|
||||||
emits('replySent', item); // 向父组件传递数据
|
emits('replySent', text); // 向父组件传递数据
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@ -33,25 +33,21 @@
|
|||||||
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℃ ff </text>
|
<text>{{ currentDate }} 多云 -3~6℃ gg </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: '',
|
logoImageUrl: '/static/hello_banner_icon@2x.png',
|
||||||
welcomeImageUrl: ''
|
welcomeImageUrl: '/static/hello_banner_bg@2x.png'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
welcomeContent: {
|
welcomeContent: {
|
||||||
|
|||||||
@ -12,7 +12,6 @@ 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
|
||||||
@ -35,7 +34,7 @@ function agentChatStream(params, onChunk) {
|
|||||||
reject(err);
|
reject(err);
|
||||||
},
|
},
|
||||||
complete(res) {
|
complete(res) {
|
||||||
if(res.statusCode !== 200) {
|
if(res.statusCode === 500) {
|
||||||
console.log("====> ", JSON.stringify(res))
|
console.log("====> ", JSON.stringify(res))
|
||||||
|
|
||||||
if (onChunk) {
|
if (onChunk) {
|
||||||
@ -48,18 +47,9 @@ 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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user