|
|
|
@ -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 |
|
|
|
|
} |
|
|
|
|
} |