From c6488b58f53be65c5ea1367e22c68bdb96eb1985 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 16 Nov 2024 11:01:14 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20registry=E6=B3=A8=E5=86=8C=E5=88=B0?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E9=87=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/pipeline/src/access/registry.ts | 4 +- packages/core/pipeline/src/plugin/registry.ts | 4 +- .../core/pipeline/src/registry/registry.ts | 18 ++++++ .../plugin-cert/src/dns-provider/registry.ts | 4 +- .../pipeline/component/task-view/index.vue | 2 - .../plugin-demo/plugins/plugin-test.ts | 59 ++++++++++++++++++- 6 files changed, 80 insertions(+), 11 deletions(-) diff --git a/packages/core/pipeline/src/access/registry.ts b/packages/core/pipeline/src/access/registry.ts index 4dea4643..10e7a366 100644 --- a/packages/core/pipeline/src/access/registry.ts +++ b/packages/core/pipeline/src/access/registry.ts @@ -1,4 +1,4 @@ -import { Registry } from "../registry/index.js"; +import { createRegistry } from "../registry/index.js"; // @ts-ignore -export const accessRegistry = new Registry("access"); +export const accessRegistry = createRegistry("access"); diff --git a/packages/core/pipeline/src/plugin/registry.ts b/packages/core/pipeline/src/plugin/registry.ts index 684cd4ca..1411053b 100644 --- a/packages/core/pipeline/src/plugin/registry.ts +++ b/packages/core/pipeline/src/plugin/registry.ts @@ -1,4 +1,4 @@ -import { OnRegisterContext, Registry } from "../registry/index.js"; +import { createRegistry, OnRegisterContext } from "../registry/index.js"; import { AbstractTaskPlugin } from "./api.js"; import { pluginGroups } from "./group.js"; @@ -13,4 +13,4 @@ const onRegister = ({ key, value }: OnRegisterContext) => { } } }; -export const pluginRegistry = new Registry("plugin", onRegister); +export const pluginRegistry = createRegistry("plugin", onRegister); diff --git a/packages/core/pipeline/src/registry/registry.ts b/packages/core/pipeline/src/registry/registry.ts index cf49899a..2be4d839 100644 --- a/packages/core/pipeline/src/registry/registry.ts +++ b/packages/core/pipeline/src/registry/registry.ts @@ -88,3 +88,21 @@ export class Registry { return item.define; } } + +export function createRegistry(type: string, onRegister?: OnRegister) { + const pipelineregistrycacheKey = "PIPELINE_REGISTRY_CACHE"; + // @ts-ignore + let cached: any = global[pipelineregistrycacheKey]; + if (!cached) { + cached = {}; + // @ts-ignore + global[pipelineregistrycacheKey] = cached; + } + + if (cached[type]) { + return cached[type]; + } + const newRegistry = new Registry(type, onRegister); + cached[type] = newRegistry; + return newRegistry; +} diff --git a/packages/plugins/plugin-cert/src/dns-provider/registry.ts b/packages/plugins/plugin-cert/src/dns-provider/registry.ts index c5c9c1ea..f11064d8 100644 --- a/packages/plugins/plugin-cert/src/dns-provider/registry.ts +++ b/packages/plugins/plugin-cert/src/dns-provider/registry.ts @@ -1,3 +1,3 @@ -import { Registry } from "@certd/pipeline"; +import { createRegistry } from "@certd/pipeline"; -export const dnsProviderRegistry = new Registry("dnsProvider"); +export const dnsProviderRegistry = createRegistry("dnsProvider"); diff --git a/packages/ui/certd-client/src/views/certd/pipeline/pipeline/component/task-view/index.vue b/packages/ui/certd-client/src/views/certd/pipeline/pipeline/component/task-view/index.vue index 16286310..98facc70 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/pipeline/component/task-view/index.vue +++ b/packages/ui/certd-client/src/views/certd/pipeline/pipeline/component/task-view/index.vue @@ -61,7 +61,6 @@ export default { if (currentHistory?.value?.logs != null) { node.logs = computed(() => { if (currentHistory?.value?.logs && currentHistory.value?.logs[node.node.id] != null) { - console.log("log changed", node.node.id); const logs = currentHistory.value?.logs[node.node.id]; const list = []; for (let log of logs) { @@ -86,7 +85,6 @@ export default { }, async () => { let el = document.querySelector(`.pi-task-view-logs.${node.node.id}`); - console.log("el", el); //判断当前是否在底部 const isBottom = el ? el.scrollHeight - el.scrollTop === el.clientHeight : true; await nextTick(); diff --git a/packages/ui/certd-server/src/plugins/plugin-demo/plugins/plugin-test.ts b/packages/ui/certd-server/src/plugins/plugin-demo/plugins/plugin-test.ts index e6166b7b..20734ff2 100644 --- a/packages/ui/certd-server/src/plugins/plugin-demo/plugins/plugin-test.ts +++ b/packages/ui/certd-server/src/plugins/plugin-demo/plugins/plugin-test.ts @@ -1,6 +1,7 @@ import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline'; import { CertInfo, CertReader } from '@certd/plugin-cert'; -import { isDev } from '@certd/basic'; +import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from '@certd/plugin-plus'; +import { optionsUtils } from '@certd/basic/dist/utils/util.options.js'; @IsTaskPlugin({ name: 'demoTest', @@ -13,8 +14,6 @@ import { isDev } from '@certd/basic'; runStrategy: RunStrategy.SkipWhenSucceed, }, }, - // 你开发的插件要删除此项,否则不会在生产环墋中显示 - deprecated: isDev() ? '测试插件,生产环境不显示' : undefined, }) export class DemoTestPlugin extends AbstractTaskPlugin { //测试参数 @@ -65,6 +64,10 @@ export class DemoTestPlugin extends AbstractTaskPlugin { }) cert!: CertInfo; + @TaskInput(createCertDomainGetterInputDefine({ props: { required: false } })) + //前端可以展示,当前申请的证书域名列表 + certDomains!: string[]; + //授权选择框 @TaskInput({ title: 'demo授权', @@ -78,7 +81,23 @@ export class DemoTestPlugin extends AbstractTaskPlugin { }) accessId!: string; + @TaskInput( + createRemoteSelectInputDefine({ + title: '从后端获取选项', + helper: '选择时可以从后端获取选项', + typeName: 'demoTest', + action: DemoTestPlugin.prototype.onGetSiteList.name, + //当以下参数变化时,触发获取选项 + watches: ['certDomains', 'accessId'], + required: true, + }) + ) + siteName!: string | string[]; + + //插件实例化时执行的方法 async onInstance() {} + + //插件执行方法 async execute(): Promise { const { select, text, cert, accessId } = this; @@ -102,6 +121,40 @@ export class DemoTestPlugin extends AbstractTaskPlugin { this.logger.info('switch:', this.switch); this.logger.info('授权id:', accessId); } + + //此方法演示,如何让前端在添加插件时可以从后端获取选项,这里是后端返回选项的方法 + async onGetSiteList() { + if (!this.accessId) { + throw new Error('请选择Access授权'); + } + + // @ts-ignore + const access = await this.accessService.getById(this.accessId); + + // const siteRes = await this.ctx.http.request({ + // url: '你的服务端获取选项的请求地址', + // method: 'GET', + // data: { + // token:access.xxxx + // }, //请求参数 + // }); + //以下是模拟数据 + const siteRes = [ + { id: 1, siteName: 'site1.com' }, + { id: 2, siteName: 'site2.com' }, + { id: 3, siteName: 'site2.com' }, + ]; + //转换为前端所需要的格式 + const options = siteRes.map((item: any) => { + return { + value: item.siteName, + label: item.siteName, + domain: item.siteName, + }; + }); + //将站点域名名称根据证书域名进行匹配分组,分成匹配的和不匹配的两组选项,返回给前端,供用户选择 + return optionsUtils.buildGroupOptions(options, this.certDomains); + } } //实例化一下,注册插件 new DemoTestPlugin();