仅能打开一个python页面限制

master
yujialong 5 months ago
parent 93987d0e74
commit 9f37d8be0a
  1. 24
      src/App.vue
  2. 8
      src/components/TestPanel.vue
  3. 84
      src/util/index.js
  4. 41
      src/views/Home.vue

@ -5,9 +5,10 @@
</template>
<script>
import Util from '@/util'
export default {
name: "App",
created() {
created () {
//sessionStorage
if (sessionStorage.getItem("store")) {
this.$store.replaceState(
@ -17,10 +18,26 @@ export default {
JSON.parse(sessionStorage.getItem("store"))
)
);
} //vuexsessionStorage
}
//vuexsessionStorage
window.addEventListener("beforeunload", () => {
console.log('beforeunload')
const opened = +localStorage.getItem('opened')
if (opened) {
localStorage.setItem('opened', opened - 1)
} else {
localStorage.removeItem('opened')
}
sessionStorage.setItem("store", JSON.stringify(this.$store.state));
});
//
if (!document.referrer) {
localStorage.setItem('opened', 2)
Util.exit()
}
}
};
</script>
@ -32,9 +49,8 @@ export default {
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
}
body {
margin: 0;
}
</style>

@ -164,7 +164,7 @@
<script>
import newmain from "../util/newMain";
import quill from "@/components/quill";
import util from '@/util'
import Util from '@/util'
import Config from '@/config'
import Cookie from 'js-cookie'
import 'quill/dist/quill.core.css';
@ -824,7 +824,7 @@ export default {
const date = await this.getNow()
const { entryTime } = this
const timeSum = Math.ceil((date - entryTime) / 60000) //
const submitTime = util.formatDate('yyyy-MM-dd hh:mm:ss', date)
const submitTime = Util.formatDate('yyyy-MM-dd hh:mm:ss', date)
const projectId = this.projectId
const pro = this.projectList.find(e => e.projectId == projectId)
const projectName = pro ? pro.projectName : '' //
@ -847,7 +847,7 @@ export default {
classId: this.classId ? this.classId : '',
className: this.className ? this.className : '',
curriculumId: this.courseId,
startTime: util.formatDate('yyyy-MM-dd hh:mm:ss', entryTime), //
startTime: Util.formatDate('yyyy-MM-dd hh:mm:ss', entryTime), //
endTime: this.projectPermissions ? this.endTime : submitTime, //
submitTime, // 3
timeSum,
@ -881,7 +881,7 @@ export default {
}
score += e.examScore //
})
this.grade = util.handleZero(score) // 0()
this.grade = Util.handleZero(score) // 0()
this.reportId = reportId
this.$store.commit('setReportId', reportId)
this.$store.commit('setTaskList', taskList)

