perf: cname校验配置增加未校验通过提示

This commit is contained in:
xiaojunnuo
2024-10-10 03:08:31 +08:00
parent 8f79107d2b
commit 77cc3c4a5c
7 changed files with 51 additions and 12 deletions
@@ -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<string, CnameRecord>;
};
type DomainsVerifyPlanInput = {
[key: string]: DomainVerifyPlanInput;
};
const challengeTypeOptions = ref<any[]>([
{
label: "DNS验证",
@@ -122,8 +113,12 @@ const planRef = ref<DomainsVerifyPlanInput>(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<string>("");
@@ -0,0 +1,12 @@
import { CnameRecord } from "@certd/pipeline";
export type DomainVerifyPlanInput = {
domain: string;
type: "cname" | "dns";
dnsProviderType?: string;
dnsProviderAccessId?: number;
cnameVerifyPlan?: Record<string, CnameRecord>;
};
export type DomainsVerifyPlanInput = {
[key: string]: DomainVerifyPlanInput;
};
@@ -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);
@@ -0,0 +1 @@
export * from "./domains-verify-plan-editor/validator.js";
@@ -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);