mirror of https://github.com/certd/certd
chore: registry注册到全局里面
parent
18bfcc24ad
commit
c6488b58f5
|
@ -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");
|
||||
|
|
|
@ -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<AbstractTaskPlugin>) => {
|
|||
}
|
||||
}
|
||||
};
|
||||
export const pluginRegistry = new Registry<AbstractTaskPlugin>("plugin", onRegister);
|
||||
export const pluginRegistry = createRegistry<AbstractTaskPlugin>("plugin", onRegister);
|
||||
|
|
|
@ -88,3 +88,21 @@ export class Registry<T> {
|
|||
return item.define;
|
||||
}
|
||||
}
|
||||
|
||||
export function createRegistry<T>(type: string, onRegister?: OnRegister<T>) {
|
||||
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<T>(type, onRegister);
|
||||
cached[type] = newRegistry;
|
||||
return newRegistry;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<void> {
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue