gerson
2024-09-07 37179a65229455f540dc3ca62d31c4716e15d12d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { ref } from 'vue';
import { getQuestionProcess } from '/@/api/ai/chat';
 
export const useQueryProcess = () => {
    const processId = ref('');
    const QUERY_PROCESS_INTERVAL = 1000;
    const process = ref('');
    let processTimer = null;
    let finishProcess = true;
 
    const queryProcessApi = async () => {
        const res = await getQuestionProcess({
            process_id: processId.value,
        }).catch((err) => {
            process.value = err;
        });
 
        process.value = res.process;
        finishProcess = true;
    };
 
    const queryProcess = () => {
        processTimer = setInterval(() => {
            if (!finishProcess) return;
            finishProcess = false;
            queryProcessApi();
        }, QUERY_PROCESS_INTERVAL);
    };
 
    const clearQueryProcess = () => {
        process.value = '';
        clearInterval(processTimer);
    };
 
    return {
        processId,
        process,
        queryProcess,
        clearQueryProcess
    };
};