refactor: ♻️ 相对时间显示

[skip ci]
This commit is contained in:
tk
2025-06-18 16:26:57 +08:00
committed by nsnail
parent 51cc9fa80c
commit fe31bf0579
7 changed files with 54 additions and 35 deletions

View File

@ -17,7 +17,7 @@
以什么结束 以什么结束
作业名称 作业名称
作业状态 作业状态
信息 信息
倒序排序 倒序排序
全部数据 全部数据

View File

@ -1,7 +1,7 @@
{ {
"version": "2.3.1", "version": "2.3.1",
"devDependencies": { "devDependencies": {
"cz-git": "^1.11.1", "cz-git": "^1.11.2",
"commitizen": "^4.3.1", "commitizen": "^4.3.1",
"prettier": "^3.5.3", "prettier": "^3.5.3",
"standard-version": "^9.5.0" "standard-version": "^9.5.0"

View File

@ -23,8 +23,8 @@ public enum Genders
, ,
/// <summary> /// <summary>
/// /// 密
/// </summary> /// </summary>
[ResourceDescription<Ln>(nameof(Ln.密))] [ResourceDescription<Ln>(nameof(Ln.密))]
Secrecy = 3 Secrecy = 3
} }

View File

@ -12,10 +12,11 @@
"@element-plus/icons-vue": "2.3.1", "@element-plus/icons-vue": "2.3.1",
"ace-builds": "1.42.0", "ace-builds": "1.42.0",
"aieditor": "1.3.9", "aieditor": "1.3.9",
"axios": "1.9.0", "axios": "1.10.0",
"crypto-js": "4.2.0", "crypto-js": "4.2.0",
"dayjs": "1.11.13",
"echarts": "5.6.0", "echarts": "5.6.0",
"element-plus": "2.10.1", "element-plus": "2.10.2",
"json-bigint": "1.0.0", "json-bigint": "1.0.0",
"markdown-it": "14.1.0", "markdown-it": "14.1.0",
"markdown-it-emoji": "3.0.0", "markdown-it-emoji": "3.0.0",
@ -23,7 +24,7 @@
"sortablejs": "1.15.6", "sortablejs": "1.15.6",
"vkbeautify": "0.99.3", "vkbeautify": "0.99.3",
"vue": "3.5.16", "vue": "3.5.16",
"vue-i18n": "11.1.5", "vue-i18n": "11.1.6",
"vue-router": "4.5.1", "vue-router": "4.5.1",
"vue3-ace-editor": "2.2.4", "vue3-ace-editor": "2.2.4",
"vue3-json-viewer": "2.4.0", "vue3-json-viewer": "2.4.0",
@ -35,7 +36,7 @@
"prettier": "3.5.3", "prettier": "3.5.3",
"prettier-plugin-organize-attributes": "1.0.0", "prettier-plugin-organize-attributes": "1.0.0",
"sass": "1.89.2", "sass": "1.89.2",
"terser": "5.42.0", "terser": "5.43.0",
"vite": "6.3.5" "vite": "6.3.5"
}, },
"browserslist": [ "browserslist": [

View File

@ -566,10 +566,12 @@ export default {
外部组件: 'External components', 外部组件: 'External components',
至今: 'Ever since', 至今: 'Ever since',
未发现新的异常作业: 'No new anomalous jobs were found', 未发现新的异常作业: 'No new anomalous jobs were found',
刚刚: 'Newly', '{n} 秒': '{n} seconds',
'{n} 天前': '{n} days ago', '{n} 分钟': '{n} minutes',
'{n} 分钟前': '{n} minutes ago', '{n} 小时': '{n} hours',
'{n} 小时前': '{n} hours ago', '{n} ': '{n} days',
: ' ago',
: ' after',
下次执行: 'Next time', 下次执行: 'Next time',
成功率: 'Success rate', 成功率: 'Success rate',
总数: 'Total', 总数: 'Total',

View File

@ -564,10 +564,12 @@ export default {
外部组件: '外部组件', 外部组件: '外部组件',
至今: '至今', 至今: '至今',
未发现新的异常作业: '未发现新的异常作业', 未发现新的异常作业: '未发现新的异常作业',
刚刚: '刚刚', '{n} 秒': '{n} 秒',
'{n} 天前': '{n} 天前', '{n} 分钟': '{n} 分钟',
'{n} 分钟前': '{n} 分钟前', '{n} 小时': '{n} 小时',
'{n} 小时前': '{n} 小时前', '{n} ': '{n} ',
: '前',
: '后',
下次执行: '下次执行', 下次执行: '下次执行',
成功率: '成功率', 成功率: '成功率',
总数: '总数', 总数: '总数',

View File

@ -1,6 +1,12 @@
import CryptoJS from 'crypto-js' import CryptoJS from 'crypto-js'
import sysConfig from '@/config' import sysConfig from '@/config'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
// 扩展插件和语言设置
dayjs.extend(relativeTime)
const tool = {} const tool = {}
tool.time = { tool.time = {
@ -38,27 +44,35 @@ tool.time = {
}, },
//转换时间 //转换时间
getFormatTime: function (_this, timestamp) { getFormatTime: function (_this, timestamp) {
timestamp = new Date(timestamp) if (!timestamp) return '--'
const now = this.getUnix()
const today = this.getTodayUnix()
//var year = this.getYearUnix();
const timer = (now - timestamp) / 1000
let tip
if (timer <= 0) { const now = dayjs()
tip = _this.$t('刚刚') const target = dayjs(timestamp)
} else if (Math.floor(timer / 60) <= 0) { const diffSeconds = now.diff(target, 'second', true)
tip = _this.$t('刚刚') const isFuture = diffSeconds < 0 // 是否未来时间
} else if (timer < 3600) { const absDiff = Math.abs(diffSeconds) // 时间差绝对值
tip = _this.$t('{n} 分钟前', { n: Math.floor(timer / 60) })
} else if (timer >= 3600 && (timestamp - today >= 0 || Math.floor(timer / 86400) <= 0)) { // 超过10天10 * 24 * 60 * 60 秒)显示具体日期
tip = _this.$t('{n} 小时前', { n: Math.floor(timer / 3600) }) if (absDiff > 10 * 86400) {
} else if (timer / 86400 <= 31) { return target.format('YYYY-MM-DD')
tip = _this.$t('{n} 天前', { n: Math.floor(timer / 86400) })
} else {
tip = this.getLastDate(timestamp)
} }
return tip
let result = ''
if (absDiff < 60) {
// 1分钟内
result = _this.$t(`{n} 秒`, { n: Math.floor(absDiff) })
} else if (absDiff < 3600) {
// 1小时内
result = _this.$t(`{n} 分钟`, { n: Math.floor(absDiff / 60) })
} else if (absDiff < 86400) {
// 24小时内
result = _this.$t(`{n} 小时`, { n: Math.floor(absDiff / 3600) })
} else {
// 10天内
result = _this.$t(`{n} 天`, { n: Math.floor(absDiff / 86400) })
}
// 未来时间加“后”,过去时间加“前”
return isFuture ? `${result}${_this.$t('后')}` : `${result}${_this.$t('前')}`
}, },
} }