mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-06 17:36:45 +08:00
267 lines
5.1 KiB
JavaScript
267 lines
5.1 KiB
JavaScript
// 类型过滤
|
||
const contentTypeMaps = {
|
||
10: '视频',
|
||
20: '音频',
|
||
30: '图片',
|
||
40: '文档',
|
||
41: '图文',
|
||
50: 'scrom包',
|
||
52: '外部连接',
|
||
60: '作业',
|
||
61: '考试',
|
||
62: '评估',
|
||
90: '其它',
|
||
};
|
||
|
||
/**
|
||
* 获取课程内容的类型名称
|
||
* @param {Object} type
|
||
*/
|
||
export function getContentType(type) {
|
||
let name = contentTypeMaps[type];
|
||
return name;
|
||
}
|
||
|
||
/**
|
||
* 获取课程类型的名称 10微课,21在线课(直播);20:在线课( 录播);30:面授课;40:混合式,
|
||
* @param {Object} type
|
||
*/
|
||
export function getCourseType(type) {
|
||
const maps = {
|
||
10: '录播课',
|
||
21: '直播课',
|
||
20: '录播课',
|
||
30: '面授课',
|
||
40: '学习项目',
|
||
};
|
||
return maps[type];
|
||
}
|
||
|
||
/**
|
||
* 获取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;
|
||
}
|
||
|
||
/**
|
||
* 格式化日期,转化为 yyyy-MM-dd HH:mm:ss 格式
|
||
* @param {Object} date
|
||
*/
|
||
export function formatDate(date) {
|
||
if (date == null || date == '') {
|
||
return;
|
||
}
|
||
var year = new Date(Number(date)).getFullYear(),
|
||
month = new Date(Number(date)).getMonth() + 1, //月份是从0开始的
|
||
day = new Date(Number(date)).getDate(),
|
||
hour = new Date(Number(date)).getHours(),
|
||
min = new Date(Number(date)).getMinutes(),
|
||
sec = new Date(Number(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 toScore(score) {
|
||
if (!score || score == 0) {
|
||
return '未评';
|
||
}
|
||
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 {Object} x
|
||
*/
|
||
export function numberToLetter(x) {
|
||
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 getQuestionType(type) {
|
||
let name = '';
|
||
switch (type) {
|
||
case 101:
|
||
name = '单选';
|
||
break;
|
||
case 102:
|
||
name = '多选';
|
||
break;
|
||
case 103:
|
||
name = '判断';
|
||
break;
|
||
}
|
||
return name;
|
||
}
|
||
export function examType(type) {
|
||
let name = '';
|
||
switch (type) {
|
||
case 1:
|
||
name = '单选';
|
||
break;
|
||
case 2:
|
||
name = '多选';
|
||
break;
|
||
case 3:
|
||
name = '判断';
|
||
break;
|
||
}
|
||
return name;
|
||
}
|
||
/**
|
||
* 上方法没有说明
|
||
* @param {Object} ditem
|
||
*/
|
||
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;
|
||
}
|
||
|
||
/**
|
||
* 头像文字
|
||
* @param {*} text
|
||
* @returns
|
||
*/
|
||
export function userAvatarText(text) {
|
||
if (text) {
|
||
let len = text.length;
|
||
if (len > 2) {
|
||
text = text.substring(len - 2);
|
||
}
|
||
}
|
||
return text;
|
||
}
|
||
/**截取机构名称路径namePath最后两段,不包含第一个 */
|
||
export const cutOrgNamePath = (namePath) => {
|
||
let newName=namePath;
|
||
if(newName){
|
||
let names=newName.split('/');
|
||
let len=names.length;
|
||
//使用最后两们
|
||
if(len>1){
|
||
//newName=names[len-2]+'/'+names[len-1];
|
||
newName=names[1];
|
||
}
|
||
}
|
||
return newName;
|
||
};
|
||
/**
|
||
* 将秒转换成小时
|
||
* @author wn
|
||
* @date 2022.10.18
|
||
* @param {Object} second 秒
|
||
* @@return 小时
|
||
*/
|
||
export function formatSecondToHour(second) {
|
||
var n = 1; // 保留小数位
|
||
second = Number(second);
|
||
var h = second / 3600;
|
||
h = h.toFixed(n);
|
||
if(isNaN(h)){
|
||
h = 0;
|
||
}
|
||
return h;
|
||
}
|
||
// 秒换成时分秒
|
||
export function getHMS(time) {
|
||
const hour = parseInt(time / 3600) < 10 ? '0' + parseInt(time / 3600) : parseInt(time / 3600)
|
||
const min = parseInt(time % 3600 / 60) < 10 ? '0' + parseInt(time % 3600 / 60) : parseInt(time % 3600 / 60)
|
||
const sec = parseInt(time % 3600 % 60) < 10 ? '0' + parseInt(time % 3600 % 60) : parseInt(time % 3600 % 60)
|
||
return hour + ':' + min + ':' + sec
|
||
}
|
||
|
||
/**格式化人数的文档 ,学习人数,关注人数等*/
|
||
export function formatUserNumber(num) {
|
||
let rsNum =0;
|
||
if(num<5){return 0;}
|
||
if(num>=5 && num<= 10){return 10 +"+";}
|
||
if(num<=94){
|
||
rsNum=Math.round((num)/10)*10;
|
||
return rsNum+'+';
|
||
}
|
||
if(num>94 && num <= 1000){
|
||
rsNum=Math.round((num)/100)*100;
|
||
return rsNum+'+';
|
||
}
|
||
if(num>1000 && num <= 10000){
|
||
rsNum=Math.round((num)/1000)*1000;
|
||
return rsNum+'+';
|
||
}
|
||
if(num>10000){
|
||
// rsNum=Math.round((num)/10000)*10000;
|
||
// return rsNum+'+';
|
||
rsNum=Math.round((num)/10000);
|
||
return rsNum+'W+';
|
||
}
|
||
return num;
|
||
}
|