fix: 主机运行时长格式化天时分秒

This commit is contained in:
TsMask
2023-10-23 19:16:34 +08:00
parent 92c71958ae
commit 28f487aff6
3 changed files with 50 additions and 2 deletions

View File

@@ -42,6 +42,16 @@ export default {
},
rowId: 'RowID',
operate: 'Operate',
units: {
second: 'Second',
minute: 'Minute',
hour: 'Hour',
day: 'Day',
week: 'Week',
month: 'Month',
year: 'Year',
core: 'Core',
}
},
// 全局页脚

View File

@@ -42,6 +42,17 @@ export default {
},
rowId: '记录编号',
operate: '操作',
units: {
second: '秒',
minute: '分钟',
hour: '小时',
day: '天',
week: '周',
month: '月',
year: '年',
time: '次',
core: '核',
}
},
// 全局页脚

View File

@@ -4,6 +4,8 @@ import { PageContainer } from '@ant-design-vue/pro-layout';
import { ColumnsType } from 'ant-design-vue/lib/table';
import { getSystemInfo } from '@/api/monitor/system';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import useI18n from '@/hooks/useI18n';
const { t } = useI18n();
/**加载状态 */
let loading = ref<boolean>(true);
@@ -66,6 +68,31 @@ let server: ServerType = reactive({
time: {},
});
function loadUpTime(uptime: string | number) {
if (typeof uptime === 'string') {
return uptime;
}
if (uptime <= 0) {
return '-';
}
let days = Math.floor(uptime / 86400);
let hours = Math.floor((uptime % 86400) / 3600);
let minutes = Math.floor((uptime % 3600) / 60);
let seconds = uptime % 60;
let strArr: string[] = [];
if (days !== 0) {
strArr.push(`${days}${t('common.units.day')}`);
}
if (hours !== 0) {
strArr.push(`${hours}${t('common.units.hour')}`);
}
if (minutes !== 0) {
strArr.push(`${minutes}${t('common.units.minute')}`);
}
strArr.push(`${seconds}${t('common.units.second')}`);
return strArr.join(' ');
}
onMounted(() => {
getSystemInfo().then(res => {
if (res.code === RESULT_CODE_SUCCESS && res.data) {
@@ -120,9 +147,9 @@ onMounted(() => {
</a-descriptions-item>
<a-descriptions-item label="主机名称">
{{ server.system.hostname }}
</a-descriptions-item>
</a-descriptions-item>
<a-descriptions-item label="运行时长">
{{ server.system.bootTime }}
{{ loadUpTime(server.system.bootTime) }}
</a-descriptions-item>
</a-descriptions>
</a-card>