feat: enhance the marketplace page (#298)

This commit is contained in:
Fine0830 2023-07-11 22:32:36 +08:00 committed by GitHub
parent a521e041a7
commit 5367af47c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 80 additions and 38 deletions

View File

@ -75,9 +75,12 @@ limitations under the License. -->
/*global Recordable*/ /*global Recordable*/
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const name = ref<string>(String(useRouter().currentRoute.value.name)); const router = useRouter();
const name = ref<string>(String(router.currentRoute.value.name));
const theme = ["VirtualMachine", "Kubernetes"].includes(name.value || "") ? ref("light") : ref("black"); const theme = ["VirtualMachine", "Kubernetes"].includes(name.value || "") ? ref("light") : ref("black");
const routes = ref<RouteRecordRaw[] | any>(useRouter().options.routes); const routes = ref<RouteRecordRaw[] | any>(
(router.options.routes || []).filter((d: any) => d.meta && d.meta.activate),
);
const route = useRoute(); const route = useRoute();
const isCollapse = ref(true); const isCollapse = ref(true);
const showMenu = ref(true); const showMenu = ref(true);
@ -95,7 +98,7 @@ limitations under the License. -->
theme.value = ["VirtualMachine", "Kubernetes"].includes(String(menu.name)) ? "light" : "black"; theme.value = ["VirtualMachine", "Kubernetes"].includes(String(menu.name)) ? "light" : "black";
}; };
const filterMenus = (menus: Recordable[]) => { const filterMenus = (menus: Recordable[]) => {
return menus.filter((d) => d.meta && !d.meta.notShow); return menus.filter((d) => d.meta && !d.meta.notShow && d.meta.activate);
}; };
function setCollapse() { function setCollapse() {
open.value = true; open.value = true;

View File

@ -25,6 +25,7 @@ export const routesAlarm: Array<RouteRecordRaw> = [
title: "Alerting", title: "Alerting",
icon: "spam", icon: "spam",
hasGroup: false, hasGroup: false,
activate: true,
}, },
component: Layout, component: Layout,
children: [ children: [

View File

@ -26,6 +26,7 @@ export const routesDashboard: Array<RouteRecordRaw> = [
title: "Dashboards", title: "Dashboards",
icon: "dashboard_customize", icon: "dashboard_customize",
hasGroup: true, hasGroup: true,
activate: true,
}, },
children: [ children: [
{ {
@ -34,6 +35,7 @@ export const routesDashboard: Array<RouteRecordRaw> = [
name: "List", name: "List",
meta: { meta: {
title: "Dashboard List", title: "Dashboard List",
activate: true,
}, },
}, },
{ {
@ -42,6 +44,7 @@ export const routesDashboard: Array<RouteRecordRaw> = [
name: "New", name: "New",
meta: { meta: {
title: "New Dashboard", title: "New Dashboard",
activate: true,
}, },
}, },
{ {

View File

@ -20,8 +20,15 @@ import { routesDashboard } from "./dashboard";
import { routesMarketplace } from "./marketplace"; import { routesMarketplace } from "./marketplace";
import { routesAlarm } from "./alarm"; import { routesAlarm } from "./alarm";
import routesLayers from "./layer"; import routesLayers from "./layer";
import { routesSettings } from "./settings";
const routes: Array<RouteRecordRaw> = [...routesMarketplace, ...routesLayers, ...routesDashboard, ...routesAlarm]; const routes: Array<RouteRecordRaw> = [
...routesMarketplace,
...routesLayers,
...routesAlarm,
...routesDashboard,
...routesSettings,
];
const router = createRouter({ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL), history: createWebHistory(import.meta.env.BASE_URL),
@ -30,8 +37,6 @@ const router = createRouter({
(window as any).axiosCancel = []; (window as any).axiosCancel = [];
const defaultPath = (routesLayers[0] && routesLayers[0].children[0].path) || "";
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// const token = window.localStorage.getItem("skywalking-authority"); // const token = window.localStorage.getItem("skywalking-authority");
if ((window as any).axiosCancel.length !== 0) { if ((window as any).axiosCancel.length !== 0) {
@ -42,6 +47,7 @@ router.beforeEach((to, from, next) => {
} }
if (to.path === "/") { if (to.path === "/") {
const defaultPath = (routesLayers[0] && routesLayers[0].children[0].path) || "";
next({ path: defaultPath }); next({ path: defaultPath });
} else { } else {
next(); next();

View File

@ -21,7 +21,7 @@ import type { MenuOptions } from "@/types/app";
async function layerDashboards() { async function layerDashboards() {
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
await appStore.getActivateMenus(); await appStore.getActivateMenus();
const routes = appStore.activateMenus.map((item: MenuOptions) => { const routes = appStore.allMenus.map((item: MenuOptions) => {
const route: any = { const route: any = {
path: "", path: "",
name: item.name, name: item.name,
@ -30,6 +30,7 @@ async function layerDashboards() {
icon: item.icon || "cloud_queue", icon: item.icon || "cloud_queue",
title: item.title, title: item.title,
hasGroup: item.hasGroup, hasGroup: item.hasGroup,
activate: item.activate,
}, },
children: item.subItems && item.subItems.length ? [] : undefined, children: item.subItems && item.subItems.length ? [] : undefined,
}; };
@ -41,6 +42,7 @@ async function layerDashboards() {
title: child.title, title: child.title,
layer: child.layer, layer: child.layer,
icon: child.icon || "cloud_queue", icon: child.icon || "cloud_queue",
activate: child.activate,
}, },
component: () => import("@/views/Layer.vue"), component: () => import("@/views/Layer.vue"),
}; };
@ -65,6 +67,7 @@ async function layerDashboards() {
title: item.title, title: item.title,
layer: item.layer, layer: item.layer,
icon: item.icon, icon: item.icon,
activate: item.activate,
}, },
component: () => import("@/views/Layer.vue"), component: () => import("@/views/Layer.vue"),
}, },

View File

@ -24,26 +24,16 @@ export const routesMarketplace: Array<RouteRecordRaw> = [
meta: { meta: {
title: "Marketplace", title: "Marketplace",
icon: "marketplace", icon: "marketplace",
hasGroup: true, hasGroup: false,
activate: true,
}, },
component: Layout, component: Layout,
children: [ children: [
{ {
path: "/marketplace/menus", path: "/marketplace",
name: "MenusManagement", name: "MenusManagement",
meta: {
title: "Categories",
},
component: () => import("@/views/marketplace/Menus.vue"), component: () => import("@/views/marketplace/Menus.vue"),
}, },
{
path: "/marketplace/settings",
name: "Settings",
meta: {
title: "Settings",
},
component: () => import("@/views/marketplace/Settings.vue"),
},
], ],
}, },
]; ];

39
src/router/settings.ts Normal file
View File

@ -0,0 +1,39 @@
/**
* 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.
*/
import type { RouteRecordRaw } from "vue-router";
import Layout from "@/layout/Index.vue";
export const routesSettings: Array<RouteRecordRaw> = [
{
path: "",
name: "Settings",
meta: {
title: "Settings",
icon: "settings",
hasGroup: false,
activate: true,
},
component: Layout,
children: [
{
path: "/settings",
name: "Settings",
component: () => import("@/views/marketplace/Settings.vue"),
},
],
},
];

View File

@ -36,7 +36,7 @@ interface AppState {
version: string; version: string;
isMobile: boolean; isMobile: boolean;
reloadTimer: Nullable<IntervalHandle>; reloadTimer: Nullable<IntervalHandle>;
activateMenus: MenuOptions[]; allMenus: MenuOptions[];
} }
export const appStore = defineStore({ export const appStore = defineStore({
@ -57,7 +57,7 @@ export const appStore = defineStore({
version: "", version: "",
isMobile: false, isMobile: false,
reloadTimer: null, reloadTimer: null,
activateMenus: [], allMenus: [],
}), }),
getters: { getters: {
duration(): Duration { duration(): Duration {
@ -163,7 +163,8 @@ export const appStore = defineStore({
}, },
async getActivateMenus() { async getActivateMenus() {
const resp = (await this.queryMenuItems()) || {}; const resp = (await this.queryMenuItems()) || {};
const menus = (resp.getMenuItems || []).map((d: MenuOptions, index: number) => {
this.allMenus = (resp.getMenuItems || []).map((d: MenuOptions, index: number) => {
const t = `${d.title.replace(/\s+/g, "-")}`; const t = `${d.title.replace(/\s+/g, "-")}`;
d.name = `${t}-${index}`; d.name = `${t}-${index}`;
d.path = `/${t}`; d.path = `/${t}`;
@ -179,16 +180,6 @@ export const appStore = defineStore({
return d; return d;
}); });
this.activateMenus = menus.filter((d: MenuOptions) => {
if (d.activate) {
d.subItems = d.subItems.filter((item: SubItem) => {
if (item.activate) {
return item;
}
});
return d;
}
});
}, },
async queryOAPTimeInfo() { async queryOAPTimeInfo() {
const res: AxiosResponse = await graphql.query("queryOAPTimeInfo").params({}); const res: AxiosResponse = await graphql.query("queryOAPTimeInfo").params({});

View File

@ -18,13 +18,15 @@ limitations under the License. -->
<div class="mr-20 mt-10 flex-h category"> <div class="mr-20 mt-10 flex-h category">
<el-card <el-card
class="item" class="item"
v-for="(menu, index) in appStore.activateMenus" v-for="(menu, index) in appStore.allMenus"
:key="index" :key="index"
@click="handleItems(menu)" @click="handleItems(menu)"
:class="currentItems.name === menu.name ? 'active' : ''" :class="currentItems.name === menu.name ? 'active' : ''"
> >
<router-link :to="menu.hasGroup ? '' : menu.path || ''"> <router-link :to="menu.hasGroup ? '' : menu.path || ''">
<div class="title" :class="menu.hasGroup ? '' : 'actived-font'"> {{ menu.title }}</div> <div class="title" :class="menu.activate ? (menu.hasGroup ? '' : 'actived-font') : 'disabled'">
{{ menu.title }}</div
>
</router-link> </router-link>
<div class="mt-10"> {{ menu.description }} </div> <div class="mt-10"> {{ menu.description }} </div>
<el-link :href="menu.documentLink" target="_blank" class="link" v-show="menu.documentLink"> <el-link :href="menu.documentLink" target="_blank" class="link" v-show="menu.documentLink">
@ -35,7 +37,7 @@ limitations under the License. -->
<div class="mt-10 cards"> <div class="mt-10 cards">
<el-card shadow="hover" v-for="(item, index) in currentItems.subItems || []" :key="index" class="card"> <el-card shadow="hover" v-for="(item, index) in currentItems.subItems || []" :key="index" class="card">
<router-link :to="item.path || ''"> <router-link :to="item.path || ''">
<div class="title actived-font"> {{ item.title }}</div> <div class="title" :class="item.activate ? 'actived-font' : 'disabled'"> {{ item.title }}</div>
</router-link> </router-link>
<div class="mt-10"> {{ item.description }} </div> <div class="mt-10"> {{ item.description }} </div>
<el-link :href="item.documentLink" target="_blank" class="link" v-show="item.documentLink"> <el-link :href="item.documentLink" target="_blank" class="link" v-show="item.documentLink">
@ -54,13 +56,13 @@ limitations under the License. -->
const { t } = useI18n(); const { t } = useI18n();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const currentItems = ref<MenuOptions>(appStore.activateMenus[0] || {}); const currentItems = ref<MenuOptions>(appStore.allMenus[0] || {});
function handleItems(item: MenuOptions) { function handleItems(item: MenuOptions) {
currentItems.value = item; currentItems.value = item;
} }
appStore.setPageTitle("Categories"); appStore.setPageTitle("Marketplace");
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.menus { .menus {
@ -86,6 +88,10 @@ limitations under the License. -->
color: $active-color; color: $active-color;
} }
.disabled {
color: #aaa;
}
.card { .card {
margin-bottom: 30px; margin-bottom: 30px;
cursor: pointer; cursor: pointer;