diff --git a/console/docs/extension-points/plugin-self-tabs.md b/console/docs/extension-points/plugin-self-tabs.md new file mode 100644 index 000000000..98cf6ebe2 --- /dev/null +++ b/console/docs/extension-points/plugin-self-tabs.md @@ -0,0 +1,40 @@ +# 插件详情选项卡扩展点 + +## 原由 + +部分插件可能需要在 Console 端自行实现 UI 以完成一些自定义的需求,但可能并不希望在菜单中添加一个菜单项,所以希望可以在插件详情页面添加一个自定义 UI 的选项卡。 + +## 定义方式 + +```ts +import { definePlugin, PluginTab } from "@halo-dev/console-shared"; +import MyComponent from "@/views/my-component.vue"; +import { markRaw } from "vue"; +export default definePlugin({ + components: {}, + routes: [], + extensionPoints: { + "plugin:self:tabs:create": () : PluginTab[] => { + return [ + { + id: "my-tab-panel", + label: "Custom Panel", + component: markRaw(MyComponent), + permissions: [] + }, + ]; + }, + }, +}); +``` + +PluginTab 类型: + +```ts +export interface PluginTab { + id: string; + label: string; + component: Raw; + permissions?: string[]; +} +``` diff --git a/console/packages/shared/src/index.ts b/console/packages/shared/src/index.ts index 5f5917436..dc4783820 100644 --- a/console/packages/shared/src/index.ts +++ b/console/packages/shared/src/index.ts @@ -4,4 +4,5 @@ export * from "./core/plugins"; export * from "./states/pages"; export * from "./states/attachment-selector"; export * from "./states/editor"; +export * from "./states/plugin-tab"; export * from "./states/comment-subject-ref"; diff --git a/console/packages/shared/src/states/plugin-tab.ts b/console/packages/shared/src/states/plugin-tab.ts new file mode 100644 index 000000000..064f03a72 --- /dev/null +++ b/console/packages/shared/src/states/plugin-tab.ts @@ -0,0 +1,8 @@ +import type { Component, Raw } from "vue"; + +export interface PluginTab { + id: string; + label: string; + component: Raw; + permissions?: string[]; +} diff --git a/console/packages/shared/src/types/plugin.ts b/console/packages/shared/src/types/plugin.ts index 0fa907e24..bb1955cd0 100644 --- a/console/packages/shared/src/types/plugin.ts +++ b/console/packages/shared/src/types/plugin.ts @@ -2,7 +2,7 @@ import type { Component } from "vue"; import type { RouteRecordRaw, RouteRecordName } from "vue-router"; import type { FunctionalPage } from "../states/pages"; import type { AttachmentSelectProvider } from "../states/attachment-selector"; -import type { EditorProvider } from ".."; +import type { EditorProvider, PluginTab } from ".."; import type { AnyExtension } from "@tiptap/vue-3"; import type { CommentSubjectRefProvider } from "@/states/comment-subject-ref"; @@ -21,6 +21,8 @@ export interface ExtensionPoint { "editor:create"?: () => EditorProvider[] | Promise; + "plugin:self:tabs:create"?: () => PluginTab[] | Promise; + "default:editor:extension:create": () => | AnyExtension[] | Promise; diff --git a/console/src/locales/en.yaml b/console/src/locales/en.yaml index 42d2df820..3269b8e7f 100644 --- a/console/src/locales/en.yaml +++ b/console/src/locales/en.yaml @@ -788,8 +788,6 @@ core: license: License role_templates: Role Templates last_starttime: Last Start Time - settings: - title: Plugin settings loader: toast: entry_load_failed: "{name}: Failed to load plugin entry file" diff --git a/console/src/locales/zh-CN.yaml b/console/src/locales/zh-CN.yaml index 00f733d38..95d3b9642 100644 --- a/console/src/locales/zh-CN.yaml +++ b/console/src/locales/zh-CN.yaml @@ -788,8 +788,6 @@ core: license: 协议 role_templates: 权限模板 last_starttime: 最近一次启动 - settings: - title: 插件设置 loader: toast: entry_load_failed: "{name}:加载插件入口文件失败" diff --git a/console/src/locales/zh-TW.yaml b/console/src/locales/zh-TW.yaml index 6f9c05482..c7d7f3446 100644 --- a/console/src/locales/zh-TW.yaml +++ b/console/src/locales/zh-TW.yaml @@ -788,8 +788,6 @@ core: license: 協議 role_templates: 權限模板 last_starttime: 最近一次啟動 - settings: - title: 插件設置 loader: toast: entry_load_failed: "{name}:讀取插件入口文件失敗" diff --git a/console/src/modules/system/plugins/PluginDetail.vue b/console/src/modules/system/plugins/PluginDetail.vue index a7ae578bd..32cc66f59 100644 --- a/console/src/modules/system/plugins/PluginDetail.vue +++ b/console/src/modules/system/plugins/PluginDetail.vue @@ -1,204 +1,148 @@ - diff --git a/console/src/modules/system/plugins/layouts/PluginLayout.vue b/console/src/modules/system/plugins/layouts/PluginLayout.vue deleted file mode 100644 index fb07aa2c2..000000000 --- a/console/src/modules/system/plugins/layouts/PluginLayout.vue +++ /dev/null @@ -1,184 +0,0 @@ - - diff --git a/console/src/modules/system/plugins/module.ts b/console/src/modules/system/plugins/module.ts index 5c162759c..8b44f8e9b 100644 --- a/console/src/modules/system/plugins/module.ts +++ b/console/src/modules/system/plugins/module.ts @@ -1,9 +1,7 @@ import { definePlugin } from "@halo-dev/console-shared"; import BasicLayout from "@/layouts/BasicLayout.vue"; import BlankLayout from "@/layouts/BlankLayout.vue"; -import PluginLayout from "./layouts/PluginLayout.vue"; import PluginList from "./PluginList.vue"; -import PluginSetting from "./PluginSetting.vue"; import PluginDetail from "./PluginDetail.vue"; import { IconPlug } from "@halo-dev/components"; import { markRaw } from "vue"; @@ -39,10 +37,10 @@ export default definePlugin({ }, { path: ":name", - component: PluginLayout, + component: BasicLayout, children: [ { - path: "detail", + path: "", name: "PluginDetail", component: PluginDetail, meta: { @@ -50,15 +48,6 @@ export default definePlugin({ permissions: ["system:plugins:view"], }, }, - { - path: "settings/:group", - name: "PluginSetting", - component: PluginSetting, - meta: { - title: "core.plugin.settings.title", - permissions: ["system:plugins:manage"], - }, - }, ], }, ], diff --git a/console/src/modules/system/plugins/tabs/Detail.vue b/console/src/modules/system/plugins/tabs/Detail.vue new file mode 100644 index 000000000..2e1e14af8 --- /dev/null +++ b/console/src/modules/system/plugins/tabs/Detail.vue @@ -0,0 +1,204 @@ + + + diff --git a/console/src/modules/system/plugins/PluginSetting.vue b/console/src/modules/system/plugins/tabs/Setting.vue similarity index 93% rename from console/src/modules/system/plugins/PluginSetting.vue rename to console/src/modules/system/plugins/tabs/Setting.vue index 481e98bb6..2e20deb7d 100644 --- a/console/src/modules/system/plugins/PluginSetting.vue +++ b/console/src/modules/system/plugins/tabs/Setting.vue @@ -11,7 +11,7 @@ import { Toast, VButton } from "@halo-dev/components"; // types import type { ConfigMap, Plugin, Setting } from "@halo-dev/api-client"; -import { useRouteParams } from "@vueuse/router"; +import { useRouteQuery } from "@vueuse/router"; import { useI18n } from "vue-i18n"; import { useQuery, useQueryClient } from "@tanstack/vue-query"; import { toRaw } from "vue"; @@ -19,13 +19,13 @@ import { toRaw } from "vue"; const { t } = useI18n(); const queryClient = useQueryClient(); -const group = useRouteParams("group"); +const group = useRouteQuery("tab", undefined, { mode: "push" }); const plugin = inject>("plugin"); const setting = inject>("setting", ref()); const saving = ref(false); -const { data: configMap, suspense } = useQuery({ +const { data: configMap } = useQuery({ queryKey: ["plugin-configMap", plugin], queryFn: async () => { const { data } = await apiClient.plugin.fetchPluginConfig({ @@ -63,8 +63,6 @@ const handleSaveConfigMap = async () => { saving.value = false; }; - -await suspense();