From 0e36f03954bd5cbe1cc8cb8420ac8b05cfd61f12 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Thu, 10 Apr 2025 00:22:05 +0800 Subject: [PATCH] chore: plugin default --- .../src/components/code-editor/index.vue | 29 ++- .../src/views/sys/plugin/crud.tsx | 43 ++++- .../src/views/sys/plugin/edit.vue | 85 +++++++-- .../modules/plugin/service/default-plugin.ts | 169 ++++++++++++++++++ .../modules/plugin/service/plugin-service.ts | 35 ++++ 5 files changed, 336 insertions(+), 25 deletions(-) create mode 100644 packages/ui/certd-server/src/modules/plugin/service/default-plugin.ts diff --git a/packages/ui/certd-client/src/components/code-editor/index.vue b/packages/ui/certd-client/src/components/code-editor/index.vue index 8219f5f0..1c49088c 100644 --- a/packages/ui/certd-client/src/components/code-editor/index.vue +++ b/packages/ui/certd-client/src/components/code-editor/index.vue @@ -77,7 +77,7 @@ onUnmounted(() => { disposeEditor(); }); -const emits = defineEmits(["update:modelValue", "change", "ready"]); +const emits = defineEmits(["update:modelValue", "change", "ready", "save"]); const emitValue = lodashDebounce((value: any) => { emits("update:modelValue", value); @@ -91,6 +91,10 @@ async function createEditor(ctx: EditorCodeCtx) { language: ctx.language, theme: "vs-dark", minimap: { enabled: false }, + insertSpaces: true, + tabSize: 2, + autoIndent: true, // 自动布局 + renderWhitespace: true, readOnly: props.readonly || props.disabled, hover: { enabled: true, @@ -113,6 +117,20 @@ async function createEditor(ctx: EditorCodeCtx) { if (props.modelValue) { instanceRef.setValue(props.modelValue); } + + instance.addAction({ + id: "custom_save", + label: "save", + contextMenuOrder: 1, // 菜单项的排序权重 越小,越靠前 + contextMenuGroupId: "customCommand", // 菜单项的分组 + keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS], + run: async () => { + await instanceRef.getAction("editor.action.formatDocument").run(); + emits("save", { + value: props.modelValue, + }); + }, //方法 + }); return instance; } @@ -128,7 +146,7 @@ async function initJson(ctx: EditorCodeCtx) { const schemas = []; if (ctx.schema) { schemas.push({ - // uri: "http://myserver/foo-schema.json", // id of the first schema + uri: "http://myserver/foo-schema.json", // id of the first schema fileMatch: ["*"], // associate with our model schema: { ...ctx.schema, @@ -147,7 +165,8 @@ async function initYaml(ctx: EditorCodeCtx) { await importYamlContribution(); const { configureMonacoYaml } = await importMonacoYaml(); monaco.languages.register({ id: "yaml" }); - + const id = `fs-editor-code-yaml-${props.id || ""}.yaml`; + const uri = monaco.Uri.parse(id); const schemas = []; if (ctx.schema) { schemas.push({ @@ -155,7 +174,7 @@ async function initYaml(ctx: EditorCodeCtx) { schema: { ...ctx.schema, }, - uri: "http://myserver/foo-schema.json", + uri: id, }); } configureMonacoYaml(monaco, { @@ -167,7 +186,7 @@ async function initYaml(ctx: EditorCodeCtx) { isKubernetes: false, enableSchemaRequest: false, }); - const uri = monaco.Uri.parse(`fs-editor-code-yaml-${props.id || ""}.yaml`); + const oldModel = monaco.editor.getModel(uri); if (oldModel) { oldModel.dispose(); 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 6c32bc48..0570eb8d 100644 --- a/packages/ui/certd-client/src/views/sys/plugin/crud.tsx +++ b/packages/ui/certd-client/src/views/sys/plugin/crud.tsx @@ -117,7 +117,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat form: { show: true, order: 0, - helper: "必须为英文,驼峰命名,类型作为前缀\n例如AliyunDeployToCDN", + helper: "必须为英文,驼峰命名,类型作为前缀\n例如AliyunDeployToCDN\n插件一旦被使用,不要修改名称", rules: [{ required: true }], }, column: { @@ -140,7 +140,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat form: { show: true, order: 0, - helper: "上传到应用商店时,将作为插件名称前缀,例如:greper/pluginName", + helper: "上传到插件商店时,将作为插件名称前缀,例如:greper/pluginName", rules: [{ required: true }], }, column: { @@ -187,7 +187,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat }, desc: { title: "描述", - type: "text", + type: "textarea", helper: "插件的描述", column: { width: 300, @@ -230,6 +230,11 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat form: { rules: [{ required: true }], }, + editForm: { + component: { + disabled: true, + }, + }, dict: dict({ data: [ { label: "授权", value: "access" }, @@ -245,6 +250,14 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat }, }, }, + version: { + title: "版本", + type: "text", + column: { + width: 100, + align: "center", + }, + }, group: { title: "分组", type: "dict-select", @@ -264,6 +277,29 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat }, }, }, + "default.strategy.runStrategy": { + title: "运行策略", + type: "dict-select", + + dict: dict({ + data: [ + { value: 0, label: "正常运行" }, + { value: 1, label: "成功后跳过(部署任务)" }, + ], + }), + form: { + value: 1, + rules: [{ required: true }], + helper: "默认运行策略", + }, + column: { + width: 100, + align: "left", + component: { + color: "auto", + }, + }, + }, disabled: { title: "点击禁用/启用", type: "dict-switch", @@ -274,6 +310,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat ], }), form: { + title: "禁用/启用", value: false, }, column: { diff --git a/packages/ui/certd-client/src/views/sys/plugin/edit.vue b/packages/ui/certd-client/src/views/sys/plugin/edit.vue index 29756c09..ee160c7e 100644 --- a/packages/ui/certd-client/src/views/sys/plugin/edit.vue +++ b/packages/ui/certd-client/src/views/sys/plugin/edit.vue @@ -13,29 +13,39 @@
+
+ + + +
+ +
+
- +