From f1a168fa530cf6b0ea001cc3c384ad7916c8cc83 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 26 Aug 2025 18:42:54 +0800 Subject: [PATCH] chore: plugin config --- .../src/router/source/modules/sys.ts | 2 +- .../src/views/certd/access/common.tsx | 1 + .../src/views/certd/access/crud.tsx | 1 + .../certd-client/src/views/sys/plugin/api.ts | 9 ++ .../plugin/{config.vue => config-common.vue} | 0 .../src/views/sys/plugin/config-editor.vue | 86 ++++++++++++++++ .../src/views/sys/plugin/crud.tsx | 98 +++++-------------- .../src/views/sys/plugin/use-config.tsx | 50 ++++++++++ .../src/views/sys/plugin/use-import.ts | 80 +++++++++++++++ .../plugin/service/plugin-config-service.ts | 10 +- 10 files changed, 263 insertions(+), 74 deletions(-) rename packages/ui/certd-client/src/views/sys/plugin/{config.vue => config-common.vue} (100%) create mode 100644 packages/ui/certd-client/src/views/sys/plugin/config-editor.vue create mode 100644 packages/ui/certd-client/src/views/sys/plugin/use-config.tsx create mode 100644 packages/ui/certd-client/src/views/sys/plugin/use-import.ts diff --git a/packages/ui/certd-client/src/router/source/modules/sys.ts b/packages/ui/certd-client/src/router/source/modules/sys.ts index 22937dd4..b634f254 100644 --- a/packages/ui/certd-client/src/router/source/modules/sys.ts +++ b/packages/ui/certd-client/src/router/source/modules/sys.ts @@ -133,7 +133,7 @@ export const sysResources = [ title: "certd.sysResources.sysPluginConfig", name: "SysPluginConfig", path: "/sys/plugin/config", - component: "/sys/plugin/config.vue", + component: "/sys/plugin/config-common.vue", meta: { show: () => { const settingStore = useSettingStore(); diff --git a/packages/ui/certd-client/src/views/certd/access/common.tsx b/packages/ui/certd-client/src/views/certd/access/common.tsx index 55ce6fe8..65d30afe 100644 --- a/packages/ui/certd-client/src/views/certd/access/common.tsx +++ b/packages/ui/certd-client/src/views/certd/access/common.tsx @@ -84,6 +84,7 @@ export function getCommonColumnDefine(crudExpose: any, typeRef: any, api: any) { component: { color: "auto", }, + order: -1, }, form: { component: { diff --git a/packages/ui/certd-client/src/views/certd/access/crud.tsx b/packages/ui/certd-client/src/views/certd/access/crud.tsx index 0e8aea81..c0490c42 100644 --- a/packages/ui/certd-client/src/views/certd/access/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/access/crud.tsx @@ -82,6 +82,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat }, column: { width: 300, + order: -11, }, }, from: { diff --git a/packages/ui/certd-client/src/views/sys/plugin/api.ts b/packages/ui/certd-client/src/views/sys/plugin/api.ts index f31a2b4c..a773fc9b 100644 --- a/packages/ui/certd-client/src/views/sys/plugin/api.ts +++ b/packages/ui/certd-client/src/views/sys/plugin/api.ts @@ -97,6 +97,7 @@ export type CertApplyPluginSysInput = { export type PluginSysSetting = { sysSetting: { input?: T; + metadata?: Record; }; }; export type CommPluginConfig = { @@ -118,6 +119,14 @@ export async function SaveCommPluginConfigs(data: CommPluginConfig): Promise { + return await request({ + url: apiPrefix + "/saveSetting", + method: "post", + data: req, + }); +} + export async function DoTest(req: { id: number; input: any }): Promise { return await request({ url: apiPrefix + "/doTest", diff --git a/packages/ui/certd-client/src/views/sys/plugin/config.vue b/packages/ui/certd-client/src/views/sys/plugin/config-common.vue similarity index 100% rename from packages/ui/certd-client/src/views/sys/plugin/config.vue rename to packages/ui/certd-client/src/views/sys/plugin/config-common.vue diff --git a/packages/ui/certd-client/src/views/sys/plugin/config-editor.vue b/packages/ui/certd-client/src/views/sys/plugin/config-editor.vue new file mode 100644 index 00000000..26ab22c5 --- /dev/null +++ b/packages/ui/certd-client/src/views/sys/plugin/config-editor.vue @@ -0,0 +1,86 @@ + + + diff --git a/packages/ui/certd-client/src/views/sys/plugin/crud.tsx b/packages/ui/certd-client/src/views/sys/plugin/crud.tsx index adfda4db..45679128 100644 --- a/packages/ui/certd-client/src/views/sys/plugin/crud.tsx +++ b/packages/ui/certd-client/src/views/sys/plugin/crud.tsx @@ -1,11 +1,14 @@ import * as api from "./api"; import { useI18n } from "/src/locales"; -import { Ref, ref } from "vue"; +import { Ref, ref, computed } from "vue"; import { useRouter } from "vue-router"; -import { AddReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, useFormWrapper, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud"; -import { Modal, notification } from "ant-design-vue"; +import { AddReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud"; +import { Modal } from "ant-design-vue"; //@ts-ignore import yaml from "js-yaml"; +import { usePluginImport } from "./use-import"; +import { usePluginConfig } from "./use-config"; +import { useSettingStore } from "/src/store/settings/index"; export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { const router = useRouter(); @@ -35,75 +38,11 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat const selectedRowKeys: Ref = ref([]); context.selectedRowKeys = selectedRowKeys; - const { openCrudFormDialog } = useFormWrapper(); - async function openImportDialog() { - function createCrudOptions() { - return { - crudOptions: { - columns: { - content: { - title: t("certd.pluginFile"), - type: "text", - form: { - component: { - name: "pem-input", - vModel: "modelValue", - textarea: { - rows: 8, - }, - }, - col: { - span: 24, - }, - helper: t("certd.selectPluginFile"), - }, - }, - override: { - title: t("certd.overrideSameName"), - type: "dict-switch", - dict: dict({ - data: [ - { - value: true, - label: t("certd.override"), - }, - { - value: false, - label: t("certd.noOverride"), - }, - ], - }), - form: { - value: false, - col: { - span: 24, - }, - helper: t("certd.overrideHelper"), - }, - }, - }, - form: { - wrapper: { - title: t("certd.importPlugin"), - saveRemind: false, - }, - afterSubmit() { - notification.success({ message: t("certd.operationSuccess") }); - crudExpose.doRefresh(); - }, - async doSubmit({ form }: any) { - return await api.ImportPlugin({ - ...form, - }); - }, - }, - }, - }; - } - const { crudOptions } = createCrudOptions(); - await openCrudFormDialog({ crudOptions }); - } + const { openImportDialog } = usePluginImport(); + const { openConfigDialog } = usePluginConfig(); + + const settingStore = useSettingStore(); return { crudOptions: { settings: { @@ -139,7 +78,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat text: t("certd.import"), type: "primary", async click() { - await openImportDialog(); + await openImportDialog({ crudExpose }); }, }, }, @@ -186,6 +125,21 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat } }, }, + config: { + show: computed(() => { + return settingStore.isComm; + }), + text: null, + icon: "ion:settings-outline", + title: t("certd.config"), + type: "link", + async click({ row }) { + await openConfigDialog({ + row, + crudExpose, + }); + }, + }, }, }, table: { diff --git a/packages/ui/certd-client/src/views/sys/plugin/use-config.tsx b/packages/ui/certd-client/src/views/sys/plugin/use-config.tsx new file mode 100644 index 00000000..3cefb462 --- /dev/null +++ b/packages/ui/certd-client/src/views/sys/plugin/use-config.tsx @@ -0,0 +1,50 @@ +import * as api from "/@/views/sys/plugin/api"; +import { useFormWrapper } from "@fast-crud/fast-crud"; +import { useI18n } from "/@/locales"; +import { Modal, notification } from "ant-design-vue"; +import ConfigEditor from "./config-editor.vue"; +export function usePluginConfig() { + const { openCrudFormDialog } = useFormWrapper(); + const { t } = useI18n(); + + async function openConfigDialog({ row, crudExpose }) { + function createCrudOptions() { + return { + crudOptions: { + columns: {}, + form: { + wrapper: { + width: "80%", + title: "插件元数据配置", + saveRemind: false, + slots: { + "form-body-top": () => { + return ( +
+ +
+ ); + }, + }, + }, + afterSubmit() { + notification.success({ message: t("certd.operationSuccess") }); + crudExpose.doRefresh(); + }, + async doSubmit({ form }: any) { + return await api.ImportPlugin({ + ...form, + }); + }, + }, + }, + }; + } + const { crudOptions } = createCrudOptions(); + await openCrudFormDialog({ crudOptions }); + } + + return { + openConfigDialog, + }; +} diff --git a/packages/ui/certd-client/src/views/sys/plugin/use-import.ts b/packages/ui/certd-client/src/views/sys/plugin/use-import.ts new file mode 100644 index 00000000..b398752a --- /dev/null +++ b/packages/ui/certd-client/src/views/sys/plugin/use-import.ts @@ -0,0 +1,80 @@ +import * as api from "/@/views/sys/plugin/api"; +import { useFormWrapper } from "@fast-crud/fast-crud"; +import { useI18n } from "/@/locales"; +import { Modal, notification } from "ant-design-vue"; +export function usePluginImport() { + const { openCrudFormDialog } = useFormWrapper(); + const { t } = useI18n(); + + async function openImportDialog({ crudExpose }) { + function createCrudOptions() { + return { + crudOptions: { + columns: { + content: { + title: t("certd.pluginFile"), + type: "text", + form: { + component: { + name: "pem-input", + vModel: "modelValue", + textarea: { + rows: 8, + }, + }, + col: { + span: 24, + }, + helper: t("certd.selectPluginFile"), + }, + }, + override: { + title: t("certd.overrideSameName"), + type: "dict-switch", + dict: dict({ + data: [ + { + value: true, + label: t("certd.override"), + }, + { + value: false, + label: t("certd.noOverride"), + }, + ], + }), + form: { + value: false, + col: { + span: 24, + }, + helper: t("certd.overrideHelper"), + }, + }, + }, + form: { + wrapper: { + title: t("certd.importPlugin"), + saveRemind: false, + }, + afterSubmit() { + notification.success({ message: t("certd.operationSuccess") }); + crudExpose.doRefresh(); + }, + async doSubmit({ form }: any) { + return await api.ImportPlugin({ + ...form, + }); + }, + }, + }, + }; + } + const { crudOptions } = createCrudOptions(); + await openCrudFormDialog({ crudOptions }); + } + + return { + openImportDialog, + }; +} diff --git a/packages/ui/certd-server/src/modules/plugin/service/plugin-config-service.ts b/packages/ui/certd-server/src/modules/plugin/service/plugin-config-service.ts index 697a7920..cc8bbd9b 100644 --- a/packages/ui/certd-server/src/modules/plugin/service/plugin-config-service.ts +++ b/packages/ui/certd-server/src/modules/plugin/service/plugin-config-service.ts @@ -6,6 +6,7 @@ export type PluginConfig = { disabled: boolean; sysSetting: { input?: Record; + metadata?: Record; }; }; @@ -57,7 +58,14 @@ export class PluginConfigService { author: "certd", }); } else { - await this.pluginService.getRepository().update({ name }, { sysSetting: JSON.stringify(sysSetting) }); + let setting = JSON.parse(pluginEntity.sysSetting || "{}"); + if (sysSetting.metadata) { + setting.metadata = sysSetting.metadata; + } + if (sysSetting.input) { + setting.input = sysSetting.input; + } + await this.pluginService.getRepository().update({ name }, { sysSetting: JSON.stringify(setting) }); } }