#AI
Junjie
14 小时以前 70af762aa04fccfd68f211a9991c9a36f0228dfd
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
42
43
var sse;
 
function startDiagnosis() {
    if (sse) {
        sse.close();
    }
    $('#ai-output').text('');
    $('#start-btn').attr('disabled', true);
    $('#stop-btn').attr('disabled', false);
 
    var url = baseUrl + '/ai/diagnose/runAiStream';
    sse = new EventSource(url);
 
    sse.onmessage = function (e) {
        var curr = $('#ai-output').text();
        $('#ai-output').text(curr + e.data);
    };
 
    sse.onerror = function () {
        $('#start-btn').attr('disabled', false);
        $('#stop-btn').attr('disabled', true);
        if (sse) {
            sse.close();
        }
        layer.msg('连接已关闭或发生错误');
    };
}
 
function stopDiagnosis() {
    if (sse) {
        sse.close();
        sse = null;
    }
    $('#start-btn').attr('disabled', false);
    $('#stop-btn').attr('disabled', true);
}
 
$(function () {
    $('#stop-btn').attr('disabled', true);
    $('#start-btn').on('click', startDiagnosis);
    $('#stop-btn').on('click', stopDiagnosis);
    $('#clear-btn').on('click', function () { $('#ai-output').text(''); });
});