fix: 主机运行时长格式化天时分秒
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user