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>
import newmain from "../util/newMain";
import axios from "axios";
import * as $ from "jquery";
import { get } from "http";
//"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;
}
import util from '@/util'
export default {
data() {
return {
@ -197,7 +174,7 @@ export default {
assessmentId: "",
projectPermissions: 0, //(0 1 2)
isSubmit: false,
entryTime: formatDate('yyyy-MM-dd hh:mm:ss'),
entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'),
startTime: '',
stopTime: '',
isSelected: false,
@ -263,41 +240,42 @@ export default {
}
},
mounted() {
this.assessmentId = this.getCookie("assessmentId");
this.userId = this.getCookie("userId");
this.studentId = this.getCookie("studentId");
this.projectId = this.getCookie("projectId");
this.courseId = this.getCookie("courseId");
this.startTime = this.getCookie("startTime") ? new Date(this.getCookie("startTime")).getTime() : ''
this.stopTime = this.getCookie("stopTime") ? new Date(this.getCookie("stopTime")).getTime() : ''
this.assessmentId = util.getCookie("assessmentId");
this.userId = util.getCookie("userId");
this.studentId = util.getCookie("studentId");
this.projectId = util.getCookie("projectId");
this.courseId = util.getCookie("courseId");
this.startTime = util.getCookie("startTime") ? new Date(util.getCookie("startTime")).getTime() : ''
this.stopTime = util.getCookie("stopTime") ? new Date(util.getCookie("stopTime")).getTime() : ''
this.projectPermissions = this.projectId ? 1 : 0
if(this.projectId){
this.getQueryProject();
}else{
console.log(33)
this.getProjects();
let codeCache = localStorage.getItem('codeCache')
if(codeCache){
codeCache = JSON.parse(codeCache)
if(codeCache.systemId && codeCache.systemId == this.$config.systemId){
this.$confirm('是否要继续上次的实验?', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'success'
}).then(() => {
this.value1 = codeCache.projectId
this.workbenchCus = codeCache.workbench
this.isRecovery = true
this.selectProject()
let codeIds = []
codeCache.workbench.map(n => codeIds.push(n.code.codeId))
codeIds = codeIds.filter(n => n)
this.codeIds = codeIds
this.$emit('recoveryCode',codeCache.workbench1)
}).catch(() => {
localStorage.removeItem('codeCache')
})
}
// if(codeCache.systemId && codeCache.systemId == this.$config.systemId){
// this.$confirm('', '', {
// confirmButtonText: '',
// cancelButtonText: '',
// type: 'success'
// }).then(() => {
// this.value1 = codeCache.projectId
// this.workbenchCus = codeCache.workbench
// this.isRecovery = true
// this.selectProject()
// let codeIds = []
// codeCache.workbench.map(n => codeIds.push(n.code.codeId))
// codeIds = codeIds.filter(n => n)
// this.codeIds = codeIds
// this.$emit('recoveryCode',codeCache.workbench1)
// }).catch(() => {
// localStorage.removeItem('codeCache')
// })
// }
}
}
this.assessmentId && this.projectId && this.checkVer()
@ -475,6 +453,7 @@ export default {
this.handleData(res.projectManage,1)
this.projectId = res.projectManage[0].projectId
}
// debugger
this.points = res.projectJudgmentVos;
this.$emit("tell", this.value1, this.projectPermissions, this.points);
// -
@ -539,7 +518,7 @@ export default {
let data = {
systemId: 1,
cId: this.courseId,
permissions: 0
permissions: this.projectPermissions
}
this.$get(`${this.api.queryTestProject}`,data).then(res => {
this.handleData(res.projects,2)
@ -586,24 +565,6 @@ export default {
},
passToParent(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"
class="code-mirror"
@ready="onCmReady3"
@focus="onCmFocus"
@input="onCmCodeChange"
ref="myCmGenerate"
></codemirror>
<div v-if="isSubmit" class="code-mask"></div>
<el-button
type="warning"
@click="AnswerTips()"
@ -96,11 +93,13 @@ import "codemirror/theme/base16-light.css";
import * as $ from "jquery";
import { Loading } from 'element-ui';
import axios from 'axios';
import util from '@/util'
const CANCEL_TOKEN = axios.CancelToken
export default {
props: ["workbench1", "code", "codeid", "projectId"],
data() {
return {
courseId: util.getCookie("courseId"),
datas: [],
ShowAssessmentId: false,
answer: "",
@ -153,7 +152,8 @@ export default {
inputTextReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)\(['|"]([\s\S]+?)['|"]\)/m,// input()
requestList: [],
sourceCode: '',
requestTimer: null
requestTimer: null,
assessmentId: util.getCookie("assessmentId"),
};
},
components: {
@ -171,11 +171,9 @@ export default {
}
},
mounted() {
this.assessmentId = this.getCookie("assessmentId");
if (!this.assessmentId) {
this.ShowAssessmentId = true;
}
//
newmain.$on("isSubmit", isSubmit => {
this.isSubmit = isSubmit;
@ -186,56 +184,6 @@ export default {
onCmReady3() {
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) {
var x = new XMLHttpRequest()
x.open("GET", url, true)
@ -276,9 +224,9 @@ export default {
axios.post(this.api.UpdateCode,{
code: this.exampleData,
bcId: 1,
cid: 1,
projectId: 1
bcId: this.workbench1,
cid: this.courseId,
projectId: this.projectId
},{
cancelToken: new CANCEL_TOKEN(c => { //
this.requestList.push(c)
@ -343,9 +291,9 @@ export default {
if(!isWhile) this.modifys = ''
this.$post(this.api.UpdateCode, {
code: this.exampleData,
bcId: 1,
cid: 1,
projectId: 1
bcId: this.workbench1,
cid: this.courseId,
projectId: this.projectId
}).then(res => {
let result = res.message.result
if(result.includes('File ')){
@ -374,9 +322,9 @@ export default {
//()
this.$post(this.api.UpdateCode, {
code: this.exampleData,
bcId: 1,
cid: 1,
projectId: 1
bcId: this.workbench1,
cid: this.courseId,
projectId: this.projectId
})
.then(res => {
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() {
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`, //项目选择下拉框+项目信息+判分点信息展示
ProjectId: `${host}/python/projectId`, //判分点下拉框信息展示
Submit: `${host}/python/submit`, //提交代码与判分点进行判断
AddCode: `${host}python/addCode`, //新增代码编译器
UpdateCode: `${host}python/python/runPythonCode`, //实时更新编辑器代码(修改代码)
QueryAnswer: `${host}/python/queryAnswer`, //提示答案
DeleteCodes: `${host}/python/deleteCodes`, //重新开始
@ -13,5 +12,5 @@ export default {
ChangeCode: `${host}/python/changeCode`, //input交互
queryTestProject: `${host}occupationlab/projectManage/getProjectBySystemId`, //input交互
qualifications: `${host}/python/qualifications`, //input交互
saveEvaluation: `${host}/python/saveEvaluation` //中途退出实验并保存实验数据(虚拟仿真实验)
saveCache: `${host}python/python/saveCache` //中途退出实验并保存实验数据(虚拟仿真实验)
}

@ -1,10 +1,9 @@
import axios from 'axios';
import QS from 'qs';
// import store from '../store/index'
import {
Message
} from 'element-ui'
import router from '../router/index'
import util from '@/util'
// 环境的切换
// if (process.env.NODE_ENV == 'development') {
@ -20,28 +19,9 @@ axios.defaults.timeout = 30000;
// post请求头
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 => {
const token = getCookie('admin-token')
const token = util.getCookie('admin-token')
if (token) {
// 存在将token写入 request header
config.headers.token = token

@ -18,15 +18,15 @@
<el-tabs v-model="workbench1" type="card">
<el-tab-pane
v-for="item in workbench"
:key="item.judgmentPointsId"
:label="item.judgmentPointsName"
:value="item.judgmentPointsId"
:key="item.judgmentId"
:label="item.name"
:value="item.judgmentId"
>
<codemirror
:key="codeKey"
:projectId.sync="projectId"
:code.sync="item.code"
:workbench1="item.judgmentPointsId"
:workbench1="item.judgmentId"
:codeid.sync="item.codeId"
></codemirror>
</el-tab-pane>
@ -53,32 +53,11 @@
<script>
import testPanel from "../components/TestPanel";
import codemirror from "../components/codemirror";
import { log } 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;
}
import util from '@/util'
export default {
data() {
return {
courseId: util.getCookie("courseId"),
//
isShow: false,
projectPermissions: 0, //(0 1 2)
@ -107,8 +86,8 @@ export default {
judgmentPointsIds: [],
autoStart: true,
sendSync: true,
entryTime: formatDate('yyyy-MM-dd hh:mm:ss'),
assessmentId: '',
entryTime: util.formatDate('yyyy-MM-dd hh:mm:ss'),
assessmentId: util.getCookie("assessmentId"),
defaultVal: sessionStorage.getItem("timer")
? parseInt(sessionStorage.getItem("timer"))
: 0,
@ -120,18 +99,10 @@ export default {
testPanel
},
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()
},
mounted() {
this.autoLogout()
this.assessmentId = this.getCookie("assessmentId");
if (window.history && window.history.pushState) {
//
history.pushState(null, null, document.URL);
@ -144,16 +115,13 @@ export default {
methods: {
leavePage(){
if(!this.$refs.mainindex.isSubmit && !this.assessmentId && this.workbench.length){
let workbench = this.workbench
if(workbench.some(n => n.code.code)){
let codeCache = {
systemId: this.$config.systemId,
projectId: this.projectId,
workbench1: this.workbench1,
workbench
}
localStorage.setItem('codeCache',JSON.stringify(codeCache))
let data = {
code: '',
bcId: this.workbench1,
cid: this.courseId,
projectId: this.projectId
}
this.$post(this.api.saveCache,data).then(res => {}).catch(e => {})
}
},
autoLogout(){
@ -207,54 +175,8 @@ export default {
//
this.projectId = value1;
this.projectPermissions = projectPermissions;
this.studentId = this.getCookie("studentId");
this.codeId = 1
// debugger
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>

Loading…
Cancel
Save