0.0.1-beta.2

This commit is contained in:
2024-09-30 00:13:36 +08:00
parent db37b9b06c
commit 3c3311f80f
4 changed files with 107 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
/*
* @Author: ddmt
* @Date: 2024-9-29 20:50:12
* @LastEditTime: 2024-9-29 20:50:12
* @LastEditTime: 2024-9-30 0:12:12
* @LastEditors: ddmt
* @Description: ddmt-index file
* @FilePath: /Tool/animate.js
@@ -9,13 +9,15 @@
/**
* 动画函数
* @param {HTMLElement} event
* @param {HTMLElement} HTMLElement
* @param {string} classname
* @param {boolean} forceExecute
* @returns {void}
*/
export function animateStart(event, className, forceExecute) {
if (forceExecute) event.target.classList.remove(className); // 清洗动画
event.classList.add(className);
event.addEventListener('animationend', (event) => {
export function animateStart(HTMLElement, className, forceExecute=false) {
if (forceExecute) HTMLElement.target.classList.remove(className); // 清洗动画
HTMLElement.classList.add(className);
HTMLElement.addEventListener('animationend', (event) => {
event.target.classList.remove(className); // 清洗动画
});
}

View File

@@ -1,7 +1,7 @@
/*
* @Author: ddmt
* @Date: 2024-9-29 20:50:12
* @LastEditTime: 2024-9-29 20:50:12
* @LastEditTime: 2024-9-30 0:13:12
* @LastEditors: ddmt
* @Description: ddmt-index file
* @FilePath: /Tool/number.js
@@ -29,3 +29,43 @@ export function nextArray(arr, index) {
index--;
return arr.slice(index + 1, arr.length).concat(arr.slice(0, index + 1));
}
/*
* 获取相对时间(中文)
* @param {Date} date
*/
export function getRelativeTime(date) {
const now = new Date();
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
if (diffInSeconds < 60) {
return '刚刚';
}
const diffInMinutes = Math.floor(diffInSeconds / 60);
if (diffInMinutes < 60) {
return `${diffInMinutes}分钟前`;
}
const diffInHours = Math.floor(diffInMinutes / 60);
if (diffInHours < 24) {
return `${diffInHours}小时前`;
}
const diffInDays = Math.floor(diffInHours / 24);
if (diffInDays < 30) {
return `${diffInDays}天前`;
}
const diffInMonths = Math.floor(diffInDays / 30);
if (diffInMonths < 12) {
return `${diffInMonths}个月前`;
}
const diffInYears = Math.floor(diffInMonths / 12);
if (diffInYears < 5) {
return `${diffInYears}年前`;
}
return '很久以前';
}