|
|
|
@ -1,12 +1,10 @@
|
|
|
|
|
const app = getApp();
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
current: 0,
|
|
|
|
|
titles: ["任务描述", "代码文件", "测评结果"]
|
|
|
|
|
},
|
|
|
|
|
log(e){
|
|
|
|
|
console.log(e);
|
|
|
|
|
current: 1,
|
|
|
|
|
content:"加载中...",
|
|
|
|
|
titles: ["任务描述", "代码文件", "测评结果"],
|
|
|
|
|
can_use_editor:wx.canIUse("editor")
|
|
|
|
|
},
|
|
|
|
|
enterTask(e){
|
|
|
|
|
var {target:{dataset:{identifier}}} = e;
|
|
|
|
@ -23,19 +21,53 @@ Page({
|
|
|
|
|
enterOutcome(){
|
|
|
|
|
this.setData({current:2});
|
|
|
|
|
},
|
|
|
|
|
onBlur({detail:{value}}){
|
|
|
|
|
onTextAreaBlur({detail:{value}}){
|
|
|
|
|
if (!this.modified) {
|
|
|
|
|
this.modified = this.content != value;
|
|
|
|
|
}
|
|
|
|
|
this.content = value;
|
|
|
|
|
if(this.modified)
|
|
|
|
|
}
|
|
|
|
|
if(this.modified){
|
|
|
|
|
this.content = value;
|
|
|
|
|
this.updateFile();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onInput({detail:{value}}){
|
|
|
|
|
onTextAreaInput({detail:{value}}){
|
|
|
|
|
this.modified = this.content!=value;
|
|
|
|
|
if(this.modified)
|
|
|
|
|
this.content = value;
|
|
|
|
|
},
|
|
|
|
|
addIndent(){
|
|
|
|
|
this.editor.insertText({text:" "});
|
|
|
|
|
},
|
|
|
|
|
onEditorInput(e){
|
|
|
|
|
let {text} = e.detail;
|
|
|
|
|
//console.log(e.detail.text);
|
|
|
|
|
this.modified = this.content!=text;
|
|
|
|
|
if(this.modified){
|
|
|
|
|
this.content = text;
|
|
|
|
|
// 自动缩进适配┭┮﹏┭┮,小程序限制太多了
|
|
|
|
|
this.oldLines = this.lines;
|
|
|
|
|
this.lines = this.content.split(/\n/g);
|
|
|
|
|
if(this.oldLines.length+1==this.lines.length){
|
|
|
|
|
for(var i=this.oldLines.length;i>=0;i--){
|
|
|
|
|
if(this.lines[i+1]!=this.oldLines[i]){
|
|
|
|
|
let indent = this.oldLines[i].length - this.oldLines[i].trimStart().length;
|
|
|
|
|
this.editor.insertText({text:" ".repeat(indent)});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onEditorBlur({detail}){
|
|
|
|
|
//console.log("onEditorBlur")
|
|
|
|
|
let {text} = detail;
|
|
|
|
|
if(!this.modified){
|
|
|
|
|
this.modified = this.content!=value;
|
|
|
|
|
this.modified = this.content.trimEnd()!=text.trimEnd();
|
|
|
|
|
}
|
|
|
|
|
if(this.modified){
|
|
|
|
|
this.content = text;
|
|
|
|
|
this.updateFile();
|
|
|
|
|
}
|
|
|
|
|
this.content = value;
|
|
|
|
|
},
|
|
|
|
|
processPath(path){
|
|
|
|
|
return path.replace(/[;;]$/,"");
|
|
|
|
@ -56,19 +88,21 @@ Page({
|
|
|
|
|
throw new Error();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
gameBuild({detail:{value}}){
|
|
|
|
|
buildGame({detail:{value}}){
|
|
|
|
|
//console.log("buildGame");
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
title: '代码上传中',
|
|
|
|
|
});
|
|
|
|
|
this.setData({ building: 1 });
|
|
|
|
|
var {identifier} = this.data;
|
|
|
|
|
this.content = value.content;
|
|
|
|
|
if(!this.data.can_use_editor)
|
|
|
|
|
this.content = value.content;
|
|
|
|
|
this.updateFile({evaluate:1})
|
|
|
|
|
.then(res=>{
|
|
|
|
|
var {sec_key, resubmit=""} = res;
|
|
|
|
|
app.api("tasks.game_build")({ identifier, resubmit, sec_key, content_modified:1})
|
|
|
|
|
.then(res => {
|
|
|
|
|
this.getGameStatus({sec_key, resubmit});
|
|
|
|
|
this.getBuildStatus({sec_key, resubmit});
|
|
|
|
|
})
|
|
|
|
|
.catch(e=>{
|
|
|
|
|
wx.hideLoading();
|
|
|
|
@ -82,7 +116,7 @@ Page({
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
getGameStatus({resubmit="", sec_key=""}){
|
|
|
|
|
getBuildStatus({resubmit="", sec_key=""}){
|
|
|
|
|
var { identifier } = this.data;
|
|
|
|
|
var timer = setInterval(()=>{
|
|
|
|
|
app.api("tasks.game_status")({identifier,resubmit,sec_key})
|
|
|
|
@ -101,49 +135,64 @@ Page({
|
|
|
|
|
}, 1000);
|
|
|
|
|
},
|
|
|
|
|
onSwiperChange({detail:{current,source}}){
|
|
|
|
|
if(source=="touch")
|
|
|
|
|
if(source=="touch"){
|
|
|
|
|
this.setData({current});
|
|
|
|
|
}
|
|
|
|
|
if(current==1&&!this.content){
|
|
|
|
|
this.pullContent();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async pullTask(){
|
|
|
|
|
let {identifier} = this.data;
|
|
|
|
|
let res = await app.api("tasks")({identifier});
|
|
|
|
|
res.challenge.task_pass = res.challenge.task_pass.replace(/\[TOC\]\s*-+\s*/,"")
|
|
|
|
|
this.setData(res);
|
|
|
|
|
this.pullContent();
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
async pullContent(){
|
|
|
|
|
console.log("pullContent", this.editor);
|
|
|
|
|
let {path} = this.data.challenge;
|
|
|
|
|
path = this.processPath(path);
|
|
|
|
|
let {identifier} = this.data;
|
|
|
|
|
let {content} = await app.api("tasks.rep_content")({identifier,path});
|
|
|
|
|
this.setData({content});
|
|
|
|
|
this.content = content;
|
|
|
|
|
if(this.data.can_use_editor){
|
|
|
|
|
if(!this.editor)
|
|
|
|
|
this.onEditorReady({pullContent:1});
|
|
|
|
|
else{
|
|
|
|
|
//let delta = {ops:[{insert:content}]};
|
|
|
|
|
//this.editor.setContents({delta});
|
|
|
|
|
this.editor.clear();
|
|
|
|
|
this.lines = content.split(/\n/g);
|
|
|
|
|
this.editor.insertText({text:content});
|
|
|
|
|
}
|
|
|
|
|
}else
|
|
|
|
|
this.setData({content});
|
|
|
|
|
console.log("pullContent");
|
|
|
|
|
},
|
|
|
|
|
onEditorReady({pullContent=0}={}) {
|
|
|
|
|
//console.log("editor-ready")
|
|
|
|
|
const that = this
|
|
|
|
|
wx.createSelectorQuery().select('#code-editor').context(function (res) {
|
|
|
|
|
that.editor = res.context
|
|
|
|
|
if(pullContent&&that.editor)
|
|
|
|
|
that.pullContent();
|
|
|
|
|
//that.editor.insertText({text:that.content});
|
|
|
|
|
//console.log("exced",res,that.editor);
|
|
|
|
|
}).exec();
|
|
|
|
|
//console.log("redy-fin",this.editor)
|
|
|
|
|
},
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
//console.log("onload")
|
|
|
|
|
let {identifier} = options;
|
|
|
|
|
this.setData({identifier});
|
|
|
|
|
this.pullTask();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onHide: function () {
|
|
|
|
|
this.updateFile();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
let {challenge, shixun} = this.data;
|
|
|
|
|
return app.shareApp({
|
|
|
|
|