feat: 服务器时间显示
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import { request } from '@/plugins/http-fetch';
|
import { request } from '@/plugins/http-fetch';
|
||||||
import { parseDateToStr } from '@/utils/date-utils';
|
import { parseDateToStr } from '@/utils/date-utils';
|
||||||
/**
|
/**
|
||||||
@@ -26,7 +27,7 @@ export async function listMain() {
|
|||||||
...systemState,
|
...systemState,
|
||||||
refresh: parseDateToStr(time),
|
refresh: parseDateToStr(time),
|
||||||
ipAddress: ipAddress,
|
ipAddress: ipAddress,
|
||||||
name: key.split("/").join("_"),
|
name: key.split('/').join('_'),
|
||||||
status: '正常',
|
status: '正常',
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@@ -34,7 +35,7 @@ export async function listMain() {
|
|||||||
version: '-',
|
version: '-',
|
||||||
refresh: parseDateToStr(time),
|
refresh: parseDateToStr(time),
|
||||||
ipAddress: ipAddress,
|
ipAddress: ipAddress,
|
||||||
name: key.split("/").join("_"),
|
name: key.split('/').join('_'),
|
||||||
status: '异常',
|
status: '异常',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -45,3 +46,22 @@ export async function listMain() {
|
|||||||
// console.log(rowArr)
|
// console.log(rowArr)
|
||||||
return mergedData;
|
return mergedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取服务器时间
|
||||||
|
* @returns object
|
||||||
|
*/
|
||||||
|
export async function getServerTime() {
|
||||||
|
// 发起请求
|
||||||
|
const result = await request({
|
||||||
|
url: `/api/rest/systemManagement/v1/elementType/OMC/objectType/time`,
|
||||||
|
method: 'get',
|
||||||
|
});
|
||||||
|
// 解析数据
|
||||||
|
if (result.code === RESULT_CODE_SUCCESS && result.data) {
|
||||||
|
return Object.assign(result, {
|
||||||
|
data: result.data.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import {
|
||||||
ProLayout,
|
ProLayout,
|
||||||
GlobalFooter,
|
|
||||||
WaterMark,
|
WaterMark,
|
||||||
getMenuData,
|
getMenuData,
|
||||||
clearMenuItem,
|
clearMenuItem,
|
||||||
@@ -9,7 +8,7 @@ import {
|
|||||||
import RightContent from './components/RightContent.vue';
|
import RightContent from './components/RightContent.vue';
|
||||||
import Tabs from './components/Tabs.vue';
|
import Tabs from './components/Tabs.vue';
|
||||||
import { scriptUrl } from '@/assets/js/icon_font_8d5l8fzk5b87iudi';
|
import { scriptUrl } from '@/assets/js/icon_font_8d5l8fzk5b87iudi';
|
||||||
import { computed, reactive, watch } from 'vue';
|
import { computed, reactive, ref, watch } from 'vue';
|
||||||
import useLayoutStore from '@/store/modules/layout';
|
import useLayoutStore from '@/store/modules/layout';
|
||||||
import useRouterStore from '@/store/modules/router';
|
import useRouterStore from '@/store/modules/router';
|
||||||
import useTabsStore from '@/store/modules/tabs';
|
import useTabsStore from '@/store/modules/tabs';
|
||||||
@@ -17,6 +16,10 @@ import { useRouter } from 'vue-router';
|
|||||||
import { MENU_PATH_INLINE } from '@/constants/menu-constants';
|
import { MENU_PATH_INLINE } from '@/constants/menu-constants';
|
||||||
const { proConfig, waterMarkContent } = useLayoutStore();
|
const { proConfig, waterMarkContent } = useLayoutStore();
|
||||||
import useI18n from '@/hooks/useI18n';
|
import useI18n from '@/hooks/useI18n';
|
||||||
|
import { getServerTime } from '@/api';
|
||||||
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
|
import { onMounted } from 'vue';
|
||||||
|
import { parseDateToStr } from '@/utils/date-utils';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const routerStore = useRouterStore();
|
const routerStore = useRouterStore();
|
||||||
const tabsStore = useTabsStore();
|
const tabsStore = useTabsStore();
|
||||||
@@ -113,6 +116,57 @@ function fnComponentSetName(component: any, to: any) {
|
|||||||
|
|
||||||
// 清空导航栏标签
|
// 清空导航栏标签
|
||||||
tabsStore.clear();
|
tabsStore.clear();
|
||||||
|
|
||||||
|
//
|
||||||
|
onMounted(() => {
|
||||||
|
fnGetServerTime();
|
||||||
|
});
|
||||||
|
|
||||||
|
// ==== 服务器时间显示 start
|
||||||
|
let serverTime = reactive({
|
||||||
|
timestamp: 0,
|
||||||
|
zone: '', // 时区 UTC
|
||||||
|
str: '', // 年月日时分秒
|
||||||
|
interval: 0 as any, // 定时器
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取服务器时间
|
||||||
|
function fnGetServerTime() {
|
||||||
|
getServerTime().then(res => {
|
||||||
|
console.log(res.data);
|
||||||
|
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||||
|
// 时间戳
|
||||||
|
serverTime.timestamp = parseInt(res.data.timestamp);
|
||||||
|
serverTime.interval = setInterval(() => {
|
||||||
|
serverTime.timestamp += 1000;
|
||||||
|
serverTime.str = parseDateToStr(serverTime.timestamp);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
// 时区
|
||||||
|
const offsetHours = res.data.timeZone / 3600;
|
||||||
|
if (offsetHours === 0) {
|
||||||
|
serverTime.zone = 'UTC';
|
||||||
|
} else if (offsetHours > 0) {
|
||||||
|
serverTime.zone = `UTC +${offsetHours}`;
|
||||||
|
} else {
|
||||||
|
serverTime.zone = `UTC ${offsetHours}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听可视改变
|
||||||
|
document.addEventListener('visibilitychange', function () {
|
||||||
|
if (document.visibilityState == 'hidden') {
|
||||||
|
//切离该页面时执行
|
||||||
|
clearInterval(serverTime.interval);
|
||||||
|
}
|
||||||
|
if (document.visibilityState == 'visible') {
|
||||||
|
//切换到该页面时执行
|
||||||
|
fnGetServerTime();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// ==== 服务器时间显示 end
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -179,16 +233,17 @@ tabsStore.clear();
|
|||||||
|
|
||||||
<!--插槽-内容底部-->
|
<!--插槽-内容底部-->
|
||||||
<template #footerRender>
|
<template #footerRender>
|
||||||
<GlobalFooter
|
<footer class="ant-pro-global-footer footer">
|
||||||
class="footer"
|
<div class="ant-pro-global-footer-links">
|
||||||
:links="[
|
<a target="_self" href="/">{{ t('globalFooter.help') }}</a>
|
||||||
{ blankTarget: false, title: t('globalFooter.help'), href: '/' },
|
<a target="_self" href="/">{{ t('globalFooter.privacy') }}</a>
|
||||||
{ blankTarget: false, title: t('globalFooter.privacy'), href: '/' },
|
<a target="_self" href="/">{{ t('globalFooter.term') }}</a>
|
||||||
{ blankTarget: false, title: t('globalFooter.term'), href: '/' },
|
</div>
|
||||||
]"
|
<div class="footer-time">{{ serverTime.str }} {{ serverTime.zone }}</div>
|
||||||
copyright="Copyright ©2023 For AGrand 千通"
|
<div class="ant-pro-global-footer-copyright">
|
||||||
>
|
Copyright ©2023 For AGrand 千通
|
||||||
</GlobalFooter>
|
</div>
|
||||||
|
</footer>
|
||||||
</template>
|
</template>
|
||||||
</ProLayout>
|
</ProLayout>
|
||||||
</WaterMark>
|
</WaterMark>
|
||||||
@@ -208,4 +263,9 @@ tabsStore.clear();
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
width: 180px;
|
width: 180px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.footer-time {
|
||||||
|
color: #00000075;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user