fix: 主机运行时长格式化天时分秒
This commit is contained in:
@@ -42,6 +42,16 @@ export default {
|
|||||||
},
|
},
|
||||||
rowId: 'RowID',
|
rowId: 'RowID',
|
||||||
operate: 'Operate',
|
operate: 'Operate',
|
||||||
|
units: {
|
||||||
|
second: 'Second',
|
||||||
|
minute: 'Minute',
|
||||||
|
hour: 'Hour',
|
||||||
|
day: 'Day',
|
||||||
|
week: 'Week',
|
||||||
|
month: 'Month',
|
||||||
|
year: 'Year',
|
||||||
|
core: 'Core',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 全局页脚
|
// 全局页脚
|
||||||
|
|||||||
@@ -42,6 +42,17 @@ export default {
|
|||||||
},
|
},
|
||||||
rowId: '记录编号',
|
rowId: '记录编号',
|
||||||
operate: '操作',
|
operate: '操作',
|
||||||
|
units: {
|
||||||
|
second: '秒',
|
||||||
|
minute: '分钟',
|
||||||
|
hour: '小时',
|
||||||
|
day: '天',
|
||||||
|
week: '周',
|
||||||
|
month: '月',
|
||||||
|
year: '年',
|
||||||
|
time: '次',
|
||||||
|
core: '核',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 全局页脚
|
// 全局页脚
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { PageContainer } from '@ant-design-vue/pro-layout';
|
|||||||
import { ColumnsType } from 'ant-design-vue/lib/table';
|
import { ColumnsType } from 'ant-design-vue/lib/table';
|
||||||
import { getSystemInfo } from '@/api/monitor/system';
|
import { getSystemInfo } from '@/api/monitor/system';
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
|
import useI18n from '@/hooks/useI18n';
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
/**加载状态 */
|
/**加载状态 */
|
||||||
let loading = ref<boolean>(true);
|
let loading = ref<boolean>(true);
|
||||||
@@ -66,6 +68,31 @@ let server: ServerType = reactive({
|
|||||||
time: {},
|
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(() => {
|
onMounted(() => {
|
||||||
getSystemInfo().then(res => {
|
getSystemInfo().then(res => {
|
||||||
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||||
@@ -120,9 +147,9 @@ onMounted(() => {
|
|||||||
</a-descriptions-item>
|
</a-descriptions-item>
|
||||||
<a-descriptions-item label="主机名称">
|
<a-descriptions-item label="主机名称">
|
||||||
{{ server.system.hostname }}
|
{{ server.system.hostname }}
|
||||||
</a-descriptions-item>
|
</a-descriptions-item>
|
||||||
<a-descriptions-item label="运行时长">
|
<a-descriptions-item label="运行时长">
|
||||||
{{ server.system.bootTime }}
|
{{ loadUpTime(server.system.bootTime) }}
|
||||||
</a-descriptions-item>
|
</a-descriptions-item>
|
||||||
</a-descriptions>
|
</a-descriptions>
|
||||||
</a-card>
|
</a-card>
|
||||||
|
|||||||
Reference in New Issue
Block a user