重构,联调提交等

ui
jialong.yu 3 years ago
parent 352be7ca95
commit bf85c63e2f
  1. 507
      src/components/TestPanel.vue
  2. 21
      src/components/codemirror.vue
  3. 18
      src/utils/api.js
  4. 382
      src/utils/http.js
  5. 85
      src/views/Home.vue

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<el-container class="scrollbar" v-if="ishow"> <el-container class="scrollbar" v-if="pannelVisible">
<el-header> <el-header>
<div class="flex between"> <div class="flex between">
<div class="flex" style="width: 28%"> <div class="flex" style="width: 28%">
@ -23,7 +23,7 @@
</div> </div>
<div class="countDownBox"> <div class="countDownBox">
<div style="margin-left: -40px;"> <div style="margin-left: -40px;">
<div :sendSync="sendSync" :autoStart="autoStart" :defaultVal="defaultVal"> <div :autoStart="autoStart">
实训{{text}}时间 实训{{text}}时间
<span class="timeSpan">{{day}}</span> <span class="timeSpan">{{day}}</span>
<span class="timeSpan">{{hour}}</span>小时 <span class="timeSpan">{{hour}}</span>小时
@ -44,7 +44,7 @@
v-show="projectPermissions == 0" v-show="projectPermissions == 0"
@click="reload" @click="reload"
>重新开始</el-button> >重新开始</el-button>
<el-button style="margin-right:7px" @click="Submit" :disabled="isSubmit">提交</el-button> <el-button style="margin-right:7px" @click="submit" :disabled="isSubmit">提交</el-button>
</div> </div>
</div> </div>
</el-header> </el-header>
@ -70,9 +70,9 @@
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-card shadow="hover"> <el-card shadow="hover">
<el-table :data="tableData" :stripe="true" height="405"> <el-table :data="taskList" :stripe="true" height="405">
<el-table-column type="index"></el-table-column> <el-table-column type="index"></el-table-column>
<el-table-column prop="judgmentPointsName" label="判分标准" align="center"></el-table-column> <el-table-column prop="name" label="判分标准" align="center"></el-table-column>
<el-table-column prop="right" label="完成结果" align="center"> <el-table-column prop="right" label="完成结果" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<i <i
@ -87,7 +87,7 @@
></i> ></i>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="score" label="得分" align="center"></el-table-column> <el-table-column prop="score1" label="得分" align="center"></el-table-column>
</el-table> </el-table>
</el-card> </el-card>
</el-col> </el-col>
@ -101,7 +101,7 @@
<div class="break-all" v-html="experimentDescription"></div> <div class="break-all" v-html="experimentDescription"></div>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="实验要求" name="second"> <el-tab-pane label="实验要求" name="second">
<el-collapse v-model="activeNames"> <el-collapse v-model="curReq">
<el-collapse-item v-for="(loop, index) in points" :key="index"> <el-collapse-item v-for="(loop, index) in points" :key="index">
<template slot="title"> <template slot="title">
<i class="el-icon-s-ticket"></i> <i class="el-icon-s-ticket"></i>
@ -121,11 +121,11 @@
<!-- </div> --> <!-- </div> -->
<div <div
:style="ishow ? {position: 'fixed', left: '85%',top:'50%'} : {position: 'fixed',top:'50%'}" :style="pannelVisible ? {position: 'fixed', left: '85%',top:'50%'} : {position: 'fixed',top:'50%'}"
> >
<div @click="step()"> <div @click="togglePannel">
<img src="../assets/img/left.png" alt class="m_step" v-if="ishow" /> <img src="../assets/img/left.png" alt class="left-btn" v-if="pannelVisible" />
<img src="../assets/img/right.png" alt class="n_step" v-if="!ishow" /> <img src="../assets/img/right.png" alt class="right-btn" v-if="!pannelVisible" />
</div> </div>
</div> </div>
</div> </div>
@ -133,107 +133,44 @@
<script> <script>
import newmain from "../util/newMain"; import newmain from "../util/newMain";
import * as $ from "jquery";
import { get } from "http";
import util from '@/util' import util from '@/util'
export default { export default {
data() { data() {
return { return {
userId: util.getCookie("userId"), classId: util.getCookie('classId'),
studentId: util.getCookie("studentId"), className: util.getCookie("className"),
courseId: util.getCookie("courseId"), courseId: util.getCookie("courseId"),
projectId: util.getCookie("projectId"), projectId: util.getCookie("projectId"),
assessmentId: util.getCookie("assessmentId"), assessmentId: util.getCookie("assessmentId"),
projectPermissions: 0, // (0 1 2) projectPermissions: 0, // (0 1 2)
isSubmit: false, isSubmit: false, //
entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'), entryTime: new Date(),
startTime: util.getCookie("startTime") ? new Date(util.getCookie("startTime")).getTime() : '', startTime: util.getCookie("startTime") ? new Date(util.getCookie("startTime")).getTime() : '',
stopTime: util.getCookie("stopTime") ? new Date(util.getCookie("stopTime")).getTime() : '', endTime: util.getCookie("stopTime") ? new Date(util.getCookie("stopTime")).getTime() : '',
test: [], autoStart: true,
ishow: true, pannelVisible: true, //
grade: "00", grade: '00', //
exampleData: "", text: '', //
codeid: "", counterTimer: null, // setInterval
text: "", day: 0, //
isStart: false, // seconds: 0, //
globalTimer: null, //setInterval minutes: 0, //
millisecond: 0, hour: 0, //
countVal: this.defaultVal, //
pauseTime: 0,
day: 0,
seconds: 0,
minutes: 0,
hour: 0,
createTime: '', // createTime: '', //
actEndTime: '', // actEndTime: '', //
projectList: [], projectList: [], //
experimentTarget: "", // experimentTarget: "", //
experimentDescription: "", // experimentDescription: "", //
experimentHint: "", // experimentHint: "", //
judgmentPointsName: "", // hintOpen: 1, //
points: [], points: [], //
activeNames: [], judgmentId: '', // id
tableData: [], curReq: [], //
pannelTab: "first", taskList: [], //
isSelected: false, // true pannelTab: "first", //
hintOpen: 1 // isSelected: false // true
}; };
}, },
watch: {
countVal: {
deep: true,
handler: function(val, oldVal) {
let vm = this;
// console.log(11,vm)
if (vm.needSendSunc) {
vm.passToParent(val);
}
}
},
needSendSunc: {
deep: true,
handler: function(val) {
let vm = this;
if (val) {
vm.passToParent(vm.countString);
}
}
}
},
props: {
sendSync: {
type: Boolean,
default: false
},
autoStart: {
type: Boolean,
default: false
},
defaultVal: {
type: Number,
default: null
},
codeId: {
type: Number,
default: 0
},
workbench: {
type: Array,
default: []
}
},
computed: {
needSendSunc: function() {
return this.sendSync;
},
//
second: function() {
return this.num(this.seconds);
},
minute: function() {
return this.num(this.minutes);
}
},
mounted() { mounted() {
this.projectPermissions = this.projectId ? 1 : 0 // / this.projectPermissions = this.projectId ? 1 : 0 // /
if(this.projectId){ // projectId) if(this.projectId){ // projectId)
@ -241,163 +178,39 @@ export default {
}else{ // }else{ //
// //
this.getList().then(() => { this.getList().then(() => {
let cache = localStorage.getItem('codeCache') let cache = localStorage.getItem('codeCache') //
if(cache){ //
if (cache) {
cache = JSON.parse(cache) cache = JSON.parse(cache)
this.getCache(cache.projectId, cache.judgmentId) this.getCache(cache.projectId, cache.judgmentId)
} else {
this.getCache()
} }
}).catch(res => {}) }).catch(res => {})
} }
//
newmain.$on("codeid", val => {
this.codeid = val;
let codeId = this.codeid;
});
// tableData
newmain.$on("updateJud", item => {
let list = this.tableData
list.map(n => {
if(n.judgmentPointsId == item.id) n.isError = item.isError
})
this.tableData = list
});
}, },
methods: { methods: {
// //
getCache(projectId, judgmentId) { getList(){
this.$post(this.api.getLastCache, { let data = {
bcId: judgmentId ? judgmentId : this.judgmentId, systemId: 1,
cid: this.courseId, cId: this.courseId, // id
projectId: projectId ? projectId : this.projectId permissions: this.projectPermissions // /
}).then(res => { }
const code = res.getLastCache return new Promise((resolve, reject) => {
if (code) { this.$get(`${this.api.queryTestProject}`,data).then(res => {
this.$confirm('是否要继续上次的实验?', '提示', { const list = res.projects
confirmButtonText: '是', this.projectList = list
cancelButtonText: '否', this.projectId = list ? list[0].projectId : 0 //
type: 'success' this.getProDetail().then(() => {
}).then(() => { resolve()
localStorage.removeItem('codeCache') }).catch(res => {
this.projectId = projectId reject()
this.judgmentId = judgmentId
this.points[0].code = code
this.$emit("tell", this.projectId, this.projectPermissions, this.points)
// this.$emit('recoveryCode', cache.curTab)
}).catch(() => {
localStorage.removeItem('codeCache')
}) })
} }).catch(res => {
}).catch(res => {}) reject()
},
//
reload() {
this.$post(this.api.DeleteCodes).then(res => {
this.getClearTime()
this.grade = '00'
localStorage.removeItem('codeCache')
this.isSubmit = false
newmain.$emit("isSubmit", this.isSubmit)
let workbench = this.workbench
workbench.map(n => {
n.code = {
code: ''
}
})
this.$emit('recoveryCode',workbench)
let tableData = this.tableData
tableData.map(n => {
delete n.score
delete n.right
}) })
this.tableData = JSON.parse(JSON.stringify(tableData)) })
this.startCountFn()
});
},
//
Submit() {
// if(!this.codeIds.length) return this.$message.error('')
this.$confirm("此操作将视为结束考试, 是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
center: true
}).then(() => {
this.actEndTime = new Date().getTime();
this.getClearTime();
//
this.$post(this.api.Submit, {
createTime: this.startTime,
endTime: this.stopTime,
projectId: this.projectId,
projectPermissions: this.projectPermissions,
assessmentId: this.assessmentId ? this.assessmentId : '',
studentId: this.studentId,
record: {
courseId: 1,
// courseId: this.courseId,
projectId: this.projectId,
createTime: this.startTime,
endTime: this.stopTime,
startTime: this.entryTime
}
})
.then(res => {
localStorage.removeItem('codeCache')
this.isSubmit = true
newmain.$emit("isSubmit", this.isSubmit);
let list = res.message
let workbench = this.workbenchCus.length ? this.workbenchCus : this.workbench
let result = []
workbench.map(n => {
result.push(list.find(e => e.judgmentPointsId == n.judgmentPointsId))
})
let tableData = this.tableData
result.map(n => {
if(tableData.find(e => e.judgmentPointsId == n.judgmentPointsId).isError){
n.score = 0
n.right = -1
}
})
this.tableData = result
//
var s = 0;
this.tableData.forEach(element => {
this.test = element.score;
s += this.test;
this.grade = s;
});
})
.catch(err => {});
}).catch(() => {
this.$message({
type: "info",
message: "已取消提交"
});
});
},
//
timeFormat(param) {
return param < 10 ? "0" + param : param;
},
//
step() {
$(".m_step").toggleClass("n_step");
this.ishow = !this.ishow;
},
//
getClearTime() {
// clearInterval(this.globalTimer);
clearInterval(this.countVal);
this.globalTimer = "";
// if(this.projectPermissions != 0){
this.countVal = "";
this.day = "00";
this.seconds = "00";
this.minutes = "00";
this.hour = "00";
// }else{
// this.text = ''
// }
}, },
// //
getProDetail() { getProDetail() {
@ -409,18 +222,20 @@ export default {
const points = res.projectJudgmentVos const points = res.projectJudgmentVos
const project = res.projectManage const project = res.projectManage
points.map(e => { points.map(e => {
e.code = '' e.code = '' // code
e.codeId = '' // codeIdcodeId
}) })
this.points = points this.points = points
this.judgmentId = points[0].judgmentId this.taskList = points //
this.judgmentId = points[0].judgmentId //
this.experimentTarget = project.experimentTarget this.experimentTarget = project.experimentTarget
this.experimentDescription = project.experimentDescription this.experimentDescription = project.experimentDescription
this.experimentHint = project.experimentHint this.experimentHint = project.experimentHint
// this.actEndTime = project[0].endTime // this.actEndTime = project[0].endTime
this.hintOpen = !res.projectManage.hintOpen // 01 this.hintOpen = !res.projectManage.hintOpen // 01
this.$emit("tell", projectId, this.projectPermissions, this.points) this.$emit("tell", projectId, this.projectPermissions, this.points)
if (this.projectPermissions == "1") { if (this.projectPermissions == 1) {
this.text = "剩余"; this.text = "剩余"
var interval = setInterval(() => { var interval = setInterval(() => {
// //
let newTime = new Date().getTime(); let newTime = new Date().getTime();
@ -454,13 +269,13 @@ export default {
this.minutes = obj.min; this.minutes = obj.min;
this.seconds = obj.sec; this.seconds = obj.sec;
}, 1000); }, 1000);
} else if (this.projectPermissions == "0") { } else {
this.text = "已用"; this.text = "已用";
// //
this.createTime = new Date().getTime(); this.createTime = new Date().getTime();
// //
if (this.autoStart) { if (this.autoStart) {
this.startCountFn(); this.startCount()
} }
} }
resolve() resolve()
@ -469,44 +284,158 @@ export default {
}) })
}) })
}, },
// //
getList(){ getCache(pId, jId) {
let data = { const projectId = pId ? pId : this.projectId
systemId: 1, const judgmentId = jId ? jId : this.judgmentId
cId: this.courseId, // id this.$post(this.api.getLastCache, {
permissions: this.projectPermissions bcId: judgmentId, // ididid
} projectId, // id
return new Promise((resolve, reject) => { cid: this.courseId // id
this.$get(`${this.api.queryTestProject}`,data).then(res => { }).then(res => {
const list = res.projects const code = res.getLastCache
this.projectList = list //
this.projectId = list ? list[0].projectId : 0 if (code) {
this.getProDetail().then(() => { this.$confirm('是否要继续上次的实验?', '提示', {
resolve() confirmButtonText: '是',
}).catch(res => { cancelButtonText: '否',
reject() type: 'success'
}).then(() => {
localStorage.removeItem('codeCache') //
this.projectId = projectId
this.judgmentId = judgmentId
const item = this.points.find(e => e.judgmentId === judgmentId)
if (item) item.code = code
// debugger
this.$emit("tell", this.projectId, this.projectPermissions, this.points)
this.$emit('recoveryCode', judgmentId + '')
}).catch(() => {
localStorage.removeItem('codeCache')
}) })
}).catch(res => { }
reject() }).catch(res => {})
})
})
}, },
// //
selectProject(){ selectProject(){
this.isSelected = true this.isSelected = true
this.assessmentId = '' this.getProDetail().then(() => {
// - this.getCache()
this.$parent.workbench1 = '0' }).catch(res => {})
this.getProDetail()
this.isSubmit = false this.isSubmit = false
this.countVal = 0 this.countVal = 0
this.grade = 0 this.grade = 0
newmain.$emit("isSubmit", this.isSubmit) // -
this.$emit('recoveryCode')
newmain.$emit('isSubmit', this.isSubmit)
},
//
reload() {
this.reloadCount()
this.grade = '00'
localStorage.removeItem('codeCache')
this.isSubmit = false
newmain.$emit('isSubmit', this.isSubmit)
this.$emit('recoveryCode')
this.startCount()
// let taskList = this.taskList
// taskList.map(n => {
// delete n.score
// delete n.right
// })
// this.taskList = JSON.parse(JSON.stringify(taskList))
},
//
submit() {
const pointList = this.$parent.workbench
if(!pointList.find(e => e.codeId)) return this.$message.error('请先完成实验')
this.$confirm("此操作将视为结束考试, 是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
center: true
}).then(() => {
const date = new Date()
const entryTime = this.entryTime
const timeSum = Math.ceil((date.getTime() - entryTime.getTime()) / 60000) //
const endTime = util.formatDate('yyyy-MM-dd hh:mm:ss', date) //
const projectId = this.projectId
const projectName = this.projectList.find(e => e.projectId == projectId).projectName //
this.actEndTime = date
this.reloadCount()
const attributesReqList = []
pointList.map(e => {
e.codeId && attributesReqList.push({
codeId: e.codeId,
bcId: e.judgmentId,
isSubmit: 0
})
})
const data = {
classId: this.classId ? this.classId : '',
className: this.className ? this.className : '',
curriculumId: this.courseId,
startTime: util.formatDate('yyyy-MM-dd hh:mm:ss', entryTime),
endTime,
submitTime: endTime,
timeSum,
projectId,
projectName,
assessmentId: this.assessmentId ? this.assessmentId : '',
systemId: 1,
purpose: this.experimentTarget,
attributesReqList
}
this.$post(this.api.submit, data).then(res => {
localStorage.removeItem('codeCache')
this.isSubmit = true
newmain.$emit("isSubmit", this.isSubmit);
let list = res.message
let result = []
let taskList = this.taskList
result.map(n => {
if(taskList.find(e => e.judgmentPointsId == n.judgmentPointsId).isError){
n.score = 0
n.right = -1
}
})
this.taskList = result
//
var s = 0;
this.taskList.forEach(element => {
// this.test = element.score;
// s += this.test;
this.grade = s;
});
})
.catch(err => {})
}).catch(() => {
this.$message({
type: "info",
message: "已取消提交"
})
})
},
//
togglePannel() {
this.pannelVisible = !this.pannelVisible
},
//
timeFormat(param) {
return param < 10 ? '0' + param : param
},
//
reloadCount() {
clearInterval(this.counterTimer)
this.countVal = ''
this.day = '00'
this.seconds = '00'
this.minutes = '00'
this.hour = '00'
}, },
counterFn(counterTime) { counterFn(counterTime) {
let leave1 = counterTime % (24 * 3600 * 1); // let leave1 = counterTime % (24 * 3600) //
let leave2 = leave1 % (3600 * 1); // let leave2 = leave1 % 3600 //
let leave3 = leave2 % (60 * 1); // let leave3 = leave2 % 60 //
let day = Math.floor(counterTime / (24 * 3600 * 1)); // let day = Math.floor(counterTime / (24 * 3600 * 1)); //
let hour = Math.floor(leave1 / (3600 * 1)); // let hour = Math.floor(leave1 / (3600 * 1)); //
let minutes = Math.floor(leave2 / (60 * 1)); // let minutes = Math.floor(leave2 / (60 * 1)); //
@ -521,18 +450,12 @@ export default {
this.seconds = seconds; this.seconds = seconds;
}, },
// //
startCountFn() { startCount() {
if (!this.isStart) { // clearInterval(this.counterTimer)
this.countVal = this.countVal ? this.countVal : 0; this.countVal = this.countVal ? this.countVal : 0
let timer = setInterval(() => { this.counterTimer = setInterval(() => {
this.counterFn(this.countVal++); this.counterFn(this.countVal++)
}, 1000); }, 1000)
this.globalTimer = timer;
this.isStart = true;
}
},
passToParent(data) {
this.$emit("getDataFromChild", data);
} }
} }
}; };
@ -542,13 +465,13 @@ export default {
.break-all{ .break-all{
word-break: break-all; word-break: break-all;
} }
.m_step { .left-btn {
height: 150px; height: 150px;
width: 35px; width: 35px;
cursor: pointer; cursor: pointer;
display: block !important; display: block !important;
} }
.n_step { .right-btn {
height: 150px; height: 150px;
width: 35px; width: 35px;
cursor: pointer; cursor: pointer;

@ -90,11 +90,11 @@ import axios from 'axios';
import util from '@/util' import util from '@/util'
const CANCEL_TOKEN = axios.CancelToken // input const CANCEL_TOKEN = axios.CancelToken // input
export default { export default {
props: ["workbench1", "code", "projectId"], props: ['workbench1', 'code', 'codeId', 'projectId'],
data() { data() {
return { return {
assessmentId: util.getCookie("assessmentId"), // id assessmentId: util.getCookie(';assessmentId'), // id
courseId: util.getCookie("courseId"), // id courseId: util.getCookie('courseId'), // id
showTips: false, // showTips: false, //
answer: '', // answer: '', //
codeVal: this.code, codeVal: this.code,
@ -223,10 +223,6 @@ export default {
}else if(!res.message.isError){ }else if(!res.message.isError){
this.isError = 0 this.isError = 0
this.runResult += result this.runResult += result
newmain.$emit("updateJud",{
id: res.data.judgmentPointsId,
isError: res.data.isError
})
} }
}).catch(e => { }).catch(e => {
if(e && e.message == 'interrupt'){ if(e && e.message == 'interrupt'){
@ -301,7 +297,7 @@ export default {
this.loadIns.close() this.loadIns.close()
this.picSrc = '' this.picSrc = ''
if(photo){ if(photo){
this.isError = 0 this.isError = data.retResult
this.runResult = '' this.runResult = ''
this.picSrc = `${photo}?id=${new Date().getTime()}` this.picSrc = `${photo}?id=${new Date().getTime()}`
}else{ }else{
@ -323,6 +319,7 @@ export default {
this.isError = data.retResult this.isError = data.retResult
this.runResult = result this.runResult = result
this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length)) this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length))
this.$emit('update:codeId', res.codeId)
} }
} }
}).catch(res => { }).catch(res => {
@ -339,13 +336,13 @@ export default {
}) })
} }
}, },
//
getTips() { getTips() {
this.tipsVisible = true this.tipsVisible = true
// this.$get(this.api.queryBcJudgmentByBcId, {
this.$get(this.api.QueryAnswer, { bcId: this.workbench1
judgmentPointsId: this.workbench1
}).then(res => { }).then(res => {
this.answer = res.message this.answer = res.experimentCode
}).catch(err => {}) }).catch(err => {})
} }
} }

