Commit 2b895f7e authored by chenghong_tao's avatar chenghong_tao

fix loading

parent c6b82368
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
:historyMsgId="item?.id" :historyMsgId="item?.id"
:messageType="item.type" :messageType="item.type"
:content="item.content" :content="item.content"
@messageFinished="messageFinished"
@workflow-is-error="workflowIsError"
/> />
<userBubble v-else :content="item.content"/> <userBubble v-else :content="item.content"/>
</div> </div>
...@@ -23,7 +21,7 @@ ...@@ -23,7 +21,7 @@
</div> </div>
</el-scrollbar> </el-scrollbar>
<div class="input-box"> <div class="input-box">
<InputMessage ref="inputMessageRef" @userQuery="userQuery" @getInputHeight="getInputHeight" :loadingFinished="loadingFinished" :workflowError="workflowError"/> <InputMessage ref="inputMessageRef" @userQuery="userQuery" @getInputHeight="getInputHeight" />
</div> </div>
</template> </template>
<script setup> <script setup>
...@@ -89,32 +87,10 @@ const getInputHeight = (height) => { ...@@ -89,32 +87,10 @@ const getInputHeight = (height) => {
defaultHeight.value = height + marginTop defaultHeight.value = height + marginTop
} }
const loadingFinished = ref(false)
const messageFinished = (status) => {
loadingFinished.value = status
if (!status) {
loadingFinished.value = true
nextTick(() => {
loadingFinished.value = status
})
}
if (status) {
nextTick(() => {
scrollToBottom()
})
clearInterval(scrollTimer.value);
}
}
const hasWelcomeMessage = computed(() => { const hasWelcomeMessage = computed(() => {
return appStore.appParams.opening_statement != ''; return appStore.appParams.opening_statement != '';
}); });
const workflowError = ref(false)
const workflowIsError = (isError) => {
workflowError.value = isError
}
// 滚动到底部 // 滚动到底部
const scrollToBottom = async () => { const scrollToBottom = async () => {
if (scrollbarRef.value) { if (scrollbarRef.value) {
...@@ -148,6 +124,12 @@ watch(() => props.historyMsgList, (newValue) => { ...@@ -148,6 +124,12 @@ watch(() => props.historyMsgList, (newValue) => {
}, {immediate: true}) }, {immediate: true})
}) })
watch(() => taskStore.isLoading, (newValue) => {
if (!newValue) {
clearInterval(scrollTimer.value)
}
})
defineExpose({ defineExpose({
resetChat resetChat
}) })
......
...@@ -72,6 +72,7 @@ const keyword = ref(""); ...@@ -72,6 +72,7 @@ const keyword = ref("");
const filteredList = ref([]); const filteredList = ref([]);
const currentClickItemId = ref(null); const currentClickItemId = ref(null);
const emits = defineEmits(["getHistoryMsg", "refreshConversation"]);
const getHistoryList = async () => { const getHistoryList = async () => {
const historyResult = await difyApi.getChatList({ limit: 100 }); const historyResult = await difyApi.getChatList({ limit: 100 });
list.value = historyResult.data; list.value = historyResult.data;
...@@ -96,6 +97,9 @@ const openDeleteConfirm = (id) => { ...@@ -96,6 +97,9 @@ const openDeleteConfirm = (id) => {
const deleteChat = async (id) => { const deleteChat = async (id) => {
await difyApi.deleteChat(id); await difyApi.deleteChat(id);
getHistoryList(); getHistoryList();
if (taskStore.conversation_id) {
emits("refreshConversation");
}
}; };
// 防抖函数 // 防抖函数
...@@ -121,8 +125,6 @@ const debouncedFilterList = debounce(filterList, 300); // 300 毫秒的防抖时 ...@@ -121,8 +125,6 @@ const debouncedFilterList = debounce(filterList, 300); // 300 毫秒的防抖时
watch(keyword, debouncedFilterList); watch(keyword, debouncedFilterList);
const emits = defineEmits(["getHistoryMsg"]);
const getConversationMsg = async (id) => { const getConversationMsg = async (id) => {
currentClickItemId.value = id; currentClickItemId.value = id;
const result = await difyApi.getChatHistory({ const result = await difyApi.getChatHistory({
......
...@@ -3,7 +3,12 @@ ...@@ -3,7 +3,12 @@
<el-container> <el-container>
<transition name="slide"> <transition name="slide">
<el-aside width="280px" v-show="sideBarHidden"> <el-aside width="280px" v-show="sideBarHidden">
<HistoryList @getHistoryMsg="getHistoryMsg" :isRefreshHistoryList="isRefreshHistoryList" :isResetHistoryItem="isResetHistoryItem"/> <HistoryList
@getHistoryMsg="getHistoryMsg"
:isRefreshHistoryList="isRefreshHistoryList"
:isResetHistoryItem="isResetHistoryItem"
@refreshConversation="refreshConversation"
/>
</el-aside> </el-aside>
</transition> </transition>
<el-container id="main-container"> <el-container id="main-container">
...@@ -11,7 +16,12 @@ ...@@ -11,7 +16,12 @@
<Header @getSideBarStatus="getSideBarStatus" @refreshConversation="refreshConversation" /> <Header @getSideBarStatus="getSideBarStatus" @refreshConversation="refreshConversation" />
</el-header> </el-header>
<el-main> <el-main>
<Chat ref="chatRef" v-if="!refreshChat" :historyMsgList="historyMsgList" @updateHistory="refreshHistoryList"/> <Chat
ref="chatRef"
v-if="!refreshChat"
:historyMsgList="historyMsgList"
@updateHistory="refreshHistoryList"
/>
</el-main> </el-main>
</el-container> </el-container>
</el-container> </el-container>
......
...@@ -84,6 +84,9 @@ const avatarAi = "./avatarAI.svg"; ...@@ -84,6 +84,9 @@ const avatarAi = "./avatarAI.svg";
const clickLike = ref(false) const clickLike = ref(false)
const clickDisLike = ref(false) const clickDisLike = ref(false)
const isReStartWorkflow = ref(false)
const workflowStatus = ref(null)
const props = defineProps({ const props = defineProps({
query: { query: {
type: Array, type: Array,
...@@ -103,8 +106,6 @@ const props = defineProps({ ...@@ -103,8 +106,6 @@ const props = defineProps({
}, },
}); });
const emits = defineEmits(["messageFinished", "workflow-is-error"]);
watch( watch(
() => props.query, () => props.query,
(newValue) => { (newValue) => {
...@@ -120,11 +121,11 @@ watch(() => isLoading.value, (newValue) => { ...@@ -120,11 +121,11 @@ watch(() => isLoading.value, (newValue) => {
taskStore.setIsLoading(newValue) taskStore.setIsLoading(newValue)
}) })
const isReStartWorkflow = ref(false)
const workflowStatus = ref(null)
// 默认支持 SSE 协议 // 默认支持 SSE 协议
async function startSSE(query) { async function startSSE(query) {
try { try {
taskStore.setIsLoading(true)
workflowStatus.value = 'loading';
const chatMessageOptions = difyApi.chatMessage() const chatMessageOptions = difyApi.chatMessage()
const response = await fetch(chatMessageOptions.url, { const response = await fetch(chatMessageOptions.url, {
headers: chatMessageOptions.headers, headers: chatMessageOptions.headers,
...@@ -142,6 +143,7 @@ async function startSSE(query) { ...@@ -142,6 +143,7 @@ async function startSSE(query) {
await startStream({ readableStream }); await startStream({ readableStream });
} catch (err) { } catch (err) {
console.error("Fetch error:", err); console.error("Fetch error:", err);
taskStore.setIsLoading(false)
} }
} }
...@@ -160,9 +162,6 @@ const workflowContent = computed(() => { ...@@ -160,9 +162,6 @@ const workflowContent = computed(() => {
const parsedChunk = JSON.parse(chunk); const parsedChunk = JSON.parse(chunk);
workflowList.push(parsedChunk); workflowList.push(parsedChunk);
if (parsedChunk.event === "workflow_started") { if (parsedChunk.event === "workflow_started") {
workflowStatus.value = 'loading';
console.log("workflow_started", parsedChunk);
taskStore.setTaskId(parsedChunk.task_id); taskStore.setTaskId(parsedChunk.task_id);
taskStore.setConversationId(parsedChunk.conversation_id); taskStore.setConversationId(parsedChunk.conversation_id);
taskStore.setMessageId(parsedChunk.message_id); taskStore.setMessageId(parsedChunk.message_id);
...@@ -171,12 +170,12 @@ const workflowContent = computed(() => { ...@@ -171,12 +170,12 @@ const workflowContent = computed(() => {
if (parsedChunk.event === "error") { if (parsedChunk.event === "error") {
ElMessage.error(parsedChunk.message) ElMessage.error(parsedChunk.message)
workflowStatus.value = 'error'; workflowStatus.value = 'error';
emit('workflow-is-error', true) taskStore.setIsLoading(false)
break; break;
} }
if (parsedChunk.event === "message_end") { if (parsedChunk.event === "message_end") {
workflowStatus.value = 'success'; workflowStatus.value = 'success';
emits("messageFinished", true); taskStore.setIsLoading(false)
} }
} catch (error) { } catch (error) {
// 实际项目中,以项目需要为准 // 实际项目中,以项目需要为准
...@@ -199,7 +198,6 @@ const reStartSSE = () => { ...@@ -199,7 +198,6 @@ const reStartSSE = () => {
// if(workflowItemRef.value) { // if(workflowItemRef.value) {
// workflowItemRef.value.clearWorkflow(); // workflowItemRef.value.clearWorkflow();
// } // }
emits("messageFinished", false);
startSSE(props.query); startSSE(props.query);
console.log('reStartSSE', props.query, props.messageType, props.content) console.log('reStartSSE', props.query, props.messageType, props.content)
}; };
......
...@@ -57,33 +57,6 @@ import { Close, Promotion, Loading } from "@element-plus/icons-vue"; ...@@ -57,33 +57,6 @@ import { Close, Promotion, Loading } from "@element-plus/icons-vue";
import difyApi from "../../apis/difyApi"; import difyApi from "../../apis/difyApi";
import { useTaskStore } from "../../store/task"; import { useTaskStore } from "../../store/task";
const props = defineProps({
loadingFinished: {
type: Boolean,
default: false,
},
workflowError: {
type: Boolean,
default: false,
},
});
watch(
() => props.loadingFinished,
(newValue) => {
senderLoading.value = !newValue;
}
);
watch(
() => props.workflowError,
(newValue) => {
if (newValue) {
senderLoading.value = false;
}
}
);
const taskStore = useTaskStore(); const taskStore = useTaskStore();
const senderRef = ref(); const senderRef = ref();
const senderValue = ref(""); const senderValue = ref("");
...@@ -95,6 +68,10 @@ watch(() => deepThink.value, (newValue) => { ...@@ -95,6 +68,10 @@ watch(() => deepThink.value, (newValue) => {
taskStore.setDeepThink(newValue) taskStore.setDeepThink(newValue)
}) })
watch(() => taskStore.isLoading, (newValue) => {
senderLoading.value = newValue;
})
const emit = defineEmits(["userQuery", "getInputHeight"]); const emit = defineEmits(["userQuery", "getInputHeight"]);
function handleSubmit() { function handleSubmit() {
senderLoading.value = true; senderLoading.value = true;
...@@ -116,6 +93,7 @@ const handleCancel = async () => { ...@@ -116,6 +93,7 @@ const handleCancel = async () => {
await difyApi.stop(taskStore.taskId); await difyApi.stop(taskStore.taskId);
} }
senderLoading.value = false; senderLoading.value = false;
taskStore.setIsLoading(false);
}; };
const changeLoading = (loading) => { const changeLoading = (loading) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment