2023-12-18 03:12:07 +00:00
|
|
|
// 处理时间
|
|
|
|
export const handleDate = (dateTimeStamp = new Date()) => {
|
|
|
|
dateTimeStamp = dateTimeStamp ? dateTimeStamp : null
|
|
|
|
var timestamp = new Date(dateTimeStamp)
|
|
|
|
timestamp = timestamp.getTime()
|
|
|
|
var minute = 1000 * 60
|
|
|
|
var hour = minute * 60
|
|
|
|
var day = hour * 24
|
|
|
|
var now = new Date().getTime()
|
|
|
|
var diffValue = now - timestamp
|
|
|
|
var result
|
|
|
|
if (diffValue < 0) return
|
|
|
|
|
|
|
|
var dayC = diffValue / day
|
|
|
|
var hourC = diffValue / (hour + 1)
|
|
|
|
var minC = diffValue / minute
|
|
|
|
if (dayC >= 7) {
|
|
|
|
let date = new Date(timestamp)
|
|
|
|
let Y = date.getFullYear() + "-"
|
|
|
|
let M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-"
|
|
|
|
let D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " "
|
2023-12-29 10:37:38 +00:00
|
|
|
// let h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":"
|
|
|
|
// let m = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
|
|
|
|
result = "" + Y + M + D
|
2023-12-18 03:12:07 +00:00
|
|
|
} else if (dayC >= 1) result = "" + Math.round(dayC) + "天前"
|
|
|
|
else if (hourC >= 1) result = "" + Math.round(hourC) + "小时前"
|
|
|
|
else if (minC >= 1) result = "" + Math.round(minC) + "分钟前"
|
|
|
|
else result = "刚刚"
|
|
|
|
|
|
|
|
return result
|
2023-12-18 11:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const timestampToDate = (timestamp) => {
|
|
|
|
var date = new Date(timestamp);
|
|
|
|
var year = date.getFullYear();
|
|
|
|
var month = ("0" + (date.getMonth() + 1)).slice(-2); // Months are zero based. Add leading 0.
|
|
|
|
var day = ("0" + date.getDate()).slice(-2); // Add leading 0.
|
|
|
|
return `${year}-${month}-${day}`;
|
|
|
|
}
|
2024-01-03 07:28:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
// isblank 是否需要 新标签页 默认是新标签页
|
|
|
|
export const goToURL = (url, isblank = true) => {
|
|
|
|
if (typeof document !== "object") return
|
|
|
|
|
|
|
|
let aTab = document.createElement('a')
|
|
|
|
document.body.appendChild(aTab)
|
|
|
|
aTab.setAttribute('href', url)
|
|
|
|
if (isblank) aTab.setAttribute('target', "_blank")
|
|
|
|
aTab.click()
|
2024-01-05 10:20:39 +00:00
|
|
|
}
|
|
|
|
export const numberToEnclosed = index => {
|
|
|
|
let obj = {
|
|
|
|
1: '①',
|
|
|
|
2: '②',
|
|
|
|
3: '③',
|
|
|
|
4: '④',
|
|
|
|
5: '⑤',
|
|
|
|
}
|
|
|
|
return obj[index]
|
|
|
|
}
|