仅能打开一个python页面限制

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

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

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

@ -1,118 +1,124 @@
import Config from '@/config'
import Cookie from 'js-cookie'
export default { export default {
getCookie(cookie_name) { // 返回格式化时间,传参例如:"yyyy-MM-dd hh:mm:ss"
//获取cookie中指定key的value formatDate (fmt, date) {
var allcookies = document.cookie; //索引长度,开始索引的位置 var date = date ? date : new Date()
var cookie_pos = allcookies.indexOf(cookie_name); // 如果找到了索引,就代表cookie存在,否则不存在 var o = {
"M+": date.getMonth() + 1, //月份
if (cookie_pos != -1) { "d+": date.getDate(), //日
// 把cookie_pos放在值的开始,只要给值加1即可 "h+": date.getHours(), //小时
//计算取cookie值得开始索引,加的1为“=” "m+": date.getMinutes(), //分
cookie_pos = cookie_pos + cookie_name.length + 1; //计算取cookie值得结束索引 "s+": date.getSeconds(), //秒
var cookie_end = allcookies.indexOf(";", cookie_pos); "q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
if (cookie_end == -1) { };
cookie_end = allcookies.length; if (/(y+)/.test(fmt)) {
} //得到想要的cookie的值 fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
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
},
// 传入文件后缀判断是否是视频
isVideo(ext) {
if ("mp4,3gp,mov,m4v,avi,dat,mkv,flv,vob,rmvb,rm,qlv".includes(ext)) return true;
return false;
},
// 传入文件后缀判断是否是图片
isImg(ext) {
if ("jpg,jpeg,png,gif,svg,psd".includes(ext)) return true;
return false;
},
// 传入文件后缀判断是否是pdf以外的文档
isDoc(ext) {
if ("xls,xlsx,doc,docx,pdf,ppt,pptx".includes(ext)) return true;
return false;
},
// 传入文件名获取文件后缀
getFileExt(fileName) {
return fileName.substring(fileName.lastIndexOf('.') + 1)
},
// 下载文件
downloadFile(fileName,url) {
var x = new XMLHttpRequest()
x.open("GET", url, true)
x.responseType = 'blob'
x.onload=function(e) {
var url = window.URL.createObjectURL(x.response)
var a = document.createElement('a')
a.href = url
a.download = fileName
a.click()
}
x.send()
},
// 下载图片
downloadPic(fileName, src) {
const canvas = document.createElement('canvas')
const img = document.createElement('img')
// 解决跨域 Canvas 污染问题
img.setAttribute('crossOrigin', 'anonymous')
//将资源链接赋值过去,才能触发img.onload事件
img.src = src
img.onload = function (e) {
canvas.width = img.width
canvas.height = img.height
const context = canvas.getContext('2d')
//绘制图片
context.drawImage(img, 0, 0, img.width, img.height)
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height)
//将canvas转base64码,然后创建一个a连接自动下载图片
canvas.toBlob((blob) => {
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = fileName
link.click()
})
}
},
// 传入文件名和数据,下载文件
downloadFileDirect(fileName,data) {
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(data)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
} else { // IE10+下载
navigator.msSaveBlob(data, fileName)
}
},
// 小于0前面加上0
handleZero (num) {
return num < 10 ? '0' + num : num
} }
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) {
if ("mp4,3gp,mov,m4v,avi,dat,mkv,flv,vob,rmvb,rm,qlv".includes(ext)) return true;
return false;
},
// 传入文件后缀判断是否是图片
isImg (ext) {
if ("jpg,jpeg,png,gif,svg,psd".includes(ext)) return true;
return false;
},
// 传入文件后缀判断是否是pdf以外的文档
isDoc (ext) {
if ("xls,xlsx,doc,docx,pdf,ppt,pptx".includes(ext)) return true;
return false;
},
// 传入文件名获取文件后缀
getFileExt (fileName) {
return fileName.substring(fileName.lastIndexOf('.') + 1)
},
// 下载文件
downloadFile (fileName, url) {
var x = new XMLHttpRequest()
x.open("GET", url, true)
x.responseType = 'blob'
x.onload = function (e) {
var url = window.URL.createObjectURL(x.response)
var a = document.createElement('a')
a.href = url
a.download = fileName
a.click()
}
x.send()
},
// 下载图片
downloadPic (fileName, src) {
const canvas = document.createElement('canvas')
const img = document.createElement('img')
// 解决跨域 Canvas 污染问题
img.setAttribute('crossOrigin', 'anonymous')
//将资源链接赋值过去,才能触发img.onload事件
img.src = src
img.onload = function (e) {
canvas.width = img.width
canvas.height = img.height
const context = canvas.getContext('2d')
//绘制图片
context.drawImage(img, 0, 0, img.width, img.height)
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height)
//将canvas转base64码,然后创建一个a连接自动下载图片
canvas.toBlob((blob) => {
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = fileName
link.click()
})
}
},
// 传入文件名和数据,下载文件
downloadFileDirect (fileName, data) {
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(data)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
} else { // IE10+下载
navigator.msSaveBlob(data, fileName)
}
},
// 小于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> </template>
<script> <script>
import newmain from "../util/newMain"; import newmain from "../util/newMain"
import testPanel from "../components/TestPanel"; import Util from '@/util'
import codemirror from "../components/codemirror"; import testPanel from "../components/TestPanel"
import codemirror from "../components/codemirror"
import Cookie from 'js-cookie' import Cookie from 'js-cookie'
import { Loading } from 'element-ui' import { Loading } from 'element-ui'
import Config from '@/config' import Config from '@/config'
@ -95,16 +96,19 @@ export default {
testPanel testPanel
}, },
mounted () { mounted () {
// const opened = +localStorage.getItem('opened')
if (!document.referrer) { if (opened) {
localStorage.setItem('opened', opened + 1)
this.notAllowed = 1 this.notAllowed = 1
this.$alert('我们注意到您当前已尝试打开多个实验页面。为保证实验的公平性和诚信,系统仅允许单个实验页面处于活跃状态。', '提示', { this.$alert('我们注意到您当前已尝试打开多个实验页面。为保证实验的公平性和诚信,系统仅允许单个实验页面处于活跃状态。', '提示', {
confirmButtonText: '退出当前页面', confirmButtonText: '退出当前页面',
showClose: false, showClose: false,
callback: action => { beforeClose: () => {
this.back() Util.exit()
} },
}) })
} else {
localStorage.setItem('opened', 1)
} }
document.onkeydown = function (event) { document.onkeydown = function (event) {
@ -158,7 +162,7 @@ export default {
if ((new Date().getTime() - lastTime) > this.$config.autoLogoutTime) { if ((new Date().getTime() - lastTime) > this.$config.autoLogoutTime) {
logout || this.$message.error('用户登录过期,请重新登录') logout || this.$message.error('用户登录过期,请重新登录')
logout = true logout = true
setTimeout(this.back, 1500) setTimeout(Util.exit, 1500)
} }
}, 1000) }, 1000)
}, },
@ -177,24 +181,7 @@ export default {
}, },
// 退 // 退
back () { back () {
let href = this.$config.isDev ? Util.exit()
`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
}, },
// id // id
setPoints (projectId, systemId, workbench) { setPoints (projectId, systemId, workbench) {

Loading…
Cancel
Save