@ -1,69 +1,54 @@
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);
import Config from '@/config'
import Cookie from 'js-cookie'
if (cookie_end == -1) {
cookie_end = allcookies.length;
} //得到想要的cookie的值
var value = unescape(allcookies.substring(cookie_pos, cookie_end));
}
return value;
},
export default {
// 返回格式化时间,传参例如:"yyyy-MM-dd hh:mm:ss"
formatDate(fmt,date) {
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() //毫秒
"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));
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)));
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
},
// 传入文件后缀判断是否是视频
isVideo(ext) {
isVideo (ext) {
if ("mp4,3gp,mov,m4v,avi,dat,mkv,flv,vob,rmvb,rm,qlv".includes(ext)) return true;
return false;
},
// 传入文件后缀判断是否是图片
isImg(ext) {
isImg (ext) {
if ("jpg,jpeg,png,gif,svg,psd".includes(ext)) return true;
return false;
},
// 传入文件后缀判断是否是pdf以外的文档
isDoc(ext) {
isDoc (ext) {
if ("xls,xlsx,doc,docx,pdf,ppt,pptx".includes(ext)) return true;
return false;
},
// 传入文件名获取文件后缀
getFileExt(fileName) {
getFileExt (fileName) {
return fileName.substring(fileName.lastIndexOf('.') + 1)
},
// 下载文件
downloadFile(fileName,url) {
downloadFile (fileName, url) {
var x = new XMLHttpRequest()
x.open("GET", url, true)
x.responseType = 'blob'
x.onload=function(e) {
x.onload = function (e) {
var url = window.URL.createObjectURL(x.response)
var a = document.createElement('a')
a.href = url
@ -73,7 +58,7 @@ export default {
x.send()
},
// 下载图片
downloadPic(fileName, src) {
downloadPic (fileName, src) {
const canvas = document.createElement('canvas')
const img = document.createElement('img')
// 解决跨域 Canvas 污染问题
@ -97,7 +82,7 @@ export default {
}
},
// 传入文件名和数据,下载文件
downloadFileDirect(fileName,data) {
downloadFileDirect (fileName, data) {
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = fileName
@ -114,5 +99,26 @@ export default {
// 小于0前面加上0
handleZero (num) {
return num < 10 ? '0' + num : num
},
// 退出实验
exit () {
let href = Config.isDev ?
`http://${location.hostname}:8082/#/` :
`${location.origin}${Cookie.get('admin-fromManager') ?
'/admin' :
(!Config.isTest) ?
'' :
'/student'}/#/`
// 考核
if (Cookie.get('admin-assessmentId')) {
href += `ass/list`
} else if (Cookie.get('admin-competitionId')) {
// 竞赛
href += `match/list`
} else {
// 练习
href += `station/preview?courseId=${Cookie.get('admin-courseId')}&curriculumName=${Cookie.get('admin-curriculumName') ? decodeURIComponent(Cookie.get('admin-curriculumName')) : 'python'}&mallId=${Cookie.get('admin-mallId')}`
}
location.href = href
}
}

@ -50,9 +50,10 @@
</template>
<script>
import newmain from "../util/newMain";
import testPanel from "../components/TestPanel";
import codemirror from "../components/codemirror";
import newmain from "../util/newMain"
import Util from '@/util'
import testPanel from "../components/TestPanel"
import codemirror from "../components/codemirror"
import Cookie from 'js-cookie'
import { Loading } from 'element-ui'
import Config from '@/config'
@ -95,16 +96,19 @@ export default {
testPanel
},
mounted () {
//
if (!document.referrer) {
const opened = +localStorage.getItem('opened')
if (opened) {
localStorage.setItem('opened', opened + 1)
this.notAllowed = 1
this.$alert('我们注意到您当前已尝试打开多个实验页面。为保证实验的公平性和诚信,系统仅允许单个实验页面处于活跃状态。', '提示', {
confirmButtonText: '退出当前页面',
showClose: false,
callback: action => {
this.back()
}
beforeClose: () => {
Util.exit()
},
})
} else {
localStorage.setItem('opened', 1)
}
document.onkeydown = function (event) {
@ -158,7 +162,7 @@ export default {
if ((new Date().getTime() - lastTime) > this.$config.autoLogoutTime) {
logout || this.$message.error('用户登录过期,请重新登录')
logout = true
setTimeout(this.back, 1500)
setTimeout(Util.exit, 1500)
}
}, 1000)
},
@ -177,24 +181,7 @@ export default {
},
// 退
back () {
let href = this.$config.isDev ?
`http://${location.hostname}:8082/#/` :
`${location.origin}${this.fromManager ?
'/admin' :
(!this.$config.isTest) ?
'' :
'/student'}/#/`
//
if (this.assessmentId) {
href += `ass/list`
} else if (this.competitionId) {
//
href += `match/list`
} else {
//
href += `station/preview?courseId=${this.courseId}&curriculumName=${this.curriculumName}&mallId=${this.mallId}`
}
location.href = href
Util.exit()
},
// id
setPoints (projectId, systemId, workbench) {

Loading…
Cancel
Save