更新临时对话状态显示问题
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
|
||||
<div class="toolbar-right">
|
||||
<span class="hint-text">Shift+Enter 换行</span>
|
||||
<button class="send-btn" :disabled="selectedWorkflowId === null" @click="handleSend">
|
||||
<button class="send-btn" :disabled="selectedWorkflowId === null || sendDisabled" @click="handleSend">
|
||||
<el-icon><Top /></el-icon>
|
||||
</button>
|
||||
</div>
|
||||
@@ -68,6 +68,10 @@ import { Top, MagicStick, Promotion, Close, Paperclip } from '@element-plus/icon
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { getWorkflowList } from '/@/api/settings/creation';
|
||||
|
||||
interface Props {
|
||||
sendDisabled?: boolean;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'send', message: string): void;
|
||||
(e: 'workflow-select', workflowId: string | null): void;
|
||||
@@ -79,6 +83,9 @@ interface Workflow {
|
||||
prefix: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
sendDisabled: false,
|
||||
});
|
||||
const emit = defineEmits<Emits>();
|
||||
const message = ref('');
|
||||
const isFocused = ref(false);
|
||||
@@ -100,12 +107,11 @@ const fetchWorkflows = async () => {
|
||||
};
|
||||
|
||||
const handleSend = () => {
|
||||
if (selectedWorkflowId.value === null) return;
|
||||
if (selectedWorkflowId.value === null || props.sendDisabled) return;
|
||||
const msg = message.value.trim();
|
||||
emit('send', msg || '');
|
||||
message.value = '';
|
||||
selectedWorkflowId.value = null;
|
||||
emit('workflow-select', null);
|
||||
// 不清除工作流选择,保持表单可见
|
||||
};
|
||||
|
||||
const handleAttachment = () => {
|
||||
|
||||
@@ -89,13 +89,12 @@ interface TreeNode {
|
||||
nodeType: string;
|
||||
children?: TreeNode[];
|
||||
fileUrl?: string;
|
||||
workflowId?: number | string;
|
||||
fileType?: string;
|
||||
sessionId?: string;
|
||||
}
|
||||
|
||||
interface HistoryItem {
|
||||
id: string;
|
||||
sessionId: string;
|
||||
title: string;
|
||||
time: string;
|
||||
status?: 'idle' | 'executing' | 'completed' | 'failed';
|
||||
|
||||
+31
-18
@@ -24,7 +24,7 @@
|
||||
:active-history-id="activeHistoryId"
|
||||
@close-workflow="handleCloseWorkflow"
|
||||
/>
|
||||
<InputBar ref="inputBarRef" @send="handleSend" @workflow-select="handleWorkflowSelect" />
|
||||
<InputBar ref="inputBarRef" :send-disabled="!!(activeHistoryId && sendingSessions[activeHistoryId])" @send="handleSend" @workflow-select="handleWorkflowSelect" />
|
||||
</div>
|
||||
|
||||
<!-- 预览弹窗 -->
|
||||
@@ -46,7 +46,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import Sidebar from './components/Sidebar.vue';
|
||||
import MainContent from './components/MainContent.vue';
|
||||
@@ -264,7 +264,7 @@ const mainContentRef = ref<any>(null);
|
||||
const workspacePage = ref(1);
|
||||
const hasMoreWorkspace = ref(true);
|
||||
const workspaceLoading = ref(false);
|
||||
const isSending = ref(false);
|
||||
const sendingSessions = reactive<Record<string, boolean>>({});
|
||||
const inputBarRef = ref<any>(null);
|
||||
|
||||
const getSessionId = () => {
|
||||
@@ -326,28 +326,41 @@ const addMessage = (msg: ChatMessage) => {
|
||||
};
|
||||
|
||||
const handleSend = async (message: string) => {
|
||||
if (isSending.value) return;
|
||||
isSending.value = true;
|
||||
// 无活跃会话时自动创建
|
||||
if (!activeHistoryId.value) {
|
||||
const newId = `virtual_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
|
||||
historyList.value.unshift({
|
||||
id: newId,
|
||||
sessionId: newId,
|
||||
title: '新会话 ' + (historyList.value.length + 1),
|
||||
time: '刚刚',
|
||||
});
|
||||
activeHistoryId.value = newId;
|
||||
sessionMessages.value.set(newId, []);
|
||||
}
|
||||
const sid = activeHistoryId.value;
|
||||
if (sendingSessions[sid]) return;
|
||||
sendingSessions[sid] = true;
|
||||
if (!selectedWorkflowDetail.value) {
|
||||
ElMessage.warning('请先选择一个工作流');
|
||||
isSending.value = false;
|
||||
delete sendingSessions[sid];
|
||||
return;
|
||||
}
|
||||
const mc = mainContentRef.value;
|
||||
if (!mc) {
|
||||
isSending.value = false;
|
||||
delete sendingSessions[sid];
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mc.validateFormFields()) {
|
||||
isSending.value = false;
|
||||
delete sendingSessions[sid];
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前会话的 sessionId
|
||||
const curSession = historyList.value.find((h) => h.id === activeHistoryId.value);
|
||||
const curSession = historyList.value.find((h) => h.id === sid);
|
||||
if (!curSession) {
|
||||
isSending.value = false;
|
||||
delete sendingSessions[sid];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -426,9 +439,8 @@ const handleSend = async (message: string) => {
|
||||
|
||||
// 5. 执行
|
||||
await executeFlow(params);
|
||||
// 标记完成
|
||||
const doneSession = historyList.value.find((h) => h.id === activeHistoryId.value);
|
||||
if (doneSession) doneSession.status = 'completed';
|
||||
// 标记完成(直接用 curSession 引用,避免切换会话后状态错乱)
|
||||
curSession.status = 'completed';
|
||||
addMessage({
|
||||
id: 'msg-' + Date.now() + '-done',
|
||||
content: '✅ 执行完成,可前往工作空间查看产出',
|
||||
@@ -436,7 +448,9 @@ const handleSend = async (message: string) => {
|
||||
isUser: false,
|
||||
});
|
||||
ElMessage.success('执行完成');
|
||||
// 刷新工作空间树
|
||||
// 重置分页并刷新工作空间树
|
||||
workspacePage.value = 1;
|
||||
hasMoreWorkspace.value = true;
|
||||
getExecutionList({ pageSize: 5 }).then((res) => {
|
||||
imgAddressPrefix.value = res.data?.imgAddressPrefix || '';
|
||||
treeNodes.value = buildTreeNodes(res.data?.tree || []);
|
||||
@@ -457,7 +471,7 @@ const handleSend = async (message: string) => {
|
||||
const msgs = sessionMessages.value.get(curSession.id);
|
||||
sessionMessages.value.delete(curSession.id);
|
||||
sessionMessages.value.set(match.id, msgs || []);
|
||||
historyList.value[idx] = match;
|
||||
historyList.value[idx] = { ...match, status: curSession.status };
|
||||
if (activeHistoryId.value === curSession.id) {
|
||||
activeHistoryId.value = match.id;
|
||||
}
|
||||
@@ -466,8 +480,7 @@ const handleSend = async (message: string) => {
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
const failSession = historyList.value.find((h) => h.id === activeHistoryId.value);
|
||||
if (failSession) failSession.status = 'failed';
|
||||
curSession.status = 'failed';
|
||||
addMessage({
|
||||
id: 'msg-' + Date.now() + '-fail',
|
||||
content: '❌ 执行失败,请重试或联系管理员',
|
||||
@@ -475,7 +488,7 @@ const handleSend = async (message: string) => {
|
||||
isUser: false,
|
||||
});
|
||||
} finally {
|
||||
isSending.value = false;
|
||||
delete sendingSessions[sid];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user