读取节点名称,设置页面标题

This commit is contained in:
hi2hi 2024-12-12 17:54:23 +00:00
parent 5a771a4932
commit a321ce2f69
3 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import {
createWebHashHistory, createWebHashHistory,
} from 'vue-router'; } from 'vue-router';
import config from '@/config'; import config from '@/config';
import pageTitle from '@/utils/page-title';
const constantRoutes = [{ const constantRoutes = [{
name: 'Home', name: 'Home',
@ -35,7 +36,7 @@ const routerOptions = {
const router = createRouter(routerOptions); const router = createRouter(routerOptions);
router.beforeResolve((to, from, next) => { router.beforeResolve((to, from, next) => {
document.title = [to?.meta?.title, config.nazhua.title].filter((i) => i).join(' - '); pageTitle(to?.meta?.title);
next(); next();
}); });

5
src/utils/page-title.js Normal file
View File

@ -0,0 +1,5 @@
import config from '@/config';
export default (...args) => {
document.title = [...args, config.nazhua.title].filter((i) => i).join(' - ');
};

View File

@ -54,6 +54,7 @@ import {
alias2code, alias2code,
locationCode2Info, locationCode2Info,
} from '@/utils/world-map'; } from '@/utils/world-map';
import pageTitle from '@/utils/page-title';
import WorldMap from '@/components/world-map/world-map.vue'; import WorldMap from '@/components/world-map/world-map.vue';
import ServerName from './components/server-detail/server-name.vue'; import ServerName from './components/server-detail/server-name.vue';
@ -131,6 +132,7 @@ function handleWorldMapWidth() {
watch(() => info.value, () => { watch(() => info.value, () => {
if (info.value) { if (info.value) {
pageTitle(info.value?.Name, '节点详情');
handleWorldMapWidth(); handleWorldMapWidth();
} }
}); });
@ -145,6 +147,7 @@ watch(() => dataInit.value, () => {
onMounted(() => { onMounted(() => {
if (info.value) { if (info.value) {
pageTitle(info.value?.Name, '节点详情');
handleWorldMapWidth(); handleWorldMapWidth();
} }
window.addEventListener('resize', handleWorldMapWidth); window.addEventListener('resize', handleWorldMapWidth);