重构,联调提交等

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. 380
      src/utils/http.js
  5. 85
      src/views/Home.vue

@ -1,6 +1,6 @@
<template>
<div>
<el-container class="scrollbar" v-if="ishow">
<el-container class="scrollbar" v-if="pannelVisible">
<el-header>
<div class="flex between">
<div class="flex" style="width: 28%">
@ -23,7 +23,7 @@
</div>
<div class="countDownBox">
<div style="margin-left: -40px;">
<div :sendSync="sendSync" :autoStart="autoStart" :defaultVal="defaultVal">
<div :autoStart="autoStart">
实训{{text}}时间
<span class="timeSpan">{{day}}</span>
<span class="timeSpan">{{hour}}</span>小时
@ -44,7 +44,7 @@
v-show="projectPermissions == 0"
@click="reload"
>重新开始</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>
</el-header>
@ -70,9 +70,9 @@
<el-row>
<el-col :span="24">
<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 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">
<template slot-scope="scope">
<i
@ -87,7 +87,7 @@
></i>
</template>
</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-card>
</el-col>
@ -101,7 +101,7 @@
<div class="break-all" v-html="experimentDescription"></div>
</el-tab-pane>
<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">
<template slot="title">
<i class="el-icon-s-ticket"></i>
@ -121,11 +121,11 @@
<!-- </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()">
<img src="../assets/img/left.png" alt class="m_step" v-if="ishow" />
<img src="../assets/img/right.png" alt class="n_step" v-if="!ishow" />
<div @click="togglePannel">
<img src="../assets/img/left.png" alt class="left-btn" v-if="pannelVisible" />
<img src="../assets/img/right.png" alt class="right-btn" v-if="!pannelVisible" />
</div>
</div>
</div>
@ -133,107 +133,44 @@
<script>
import newmain from "../util/newMain";
import * as $ from "jquery";
import { get } from "http";
import util from '@/util'
export default {
data() {
return {
userId: util.getCookie("userId"),
studentId: util.getCookie("studentId"),
classId: util.getCookie('classId'),
className: util.getCookie("className"),
courseId: util.getCookie("courseId"),
projectId: util.getCookie("projectId"),
assessmentId: util.getCookie("assessmentId"),
projectPermissions: 0, // (0 1 2)
isSubmit: false,
entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'),
isSubmit: false, //
entryTime: new Date(),
startTime: util.getCookie("startTime") ? new Date(util.getCookie("startTime")).getTime() : '',
stopTime: util.getCookie("stopTime") ? new Date(util.getCookie("stopTime")).getTime() : '',
test: [],
ishow: true,
grade: "00",
exampleData: "",
codeid: "",
text: "",
isStart: false, //
globalTimer: null, //setInterval
millisecond: 0,
countVal: this.defaultVal, //
pauseTime: 0,
day: 0,
seconds: 0,
minutes: 0,
hour: 0,
endTime: util.getCookie("stopTime") ? new Date(util.getCookie("stopTime")).getTime() : '',
autoStart: true,
pannelVisible: true, //
grade: '00', //
text: '', //
counterTimer: null, // setInterval
day: 0, //
seconds: 0, //
minutes: 0, //
hour: 0, //
createTime: '', //
actEndTime: '', //
projectList: [],
projectList: [], //
experimentTarget: "", //
experimentDescription: "", //
experimentHint: "", //
judgmentPointsName: "", //
points: [],
activeNames: [],
tableData: [],
pannelTab: "first",
isSelected: false, // true
hintOpen: 1 //
hintOpen: 1, //
points: [], //
judgmentId: '', // id
curReq: [], //
taskList: [], //
pannelTab: "first", //
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() {
this.projectPermissions = this.projectId ? 1 : 0 // /
if(this.projectId){ // projectId)
@ -241,163 +178,39 @@ export default {
}else{ //
//
this.getList().then(() => {
let cache = localStorage.getItem('codeCache')
if(cache){
let cache = localStorage.getItem('codeCache') //
//
if (cache) {
cache = JSON.parse(cache)
this.getCache(cache.projectId, cache.judgmentId)
} else {
this.getCache()
}
}).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: {
//
getCache(projectId, judgmentId) {
this.$post(this.api.getLastCache, {
bcId: judgmentId ? judgmentId : this.judgmentId,
cid: this.courseId,
projectId: projectId ? projectId : this.projectId
}).then(res => {
const code = res.getLastCache
if (code) {
this.$confirm('是否要继续上次的实验?', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'success'
}).then(() => {
localStorage.removeItem('codeCache')
this.projectId = projectId
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')
//
getList(){
let data = {
systemId: 1,
cId: this.courseId, // id
permissions: this.projectPermissions // /
}
return new Promise((resolve, reject) => {
this.$get(`${this.api.queryTestProject}`,data).then(res => {
const list = res.projects
this.projectList = list
this.projectId = list ? list[0].projectId : 0 //
this.getProDetail().then(() => {
resolve()
}).catch(res => {
reject()
})
}
}).catch(res => {})
},
//
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
}).catch(res => {
reject()
})
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() {
@ -409,18 +222,20 @@ export default {
const points = res.projectJudgmentVos
const project = res.projectManage
points.map(e => {
e.code = ''
e.code = '' // code
e.codeId = '' // codeIdcodeId
})
this.points = points
this.judgmentId = points[0].judgmentId
this.taskList = points //
this.judgmentId = points[0].judgmentId //
this.experimentTarget = project.experimentTarget
this.experimentDescription = project.experimentDescription
this.experimentHint = project.experimentHint
// this.actEndTime = project[0].endTime
this.hintOpen = !res.projectManage.hintOpen // 01
this.$emit("tell", projectId, this.projectPermissions, this.points)
if (this.projectPermissions == "1") {
this.text = "剩余";
if (this.projectPermissions == 1) {
this.text = "剩余"
var interval = setInterval(() => {
//
let newTime = new Date().getTime();
@ -454,13 +269,13 @@ export default {
this.minutes = obj.min;
this.seconds = obj.sec;
}, 1000);
} else if (this.projectPermissions == "0") {
} else {
this.text = "已用";
//
this.createTime = new Date().getTime();
//
if (this.autoStart) {
this.startCountFn();
this.startCount()
}
}
resolve()
@ -469,44 +284,158 @@ export default {
})
})
},
//
getList(){
let data = {
systemId: 1,
cId: this.courseId, // id
permissions: this.projectPermissions
}
return new Promise((resolve, reject) => {
this.$get(`${this.api.queryTestProject}`,data).then(res => {
const list = res.projects
this.projectList = list
this.projectId = list ? list[0].projectId : 0
this.getProDetail().then(() => {
resolve()
}).catch(res => {
reject()
//
getCache(pId, jId) {
const projectId = pId ? pId : this.projectId
const judgmentId = jId ? jId : this.judgmentId
this.$post(this.api.getLastCache, {
bcId: judgmentId, // ididid
projectId, // id
cid: this.courseId // id
}).then(res => {
const code = res.getLastCache
//
if (code) {
this.$confirm('是否要继续上次的实验?', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
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(){
this.isSelected = true
this.assessmentId = ''
// -
this.$parent.workbench1 = '0'
this.getProDetail()
this.getProDetail().then(() => {
this.getCache()
}).catch(res => {})
this.isSubmit = false
this.countVal = 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) {
let leave1 = counterTime % (24 * 3600 * 1); //
let leave2 = leave1 % (3600 * 1); //
let leave3 = leave2 % (60 * 1); //
let leave1 = counterTime % (24 * 3600) //
let leave2 = leave1 % 3600 //
let leave3 = leave2 % 60 //
let day = Math.floor(counterTime / (24 * 3600 * 1)); //
let hour = Math.floor(leave1 / (3600 * 1)); //
let minutes = Math.floor(leave2 / (60 * 1)); //
@ -521,18 +450,12 @@ export default {
this.seconds = seconds;
},
//
startCountFn() {
if (!this.isStart) { //
this.countVal = this.countVal ? this.countVal : 0;
let timer = setInterval(() => {
this.counterFn(this.countVal++);
}, 1000);
this.globalTimer = timer;
this.isStart = true;
}
},
passToParent(data) {
this.$emit("getDataFromChild", data);
startCount() {
clearInterval(this.counterTimer)
this.countVal = this.countVal ? this.countVal : 0
this.counterTimer = setInterval(() => {
this.counterFn(this.countVal++)
}, 1000)
}
}
};
@ -542,13 +465,13 @@ export default {
.break-all{
word-break: break-all;
}
.m_step {
.left-btn {
height: 150px;
width: 35px;
cursor: pointer;
display: block !important;
}
.n_step {
.right-btn {
height: 150px;
width: 35px;
cursor: pointer;

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

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

@ -4,26 +4,19 @@ import {
} from 'element-ui'
import router from '../router/index'
import util from '@/util'
import config from '@/config'
// 环境的切换
// if (process.env.NODE_ENV == 'development') {
// axios.defaults.baseURL = '/api';
// } 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;
const service = axios.create({
baseURL: config.host,
timeout: 10000000
})
// 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')
if (token) {
// 存在将token写入 request header
config.headers.token = token
}
return config;
@ -38,320 +31,75 @@ axios.interceptors.request.use(config => {
})
// 响应拦截器
// axios.interceptors.response.use(
// response => {
// consol.log(response.status)
// if (response.status === 200) {
// return Promise.resolve(response);
// } else {
// return Promise.reject(response);
// }
// },
// // 服务器状态码不是200的情况
// error => {
// if (error.response.status) {
// switch (error.response.status) {
// // 401: 未登录
// // 未登录则跳转登录页面,并携带当前页面的路径
// // 在登录成功后返回当前页面,这一步需要在登录页操作。
// case 500:
// router.replace({
// path: '/login',
// // query: { redirect: router.currentRoute.fullPath }
// });
// break;
// // 403 token过期
// // 登录过期对用户进行提示
// // 清除本地token和清空vuex中token对象
// // 跳转登录页面
// 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);
// }
// }
// );
service.interceptors.response.use(
response => {
const res = response.data;
if (res.status == 200 || res.status == 10000 || res.status == 30001) {
return Promise.resolve(res).catch(e => {});
} else if (!res.status) {
return Promise.resolve(res).catch(e => {});
} else {
Message.error(res.message)
return Promise.reject(res)
}
},
// 服务器状态码不是200的情况
error => {
if (error.response.status) {
switch (error.response.status) {
// 401: 未登录
case 401:
history.back()
break;
default:
Message.error(error.response.data.message)
Promise.reject(res);
}
return Promise.reject(error.response);
}
}
);
/**
* get方法对应get请求
*/
export function get(url, params) {
function get(url, params) {
return new Promise((resolve, reject) => {
axios.get(url, {
params: params
})
.then(res => {
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'
});
})
service.get(url, { params: params }).then(res => {
resolve(res);
}).catch(err => {
reject(err);
});
});
}
/**
* post方法对应post请求
*/
export function post(url, params) {
function post(url, params) {
return new Promise((resolve, reject) => {
axios.post(url, params)
.then(res => {
if (res.data.status) {
switch (res.data.status) {
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'
});
})
service.post(url, params).then(res => {
resolve(res);
}).catch(err => {
reject(err.data);
});
});
}
/**
* delete方法对应delete请求
*/
export function del(url, params) {
function del(url, params) {
return new Promise((resolve, reject) => {
axios.delete(url, {
params: params
})
.then(res => {
if (res.data.status) {
switch (res.data.status) {
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'
});
})
service.delete(url, {
params
}).then(res => {
resolve(res);
}).catch(err => {
reject(err.data);
});
});
}
/**
* put修改
* @param {} url
* @param {*} params
*/
export function put(url, params) {
function put(url, params) {
return new Promise((resolve, reject) => {
axios.put(url, params)
.then(res => {
if (res.data.status) {
switch (res.data.status) {
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'
});
})
service.put(url, params).then(res => {
resolve(res);
}).catch(err => {
reject(err.data);
});
});
}
export { get, post, del, put }

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

Loading…
Cancel
Save