student.js
4.24 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
$(function() {
var teacherId = document.getElementById('teacher');
var studentId = document.getElementById('student');
// var socket = io('https://live-api.gaoxiaobang.com');
var socket = io('http://localhost:5000');
var teacher = CodeMirror.fromTextArea(teacherId, {
value: '输入HTML代码',
mode: 'text/x-java',
readOnly: true,
lineNumbers: true,
smartIndent: false
});
var student = CodeMirror.fromTextArea(studentId, {
value: '输入HTML代码',
mode: 'text/x-java',
lineNumbers: true,
smartIndent: false
});
// 标准输入
socket.on('start.live', function(msg) {
console.log('start.live ---- ' + msg);
var seconds = 2;
$('.countdown').show();
var countdown = setInterval(function() {
$(".countdown h1").html(seconds);
seconds = seconds - 1;
if (seconds == -1) {
$(".countdown").hide();
clearInterval(countdown);
//
socket.on('teacher.programming', function(msg) {
console.log(msg);
var msgObj = JSON.parse(msg)
// student.setValue(msg)
processChangeObject(teacher, msgObj);
$('#messages').append($('<li>').text(msg));
window.scrollTo(0, document.body.scrollHeight);
});
}
}, 1000);
});
// 同步代码内容
socket.on('programming.content', function(msg) {
teacher.setValue(msg);
});
// 选中 input
socket.on('select.menu', function(msg) {
console.log('select.menu ---- ' + msg);
$('#runtimeArgus').addClass('effect-2');
});
// 标准输入
socket.on('stdin.value', function(msg) {
console.log('stdin.value ---- ' + msg);
$('#runtimeArgus').val(msg)
});
// 切换 tab
socket.on('check.tab', function(msg) {
console.log('check.tab ---- ' + msg);
if(msg === 0){
$('#cmprun-tabs a[href="#stdin"]').tab('show');
}else if(msg === 1){
$('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
}else if(msg === 2){
$('#cmprun-tabs a[href="#stderr"]').tab('show');
}else if(msg === 3){
$('#cmprun-tabs a[href="#output"]').tab('show');
}
// $('#runtimeArgus').val(msg)
});
socket.on('programming.compile', function(msg) {
console.log('-------------');
console.log(msg);
// $('#CompileBtn').trigger('click');
console.log('编译' + teacher.getValue());
var el = document.querySelector('#CompileBtn')
var l = Ladda.create(el);
l.start();
var input = $('#input').val() || '';
var code = teacher.getValue();
var compileData = {
code: code,
langid: 10,
input: input
}
$.ajax({
type: "post",
url: gxb_api + "/submit/submitCode/api",
data: JSON.stringify(compileData),
dataType: "json",
contentType: "application/json",
success: function(data) {
console.log(data);
l.remove();
compileResult(data);
},
error: function(){
l.stop();
alert('错误');
}
});
});
$('#studCompile').on('click', function(){
var el = document.querySelector('#studCompile')
var l = Ladda.create(el);
l.start();
var input = $('#input').val() || '';
var code = student.getValue();
var compileData = {
code: code,
langid: 10,
input: input
}
$.ajax({
type: "post",
url: gxb_api + "/submit/submitCode/api",
data: JSON.stringify(compileData),
dataType: "json",
contentType: "application/json",
success: function(data) {
console.log(data);
l.remove();
studCompileResult(data);
},
error: function(){
l.stop();
alert('错误');
}
});
})
});