feat: set path names

This commit is contained in:
Fine 2023-04-04 17:43:37 +08:00
parent ab8d076688
commit 59bfce472d
4 changed files with 67 additions and 9 deletions

View File

@ -15,11 +15,10 @@ limitations under the License. -->
<template> <template>
<div class="nav-bar flex-h"> <div class="nav-bar flex-h">
<div class="title flex-h"> <div class="title flex-h">
<div class="mr-10">
{{ route.name === "ViewWidget" ? "" : appStore.pageTitle || t(pageName) }}
</div>
<el-breadcrumb separator=">"> <el-breadcrumb separator=">">
<el-breadcrumb-item :to="{ path: '/' }">homepage</el-breadcrumb-item> <el-breadcrumb-item v-for="(item, index) in appStore.pathNames" :key="index" :to="{ path: '/' }">
{{ route.name === "ViewWidget" ? "" : appStore.pageTitle || t(pageName) }}
</el-breadcrumb-item>
</el-breadcrumb> </el-breadcrumb>
</div> </div>
<div class="app-config"> <div class="app-config">
@ -53,6 +52,7 @@ limitations under the License. -->
import timeFormat from "@/utils/timeFormat"; import timeFormat from "@/utils/timeFormat";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { deduplication } from "@/utils/arrayAlgorithm";
const { t } = useI18n(); const { t } = useI18n();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
@ -62,9 +62,8 @@ limitations under the License. -->
resetDuration(); resetDuration();
getVersion(); getVersion();
const setConfig = (value: string) => { setConfig(String(route.meta.title));
pageName.value = value || ""; getPathNames();
};
function handleReload() { function handleReload() {
const gap = appStore.duration.end.getTime() - appStore.duration.start.getTime(); const gap = appStore.duration.end.getTime() - appStore.duration.start.getTime();
@ -79,19 +78,38 @@ limitations under the License. -->
} }
appStore.setDuration(timeFormat(val)); appStore.setDuration(timeFormat(val));
} }
setConfig(String(route.meta.title));
function setConfig(value: string) {
pageName.value = value || "";
}
function getPathNames() {
const p = route.params;
if (appStore.pathNames.length && p.layerId === appStore.pathNames[0].layerId) {
const arr = [...appStore.pathNames, p];
const list = deduplication(arr, ["layerId", "entity", "name"]);
appStore.setPathNames(list);
} else {
appStore.setPathNames([p]);
}
// console.log(route.params);
}
watch( watch(
() => route.meta.title, () => route.meta.title,
(title: unknown) => { (title: unknown) => {
setConfig(String(title)); setConfig(String(title));
}, },
); );
async function getVersion() { async function getVersion() {
const res = await appStore.fetchVersion(); const res = await appStore.fetchVersion();
if (res.errors) { if (res.errors) {
ElMessage.error(res.errors); ElMessage.error(res.errors);
} }
} }
function resetDuration() { function resetDuration() {
const { duration }: any = route.params; const { duration }: any = route.params;
if (duration) { if (duration) {
@ -108,7 +126,7 @@ limitations under the License. -->
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.nav-bar { .nav-bar {
padding: 5px 10px; padding: 5px;
text-align: left; text-align: left;
justify-content: space-between; justify-content: space-between;
background-color: #fafbfc; background-color: #fafbfc;

View File

@ -35,6 +35,7 @@ interface AppState {
version: string; version: string;
isMobile: boolean; isMobile: boolean;
reloadTimer: Nullable<any>; reloadTimer: Nullable<any>;
pathNames: { name: string; layer: string; entity: string }[];
} }
export const appStore = defineStore({ export const appStore = defineStore({
@ -55,6 +56,7 @@ export const appStore = defineStore({
version: "", version: "",
isMobile: false, isMobile: false,
reloadTimer: null, reloadTimer: null,
pathNames: [],
}), }),
getters: { getters: {
duration(): Duration { duration(): Duration {
@ -146,6 +148,9 @@ export const appStore = defineStore({
setPageTitle(title: string) { setPageTitle(title: string) {
this.pageTitle = title; this.pageTitle = title;
}, },
setPathNames(names: { name: string; layer: string; entity: string }[]) {
this.pathNames = names;
},
runEventStack() { runEventStack() {
if (this.timer) { if (this.timer) {
clearTimeout(this.timer); clearTimeout(this.timer);

View File

@ -212,3 +212,7 @@ div.vis-tooltip {
div:has(> a.menu-title) { div:has(> a.menu-title) {
display: none; display: none;
} }
.el-breadcrumb {
line-height: 28px;
}

View File

@ -0,0 +1,31 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export function deduplication(arr: any, labels: string[]) {
const map = new Map();
for (const i of arr) {
const key = labels
.map((d: string) => {
return i[d];
})
.join("");
if (!map.has(i[key])) {
map.set(i[key], i);
}
}
return [...map.values()];
}