@ -1,21 +1,9 @@
import React , { Component } from 'react' ;
import React , { Component , Fragment } from 'react' ;
import ReactDOM from 'react-dom' ;
import axios from 'axios' ;
import Snackbar from 'material-ui/Snackbar' ;
import Fade from 'material-ui/transitions/Fade' ;
import update from 'immutability-helper'
import Dialog , {
DialogActions ,
DialogContent ,
DialogContentText ,
DialogTitle ,
} from 'material-ui/Dialog' ;
import Button from 'material-ui/Button' ;
import { Modal , Button , Alert } from 'antd'
import EvaluateSuccessEffectDisplay from './EvaluateSuccessEffectDisplay'
import _ from 'lodash'
@ -31,28 +19,15 @@ import _ from 'lodash'
* /
import TPIContext from './TPIContext'
import { EDU _ADMIN , EDU _SHIXUN _MANAGER , EDU _SHIXUN _MEMBER , EDU _CERTIFICATION _TEACHER
, EDU _GAME _MANAGER , EDU _TEACHER , EDU _NORMAL , EDU _BUSINESS , CNotificationHOC , getRandomNumber } from 'educoder'
import { MuiThemeProvider , createMuiTheme , withStyles } from 'material-ui/styles' ;
import MUIDialogStyleUtil from '../modules/page/component/MUIDialogStyleUtil'
const styles = MUIDialogStyleUtil . getTwoButtonStyle ( )
// 主题自定义
const theme = createMuiTheme ( {
palette : {
primary : {
main : '#4CACFF' ,
contrastText : 'rgba(255, 255, 255, 0.87)'
} ,
secondary : { main : '#4CACFF' } , // This is just green.A700 as hex.
} ,
} ) ;
import {
EDU _ADMIN , EDU _SHIXUN _MANAGER , EDU _SHIXUN _MEMBER , EDU _CERTIFICATION _TEACHER
, EDU _TEACHER , EDU _NORMAL , EDU _BUSINESS , CNotificationHOC , getRandomNumber
} from 'educoder'
const testSetsExpandedArrayInitVal = [ false , false , false , false , false ,
false , false , false , false , false ,
false , false , false , false , false ,
false , false , false , false , false ]
false , false , false , false , false ,
false , false , false , false , false ,
false , false , false , false , false ]
window . _ _fetchAllFlag = false ; // 是否调用过fetchAll TODO 如何多次使用provider?
const $ = window . $
@ -105,11 +80,11 @@ class TPIContextProvider extends Component {
const dom = document . getElementById ( 'picture_display' ) ;
window . $ ( dom ) . show ( ) ;
ReactDOM . unmountComponentAtNode ( dom )
ReactDOM . render ( < EvaluateSuccessEffectDisplay type = { "qrcode" } { ... data } / > , dom ) ;
ReactDOM . render ( < EvaluateSuccessEffectDisplay type = { "qrcode" } { ... data } / > , dom ) ;
}
onShowUpdateDialog ( ) {
this . setState ( { showUpdateDialog : true } )
this . setState ( { showUpdateDialog : true } )
}
// updateNowSuccess true 立即更新成功
// TODO updateDialogClose方法名不对, 改为updateDialogCallback
@ -138,19 +113,18 @@ class TPIContextProvider extends Component {
}
componentWillUnmount ( ) {
this . _updateCostTime ( ) ;
this . costTimeInterval && window . clearInterval ( this . costTimeInterval )
}
componentDidMount ( ) {
// TODO 登录状态的判断?
// request
// var shixunId = this.props.match.params.shixunId;
var stageId = this . props . match . params . stageId ;
var stageId = this . props . match . params . stageId ;
window . _ _fetchAllFlag = false ;
this . fetchAll ( stageId ) ;
this . costTimeInterval = window . setInterval ( ( ) => {
this . costTimeInterval = window . setInterval ( ( ) => {
const { game } = this . state ;
if ( ! game || game . status === 2 ) { // 已完成的任务不需要计时
return ;
@ -158,55 +132,35 @@ class TPIContextProvider extends Component {
if ( game . cost _time || game . cost _time === 0 ) {
// game.cost_time += 1;
this . setState ( {
game : update ( game , { cost _time : { $set : ( game . cost _time + 1 ) } } )
game : update ( game , { cost _time : { $set : ( game . cost _time + 1 ) } } )
} )
}
} , 1000 )
// // 页面离开时存下用户的任务耗时
window . $ ( window ) . bind ( 'beforeunload' , ( ) => {
this . _updateCostTime ( ) ;
} )
// window.$(window).unload( ()=>{
// this._updateCostTime();
// });
// // 页面离开时存下用户的任务耗时
// window.$(window).unload( ()=>{
// this._updateCostTime();
// });
}
// force 评测通过后, 异步执行该方法, 强制同步costTime到服务端
_updateCostTime ( async = false , force ) {
const { game , loading } = this . state ;
// TODO 还有一种情况, 通关后cost_time计时停止, 没法通过这个判断
if ( ! force && ( loading || ! game || game . status === 2 ) ) {
return ; // 已完成的任务不需要处理
}
if ( ! force && ( loading || ! game || game . status === 2 ) ) {
return ; // 已完成的任务不需要处理
}
let testPath = ''
if ( window . location . port == 3007 ) {
testPath = 'http://test-newweb.educoder.net'
}
// var url = `${testPath}/api/v1/games/${ game.identifier }/cost_time`
var url = ` ${ testPath } /api/tasks/ ${ game . identifier } /cost_time ${ getRandomNumber ( ) } `
window . $ . ajax ( {
type : 'get' ,
url : url ,
async : async , //IMPORTANT, the call will be synchronous
data : {
time : game . cost _time
}
} ) . done ( ( data ) => {
console . log ( 'complete' ) ;
} ) ;
var url = ` ${ testPath } /api/tasks/ ${ game . identifier } /cost_time ${ getRandomNumber ( ) } `
window . $ . ajax ( {
type : 'get' ,
url : url ,
async : async , //IMPORTANT, the call will be synchronous
data : {
time : game . cost _time
}
} ) . done ( ( data ) => {
console . log ( 'complete' ) ;
} ) ;
}
onGamePassed ( passed ) {
@ -214,7 +168,7 @@ class TPIContextProvider extends Component {
// 随便给个分, 以免重新评测时又出现评星组件( 注意: 目前game.star没有显示在界面上, 如果有则不能这么做)
// game.star = 6;
this . setState ( {
game : update ( game , { star : { $set : 6 } } ) ,
game : update ( game , { star : { $set : 6 } } ) ,
currentGamePassed : ! ! passed
} )
}
@ -251,40 +205,31 @@ class TPIContextProvider extends Component {
}
// praise_tread/praise_plus?obj_id=569&obj_type=Challenge&horizontal=true&game_praise=true
/ *
TODO 旧的接口在未登录时的返回值
//获取登录页面地址
var signinPath = '/' ;
var htmlvalue = '<div class="task-popup" style="width:480px;"><div class="task-popup-title clearfix"><h3 class="fl color-grey3">提示</h3></div>' +
'<div class="task-popup-content"><p class="task-popup-text-center font-16 mt10 mb10">您还没有登录,请登录后再执行此操作,谢谢!</p></div><div class="task-popup-right-sure clearfix">' +
'<a href="javascript:void(0);" onclick="hideModal();" class="task-btn">取消</a><a href="' + signinPath + '" class="task-btn task-btn-orange ml15">登录</a></div></div>' ;
pop _box _new ( htmlvalue , 480 , 182 ) ;
* /
praisePlus ( ) {
const { challenge , game } = this . state ;
let praise = true ;
const url = ` /tasks/ ${ game . identifier } /plus_or_cancel_praise.json `
// const url = `/praise_tread/praise_plus?obj_id=${challenge.id}&obj_type=Challenge&horizontal=${praise}&game_praise=true`
axios . post ( url )
. then ( ( response ) => {
if ( response . data ) {
const { praise _count , praise } = response . data ;
// challenge.praise_count = praise_tread_count;
// challenge.user_praise = praise;
this . setState ( { challenge : update ( challenge ,
{
praise _count : { $set : praise _count } ,
user _praise : { $set : praise } ,
} )
} )
}
} )
. catch ( function ( error ) {
console . log ( error ) ;
} ) ;
. then ( ( response ) => {
if ( response . data ) {
const { praise _count , praise } = response . data ;
// challenge.praise_count = praise_tread_count;
// challenge.user_praise = praise;
this . setState ( {
challenge : update ( challenge ,
{
praise _count : { $set : praise _count } ,
user _praise : { $set : praise } ,
} )
} )
}
} )
. catch ( function ( error ) {
console . log ( error ) ;
} ) ;
}
onPathChange ( index , callback ) {
@ -292,7 +237,7 @@ pop_box_new(htmlvalue, 480, 182);
// challenge = Object.assign({}, challenge)
// challenge.pathIndex = index;
this . setState ( {
challenge : update ( challenge , { pathIndex : { $set : index } } ) ,
challenge : update ( challenge , { pathIndex : { $set : index } } ) ,
} , ( ) => {
callback && callback ( )
} )
@ -310,25 +255,26 @@ pop_box_new(htmlvalue, 480, 182);
challenge . path = path ;
const newChallenge = this . handleChallengePath ( challenge ) ;
this . setState ( { challenge : newChallenge ,
myshixun : update ( myshixun , { system _tip : { $set : false } } ) ,
this . setState ( {
challenge : newChallenge ,
myshixun : update ( myshixun , { system _tip : { $set : false } } ) ,
} )
}
handleChallengePath ( challenge ) {
if ( challenge . path && typeof challenge . path === "string" ) { // 多path的处理
let path = challenge . path . split ( '; ' ) ;
_ . remove ( path , ( item ) => ! item )
if ( path . length > 1 ) {
challenge . path = path ;
challenge . multiPath = true ;
} else {
challenge . path = challenge . path . replace ( '; ' , '' ) . trim ( ) // 多path 改为单path 出现了 aaa.java; 的情况
challenge . multiPath = false ;
}
}
challenge . pathIndex = 0 ;
return challenge ;
let path = challenge . path . split ( '; ' ) ;
_ . remove ( path , ( item ) => ! item )
if ( path . length > 1 ) {
challenge . path = path ;
challenge . multiPath = true ;
} else {
challenge . path = challenge . path . replace ( '; ' , '' ) . trim ( ) // 多path 改为单path 出现了 aaa.java; 的情况
challenge . multiPath = false ;
}
}
challenge . pathIndex = 0 ;
return challenge ;
}
newResData2OldResData ( newResData ) {
@ -350,89 +296,82 @@ pop_box_new(htmlvalue, 480, 182);
newResData . output _sets . test _sets _count = newResData . test _sets _count
// newResData.output_sets.had_passed_testsests_error_count = newResData.sets_error_count
newResData . output _sets . had _passed _testsests _error _count = newResData . test _sets _count
- newResData . sets _error _count
// allowed_hidden_testset
// sets_error_count
// test_sets_count
// test_sets
// had_passed_testsests_error_count
// test_sets
// test_sets
- newResData . sets _error _count
return newResData
}
// 将若干数据重新组织一下
_handleResponseData ( resData _arg ) {
const resData = this . newResData2OldResData ( Object . assign ( { } , resData _arg ) )
let challenge = resData . challenge ;
challenge . isHtml = false ;
challenge . isWeb = false ;
challenge . isAndroid = false ;
challenge . showLanguagePictrue = false ;
challenge . hasAnswer = resData . has _answer ;
let output _sets = resData . output _sets ;
let challenge = resData . challenge ;
challenge . isHtml = false ;
challenge . isWeb = false ;
challenge . isAndroid = false ;
challenge . showLanguagePictrue = false ;
challenge . hasAnswer = resData . has _answer ;
let output _sets = resData . output _sets ;
if ( resData . st === 0 ) { // 代码题
challenge = this . handleChallengePath ( challenge )
const mirror _name = ( resData . mirror _name && resData . mirror _name . join )
? resData . mirror _name . join ( ';' ) : ( resData . mirror _name || '' ) ;
if ( mirror _name . indexOf ( 'Html' ) !== - 1 ) {
challenge . isHtml = true ;
challenge . showLanguagePictrue = true ;
} else if ( mirror _name . indexOf ( 'Web' ) !== - 1 || mirror _name . indexOf ( 'JFinal' ) !== - 1 ) {
challenge . isWeb = true ;
} else if ( mirror _name . indexOf ( 'Android' ) !== - 1 ) {
challenge . isAndroid = true ;
}
if ( output _sets && output _sets . test _sets && typeof output _sets . test _sets == 'string' ) {
const test _sets _array = JSON . parse ( "[" + output _sets . test _sets + "]" ) ;
output _sets . test _sets _array = test _sets _array ;
} else {
output _sets . test _sets _array = output _sets . test _sets
}
} else { // 选择题
// 选择题题干markdown初始化
const $ = window . $
window . setTimeout ( ( ) => {
challenge = this . handleChallengePath ( challenge )
const mirror _name = ( resData . mirror _name && resData . mirror _name . join )
? resData . mirror _name . join ( ';' ) : ( resData . mirror _name || '' ) ;
if ( mirror _name . indexOf ( 'Html' ) !== - 1 ) {
challenge . isHtml = true ;
challenge . showLanguagePictrue = true ;
} else if ( mirror _name . indexOf ( 'Web' ) !== - 1 || mirror _name . indexOf ( 'JFinal' ) !== - 1 ) {
challenge . isWeb = true ;
} else if ( mirror _name . indexOf ( 'Android' ) !== - 1 ) {
challenge . isAndroid = true ;
}
if ( output _sets && output _sets . test _sets && typeof output _sets . test _sets == 'string' ) {
const test _sets _array = JSON . parse ( "[" + output _sets . test _sets + "]" ) ;
output _sets . test _sets _array = test _sets _array ;
} else {
output _sets . test _sets _array = output _sets . test _sets
}
} else { // 选择题
// 选择题题干markdown初始化
const $ = window . $
window . setTimeout ( ( ) => {
var lens = $ ( "#choiceRepositoryView textarea" ) . length ;
for ( var i = 1 ; i <= lens ; i ++ ) {
window . editormd . markdownToHTML ( "choose_subject_" + i , {
htmlDecode : "style,script,iframe" , // you can filter tags decode
taskList : true ,
tex : true , // 数学公式
// flowChart: true, // 默认不解析
// sequenceDiagram: true // 默认不解析
} ) ;
}
} , 400 )
}
challenge . user _praise = resData . user _praise ;
challenge . praise _count = resData . praise _count ;
challenge . showWebDisplayButton = false ;
resData . challenge = challenge ;
// 将一些属性写到game上
let game = resData . game ;
game . prev _game = resData . prev _game ;
game . next _game = resData . next _game ;
for ( var i = 1 ; i <= lens ; i ++ ) {
window . editormd . markdownToHTML ( "choose_subject_" + i , {
htmlDecode : "style,script,iframe" , // you can filter tags decode
taskList : true ,
tex : true , // 数学公式
// flowChart: true, // 默认不解析
// sequenceDiagram: true // 默认不解析
} ) ;
}
} , 400 )
}
challenge . user _praise = resData . user _praise ;
challenge . praise _count = resData . praise _count ;
challenge . showWebDisplayButton = false ;
resData . challenge = challenge ;
// 将一些属性写到game上
let game = resData . game ;
game . prev _game = resData . prev _game ;
game . next _game = resData . next _game ;
if ( game . status == 2 ) {
// 已通关
game . isPassThrough = true
}
resData . game = game ;
resData . game = game ;
const { tpm _cases _modified , tpm _modified , tpm _script _modified , myshixun } = resData ;
if ( myshixun . system _tip ) {
const { tpm _cases _modified , tpm _modified , tpm _script _modified , myshixun } = resData ;
if ( myshixun . system _tip ) {
// system_tip为true的时候 不弹框提示用户更新
resData . showUpdateDialog = false
} else {
let needUpdateScript = ( tpm _modified || tpm _script _modified ) && challenge . st === 0 ;
resData . showUpdateDialog = needUpdateScript || tpm _cases _modified
}
resData . showUpdateDialog = false
} else {
let needUpdateScript = ( tpm _modified || tpm _script _modified ) && challenge . st === 0 ;
resData . showUpdateDialog = needUpdateScript || tpm _cases _modified
}
/ * *
email : "721773699@qq.com"
@ -443,29 +382,29 @@ pop_box_new(htmlvalue, 480, 182);
name : "Coder"
user _url : "/users/innov"
* /
let user = resData . user ;
user . username = resData . user . name ;
user . user _url = ` /users/ ${ resData . user . login } ` ;
// user.image_url = resData.image_url;
user . is _teacher = resData . is _teacher ;
resData . user = user ;
this . _handleUserAuthor ( resData )
// TODO 测试
// resData.power = 0;
let user = resData . user ;
user . username = resData . user . name ;
user . user _url = ` /users/ ${ resData . user . login } ` ;
// user.image_url = resData.image_url;
user . is _teacher = resData . is _teacher ;
resData . user = user ;
this . _handleUserAuthor ( resData )
// TODO 测试
// resData.power = 0;
resData . shixun . vnc = ! ! resData . vnc _url
resData . shixun . vnc _evaluate = resData . vnc _evaluate
this . setState ( {
... resData ,
currentGamePassed : false ,
loading : false ,
testSetsExpandedArray : testSetsExpandedArrayInitVal . slice ( 0 ) ,
} )
this . setState ( {
... resData ,
currentGamePassed : false ,
loading : false ,
testSetsExpandedArray : testSetsExpandedArrayInitVal . slice ( 0 ) ,
} )
window . document . title = resData . shixun . name
window . document . title = resData . shixun . name
window . _ _myshixun = resData . myshixun ; // tpi_html_show需要用到
window . _ _myshixun = resData . myshixun ; // tpi_html_show需要用到
}
_handleUserAuthor ( resData ) {
// tpi tpm权限控制
@ -522,7 +461,7 @@ pop_box_new(htmlvalue, 480, 182);
fetchAll ( stageId , noTimeout ) {
if ( window . _ _fetchAllFlag == true ) {
if ( window . _ _fetchAllFlag == true ) {
console . log ( 'TPIContextProvider call fetchAll repeatly!' )
return ;
}
@ -541,9 +480,9 @@ pop_box_new(htmlvalue, 480, 182);
this . setState ( {
loading : true ,
currentGamePassed : false , // 切换game时重置passed字段
} )
loading : true ,
currentGamePassed : false , // 切换game时重置passed字段
} )
// test
// var data = {"st":0,"discusses_count":0,"game_count":3,"record_onsume_time":0.36,"prev_game":null,"next_game":"7p9xwo2hklqv","praise_count":0,"user_praise":false,"time_limit":20,"tomcat_url":"http://47.96.157.89","is_teacher":false,"myshixun_manager":true,"game":{"id":2192828,"myshixun_id":580911,"user_id":57844,"created_at":"2019-09-03T15:50:49.000+08:00","updated_at":"2019-09-03T15:51:05.000+08:00","status":2,"final_score":0,"challenge_id":10010,"open_time":"2019-09-03T15:50:49.000+08:00","identifier":"hknvz4oaw825","answer_open":0,"end_time":"2019-09-03T15:51:04.000+08:00","retry_status":0,"resubmit_identifier":null,"test_sets_view":false,"picture_path":null,"accuracy":1.0,"modify_time":"2019-09-03T15:23:33.000+08:00","star":0,"cost_time":14,"evaluate_count":1,"answer_deduction":0},"challenge":{"id":10010,"shixun_id":3516,"subject":"1.1 列表操作","position":1,"task_pass":"[TOC]\n\n---\n\n####任务描述\n\n\n数据集a包含1-10共10个整数, 请以a为输入数据, 编写python程序, 实现如下功能: \n①\t用2种方法输出a中所有奇数\n②\t输出大于3, 小于7的偶数\n③\t用2种方法输出[1,2,3,…10,11,…20]\n④\t输出a的最大值、最小值。\n⑤\t用2种方法输出[10,9,…2,1]\n⑥\t输出[1,2,3,1,2,3,1,2,3,1,2,3]\n\n\n####相关知识\n\n\n请自行学习相关知识\n\n\n---\n开始你的任务吧, 祝你成功! ","score":100,"path":"1-1-stu.py","st":0,"web_route":null,"modify_time":"2019-09-03T15:23:33.000+08:00","exec_time":20,"praises_count":0},"shixun":{"id":3516,"name":"作业1——Python程序设计","user_id":77620,"gpid":null,"visits":23,"created_at":"2019-09-03T14:18:17.000+08:00","updated_at":"2019-09-03T15:58:16.000+08:00","status":0,"language":null,"authentication":false,"identifier":"6lzjig58","trainee":1,"major_id":null,"webssh":2,"homepage_show":false,"hidden":false,"fork_from":null,"can_copy":true,"modify_time":"2019-09-03T14:18:17.000+08:00","reset_time":"2019-09-03T14:18:17.000+08:00","publish_time":null,"closer_id":null,"end_time":null,"git_url":null,"vnc":null,"myshixuns_count":3,"challenges_count":3,"use_scope":0,"mirror_script_id":20,"image_text":null,"code_hidden":false,"task_pass":true,"exec_time":20,"test_set_permission":true,"sigle_training":false,"hide_code":false,"multi_webssh":false,"excute_time":null,"repo_name":"p09218567/6lzjig58","averge_star":5.0,"opening_time":null,"users_count":1,"forbid_copy":false,"pod_life":0},"myshixun":{"id":580911,"shixun_id":3516,"is_public":true,"user_id":57844,"gpid":null,"created_at":"2019-09-03T15:50:49.000+08:00","updated_at":"2019-09-03T15:59:04.000+08:00","status":0,"identifier":"k36hm4rwav","commit_id":"f25e1713882156480fc45ce0af57eff395a5037f","modify_time":"2019-09-03T14:18:17.000+08:00","reset_time":"2019-09-03T14:18:17.000+08:00","system_tip":false,"git_url":null,"onclick_time":"2019-09-03T15:50:49.000+08:00","repo_name":"p53276410/k36hm4rwav20190903155049"},"user":{"user_id":57844,"login":"p53276410","name":"文振乾","grade":24624,"identity":1,"image_url":"avatars/User/57844","school":"EduCoder团队"},"tpm_modified":true,"tpm_cases_modified":false,"mirror_name":["Python3.6"],"has_answer":false,"test_sets":[{"is_public":true,"result":true,"input":"","output":"result of a:\n[1, 3, 5, 7, 9]\n[1, 3, 5, 7, 9]\nresult of b:\n[2, 4, 6, 8, 10]\nresult of c:\n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\nresult of d:\nThe minimum is:1\nThe maxium is:10\nresult of e:\n[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\nresult of f:\n[10, 9, 8, 10, 9, 8, 10, 9, 8, 10, 9, 8]\n","actual_output":"result of a:\r\n[1, 3, 5, 7, 9]\r\n[1, 3, 5, 7, 9]\r\nresult of b:\r\n[2, 4, 6, 8, 10]\r\nresult of c:\r\n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\r\n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\r\nresult of d:\r\nThe minimum is:1\r\nThe maxium is:10\r\nresult of e:\r\n[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\r\n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\nresult of f:\r\n[10, 9, 8, 10, 9, 8, 10, 9, 8, 10, 9, 8]\r\n","compile_success":1,"ts_time":0.05,"ts_mem":8.77}],"allowed_unlock":true,"last_compile_output":"compile successfully","test_sets_count":1,"sets_error_count":0}
@ -557,19 +496,19 @@ pop_box_new(htmlvalue, 480, 182);
// return
axios . get ( url , {
// https://stackoverflow.com/questions/48861290/the-value-of-the-access-control-allow-origin-header-in-the-response-must-not-b
// withCredentials: true,
} )
. then ( ( response ) => {
// {"status":1,"message":"Unauthorized. \u7528\u6237\u8ba4\u8bc1\u5931\u8d25."}
// https://stackoverflow.com/questions/48861290/the-value-of-the-access-control-allow-origin-header-in-the-response-must-not-b
// withCredentials: true,
} )
. then ( ( response ) => {
// {"status":1,"message":"Unauthorized. \u7528\u6237\u8ba4\u8bc1\u5931\u8d25."}
window . _ _fetchAllFlag = false ;
if ( response . data . status == 403 ) {
if ( response . data . status == 403 ) {
window . location . href = "/403" ;
return ;
}
if ( response . data . status == 404 ) {
return ;
}
if ( response . data . status == 404 ) {
// 如果第一次发生404, 则隔1s后再调用一次本接口; ( 因为ucloud主从同步可能有延迟)
if ( ! noTimeout ) {
setTimeout ( ( ) => {
@ -577,16 +516,16 @@ pop_box_new(htmlvalue, 480, 182);
} , 1000 )
return ;
}
window . location . href = '/myshixuns/not_found'
return ;
}
window . location . href = '/myshixuns/not_found'
return ;
}
this . _handleResponseData ( response . data )
this . _handleResponseData ( response . data )
} )
. catch ( function ( error ) {
console . log ( error ) ;
} ) ;
} )
. catch ( function ( error ) {
console . log ( error ) ;
} ) ;
}
@ -595,7 +534,7 @@ pop_box_new(htmlvalue, 480, 182);
if ( resData . final _score ) {
var game = this . state . game ;
this . setState ( {
game : update ( game , { final _score : { $set : resData . final _score } } ) ,
game : update ( game , { final _score : { $set : resData . final _score } } ) ,
grade : resData . grade
} )
} else {
@ -609,7 +548,7 @@ pop_box_new(htmlvalue, 480, 182);
this . setState ( {
game : ( this . state . game . status == 2 ? update ( this . state . game , {
isPassThrough : { $set : true } ,
} ) : this . state . game ) ,
} ) : this . state . game ) ,
currentGamePassed : false
} )
}
@ -645,10 +584,11 @@ pop_box_new(htmlvalue, 480, 182);
window . clearTimeout ( this . showWebDisplayButtonTimeout )
}
this . showWebDisplayButtonTimeout = window . setTimeout ( ( ) => {
this . setState ( { challenge : update ( challenge ,
{
showWebDisplayButton : { $set : false } ,
} )
this . setState ( {
challenge : update ( challenge ,
{
showWebDisplayButton : { $set : false } ,
} )
} )
this . showWebDisplayButtonTimeout = null
} , 61 * 1000 )
@ -677,52 +617,28 @@ pop_box_new(htmlvalue, 480, 182);
language _display ( data ) {
const { game , tomcat _url } = this . state ;
const challenge = Object . assign ( { } , this . state . challenge )
if ( challenge . isWeb && data . port != - 1 ) {
// var $result = $("#php_display");
challenge . showWebDisplayButton = true ; // ActionView处是否出现查看效果按钮
if ( challenge . isWeb && data . port != - 1 ) {
// var $result = $("#php_display");
challenge . showWebDisplayButton = true ; // ActionView处是否出现查看效果按钮
this . initDisplayInterval ( )
const path = challenge . web _route || challenge . path
const webDisplayUrl = ` ${ tomcat _url } : ${ data . port } / ${ path } `
challenge . webDisplayUrl = webDisplayUrl
challenge . showLanguagePictrue = true ; // 评测通过弹出层是否出现查看效果按钮
}
// else if(challenge.isAndroid && data.picture != 0){
// // https://www.educoder.net/shixuns/qrcode?game_id=218589&_=1525571882782
// $.ajax({
// url: `/shixuns/qrcode?game_id=${game.id}`,
// dataType: 'script'
// });
// challenge.showLanguagePictrue = true;
// }
else if ( data . picture != 0 ) {
// 对应服务端erb文件为 _picture_display.html.erb
// $.ajax({
// url: "/users/picture_show?game_id="+data.picture,
// cache: false,
// dataType: 'script'
// });
/ * *
{
"type" : "image" ,
"orignal_picture" : [ ] ,
"user_picture" : [ ] ,
"answer_picture" : [ ]
}
* /
const path = challenge . web _route || challenge . path
const webDisplayUrl = ` ${ tomcat _url } : ${ data . port } / ${ path } `
challenge . webDisplayUrl = webDisplayUrl
challenge . showLanguagePictrue = true ; // 评测通过弹出层是否出现查看效果按钮
}
else if ( data . picture != 0 ) {
const url = ` /tasks/ ${ game . identifier } /picture_display.json `
axios . get ( url )
. then ( ( response ) => {
// response.data.type qrcode_str
. then ( ( response ) => {
this . showEffectDisplay ( response . data )
} )
challenge . showLanguagePictrue = true ;
}
this . setState ( {
challenge
} )
challenge . showLanguagePictrue = true ;
}
this . setState ( {
challenge
} )
}
onRunCodeTestFinish ( response ) {
console . log ( 'onRunCodeTestFinish' , response )
@ -730,7 +646,7 @@ pop_box_new(htmlvalue, 480, 182);
, had _test _count , had _passed _testsests _error _count , had _passed _testsests _hidden _count
, had _passed _testsests _public _count , final _score , gold , experience , latest _output , status
, had _done , score , tag _count , power , record , next _game , grade , picture ,
sets _error _count , last _compile _output , record _consume _time } = response ;
sets _error _count , last _compile _output , record _consume _time } = response ;
const { game } = this . state ;
@ -745,19 +661,19 @@ pop_box_new(htmlvalue, 480, 182);
const output _sets = {
"test_sets" : test _sets ,
"test_sets_array" : test _sets ,
"had_test_count" : had _test _count || test _sets _count ,
"test_sets_count" : test _sets _count ,
// "had_passed_testsests_error_count": had_passed_testsests_error_count,
"had_passed_testsests_error_count" : test _sets _count - sets _error _count ,
"test_sets_hidden_count" : test _sets _hidden _count ,
"test_sets_public_count" : test _sets _public _count ,
"had_passed_testsests_hidden_count" : had _passed _testsests _hidden _count ,
"had_passed_testsests_public_count" : had _passed _testsests _public _count
"had_test_count" : had _test _count || test _sets _count ,
"test_sets_count" : test _sets _count ,
// "had_passed_testsests_error_count": had_passed_testsests_error_count,
"had_passed_testsests_error_count" : test _sets _count - sets _error _count ,
"test_sets_hidden_count" : test _sets _hidden _count ,
"test_sets_public_count" : test _sets _public _count ,
"had_passed_testsests_hidden_count" : had _passed _testsests _hidden _count ,
"had_passed_testsests_public_count" : had _passed _testsests _public _count
} ;
// if (output_sets && output_sets.test_sets) {
// const test_sets_array = JSON.parse("[" + output_sets.test_sets + "]");
// output_sets.test_sets_array = test_sets_array;
// }
// const test_sets_array = JSON.parse("[" + output_sets.test_sets + "]");
// output_sets.test_sets_array = test_sets_array;
// }
// 检查是否编译通过
let compileSuccess = false ;
@ -813,35 +729,35 @@ pop_box_new(htmlvalue, 480, 182);
const { game , challenge } = this . state ;
const url = ` /tasks/ ${ game . identifier } /check_test_sets.json `
axios . get ( url , {
// withCredentials: true,
} )
. then ( ( response ) => {
// withCredentials: true,
} )
. then ( ( response ) => {
// TODO status -2 重复操作,直接解锁
if ( response . data . test _sets == - 1 ) {
console . error ( 'testSetUnlock失败! ' )
this . showSnackbar ( response . data . message )
return ;
} else {
// 被扣除的金币,是负数
const deltaScore = - challenge . score * 5 ;
if ( response . data . test _sets == - 1 ) {
console . error ( 'testSetUnlock失败! ' )
this . showSnackbar ( response . data . message )
return ;
} else {
// 被扣除的金币,是负数
const deltaScore = - challenge . score * 5 ;
// output_sets
let { output _sets } = this . state ;
output _sets = Object . assign ( { } , output _sets ) ;
// const test_sets_array = JSON.parse("[" + response.data.test_sets + "]");
output _sets . test _sets _array = response . data . test _sets ;
this . setState ( {
output _sets . test _sets _array = response . data . test _sets ;
this . setState ( {
output _sets : output _sets ,
grade : this . state . grade + deltaScore ,
game : update ( game , { test _sets _view : { $set : true } } ) ,
testSetsExpandedArray : testSetsExpandedArrayInitVal . slice ( 0 )
} )
this . handleGdialogClose ( ) ;
}
grade : this . state . grade + deltaScore ,
game : update ( game , { test _sets _view : { $set : true } } ) ,
testSetsExpandedArray : testSetsExpandedArrayInitVal . slice ( 0 )
} )
this . handleGdialogClose ( ) ;
}
} )
. catch ( function ( error ) {
console . log ( error ) ;
} ) ;
} )
. catch ( function ( error ) {
console . log ( error ) ;
} ) ;
}
handleSnackbarClose ( ) {
@ -884,9 +800,6 @@ pop_box_new(htmlvalue, 480, 182);
onGdialogOkBtnClick ( ) {
this . dialogOkCallback && this . dialogOkCallback ( ) ;
// this.setState({
// gDialogOpen: true
// })
}
handleGdialogClose = ( ) => {
this . setState ( {
@ -894,96 +807,87 @@ pop_box_new(htmlvalue, 480, 182);
} )
}
render ( ) {
const { classes } = this . props ;
return (
< TPIContext . Provider
value = { {
... this . props ,
... this . state ,
resetTestSetsExpandedArray : this . resetTestSetsExpandedArray ,
onRunCodeTestFinish : this . onRunCodeTestFinish ,
onRunChooseTestFinish : this . onRunChooseTestFinish ,
testSetUnlock : this . testSetUnlock ,
onTestSetHeaderClick : this . onTestSetHeaderClick ,
readGameAnswer : this . readGameAnswer ,
onShowPrevStage : this . onShowPrevStage ,
onShowNextStage : this . onShowNextStage ,
praisePlus : this . praisePlus ,
onGamePassed : this . onGamePassed ,
closeTaskResultLayer : ( ) => this . closeTaskResultLayer ( ) ,
onPathChange : this . onPathChange ,
updateChallengePath : this . updateChallengePath ,
showSnackbar : this . showSnackbar ,
showDialog : this . showDialog ,
handleGdialogClose : ( ) => this . handleGdialogClose ( ) ,
onShowUpdateDialog : this . onShowUpdateDialog ,
updateDialogClose : this . updateDialogClose ,
match : this . props . match
} }
>
< Dialog
id = "tpi-dialog"
open = { this . state . gDialogOpen }
disableEscapeKeyDown = { true }
onClose = { ( ) => this . handleGdialogClose ( ) }
>
< DialogTitle id = "alert-dialog-title" > { "提示" } < / D i a l o g T i t l e >
< DialogContent id = "dialog-content" >
< DialogContentText id = "alert-dialog-description" style = { { textAlign : 'center' } } >
{ this . state . gDialogContentText }
< / D i a l o g C o n t e n t T e x t >
< / D i a l o g C o n t e n t >
{ /* mb20 加了有样式问题 */ }
< DialogActions className = { "" } id = "dialog-actions" >
{ this . isSingleButton ? < div className = "task-popup-submit clearfix"
style = { { textAlign : 'center' , 'margin-bottom' : '14px' } } >
< a className = "task-btn task-btn-orange"
onClick = { this . handleGdialogClose }
> 知道啦 < / a >
< / d i v > :
< React . Fragment >
< Button onClick = { ( ) => this . handleGdialogClose ( ) } color = "primary"
className = { ` ${ classes . button } ${ classes . buttonGray } ${ classes . borderRadiusNone } ` } >
关闭
< / B u t t o n >
< Button variant = "raised" className = { ` ${ classes . button } ${ classes . borderRadiusNone } ` }
onClick = { ( ) => this . onGdialogOkBtnClick ( ) } color = "primary" autoFocus >
{ this . okButtonText ? this . okButtonText : '确定' }
< TPIContext . Provider
value = { {
... this . props ,
... this . state ,
resetTestSetsExpandedArray : this . resetTestSetsExpandedArray ,
onRunCodeTestFinish : this . onRunCodeTestFinish ,
onRunChooseTestFinish : this . onRunChooseTestFinish ,
testSetUnlock : this . testSetUnlock ,
onTestSetHeaderClick : this . onTestSetHeaderClick ,
readGameAnswer : this . readGameAnswer ,
onShowPrevStage : this . onShowPrevStage ,
onShowNextStage : this . onShowNextStage ,
praisePlus : this . praisePlus ,
onGamePassed : this . onGamePassed ,
closeTaskResultLayer : ( ) => this . closeTaskResultLayer ( ) ,
onPathChange : this . onPathChange ,
updateChallengePath : this . updateChallengePath ,
showSnackbar : this . showSnackbar ,
showDialog : this . showDialog ,
handleGdialogClose : ( ) => this . handleGdialogClose ( ) ,
onShowUpdateDialog : this . onShowUpdateDialog ,
updateDialogClose : this . updateDialogClose ,
match : this . props . match
} }
>
< Modal
id = "tpi-dialog"
title = '提示'
visible = { this . state . gDialogOpen }
onCancel = { ( ) => this . handleGdialogClose ( ) }
footer = {
< Fragment >
{ this . isSingleButton ? < div className = "task-popup-submit clearfix"
style = { { textAlign : 'center' , 'margin-bottom' : '14px' } } >
< a className = "task-btn task-btn-orange"
onClick = { this . handleGdialogClose }
> 知道啦 < / a >
< / d i v > :
< React . Fragment >
< Button onClick = { ( ) => this . handleGdialogClose ( ) } color = "primary" >
关闭
< / B u t t o n >
< / R e a c t . F r a g m e n t > }
{ this . moreButtonsRender && this . moreButtonsRender ( ) }
< / D i a l o g A c t i o n s >
< / D i a l o g >
< Snackbar
< Button variant = "raised"
onClick = { ( ) => this . onGdialogOkBtnClick ( ) } color = "primary" autoFocus >
{ this . okButtonText ? this . okButtonText : '确定' }
< / B u t t o n >
< / R e a c t . F r a g m e n t > }
{ this . moreButtonsRender && this . moreButtonsRender ( ) }
< / F r a g m e n t >
}
>
< div id = "alert-dialog-description" style = { { textAlign : 'center' } } >
{ this . state . gDialogContentText }
< / d i v >
< / M o d a l >
{ this . state . snackbarOpen ?
< Alert
className = { "rootSnackbar" }
open = { this . state . snackbarOpen }
autoHideDuration = { 3000 }
anchorOrigin = { { vertical : this . state . snackbarVertical || 'top'
, horizontal : this . state . snackbarHorizontal || 'center' } }
onClose = { ( ) => this . handleSnackbarClose ( ) }
transition = { Fade }
SnackbarContentProps = { {
'aria-describedby' : 'message-id' ,
} }
resumeHideDuration = { 2000 }
message = { < span id = "message-id" > { this . state . snackbarText } < / s p a n > }
/ >
{ this . props . children }
< / T P I C o n t e x t . P r o v i d e r >
onClose = { ( ) => this . handleSnackbarClose ( ) }
message = { < span id = "message-id" > { this . state . snackbarText } < / s p a n > }
/ > : n u l l
}
{ this . props . children }
< / T P I C o n t e x t . P r o v i d e r >
)
}
}
export default CNotificationHOC ( ) ( withStyles ( styles ) ( TPIContextProvider ) ) ;
export default CNotificationHOC ( ) ( TPIContextProvider ) ;