@ -1,13 +1,9 @@
import config from '@/config'
let host = `${config.host}`
export default { export default {
QueryProject: `${host}occupationlab/projectManage/getProjectDetail`, QueryProject: 'occupationlab/projectManage/getProjectDetail',
Submit: `${host}/python/submit`, submit: 'python/python/submit',
runPythonCode: `${host}python/python/runPythonCode`, runPythonCode: 'python/python/runPythonCode',
QueryAnswer: `${host}/python/queryAnswer`, queryBcJudgmentByBcId: 'judgment/bcJudgmentPoint/queryBcJudgmentByBcId',
DeleteCodes: `${host}/python/deleteCodes`, queryTestProject: 'occupationlab/projectManage/getProjectBySystemId',
queryTestProject: `${host}occupationlab/projectManage/getProjectBySystemId`, saveCache: 'python/python/saveCache',
saveCache: `${host}python/python/saveCache`, getLastCache: 'python/python/getLastCache',
getLastCache: `${host}python/python/getLastCache`
} }

@ -4,26 +4,19 @@ import {
} from 'element-ui' } from 'element-ui'
import router from '../router/index' import router from '../router/index'
import util from '@/util' import util from '@/util'
import config from '@/config'
// 环境的切换 const service = axios.create({
// if (process.env.NODE_ENV == 'development') { baseURL: config.host,
// axios.defaults.baseURL = '/api'; timeout: 10000000
// } else if (process.env.NODE_ENV == 'debug') { })
// axios.defaults.baseURL = '';
// } else if (process.env.NODE_ENV == 'production') {
// axios.defaults.baseURL = 'http://api.123dailu.com/';
// }
// 请求超时时间
axios.defaults.timeout = 30000;
// post请求头 // post请求头
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
// 请求拦截器 // 请求拦截器
axios.interceptors.request.use(config => { service.interceptors.request.use(config => {
const token = util.getCookie('admin-token') const token = util.getCookie('admin-token')
if (token) { if (token) {
// 存在将token写入 request header
config.headers.token = token config.headers.token = token
} }
return config; return config;
@ -38,320 +31,75 @@ axios.interceptors.request.use(config => {
}) })
// 响应拦截器 // 响应拦截器
// axios.interceptors.response.use( service.interceptors.response.use(
// response => { response => {
// consol.log(response.status) const res = response.data;
// if (response.status === 200) { if (res.status == 200 || res.status == 10000 || res.status == 30001) {
// return Promise.resolve(response); return Promise.resolve(res).catch(e => {});
// } else { } else if (!res.status) {
// return Promise.reject(response); return Promise.resolve(res).catch(e => {});
// } } else {
// }, Message.error(res.message)
// // 服务器状态码不是200的情况 return Promise.reject(res)
// error => { }
// if (error.response.status) { },
// switch (error.response.status) { // 服务器状态码不是200的情况
// // 401: 未登录 error => {
// // 未登录则跳转登录页面,并携带当前页面的路径 if (error.response.status) {
// // 在登录成功后返回当前页面,这一步需要在登录页操作。 switch (error.response.status) {
// case 500: // 401: 未登录
// router.replace({ case 401:
// path: '/login', history.back()
// // query: { redirect: router.currentRoute.fullPath } break;
// }); default:
// break; Message.error(error.response.data.message)
// // 403 token过期 Promise.reject(res);
// // 登录过期对用户进行提示 }
// // 清除本地token和清空vuex中token对象 return Promise.reject(error.response);
// // 跳转登录页面 }
// case 403: }
// // Toast({ );
// // message: '登录过期,请重新登录',
// // duration: 1000,
// // forbidClick: true
// // });
// // 清除token
// sessionStorage.removeItem('token');
// store.commit('loginSuccess', null);
// // 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面
// setTimeout(() => {
// router.replace({
// path: '/login',
// query: {
// redirect: router.currentRoute.fullPath
// }
// });
// }, 1000);
// break;
// // 404请求不存在
// case 404:
// router.replace({
// path: '/404',
// });
// break;
// // 其他错误,直接抛出错误提示
// default:
// router.replace({
// path: '/500',
// });
// }
// return Promise.reject(error.response);
// }
// }
// );
/** function get(url, params) {
* get方法对应get请求
*/
export function get(url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(url, { service.get(url, { params: params }).then(res => {
params: params resolve(res);
}) }).catch(err => {
.then(res => { reject(err);
if (res.data.status) { });
switch (res.data.status) {
case 200:
resolve(res.data);
break;
case 10000:
resolve(res.data);
break;
case 300:
this.$message.error(
res.data.errmessage
);
break;
case 500:
this.$message.error(
res.data.errmessage
);
break;
case 404:
this.$message.error(
res.data.errmessage
);
break;
case 403:
this.$message.error(
res.data.errmessage
);
break;
case 401:
Message.error("token失效,请重新登录");
sessionStorage.removeItem('token');
router.replace('/login')
break;
case 405:
this.$message.error(
res.data.errmessage
);
break;
case 406:
this.$message.error(
res.data.errmessage
);
break;
}
}
})
.catch(err => {
reject(err.data)
this.$message({
showClose: true,
message: '请求失败,请刷新页面重新进行请求',
type: 'error'
});
})
}); });
} }
/**
* post方法对应post请求 function post(url, params) {
*/
export function post(url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.post(url, params) service.post(url, params).then(res => {
.then(res => { resolve(res);
if (res.data.status) { }).catch(err => {
switch (res.data.status) { reject(err.data);
case 200: });
resolve(res.data);
break;
case 300:
this.$message.error(
res.data.errmessage
);
break;
case 500:
reject(res.data)
break;
case 404:
this.$message.error(
res.data.errmessage
);
break;
case 403:
this.$message.error(
res.data.errmessage
);
break;
case 401:
Message.error("token失效,请重新登录");
sessionStorage.removeItem('token');
router.replace('/login')
break;
case 405:
this.$message.error(
res.data.errmessage
);
break;
case 406:
this.$message.error(
res.data.errmessage
);
break;
}
}
})
.catch(err => {
reject(err.data)
this.$message({
showClose: true,
message: '请求失败,请刷新页面重新进行请求',
type: 'error'
});
})
}); });
} }
/** function del(url, params) {
* delete方法对应delete请求
*/
export function del(url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.delete(url, { service.delete(url, {
params: params params
}) }).then(res => {
.then(res => { resolve(res);
if (res.data.status) { }).catch(err => {
switch (res.data.status) { reject(err.data);
case 200: });
resolve(res.data);
break;
case 300:
this.$message.error(
res.data.errmessage
);
break;
case 500:
this.$message.error(
res.data.errmessage
);
break;
case 404:
this.$message.error(
res.data.errmessage
);
router.replace({
path: '/404',
});
break;
case 403:
this.$message.error(
res.data.errmessage
);
break;
case 401:
Message.error("token失效,请重新登录");
sessionStorage.removeItem('token');
router.replace('/login')
break;
case 405:
this.$message.error(
res.data.errmessage
);
break;
case 406:
this.$message.error(
res.data.errmessage
);
break;
}
}
})
.catch(err => {
reject(err.data)
this.$message({
showClose: true,
message: '请求失败,请刷新页面重新进行请求',
type: 'error'
});
})
}); });
} }
/** function put(url, params) {
* put修改
* @param {} url
* @param {*} params
*/
export function put(url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.put(url, params) service.put(url, params).then(res => {
.then(res => { resolve(res);
if (res.data.status) { }).catch(err => {
switch (res.data.status) { reject(err.data);
case 200: });
resolve(res.data);
break;
case 300:
this.$message.error(
res.data.errmessage
);
break;
case 500:
this.$message.error(
res.data.errmessage
);
break;
case 404:
this.$message.error(
res.data.errmessage
);
break;
case 403:
this.$message.error(
res.data.errmessage
);
break;
case 401:
Message.error("token失效,请重新登录");
sessionStorage.removeItem('token');
router.replace('/login')
break;
case 405:
this.$message.error(
res.data.errmessage
);
break;
case 406:
this.$message.error(
res.data.errmessage
);
break;
}
}
})
.catch(err => {
reject(err.data)
this.$message({
showClose: true,
message: '请求失败,请刷新页面重新进行请求',
type: 'error'
});
})
}); });
} }
export { get, post, del, put }

