push Develop

This commit is contained in:
X1627315083
2024-06-17 09:39:01 +08:00
parent c93483e36f
commit 363b880276
55 changed files with 5880 additions and 1359 deletions

View File

@@ -12,6 +12,20 @@ const getUploadUrl = () => {
return url
}
function base64ToFile(urlData,name) {
let arr = urlData.split(',');
let mime = arr[0].match(/:(.*?);/)[1];
let bstr = atob(arr[1]);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], name, {
type: mime
});
}
function dataURLtoBlob(dataurl) {//吧data url转为blob对象
var arr = dataurl.split(',');
var mime = arr[0].match(/:(.*?);/)[1];
@@ -47,6 +61,7 @@ function downloadIamge(imgsrc, name) { // 下载图片地址和图片名
a.href = url // 将生成的URL设置为a.href属性
a.target = '_blank'
a.dispatchEvent(event) // 触发a的单击事件
image.remove()
}
image.src = imgsrc
}
@@ -164,6 +179,36 @@ const isMoible = () => {//判断是否是移动端
}
}
let setPubDate = (date)=>{
const timestamp = new Date(date);
const now = new Date();
// 计算时间差(以毫秒为单位)
const differenceMs = now - timestamp;
const seconds = Math.floor(differenceMs / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const weeks = Math.floor(days / 7);
const months = Math.floor(days / 30);
const years = Math.floor(days / 365);
// 根据时间差的大小返回不同的描述
if (years > 0) {
return `${years} 年前`;
} else if (months > 0) {
return `${months} 个月前`;
} else if (weeks > 0) {
return `${weeks} 周前`;
} else if (days > 0) {
return `一天前`;
} else if (hours > 0) {
return `${hours} 小时前`;
} else if (minutes > 0) {
return `${minutes} 分钟前`;
} else {
return `1 分钟前`;
}
}
function getBrowserInfo() {//获取是什么浏览器
var agent = navigator.userAgent.toLowerCase();
@@ -386,6 +431,7 @@ const setGradual = (colorObj,colorWidth,colorHeight)=>{
export {
isEmail,
getUploadUrl,
base64ToFile,
dataURLtoFile,
blobToFile,
base64toFile,
@@ -395,6 +441,8 @@ export {
isMoible,
downloadIamge,
getBrowserInfo,
setPubDate,
murmur,
setGradual,
calculateGradientCoordinate,
}