File tree Expand file tree Collapse file tree 1 file changed +28
-8
lines changed
ui/src/views/knowledge-workflow/component/action Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -21,18 +21,38 @@ const state = computed(() => {
2121 return ' PADDING'
2222})
2323const knowledge_action = ref <any >()
24+ let pollingTimer: any = null
25+
2426const getKnowledgeWorkflowAction = () => {
25- knowledgeApi .getWorkflowAction (props .knowledge_id , props .id ).then ((ok ) => {
26- knowledge_action .value = ok .data
27- if ([' SUCCESS' , ' FAILURE' , ' REVOKED' ].includes (state .value )) {
28- clearInterval (polling )
29- }
30- })
27+ knowledgeApi .getWorkflowAction (props .knowledge_id , props .id )
28+ .then ((ok ) => {
29+ knowledge_action .value = ok .data
30+ if ([' SUCCESS' , ' FAILURE' , ' REVOKED' ].includes (state .value )) {
31+ stopPolling ()
32+ } else {
33+ // 请求完成后再设置下次轮询
34+ pollingTimer = setTimeout (getKnowledgeWorkflowAction , 2000 )
35+ }
36+ })
37+ .catch (() => {
38+ // 错误时也继续轮询
39+ pollingTimer = setTimeout (getKnowledgeWorkflowAction , 2000 )
40+ })
41+ }
42+
43+ const stopPolling = () => {
44+ if (pollingTimer ) {
45+ clearTimeout (pollingTimer )
46+ pollingTimer = null
47+ }
3148}
32- const polling = setInterval (getKnowledgeWorkflowAction , 2000 )
49+
50+ // 启动轮询
51+ getKnowledgeWorkflowAction ()
3352
3453onUnmounted (() => {
35- clearInterval ( polling )
54+ stopPolling ( )
3655})
56+
3757 </script >
3858<style lang="scss"></style >
You can’t perform that action at this time.
0 commit comments