chore: domain manager

v2-dev-auto
xiaojunnuo 2025-07-10 17:00:47 +08:00
parent f3002e4fb6
commit 39dc5c8160
6 changed files with 110 additions and 7 deletions

View File

@ -7,7 +7,13 @@ export const Dicts = {
{ value: "zerossl", label: "ZeroSSL" },
],
}),
challengeTypeDict: dict({ data: [{ value: "dns", label: "DNS校验" }] }),
challengeTypeDict: dict({
data: [
{ value: "dns", label: "DNS校验" },
{ value: "cname", label: "CNAME代理校验" },
{ value: "http", label: "HTTP校验" },
],
}),
dnsProviderTypeDict: dict({
url: "pi/dnsProvider/dnsProviderTypeDict",
}),

View File

@ -717,5 +717,6 @@ export default {
httpUploaderType: "HTTP Uploader Type",
httpUploaderAccess: "HTTP Uploader Access",
httpUploadRootDir: "HTTP Upload Root Dir",
disabled: "Disabled",
},
};

View File

@ -720,5 +720,6 @@ export default {
httpUploaderType: "上传方式",
httpUploaderAccess: "上传授权信息",
httpUploadRootDir: "网站根路径",
disabled: "禁用/启用",
},
};

View File

@ -122,7 +122,7 @@ export const certdResources = [
path: "/certd/cert/domain",
component: "/certd/cert/domain/index.vue",
meta: {
icon: "material-symbols:approval-delegation-outline",
icon: "ion:globe-outline",
auth: true,
keepAlive: true,
},

View File

@ -82,17 +82,21 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
search: {
show: true,
},
form: {
required: true,
},
editForm: {
component: {
disabled: true,
disabled: false,
},
},
},
challengeType: {
title: t("certd.domain.challengeType"),
type: "dict-select",
dict: Dicts.challengeTypeDict,
form: {
show: false,
required: true,
},
},
/**
@ -110,6 +114,10 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
component: {
name: "DnsProviderSelector",
},
show: compute(({ form }) => {
return form.challengeType === "dns";
}),
required: true,
},
},
dnsProviderAccess: {
@ -118,16 +126,27 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
form: {
component: {
name: "AccessSelector",
vModel: "modelValue",
type: compute(({ form }) => {
return form.dnsProviderType;
}),
},
show: compute(({ form }) => {
return form.challengeType === "dns";
}),
required: true,
},
},
httpUploaderType: {
title: t("certd.domain.httpUploaderType"),
type: "dict-text",
dict: Dicts.uploaderTypeDict,
form: {
show: compute(({ form }) => {
return form.challengeType === "http";
}),
required: true,
},
},
httpUploaderAccess: {
title: t("certd.domain.httpUploaderAccess"),
@ -136,10 +155,41 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
component: {
name: "AccessSelector",
},
show: compute(({ form }) => {
return form.challengeType === "http";
}),
required: true,
},
},
httpUploadRootDir: {
title: t("certd.domain.httpUploadRootDir"),
type: "text",
form: {
show: compute(({ form }) => {
return form.challengeType === "http";
}),
required: true,
},
},
disabled: {
title: t("certd.domain.disabled"),
type: "dict-switch",
dict: dict({
data: [
{ label: "启用", value: false },
{ label: "禁用", value: true },
],
}),
form: {
value: false,
required: true,
},
column: {
width: 80,
},
},
createTime: {
title: t("certd.create_time"),
title: t("certd.createTime"),
type: "datetime",
form: {
show: false,
@ -151,7 +201,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
},
},
updateTime: {
title: t("certd.update_time"),
title: t("certd.updateTime"),
type: "datetime",
form: {
show: false,

View File

@ -1,6 +1,6 @@
import {Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core';
import {InjectEntityModel} from '@midwayjs/typeorm';
import {Repository} from 'typeorm';
import {Not, Repository} from 'typeorm';
import {AccessService, BaseService} from '@certd/lib-server';
import {DomainEntity} from '../entity/domain.js';
@ -22,4 +22,49 @@ export class DomainService extends BaseService<DomainEntity> {
return this.repository;
}
async add(param) {
if (param.userId == null ){
throw new Error('userId 不能为空');
}
if (!param.domain) {
throw new Error('domain 不能为空');
}
const old = await this.repository.findOne({
where: {
domain: param.domain,
userId: param.userId
}
});
if (old) {
throw new Error(`域名(${param.domain})不能重复`);
}
return await super.add(param);
}
async update(param) {
if (!param.id) {
throw new Error('id 不能为空');
}
const old = await this.info(param.id)
if (!old) {
throw new Error('domain记录不存在');
}
const same = await this.repository.findOne({
where: {
domain: param.domain,
userId: old.userId,
id: Not(param.id)
}
});
if (same) {
throw new Error(`域名(${param.domain})不能重复`);
}
delete param.userId
return await super.update(param);
}
}