diff --git a/src/modules/system/plugins/PluginDetail.vue b/src/modules/system/plugins/PluginDetail.vue index 338806461..e3a40b6b9 100644 --- a/src/modules/system/plugins/PluginDetail.vue +++ b/src/modules/system/plugins/PluginDetail.vue @@ -16,6 +16,7 @@ import type { ConfigMap, Setting, SettingSpec, + Role, } from "@halo-dev/api-client"; import cloneDeep from "lodash.clonedeep"; import type { FormKitSchemaCondition, FormKitSchemaNode } from "@formkit/core"; @@ -174,7 +175,57 @@ const handleChangePluginStatus = async () => { }); }; -onMounted(handleFetchPlugin); +// TODO 临时解决方案 +interface RoleTemplateGroup { + module: string | null | undefined; + roles: Role[]; +} + +const roles = ref([]); + +const handleFetchRoles = async () => { + try { + const { data } = await apiClient.extension.role.listv1alpha1Role(); + roles.value = data.items; + } catch (e) { + console.error(e); + } +}; + +const pluginRoleTemplates = computed(() => { + return roles.value.filter((item) => { + return ( + item.metadata.labels?.["plugin.halo.run/plugin-name"] === + plugin.value.metadata.name + ); + }); +}); + +const pluginRoleTemplateGroups = computed(() => { + const groups: RoleTemplateGroup[] = []; + pluginRoleTemplates.value.forEach((role) => { + const group = groups.find( + (group) => + group.module === + role.metadata.annotations?.["rbac.authorization.halo.run/module"] + ); + if (group) { + group.roles.push(role); + } else { + groups.push({ + module: + role.metadata.annotations?.["rbac.authorization.halo.run/module"], + roles: [role], + }); + } + }); + return groups; +}); + +onMounted(() => { + handleFetchPlugin(); + handleFetchRoles(); +});