合并课程

This commit is contained in:
kclf
2022-11-25 20:25:27 +08:00
parent c2e43611c8
commit 7a6f118bac
17 changed files with 3379 additions and 1298 deletions

View File

@@ -26,20 +26,20 @@ export function traverseArr(arr, traverseObj, saveOld = false) {
return newArr;
}
// export function deepClone(obj) {
// let result = typeof obj.splice === "function" ? [] : {};
// if (obj && typeof obj === "object") {
// for (let key in obj) {
// if (obj[key] && typeof obj[key] === "object") {
// result[key] = deepClone(obj[key]);
// } else {
// result[key] = obj[key];
// }
// }
// return result;
// }
// return obj;
// }
export function deepClone(obj) {
let result = typeof obj.splice === "function" ? [] : {};
if (obj && typeof obj === "object") {
for (let key in obj) {
if (obj[key] && typeof obj[key] === "object") {
result[key] = deepClone(obj[key]);
} else {
result[key] = obj[key];
}
}
return result;
}
return obj;
}
export function deepCloneFilterString(obj, fillterKeys) {
let result = typeof obj.splice === "function" ? [] : {};
@@ -95,6 +95,14 @@ export function getdateToTime(date) {
return `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${hh}:${mm}`;
}
export function getdateToDate(date) {
let now = new Date(parseInt(date)),
y = now.getFullYear(),
m = now.getMonth() + 1,
d = now.getDate();
return `${y}${m < 10 ? "0" + m : m}${d < 10 ? "0" + d : d}`;
}
//计算两个时间之间的时间差 多少天时分秒
export function intervalTime(startTime) {
const curTime = new Date().getTime(); //计算当前时间戳
@@ -117,3 +125,47 @@ export function intervalTime(startTime) {
seconds,
};
}
// 分片处理
export function batchLoadList(
sourceData,
dataTotal,
splitNumber = 10,
callback,
complete
) {
if (sourceData.length <= splitNumber) {
typeof callback === "function" && callback(sourceData);
typeof callback === "function" && complete();
return;
}
let first = 0;
const intTime = parseInt(String(dataTotal / splitNumber));
const floatTime = sourceData.length % splitNumber;
const total = intTime + (floatTime > 0 ? 1 : 0);
for (let i = 0; i < total; i += 1) {
const end = first + splitNumber;
const splitArray = sourceData.slice(first, end);
setTimeout(() => {
typeof callback === "function" && callback(splitArray);
if (i === total - 1) {
// 分片处理完成
typeof callback === "function" && complete();
}
});
first = end;
}
}
export function newFile(code) {
const blob = new Blob([code], {
type: "application/vnd.ms-excel",
});
const linkNode = document.createElement("a");
linkNode.style.display = "none";
linkNode.href = URL.createObjectURL(blob); //生成一个Blob URL
document.body.appendChild(linkNode);
linkNode.click(); //模拟在按钮上的一次鼠标单击
URL.revokeObjectURL(linkNode.href); // 释放URL 对象
document.body.removeChild(linkNode);
}