Iterm.js
5.83 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(window){
function Iterm(){
this.initIterm.apply(this, arguments);
}
Iterm.prototype = {
constructor: Iterm,
options: {
userId: 826920,
languageId: null,
compileCallback: null // 编译回调
},
initIterm: function(options){
var _this = this;
// _this.options = $.extend(this.options, options);
_this.options = Object.assign(this.options, options);
_this.events();
},
events: function(){
var _this = this;
$('#teacherCompileBtn').on('click', function(){ _this.teacherCompile(); })
$('#studentCompileBtn').on('click', function(){ _this.studentCompile(); })
$('#save_compile').on('click', function(){ _this.saveCompile(); })
$('#cancel_compile').on('click', function(){ _this.cancelCompile(); })
},
teacherCompile: function(){
console.log('========================');
console.log(Iterm.prototype.options);
Hourglass.pauseTimer(); // 暂停计时器
recorder.pause(); // 音频暂停
$('.pause-shodow').show()
// 编译时插入操作
var treeNode = null;
var check_tree_time = new Date().getTime();
CodingEditer.addRecord(treeNode, check_tree_time);
var _this = this;
var el = document.querySelector('#teacherCompileBtn');
var userId = _this.options.userId;
var languageId = _this.options.languageId;
compileMode(el, userId, languageId)
},
studentCompile: function(){
var _this = this;
var el = document.querySelector('#studentCompileBtn');
var userId = _this.options.userId;
var languageId = _this.options.languageId;
compileMode(el, userId, languageId)
},
saveCompile: function(){
recodingConf()
var length = CodingEditer.records.length - 1;
CodingEditer.records[length].compile = CodingEditer.compileResultData;
CodingEditer.records[length].content = CodingEditer.compileResultData.content;
CodingEditer.records[length].error = CodingEditer.compileResultData.error;
CodingEditer.records[length].compilerInfo = CodingEditer.compileResultData.compilerInfo;
CodingEditer.records[length].code = CodingEditer.compileResultData.code;
},
cancelCompile: function(){
recodingConf()
}
}
// 继续录制配置
function recodingConf(){
$('.pause-shodow').hide()
Hourglass.pauseTimer();
recorder.pause();
CodingEditer.record_startime = new Date().getTime();
}
// 编译
function compileMode(el, userId, languageId){
var l = Ladda.create(el);
l.start();
// 获取标准输入值
var runtimeArgus = $('#runtimeArgus').val() || '';
var mainPath = Dir.mainPath;
var _fileList = Dir.getTreeData();
var compileData = {
"userId": userId,
"langId": languageId,
"mainPath": mainPath,
"mainArgus": "",
"runtimeArgus": runtimeArgus,
"rand": "123456",
"fileList": _fileList || []
}
console.log(compileData);
$.ajax({
type: "POST",
url: gxb_api + "/gxb-web/programmingMulti/codeRun/api",
data: JSON.stringify(compileData),
dataType: "json",
contentType: "application/json",
success: function(data) {
console.log(data);
$('.pause-shodow img').hide()
$('.pause-shodow .compile-reslut').show()
compileResult(data)
l.remove();
CodingEditer.compileResultData = data;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('.pause-shodow img').remove()
l.remove();
alert('错误');
console.log(XMLHttpRequest);
},
});
}
// 编译结果
function compileResult(data, value) {
var runtimeArgus = value || '';
console.info('compileResult')
if (value != '') {
$('#cmprun-tabs a[href="#stdin"]').tab('show');
$('#stdin input').val(runtimeArgus);
}else{
return;
}
if (data.status == 200) {
$('#cmpinfo').html('<p class="text-warning">' + data.compilerInfo.replace(/\n/g, "<br />") + "</p>");
$('#stderr').html('<p class="text-danger">' + data.error.replace(/\n/g, "<br />") + "</p>");
$('#output').html('<p class="text-success">' + data.content.replace(/\n/g, "<br />") + "</p>");
if(data.compilerInfo.length){
$('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
}else if(data.error.length){
$('#cmprun-tabs a[href="#stderr"]').tab('show');
}else if(data.content.length){
$('#cmprun-tabs a[href="#output"]').tab('show');
}
if(!data.compilerInfo.length){
$('#cmpinfo').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 编译已成功</p>');
}
}else if(data.status == 500){
$('#cmprun-tabs a[href="#stderr"]').tab('show');
$('#stderr').html('<p class="text-danger">' + data.error.replace(/\n/g, "<br />") + "</p>");
}else{
$('#cmpinfo').html('<p class="alert alert-danger"><i class="glyphicon glyphicon-exclamation-sign"></i> 请求失败 </p>');
$('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
}
}
window.Iterm = Iterm
})(window)