@ -27,7 +27,7 @@
:projectId.sync="projectId" :projectId.sync="projectId"
:code.sync="item.code" :code.sync="item.code"
:workbench1="item.judgmentId" :workbench1="item.judgmentId"
:codeid.sync="item.codeId" :codeId.sync="item.codeId"
></codemirror> ></codemirror>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
@ -38,13 +38,7 @@
@tell="getQueryIndex" @tell="getQueryIndex"
@recoveryCode="recoveryCode" @recoveryCode="recoveryCode"
ref="mainindex" ref="mainindex"
:autoStart="autoStart"
:sendSync="sendSync"
:defaultVal="defaultVal"
@getDataFromChild="getDataFromChild"
:codeId="codeId"
:workbench.sync="workbench" :workbench.sync="workbench"
:key="codeId"
></testPanel> ></testPanel>
</div> </div>
</div> </div>
@ -58,23 +52,12 @@ export default {
data() { data() {
return { return {
courseId: util.getCookie("courseId"), // id courseId: util.getCookie("courseId"), // id
assessmentId: util.getCookie("assessmentId"), // id
projectPermissions: 0, // (0 1 2) projectPermissions: 0, // (0 1 2)
codeId: 0, language: 'Python', //
language: "Python", // curTab: '', //
curTab: "", //
workbench: [], // workbench: [], //
editableTabs: [], codeKey: 1 //
tabIndex: 2,
name: "",
judgmentPointsIds: [],
autoStart: true,
sendSync: true,
entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'),
assessmentId: util.getCookie("assessmentId"),
defaultVal: sessionStorage.getItem("timer")
? parseInt(sessionStorage.getItem("timer"))
: 0,
codeKey: 1,
}; };
}, },
components: { components: {
@ -91,28 +74,26 @@ export default {
// //
leavePage(){ leavePage(){
const list = this.workbench const list = this.workbench
if(!this.$refs.mainindex.isSubmit && !this.assessmentId && list.length){ if(!this.$refs.mainindex.isSubmit && !this.assessmentId && list.length && list.some(e => e.code)){
if(list.some(e => e.code)){ const cache = {
const cache = { projectId: this.projectId,
projectId: this.projectId, judgmentId: list[this.curTab].judgmentId
judgmentId: list[this.curTab].judgmentId
}
localStorage.setItem('codeCache', JSON.stringify(cache))
list.map(e => {
if (e.code) {
let data = {
code: e.code,
bcId: e.judgmentId,
cid: this.courseId,
projectId: this.projectId
}
this.$post(this.api.saveCache,data).then(res => {}).catch(e => {})
}
})
} }
localStorage.setItem('codeCache', JSON.stringify(cache))
list.map(e => {
if (e.code) {
let data = {
code: e.code,
bcId: e.judgmentId,
cid: this.courseId,
projectId: this.projectId
}
this.$post(this.api.saveCache,data).then(res => {}).catch(e => {})
}
})
} }
}, },
// 退 // 退
autoLogout(){ autoLogout(){
let lastTime = new Date().getTime() let lastTime = new Date().getTime()
let logout = false let logout = false
@ -120,6 +101,7 @@ export default {
document.onmousedown = () => { document.onmousedown = () => {
lastTime = new Date().getTime() lastTime = new Date().getTime()
} }
// 退
setInterval(() => { setInterval(() => {
if((new Date().getTime() - lastTime) > this.$config.autoLogoutTime){ if((new Date().getTime() - lastTime) > this.$config.autoLogoutTime){
logout || this.$message.error('用户登录过期,请重新登录') logout || this.$message.error('用户登录过期,请重新登录')
@ -128,16 +110,10 @@ export default {
} }
},1000) },1000)
}, },
getDataFromChild(data) { //
sessionStorage.setItem("timer", parseInt(data)); recoveryCode(curTab){
},
recoveryCode(workbench){
this.workbench = workbench
this.codeKey++
this.curTab = '0' this.curTab = '0'
}, this.codeKey++
reload(){
this.$refs.mainindex.reload()
}, },
// 退 // 退
back() { back() {
@ -156,14 +132,11 @@ export default {
} }
this.$refs.mainindex.getClearTime(); this.$refs.mainindex.getClearTime();
}, },
// // id
getQueryIndex(value1, projectPermissions,workBench) { getQueryIndex(projectId, projectPermissions, workBench) {
// this.projectId = projectId
console.log(5555,workBench)
this.projectId = value1
this.projectPermissions = projectPermissions this.projectPermissions = projectPermissions
this.workbench = workBench this.workbench = workBench
this.codeKey++
}, },
} }
}; };

Loading…
Cancel
Save