mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-12 12:26:44 +08:00
2022年5月29日从svn移到git
This commit is contained in:
221
src/utils/tools.js
Normal file
221
src/utils/tools.js
Normal file
@@ -0,0 +1,221 @@
|
||||
/**
|
||||
* 对象复制
|
||||
*/
|
||||
export const deepCopy = (obj) => {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取url协议
|
||||
* @param {Object} type
|
||||
*/
|
||||
export function getUrlPre(type) {
|
||||
const isHttps='https:'==document.location.prototype ? true:false;
|
||||
let isUrl='https';
|
||||
if(isHttps){
|
||||
isUrl='https';
|
||||
}else{
|
||||
isUrl='http';
|
||||
}
|
||||
return isUrl;
|
||||
}
|
||||
|
||||
// 类型过滤
|
||||
const contentTypeMaps = {
|
||||
10: '视频',
|
||||
20: '音频',
|
||||
30: '图片',
|
||||
40: '文档',
|
||||
41: '图文',
|
||||
50: 'scrom包',
|
||||
52: '外链',
|
||||
60: '作业',
|
||||
61: '考试',
|
||||
62: '评估',
|
||||
90: '其它',
|
||||
};
|
||||
export function getType(type) {
|
||||
let name = contentTypeMaps[type];
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件类型后续不带点的。比如 mp4 转化为对应的资源数字
|
||||
*/
|
||||
export function toContentType(fileType) {
|
||||
let docTypes=["pdf","doc","xls", "ppt","docx", "xlsx", "pptx"];
|
||||
let type = null;
|
||||
// ["doc", "xls", "ppt","docx", "xlsx", "pptx","png","txt", "pdf","jpg","gif","bmp","mp4","mp3"]
|
||||
if (fileType === "mp4") {
|
||||
type = 10;
|
||||
} else if (fileType === "mp3") {
|
||||
type = 20;
|
||||
} else if (fileType === "jpg" ||fileType === "png" ||fileType === "gif") {
|
||||
type = 30;
|
||||
} else if (docTypes.indexOf(fileType)>-1){
|
||||
type = 40;
|
||||
} else {
|
||||
type = 90;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
// 10微课,21在线课(直播);20:在线课( 录播);30:面授课;40:混合式,
|
||||
|
||||
// export function courseType(type) {
|
||||
// const maps = {
|
||||
// 10: '微课',
|
||||
// 21: '在线课(直播)',
|
||||
// 20: '在线课(录播)',
|
||||
// 30: '面授课',
|
||||
// 40: '混合式',
|
||||
// };
|
||||
// return maps[type];
|
||||
// }
|
||||
export function courseType(type) {
|
||||
const maps = {
|
||||
10: '微课',
|
||||
21: '在线课(直播)',
|
||||
20: '录播课',
|
||||
30: '线下课',
|
||||
40: '学习项目',
|
||||
};
|
||||
return maps[type];
|
||||
}
|
||||
|
||||
/**
|
||||
* 把日期格式化为显示时间,yyyy-MM-dd HH:mm:ss
|
||||
* @param {Object} date
|
||||
*/
|
||||
export function formatDate(date){
|
||||
var year = date.getFullYear(),
|
||||
month = date.getMonth() + 1,//月份是从0开始的
|
||||
day = date.getDate(),
|
||||
hour = date.getHours(),
|
||||
min = date.getMinutes(),
|
||||
sec = date.getSeconds();
|
||||
if(month<10){month='0'+month}
|
||||
if(day<10){day='0'+day}
|
||||
if(hour<10){hour='0'+hour}
|
||||
if(min<10){min='0'+min}
|
||||
if(sec<10){sec='0'+sec}
|
||||
var newTime = year + '-' +
|
||||
month + '-' +
|
||||
day + ' ' +
|
||||
hour + ':' +
|
||||
min + ':' +
|
||||
sec;
|
||||
return newTime;
|
||||
|
||||
}
|
||||
export function numberToLetter(x){ //此方法和移到utils中去
|
||||
let s = "";
|
||||
while (x > 0) {
|
||||
let m = x % 26;
|
||||
m = m === 0 ? (m = 26) : m;
|
||||
s = String.fromCharCode(96 + parseInt(m)) + s;
|
||||
x = (x - m) / 26;
|
||||
}
|
||||
return s.toUpperCase();
|
||||
}
|
||||
|
||||
export function testType(type) { //此方法移到tools中
|
||||
let name = '';
|
||||
switch (type) {
|
||||
case 101:
|
||||
name = '单选';
|
||||
break;
|
||||
case 102:
|
||||
name = '多选';
|
||||
break;
|
||||
case 103:
|
||||
name = '判断';
|
||||
break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
export function examType(type) { //此方法移到tools中
|
||||
let name = '';
|
||||
switch (type) {
|
||||
case 1:
|
||||
name = '单选';
|
||||
break;
|
||||
case 2:
|
||||
name = '多选';
|
||||
break;
|
||||
case 3:
|
||||
name = '判断';
|
||||
break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
export function correctJudgment(ditem) {
|
||||
let judgment = false;
|
||||
if(ditem.type == 101 || ditem.type == 103) {
|
||||
ditem.options.forEach(item=>{
|
||||
if(item.answer){
|
||||
if(item.id == ditem.userAnswer) {
|
||||
judgment = true;
|
||||
} else{
|
||||
judgment = false;
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
ditem.options.forEach(item=>{
|
||||
if(item.answer == item.isCheck){
|
||||
judgment = true;
|
||||
|
||||
}else{
|
||||
judgment = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
return judgment;
|
||||
}
|
||||
export function toScore(score) {
|
||||
if (!score) {
|
||||
return '0';
|
||||
}
|
||||
if((''+score).indexOf('.')>-1){
|
||||
return score.toFixed(1);
|
||||
}else{
|
||||
return score+'.0';
|
||||
}
|
||||
}
|
||||
export function toScoreTow(score) {// 返回两位小数
|
||||
if (!score) {
|
||||
return '0';
|
||||
}
|
||||
if((''+score).indexOf('.')>-1){
|
||||
return score.toFixed(2);
|
||||
}else{
|
||||
return score+'.00';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 数组互换位置
|
||||
* @param {array} arr 数组
|
||||
* @param {number} index1 添加项目的位置
|
||||
* @param {number} index2 删除项目的位置
|
||||
* index1和index2分别是两个数组的索引值,即是两个要交换元素位置的索引值,如1,5就是数组中下标为1和5的两个元素交换位置
|
||||
*/
|
||||
export function swapArray(arr, index1, index2) {
|
||||
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像文字
|
||||
* @param {*} text
|
||||
* @returns
|
||||
*/
|
||||
export function userAvatarText(text){
|
||||
if(text){
|
||||
let len=text.length;
|
||||
if(len>2){
|
||||
text=text.substring(len-2);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
Reference in New Issue
Block a user