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

pull/213/head
xiaojunnuo 2024-10-10 03:08:31 +08:00
parent 8f79107d2b
commit 77cc3c4a5c
7 changed files with 51 additions and 12 deletions

View File

@ -10,6 +10,7 @@ export type CnameRecord = {
hostRecord: string;
recordValue: string;
cnameProvider: CnameProvider;
status: string;
};
export type ICnameProxyService = {
getByDomain: (domain: string) => Promise<CnameRecord>;

View File

@ -100,6 +100,7 @@ export class CertApplyPlugin extends CertApplyBasePlugin {
component: {
name: "domains-verify-plan-editor",
},
rules: [{ type: "checkCnameVerifyPlan" }],
required: true,
helper: "如果选择CNAME方式请按照上面的显示给域名添加CNAME记录添加后点击验证验证成功后不要删除记录申请和续期证书会一直用它",
col: {

View File

@ -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>("");

View File

@ -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;
};

View File

@ -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);

View File

@ -0,0 +1 @@
export * from "./domains-verify-plan-editor/validator.js";

View File

@ -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);