ToolBox.js 4.37 KB
;(function(window){
    var ToolBox = {
        compileMode: function(userId, languageid){
            // 获取标准输入值
            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);

                    compileResult(data)
                    ladda.remove();

                    CodingEditer.compileResultData = data;
                    
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    ladda.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.ToolBox = ToolBox;
})(window)



// 云编译
// function compileRun(ladda){
//     // 获取标准输入值
//     var runtimeArgus = $('#runtimeArgus').val() || '';

//     fileList = ZTREE.getTreeData();
//     console.log(fileList);
//     if(!fileList){
//         alert('请输入代码');
//         ladda.remove();
//         return false;
//     }
//     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);

//             compileResult(data)
//             ladda.remove();

//             $('.compile-loading').hide();
//             $('.compile-reslut').show();
//             GBCodePlayBack.compileResultData = data;
            
//         },
//         error: function(XMLHttpRequest, textStatus, errorThrown) {
//             ladda.remove();
//             alert('错误');
//             console.log(XMLHttpRequest);
//         },
//     });
// }