-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tools page for console (#5252)
#### What type of PR is this? /area console /kind feature /milestone 2.12.x #### What this PR does / why we need it: 为 Console 提供工具页面和菜单项,方便插件集成。 <img width="1920" alt="image" src="https://github.com/halo-dev/halo/assets/21301288/9b63284f-7bdb-4eed-bc6e-cbe2c78359db"> #### Which issue(s) this PR fixes: Fixes #5249 #### Special notes for your reviewer: 可以使用以下插件进行测试: 1. [plugin-umami-1.0.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/halo/files/14049119/plugin-umami-1.0.0-SNAPSHOT.jar.zip) 2. [plugin-metrics-graph-1.0.0-beta.1.jar.zip](https://github.com/halo-dev/halo/files/14049127/plugin-metrics-graph-1.0.0-beta.1.jar.zip) 3. [NotifyMe-1.1.0.jar.zip](https://github.com/halo-dev/halo/files/14049131/NotifyMe-1.1.0.jar.zip) #### Does this PR introduce a user-facing change? ```release-note 为 Console 提供工具页面和菜单项,方便插件集成。 ```
- Loading branch information
Showing
6 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<script lang="ts" setup> | ||
import { useRoleStore } from "@/stores/role"; | ||
import { hasPermission } from "@/utils/permission"; | ||
import { | ||
VPageHeader, | ||
IconToolsFill, | ||
VCard, | ||
VEntity, | ||
VEntityField, | ||
VButton, | ||
VEmpty, | ||
} from "@halo-dev/components"; | ||
import { computed } from "vue"; | ||
import type { RouteRecordRaw } from "vue-router"; | ||
import { useRouter } from "vue-router"; | ||
const router = useRouter(); | ||
const roleStore = useRoleStore(); | ||
const { uiPermissions } = roleStore.permissions; | ||
function isRouteValid(route?: RouteRecordRaw) { | ||
if (!route) return false; | ||
const { meta } = route; | ||
if (!meta?.menu) return false; | ||
return ( | ||
!meta.permissions || hasPermission(uiPermissions, meta.permissions, true) | ||
); | ||
} | ||
const routes = computed(() => { | ||
const matchedRoute = router.currentRoute.value.matched[0]; | ||
return router | ||
.getRoutes() | ||
.find((route) => route.name === matchedRoute.name) | ||
?.children.filter((route) => route.path !== "") | ||
.filter((route) => isRouteValid(route)); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<VPageHeader :title="$t('core.tool.title')"> | ||
<template #icon> | ||
<IconToolsFill class="mr-2 self-center" /> | ||
</template> | ||
</VPageHeader> | ||
|
||
<div class="m-0 md:m-4"> | ||
<VCard :body-class="['!p-0']"> | ||
<VEmpty | ||
v-if="!routes?.length" | ||
:title="$t('core.tool.empty.title')" | ||
:message="$t('core.tool.empty.message')" | ||
></VEmpty> | ||
<ul | ||
v-else | ||
class="box-border h-full w-full divide-y divide-gray-100" | ||
role="list" | ||
> | ||
<li v-for="route in routes" :key="route.name"> | ||
<VEntity> | ||
<template #start> | ||
<VEntityField> | ||
<template #description> | ||
<component | ||
:is="route.meta?.menu?.icon" | ||
v-if="route.meta?.menu?.icon" | ||
class="text-lg" | ||
/> | ||
<IconToolsFill v-else class="text-lg" /> | ||
</template> | ||
</VEntityField> | ||
<VEntityField | ||
:route="{ name: route.name }" | ||
:title="route.meta?.menu?.name" | ||
:description="route.meta?.description" | ||
></VEntityField> | ||
</template> | ||
|
||
<template #end> | ||
<VEntityField> | ||
<template #description> | ||
<VButton | ||
size="sm" | ||
@click="$router.push({ name: route.name })" | ||
> | ||
{{ $t("core.common.buttons.access") }} | ||
</VButton> | ||
</template> | ||
</VEntityField> | ||
</template> | ||
</VEntity> | ||
</li> | ||
</ul> | ||
</VCard> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { definePlugin } from "@halo-dev/console-shared"; | ||
import Tools from "./Tools.vue"; | ||
import { markRaw } from "vue"; | ||
import BasicLayout from "@console/layouts/BasicLayout.vue"; | ||
import { IconToolsFill } from "@halo-dev/components"; | ||
|
||
export default definePlugin({ | ||
components: {}, | ||
routes: [ | ||
{ | ||
path: "/tools", | ||
name: "ToolsRoot", | ||
component: BasicLayout, | ||
meta: { | ||
title: "core.tool.title", | ||
menu: { | ||
name: "core.sidebar.menu.items.tools", | ||
group: "system", | ||
icon: markRaw(IconToolsFill), | ||
priority: 5, | ||
}, | ||
}, | ||
children: [ | ||
{ | ||
path: "", | ||
name: "Tools", | ||
component: Tools, | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters