Skip to content

Commit fe31bf0

Browse files
tknsnail
authored andcommitted
refactor: ♻️ 相对时间显示
[skip ci]
1 parent 51cc9fa commit fe31bf0

7 files changed

Lines changed: 53 additions & 34 deletions

File tree

assets/res/NetAdmin.Fields.ln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
以什么结束
1818
作业名称
1919
作业状态
20-
保密
20+
2121
信息
2222
倒序排序
2323
全部数据

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": "2.3.1",
33
"devDependencies": {
4-
"cz-git": "^1.11.1",
4+
"cz-git": "^1.11.2",
55
"commitizen": "^4.3.1",
66
"prettier": "^3.5.3",
77
"standard-version": "^9.5.0"

src/backend/NetAdmin/NetAdmin.Infrastructure/Enums/Genders.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public enum Genders
2323
,
2424

2525
/// <summary>
26-
/// 保密
26+
///
2727
/// </summary>
28-
[ResourceDescription<Ln>(nameof(Ln.保密))]
28+
[ResourceDescription<Ln>(nameof(Ln.))]
2929
Secrecy = 3
3030
}

src/frontend/admin/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
"@element-plus/icons-vue": "2.3.1",
1313
"ace-builds": "1.42.0",
1414
"aieditor": "1.3.9",
15-
"axios": "1.9.0",
15+
"axios": "1.10.0",
1616
"crypto-js": "4.2.0",
17+
"dayjs": "1.11.13",
1718
"echarts": "5.6.0",
18-
"element-plus": "2.10.1",
19+
"element-plus": "2.10.2",
1920
"json-bigint": "1.0.0",
2021
"markdown-it": "14.1.0",
2122
"markdown-it-emoji": "3.0.0",
2223
"nprogress": "0.2.0",
2324
"sortablejs": "1.15.6",
2425
"vkbeautify": "0.99.3",
2526
"vue": "3.5.16",
26-
"vue-i18n": "11.1.5",
27+
"vue-i18n": "11.1.6",
2728
"vue-router": "4.5.1",
2829
"vue3-ace-editor": "2.2.4",
2930
"vue3-json-viewer": "2.4.0",
@@ -35,7 +36,7 @@
3536
"prettier": "3.5.3",
3637
"prettier-plugin-organize-attributes": "1.0.0",
3738
"sass": "1.89.2",
38-
"terser": "5.42.0",
39+
"terser": "5.43.0",
3940
"vite": "6.3.5"
4041
},
4142
"browserslist": [

src/frontend/admin/src/locales/lang/en.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,12 @@ export default {
566566
外部组件: 'External components',
567567
至今: 'Ever since',
568568
未发现新的异常作业: 'No new anomalous jobs were found',
569-
刚刚: 'Newly',
570-
'{n} 天前': '{n} days ago',
571-
'{n} 分钟前': '{n} minutes ago',
572-
'{n} 小时前': '{n} hours ago',
569+
'{n} 秒': '{n} seconds',
570+
'{n} 分钟': '{n} minutes',
571+
'{n} 小时': '{n} hours',
572+
'{n} 天': '{n} days',
573+
: ' ago',
574+
: ' after',
573575
下次执行: 'Next time',
574576
成功率: 'Success rate',
575577
总数: 'Total',

src/frontend/admin/src/locales/lang/zh-cn.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,12 @@ export default {
564564
外部组件: '外部组件',
565565
至今: '至今',
566566
未发现新的异常作业: '未发现新的异常作业',
567-
刚刚: '刚刚',
568-
'{n} 天前': '{n} 天前',
569-
'{n} 分钟前': '{n} 分钟前',
570-
'{n} 小时前': '{n} 小时前',
567+
'{n} 秒': '{n} 秒',
568+
'{n} 分钟': '{n} 分钟',
569+
'{n} 小时': '{n} 小时',
570+
'{n} 天': '{n} 天',
571+
: '前',
572+
: '后',
571573
下次执行: '下次执行',
572574
成功率: '成功率',
573575
总数: '总数',

src/frontend/admin/src/utils/tool.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import CryptoJS from 'crypto-js'
22
import sysConfig from '@/config'
33

4+
import dayjs from 'dayjs'
5+
import relativeTime from 'dayjs/plugin/relativeTime'
6+
7+
// 扩展插件和语言设置
8+
dayjs.extend(relativeTime)
9+
410
const tool = {}
511

612
tool.time = {
@@ -38,27 +44,35 @@ tool.time = {
3844
},
3945
//转换时间
4046
getFormatTime: function (_this, timestamp) {
41-
timestamp = new Date(timestamp)
42-
const now = this.getUnix()
43-
const today = this.getTodayUnix()
44-
//var year = this.getYearUnix();
45-
const timer = (now - timestamp) / 1000
46-
let tip
47+
if (!timestamp) return '--'
48+
49+
const now = dayjs()
50+
const target = dayjs(timestamp)
51+
const diffSeconds = now.diff(target, 'second', true)
52+
const isFuture = diffSeconds < 0 // 是否未来时间
53+
const absDiff = Math.abs(diffSeconds) // 时间差绝对值
54+
55+
// 超过10天(10 * 24 * 60 * 60 秒)显示具体日期
56+
if (absDiff > 10 * 86400) {
57+
return target.format('YYYY-MM-DD')
58+
}
4759

48-
if (timer <= 0) {
49-
tip = _this.$t('刚刚')
50-
} else if (Math.floor(timer / 60) <= 0) {
51-
tip = _this.$t('刚刚')
52-
} else if (timer < 3600) {
53-
tip = _this.$t('{n} 分钟前', { n: Math.floor(timer / 60) })
54-
} else if (timer >= 3600 && (timestamp - today >= 0 || Math.floor(timer / 86400) <= 0)) {
55-
tip = _this.$t('{n} 小时前', { n: Math.floor(timer / 3600) })
56-
} else if (timer / 86400 <= 31) {
57-
tip = _this.$t('{n} 天前', { n: Math.floor(timer / 86400) })
60+
let result = ''
61+
if (absDiff < 60) {
62+
// 1分钟内
63+
result = _this.$t(`{n} 秒`, { n: Math.floor(absDiff) })
64+
} else if (absDiff < 3600) {
65+
// 1小时内
66+
result = _this.$t(`{n} 分钟`, { n: Math.floor(absDiff / 60) })
67+
} else if (absDiff < 86400) {
68+
// 24小时内
69+
result = _this.$t(`{n} 小时`, { n: Math.floor(absDiff / 3600) })
5870
} else {
59-
tip = this.getLastDate(timestamp)
71+
// 10天内
72+
result = _this.$t(`{n} 天`, { n: Math.floor(absDiff / 86400) })
6073
}
61-
return tip
74+
// 未来时间加“后”,过去时间加“前”
75+
return isFuture ? `${result}${_this.$t('后')}` : `${result}${_this.$t('前')}`
6276
},
6377
}
6478

0 commit comments

Comments
 (0)