From 77cc3c4a5cbd81f8233a8e0bb33fab0621c0905f Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Thu, 10 Oct 2024 03:08:31 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20cname=E6=A0=A1=E9=AA=8C=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=A2=9E=E5=8A=A0=E6=9C=AA=E6=A0=A1=E9=AA=8C=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/pipeline/src/service/cname.ts | 1 + .../src/plugin/cert-plugin/index.ts | 1 + .../cert/domains-verify-plan-editor/index.vue | 17 ++++------- .../cert/domains-verify-plan-editor/type.ts | 12 ++++++++ .../domains-verify-plan-editor/validator.ts | 29 +++++++++++++++++++ .../src/components/plugins/cert/index.ts | 1 + .../src/components/plugins/index.ts | 2 +- 7 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/type.ts create mode 100644 packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/validator.ts create mode 100644 packages/ui/certd-client/src/components/plugins/cert/index.ts diff --git a/packages/core/pipeline/src/service/cname.ts b/packages/core/pipeline/src/service/cname.ts index 4cd12a60..3ad75f72 100644 --- a/packages/core/pipeline/src/service/cname.ts +++ b/packages/core/pipeline/src/service/cname.ts @@ -10,6 +10,7 @@ export type CnameRecord = { hostRecord: string; recordValue: string; cnameProvider: CnameProvider; + status: string; }; export type ICnameProxyService = { getByDomain: (domain: string) => Promise; diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts index 5c478da2..526bd993 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts @@ -100,6 +100,7 @@ export class CertApplyPlugin extends CertApplyBasePlugin { component: { name: "domains-verify-plan-editor", }, + rules: [{ type: "checkCnameVerifyPlan" }], required: true, helper: "如果选择CNAME方式,请按照上面的显示,给域名添加CNAME记录,添加后,点击验证,验证成功后不要删除记录,申请和续期证书会一直用它", col: { diff --git a/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/index.vue b/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/index.vue index a00e8708..08e8f40f 100644 --- a/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/index.vue +++ b/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/index.vue @@ -77,21 +77,12 @@ import { dict, FsDictSelect } from "@fast-crud/fast-crud"; import AccessSelector from "/@/views/certd/access/access-selector/index.vue"; import CnameVerifyPlan from "./cname-verify-plan.vue"; import psl from "psl"; +import { Form } from "ant-design-vue"; +import { DomainsVerifyPlanInput } from "./type"; defineOptions({ name: "DomainsVerifyPlanEditor" }); -type DomainVerifyPlanInput = { - domain: string; - type: "cname" | "dns"; - dnsProviderType?: string; - dnsProviderAccessId?: number; - cnameVerifyPlan?: Record; -}; -type DomainsVerifyPlanInput = { - [key: string]: DomainVerifyPlanInput; -}; - const challengeTypeOptions = ref([ { label: "DNS验证", @@ -122,8 +113,12 @@ const planRef = ref(props.modelValue || {}); const dnsProviderTypeDict = dict({ url: "pi/dnsProvider/dnsProviderTypeDict" }); + +const formItemContext = Form.useInjectFormItemContext(); function onPlanChanged() { + console.log("plan changed", planRef.value); emit("update:modelValue", planRef.value); + formItemContext.onFieldChange(); } const errorMessageRef = ref(""); diff --git a/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/type.ts b/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/type.ts new file mode 100644 index 00000000..30deeca5 --- /dev/null +++ b/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/type.ts @@ -0,0 +1,12 @@ +import { CnameRecord } from "@certd/pipeline"; + +export type DomainVerifyPlanInput = { + domain: string; + type: "cname" | "dns"; + dnsProviderType?: string; + dnsProviderAccessId?: number; + cnameVerifyPlan?: Record; +}; +export type DomainsVerifyPlanInput = { + [key: string]: DomainVerifyPlanInput; +}; diff --git a/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/validator.ts b/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/validator.ts new file mode 100644 index 00000000..1df53c6a --- /dev/null +++ b/packages/ui/certd-client/src/components/plugins/cert/domains-verify-plan-editor/validator.ts @@ -0,0 +1,29 @@ +import Validator from "async-validator"; +import { DomainsVerifyPlanInput } from "./type"; + +function checkCnameVerifyPlan(rule, value: DomainsVerifyPlanInput) { + debugger; + if (value == null) { + return true; + } + for (const domain in value) { + if (value[domain].type === "cname") { + const subDomains = Object.keys(value[domain].cnameVerifyPlan); + if (subDomains.length > 0) { + for (const subDomain of subDomains) { + const plan = value[domain].cnameVerifyPlan[subDomain]; + if (plan.status !== "valid") { + throw new Error(`域名${subDomain}的CNAME未验证通过,请先设置CNAME记录,点击验证按钮`); + } + } + } + } else { + if (value[domain].dnsProviderType == null || value[domain].dnsProviderAccessId == null) { + throw new Error(`DNS模式下,域名${domain}的DNS类型和授权信息必须填写`); + } + } + } + return true; +} +// 注册自定义验证器 +Validator.register("checkCnameVerifyPlan", checkCnameVerifyPlan); diff --git a/packages/ui/certd-client/src/components/plugins/cert/index.ts b/packages/ui/certd-client/src/components/plugins/cert/index.ts new file mode 100644 index 00000000..1b38d822 --- /dev/null +++ b/packages/ui/certd-client/src/components/plugins/cert/index.ts @@ -0,0 +1 @@ +export * from "./domains-verify-plan-editor/validator.js"; diff --git a/packages/ui/certd-client/src/components/plugins/index.ts b/packages/ui/certd-client/src/components/plugins/index.ts index dc93c7e2..6f1f7713 100644 --- a/packages/ui/certd-client/src/components/plugins/index.ts +++ b/packages/ui/certd-client/src/components/plugins/index.ts @@ -5,7 +5,7 @@ import OutputSelector from "/@/components/plugins/common/output-selector/index.v import DnsProviderSelector from "/@/components/plugins/cert/dns-provider-selector/index.vue"; import DomainsVerifyPlanEditor from "/@/components/plugins/cert/domains-verify-plan-editor/index.vue"; import AccessSelector from "/@/views/certd/access/access-selector/index.vue"; - +export * from "./cert/index.js"; export default { install(app: any) { app.component("OutputSelector", OutputSelector);