tab切换修复等

ui
jialong.yu 3 years ago
parent d83a59643b
commit cba2750588
  1. 101
      src/components/TestPanel.vue
  2. 93
      src/components/codemirror.vue
  3. 42
      src/util/index.js
  4. 3
      src/utils/api.js
  5. 24
      src/utils/http.js
  6. 106
      src/views/Home.vue

@ -133,32 +133,9 @@
<script> <script>
import newmain from "../util/newMain"; import newmain from "../util/newMain";
import axios from "axios";
import * as $ from "jquery"; import * as $ from "jquery";
import { get } from "http"; import { get } from "http";
//"yyyy-MM-dd hh:mm:ss" import util from '@/util'
function formatDate(fmt,date) {
var date = date ? date : new Date()
var o = {
"M+" : date.getMonth()+1, //
"d+" : date.getDate(), //
"h+" : date.getHours(), //
"m+" : date.getMinutes(), //
"s+" : date.getSeconds(), //
"q+" : Math.floor((date.getMonth()+3)/3), //
"S" : date.getMilliseconds() //
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt;
}
export default { export default {
data() { data() {
return { return {
@ -197,7 +174,7 @@ export default {
assessmentId: "", assessmentId: "",
projectPermissions: 0, //(0 1 2) projectPermissions: 0, //(0 1 2)
isSubmit: false, isSubmit: false,
entryTime: formatDate('yyyy-MM-dd hh:mm:ss'), entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'),
startTime: '', startTime: '',
stopTime: '', stopTime: '',
isSelected: false, isSelected: false,
@ -263,41 +240,42 @@ export default {
} }
}, },
mounted() { mounted() {
this.assessmentId = this.getCookie("assessmentId"); this.assessmentId = util.getCookie("assessmentId");
this.userId = this.getCookie("userId"); this.userId = util.getCookie("userId");
this.studentId = this.getCookie("studentId"); this.studentId = util.getCookie("studentId");
this.projectId = this.getCookie("projectId"); this.projectId = util.getCookie("projectId");
this.courseId = this.getCookie("courseId"); this.courseId = util.getCookie("courseId");
this.startTime = this.getCookie("startTime") ? new Date(this.getCookie("startTime")).getTime() : '' this.startTime = util.getCookie("startTime") ? new Date(util.getCookie("startTime")).getTime() : ''
this.stopTime = this.getCookie("stopTime") ? new Date(this.getCookie("stopTime")).getTime() : '' this.stopTime = util.getCookie("stopTime") ? new Date(util.getCookie("stopTime")).getTime() : ''
this.projectPermissions = this.projectId ? 1 : 0 this.projectPermissions = this.projectId ? 1 : 0
if(this.projectId){ if(this.projectId){
this.getQueryProject(); this.getQueryProject();
}else{ }else{
console.log(33)
this.getProjects(); this.getProjects();
let codeCache = localStorage.getItem('codeCache') let codeCache = localStorage.getItem('codeCache')
if(codeCache){ if(codeCache){
codeCache = JSON.parse(codeCache) codeCache = JSON.parse(codeCache)
if(codeCache.systemId && codeCache.systemId == this.$config.systemId){ // if(codeCache.systemId && codeCache.systemId == this.$config.systemId){
this.$confirm('是否要继续上次的实验?', '提示', { // this.$confirm('', '', {
confirmButtonText: '是', // confirmButtonText: '',
cancelButtonText: '否', // cancelButtonText: '',
type: 'success' // type: 'success'
}).then(() => { // }).then(() => {
this.value1 = codeCache.projectId // this.value1 = codeCache.projectId
this.workbenchCus = codeCache.workbench // this.workbenchCus = codeCache.workbench
this.isRecovery = true // this.isRecovery = true
this.selectProject() // this.selectProject()
let codeIds = [] // let codeIds = []
codeCache.workbench.map(n => codeIds.push(n.code.codeId)) // codeCache.workbench.map(n => codeIds.push(n.code.codeId))
codeIds = codeIds.filter(n => n) // codeIds = codeIds.filter(n => n)
this.codeIds = codeIds // this.codeIds = codeIds
this.$emit('recoveryCode',codeCache.workbench1) // this.$emit('recoveryCode',codeCache.workbench1)
}).catch(() => { // }).catch(() => {
localStorage.removeItem('codeCache') // localStorage.removeItem('codeCache')
}) // })
} // }
} }
} }
this.assessmentId && this.projectId && this.checkVer() this.assessmentId && this.projectId && this.checkVer()
@ -475,6 +453,7 @@ export default {
this.handleData(res.projectManage,1) this.handleData(res.projectManage,1)
this.projectId = res.projectManage[0].projectId this.projectId = res.projectManage[0].projectId
} }
// debugger
this.points = res.projectJudgmentVos; this.points = res.projectJudgmentVos;
this.$emit("tell", this.value1, this.projectPermissions, this.points); this.$emit("tell", this.value1, this.projectPermissions, this.points);
// - // -
@ -539,7 +518,7 @@ export default {
let data = { let data = {
systemId: 1, systemId: 1,
cId: this.courseId, cId: this.courseId,
permissions: 0 permissions: this.projectPermissions
} }
this.$get(`${this.api.queryTestProject}`,data).then(res => { this.$get(`${this.api.queryTestProject}`,data).then(res => {
this.handleData(res.projects,2) this.handleData(res.projects,2)
@ -586,24 +565,6 @@ export default {
}, },
passToParent(data) { passToParent(data) {
this.$emit("getDataFromChild", data); this.$emit("getDataFromChild", data);
},
getCookie(cookie_name) {
//cookiekeyvalue
var allcookies = document.cookie; //
var cookie_pos = allcookies.indexOf(cookie_name); // cookie,
if (cookie_pos != -1) {
// cookie_pos1
//cookie1=
cookie_pos = cookie_pos + cookie_name.length + 1; //cookie
var cookie_end = allcookies.indexOf(";", cookie_pos);
if (cookie_end == -1) {
cookie_end = allcookies.length;
} //cookie
var value = unescape(allcookies.substring(cookie_pos, cookie_end));
}
return value;
} }
} }
}; };

@ -7,12 +7,9 @@
:options="cmOption" :options="cmOption"
class="code-mirror" class="code-mirror"
@ready="onCmReady3" @ready="onCmReady3"
@focus="onCmFocus"
@input="onCmCodeChange"
ref="myCmGenerate" ref="myCmGenerate"
></codemirror> ></codemirror>
<div v-if="isSubmit" class="code-mask"></div> <div v-if="isSubmit" class="code-mask"></div>
<el-button <el-button
type="warning" type="warning"
@click="AnswerTips()" @click="AnswerTips()"
@ -96,11 +93,13 @@ import "codemirror/theme/base16-light.css";
import * as $ from "jquery"; import * as $ from "jquery";
import { Loading } from 'element-ui'; import { Loading } from 'element-ui';
import axios from 'axios'; import axios from 'axios';
import util from '@/util'
const CANCEL_TOKEN = axios.CancelToken const CANCEL_TOKEN = axios.CancelToken
export default { export default {
props: ["workbench1", "code", "codeid", "projectId"], props: ["workbench1", "code", "codeid", "projectId"],
data() { data() {
return { return {
courseId: util.getCookie("courseId"),
datas: [], datas: [],
ShowAssessmentId: false, ShowAssessmentId: false,
answer: "", answer: "",
@ -153,7 +152,8 @@ export default {
inputTextReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)\(['|"]([\s\S]+?)['|"]\)/m,// input() inputTextReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)\(['|"]([\s\S]+?)['|"]\)/m,// input()
requestList: [], requestList: [],
sourceCode: '', sourceCode: '',
requestTimer: null requestTimer: null,
assessmentId: util.getCookie("assessmentId"),
}; };
}, },
components: { components: {
@ -171,11 +171,9 @@ export default {
} }
}, },
mounted() { mounted() {
this.assessmentId = this.getCookie("assessmentId");
if (!this.assessmentId) { if (!this.assessmentId) {
this.ShowAssessmentId = true; this.ShowAssessmentId = true;
} }
// //
newmain.$on("isSubmit", isSubmit => { newmain.$on("isSubmit", isSubmit => {
this.isSubmit = isSubmit; this.isSubmit = isSubmit;
@ -186,56 +184,6 @@ export default {
onCmReady3() { onCmReady3() {
this.$refs.myCmGenerate.codemirror.setSize("auto", "calc(100vh - 149px)"); this.$refs.myCmGenerate.codemirror.setSize("auto", "calc(100vh - 149px)");
}, },
onCmFocus(instance, event) {},
getCookie(cookie_name) {
//cookiekeyvalue
var allcookies = document.cookie; //
var cookie_pos = allcookies.indexOf(cookie_name); // cookie,
if (cookie_pos != -1) {
// cookie_pos1
//cookie1=
cookie_pos = cookie_pos + cookie_name.length + 1; //cookie
var cookie_end = allcookies.indexOf(";", cookie_pos);
if (cookie_end == -1) {
cookie_end = allcookies.length;
} //cookie
var value = unescape(allcookies.substring(cookie_pos, cookie_end));
}
return value;
},
onCmCodeChange(instance, obj) {
if(!this.submiting){
this.submiting = true
this.submit = 0;
this.projectId = this.projectId;
this.userId = this.getCookie("userId");
this.studentId = this.getCookie("studentId");
//
if (this.codeId == "") {
this.$post(this.api.AddCode, {
code: this.exampleData,
projectId: this.projectId,
judgmentPointsId: this.workbench1,
userId: parseInt(this.userId),
studentId: this.studentId,
submit: this.submit
})
.then(res => {
this.codeId = res.message;
this.submiting = false
newmain.$emit("codeid", this.codeId);
})
.catch(err => {});
} else {
//
// this.timer = setTimeout(this.UpdateCode, 300000);
this.submit = 0;
}
}
},
downloadFile(fileName,url) { downloadFile(fileName,url) {
var x = new XMLHttpRequest() var x = new XMLHttpRequest()
x.open("GET", url, true) x.open("GET", url, true)
@ -276,9 +224,9 @@ export default {
axios.post(this.api.UpdateCode,{ axios.post(this.api.UpdateCode,{
code: this.exampleData, code: this.exampleData,
bcId: 1, bcId: this.workbench1,
cid: 1, cid: this.courseId,
projectId: 1 projectId: this.projectId
},{ },{
cancelToken: new CANCEL_TOKEN(c => { // cancelToken: new CANCEL_TOKEN(c => { //
this.requestList.push(c) this.requestList.push(c)
@ -343,9 +291,9 @@ export default {
if(!isWhile) this.modifys = '' if(!isWhile) this.modifys = ''
this.$post(this.api.UpdateCode, { this.$post(this.api.UpdateCode, {
code: this.exampleData, code: this.exampleData,
bcId: 1, bcId: this.workbench1,
cid: 1, cid: this.courseId,
projectId: 1 projectId: this.projectId
}).then(res => { }).then(res => {
let result = res.message.result let result = res.message.result
if(result.includes('File ')){ if(result.includes('File ')){
@ -374,9 +322,9 @@ export default {
//() //()
this.$post(this.api.UpdateCode, { this.$post(this.api.UpdateCode, {
code: this.exampleData, code: this.exampleData,
bcId: 1, bcId: this.workbench1,
cid: 1, cid: this.courseId,
projectId: 1 projectId: this.projectId
}) })
.then(res => { .then(res => {
this.loadIns.close() this.loadIns.close()
@ -448,21 +396,6 @@ export default {
}); });
} }
}, },
UpdateCode() {
//()
this.$post(this.api.UpdateCode, {
code: this.exampleData,
bcId: 1,
cid: 1,
projectId: 1
})
.then(res => {
})
.catch(err => {});
clearTimeout(this.timer);
},
getQueryAnswer() { getQueryAnswer() {
this.error = true; this.error = true;
// //

@ -0,0 +1,42 @@
export default {
getCookie(cookie_name) {
//获取cookie中指定key的value
var allcookies = document.cookie; //索引长度,开始索引的位置
var cookie_pos = allcookies.indexOf(cookie_name); // 如果找到了索引,就代表cookie存在,否则不存在
if (cookie_pos != -1) {
// 把cookie_pos放在值的开始,只要给值加1即可
//计算取cookie值得开始索引,加的1为“=”
cookie_pos = cookie_pos + cookie_name.length + 1; //计算取cookie值得结束索引
var cookie_end = allcookies.indexOf(";", cookie_pos);
if (cookie_end == -1) {
cookie_end = allcookies.length;
} //得到想要的cookie的值
var value = unescape(allcookies.substring(cookie_pos, cookie_end));
}
return value;
},
// 返回格式化时间,传参例如:"yyyy-MM-dd hh:mm:ss"
formatDate(fmt,date) {
var date = date ? date : new Date()
var o = {
"M+" : date.getMonth()+1, //月份
"d+" : date.getDate(), //日
"h+" : date.getHours(), //小时
"m+" : date.getMinutes(), //分
"s+" : date.getSeconds(), //秒
"q+" : Math.floor((date.getMonth()+3)/3), //季度
"S" : date.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt
}
}

@ -5,7 +5,6 @@ export default {
QueryProject: `${host}occupationlab/projectManage/getProjectDetail`, //项目选择下拉框+项目信息+判分点信息展示 QueryProject: `${host}occupationlab/projectManage/getProjectDetail`, //项目选择下拉框+项目信息+判分点信息展示
ProjectId: `${host}/python/projectId`, //判分点下拉框信息展示 ProjectId: `${host}/python/projectId`, //判分点下拉框信息展示
Submit: `${host}/python/submit`, //提交代码与判分点进行判断 Submit: `${host}/python/submit`, //提交代码与判分点进行判断
AddCode: `${host}python/addCode`, //新增代码编译器
UpdateCode: `${host}python/python/runPythonCode`, //实时更新编辑器代码(修改代码) UpdateCode: `${host}python/python/runPythonCode`, //实时更新编辑器代码(修改代码)
QueryAnswer: `${host}/python/queryAnswer`, //提示答案 QueryAnswer: `${host}/python/queryAnswer`, //提示答案
DeleteCodes: `${host}/python/deleteCodes`, //重新开始 DeleteCodes: `${host}/python/deleteCodes`, //重新开始
@ -13,5 +12,5 @@ export default {
ChangeCode: `${host}/python/changeCode`, //input交互 ChangeCode: `${host}/python/changeCode`, //input交互
queryTestProject: `${host}occupationlab/projectManage/getProjectBySystemId`, //input交互 queryTestProject: `${host}occupationlab/projectManage/getProjectBySystemId`, //input交互
qualifications: `${host}/python/qualifications`, //input交互 qualifications: `${host}/python/qualifications`, //input交互
saveEvaluation: `${host}/python/saveEvaluation` //中途退出实验并保存实验数据(虚拟仿真实验) saveCache: `${host}python/python/saveCache` //中途退出实验并保存实验数据(虚拟仿真实验)
} }

@ -1,10 +1,9 @@
import axios from 'axios'; import axios from 'axios';
import QS from 'qs';
// import store from '../store/index'
import { import {
Message Message
} from 'element-ui' } from 'element-ui'
import router from '../router/index' import router from '../router/index'
import util from '@/util'
// 环境的切换 // 环境的切换
// if (process.env.NODE_ENV == 'development') { // if (process.env.NODE_ENV == 'development') {
@ -20,28 +19,9 @@ axios.defaults.timeout = 30000;
// post请求头 // post请求头
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
function getCookie (cookie_name) {
//获取cookie中指定key的value
var allcookies = document.cookie; //索引长度,开始索引的位置
var cookie_pos = allcookies.indexOf(cookie_name); // 如果找到了索引,就代表cookie存在,否则不存在
if (cookie_pos != -1) {
// 把cookie_pos放在值的开始,只要给值加1即可
//计算取cookie值得开始索引,加的1为“=”
cookie_pos = cookie_pos + cookie_name.length + 1; //计算取cookie值得结束索引
var cookie_end = allcookies.indexOf(";", cookie_pos);
if (cookie_end == -1) {
cookie_end = allcookies.length;
} //得到想要的cookie的值
var value = unescape(allcookies.substring(cookie_pos, cookie_end));
}
return value;
}
// 请求拦截器 // 请求拦截器
axios.interceptors.request.use(config => { axios.interceptors.request.use(config => {
const token = getCookie('admin-token') const token = util.getCookie('admin-token')
if (token) { if (token) {
// 存在将token写入 request header // 存在将token写入 request header
config.headers.token = token config.headers.token = token

@ -18,15 +18,15 @@
<el-tabs v-model="workbench1" type="card"> <el-tabs v-model="workbench1" type="card">
<el-tab-pane <el-tab-pane
v-for="item in workbench" v-for="item in workbench"
:key="item.judgmentPointsId" :key="item.judgmentId"
:label="item.judgmentPointsName" :label="item.name"
:value="item.judgmentPointsId" :value="item.judgmentId"
> >
<codemirror <codemirror
:key="codeKey" :key="codeKey"
:projectId.sync="projectId" :projectId.sync="projectId"
:code.sync="item.code" :code.sync="item.code"
:workbench1="item.judgmentPointsId" :workbench1="item.judgmentId"
:codeid.sync="item.codeId" :codeid.sync="item.codeId"
></codemirror> ></codemirror>
</el-tab-pane> </el-tab-pane>
@ -53,32 +53,11 @@
<script> <script>
import testPanel from "../components/TestPanel"; import testPanel from "../components/TestPanel";
import codemirror from "../components/codemirror"; import codemirror from "../components/codemirror";
import { log } from "util"; import util from '@/util'
//"yyyy-MM-dd hh:mm:ss"
function formatDate(fmt,date) {
var date = date ? date : new Date()
var o = {
"M+" : date.getMonth()+1, //
"d+" : date.getDate(), //
"h+" : date.getHours(), //
"m+" : date.getMinutes(), //
"s+" : date.getSeconds(), //
"q+" : Math.floor((date.getMonth()+3)/3), //
"S" : date.getMilliseconds() //
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt;
}
export default { export default {
data() { data() {
return { return {
courseId: util.getCookie("courseId"),
// //
isShow: false, isShow: false,
projectPermissions: 0, //(0 1 2) projectPermissions: 0, //(0 1 2)
@ -107,8 +86,8 @@ export default {
judgmentPointsIds: [], judgmentPointsIds: [],
autoStart: true, autoStart: true,
sendSync: true, sendSync: true,
entryTime: formatDate('yyyy-MM-dd hh:mm:ss'), entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'),
assessmentId: '', assessmentId: util.getCookie("assessmentId"),
defaultVal: sessionStorage.getItem("timer") defaultVal: sessionStorage.getItem("timer")
? parseInt(sessionStorage.getItem("timer")) ? parseInt(sessionStorage.getItem("timer"))
: 0, : 0,
@ -120,18 +99,10 @@ export default {
testPanel testPanel
}, },
beforeDestroy(){ beforeDestroy(){
let data = {
studentId: this.studentId,
startTime: this.entryTime,
endTime: formatDate('yyyy-MM-dd hh:mm:ss'),
projectId: this.projectId
}
this.$post(this.api.saveEvaluation,data).then(res => {})
this.leavePage() this.leavePage()
}, },
mounted() { mounted() {
this.autoLogout() this.autoLogout()
this.assessmentId = this.getCookie("assessmentId");
if (window.history && window.history.pushState) { if (window.history && window.history.pushState) {
// //
history.pushState(null, null, document.URL); history.pushState(null, null, document.URL);
@ -144,16 +115,13 @@ export default {
methods: { methods: {
leavePage(){ leavePage(){
if(!this.$refs.mainindex.isSubmit && !this.assessmentId && this.workbench.length){ if(!this.$refs.mainindex.isSubmit && !this.assessmentId && this.workbench.length){
let workbench = this.workbench let data = {
if(workbench.some(n => n.code.code)){ code: '',
let codeCache = { bcId: this.workbench1,
systemId: this.$config.systemId, cid: this.courseId,
projectId: this.projectId, projectId: this.projectId
workbench1: this.workbench1,
workbench
}
localStorage.setItem('codeCache',JSON.stringify(codeCache))
} }
this.$post(this.api.saveCache,data).then(res => {}).catch(e => {})
} }
}, },
autoLogout(){ autoLogout(){
@ -207,54 +175,8 @@ export default {
// //
this.projectId = value1; this.projectId = value1;
this.projectPermissions = projectPermissions; this.projectPermissions = projectPermissions;
this.studentId = this.getCookie("studentId");
this.codeId = 1
// debugger
this.workbench = workBench this.workbench = workBench
// this.$get(this.api.ProjectId, {
// projectId: this.projectId,
// studentId: this.studentId
// })
// .then(res => {
// if(workBench.length){
// this.workbench = workBench
// }else{
// this.workbench = res.message;
// this.workbench.map(item => {
// if (item.code.codeId == 0) {
// item.code.codeId = "";
// }
// if (this.projectPermissions == "0") {
// item.code.codeId = "";
// item.code.code = "";
// }
// });
// }
// this.assessmentId && (this.codeId = this.workbench[0].code.codeId)
// })
// .catch(err => {
// console.log(err);
// });
}, },
getCookie(cookie_name) {
//cookiekeyvalue
var allcookies = document.cookie; //
var cookie_pos = allcookies.indexOf(cookie_name); // cookie,
if (cookie_pos != -1) {
// cookie_pos1
//cookie1=
cookie_pos = cookie_pos + cookie_name.length + 1; //cookie
var cookie_end = allcookies.indexOf(";", cookie_pos);
if (cookie_end == -1) {
cookie_end = allcookies.length;
} //cookie
var value = unescape(allcookies.substring(cookie_pos, cookie_end));
}
return value;
}
} }
}; };
</script> </script>

Loading…
Cancel
Save