cs
3 months ago
15 changed files with 1031 additions and 621 deletions
-
71package.json
-
10src/App.css
-
6src/components/action/Action.tsx
-
86src/components/r-form/index.tsx
-
26src/components/r-form/utils/index.tsx
-
23src/i18n.ts
-
6src/locales/lang/zh-CN.ts
-
111src/pages/login/index.tsx
-
60src/pages/r-form/index.tsx
-
374src/pages/websites/cert/apply.tsx
-
102src/service/websites.ts
-
325src/store/websites/cert.ts
-
3src/types/r-form/model.d.ts
-
2src/utils/index.ts
-
1vite.config.ts
@ -1,84 +1,100 @@ |
|||
import { createCURD } from '@/service/base.ts' |
|||
import { WebSite } from '@/types' |
|||
import request from '@/request.ts' |
|||
import { IWebsiteDomain, INameServer } from '@/types/website/domain' |
|||
import { IWebsiteDnsRecords } from '@/types/website/record' |
|||
import { IWebsiteDnsAccount } from '@/types/website/dns_account' |
|||
import { createCURD } from "@/service/base.ts"; |
|||
import { WebSite } from "@/types"; |
|||
import request from "@/request.ts"; |
|||
import { IWebsiteDomain, INameServer } from "@/types/website/domain"; |
|||
import { IWebsiteDnsRecords } from "@/types/website/record"; |
|||
import { IWebsiteDnsAccount } from "@/types/website/dns_account"; |
|||
|
|||
const websitesServ = { |
|||
cert: { |
|||
...createCURD<any, ICertificate>('/website/cert'), |
|||
//dns_config
|
|||
dnsConfig: async (params: any) => { |
|||
return request.post<any, any>('/website/cert/dns_config', params) |
|||
...createCURD<any, ICertificate>("/website/cert"), |
|||
// 发起域名检测
|
|||
checkDomain: async (params: any) => { |
|||
return request.post<any, any>("/cert/apply/dns_config", params); |
|||
}, |
|||
//dns_verify
|
|||
dnsVerify: async (params: any) => { |
|||
return request.post<any, any>('/website/cert/dns_verify', params) |
|||
getCertConfig: async () => { |
|||
return request.get<any, any>("/cert/apply/acme/key"); |
|||
}, |
|||
//cert-apply
|
|||
certApply: async (params: any) => { |
|||
return request.post<any, any>('/website/cert/dns_verify', params) |
|||
// 申请list
|
|||
getCertList: async (arams: any) => { |
|||
return request.post<any, any>("/cert/apply/list"); |
|||
}, |
|||
// 证书续签
|
|||
renewCertificate: async (params: any) => { |
|||
return request.post<any, any>("/website/cert/renew_certificate", params); |
|||
}, |
|||
// 添加记录
|
|||
addCnameCertificate: async (params: any) => { |
|||
return request.post<any, any>("/cert/apply/add/cname", params); |
|||
}, |
|||
// 下载证书
|
|||
downloadCertificate: async (params: any) => { |
|||
return request.post<any, any>("/website/cert/download_certificate", params); |
|||
}, |
|||
// 获取证书申请日志
|
|||
getCertificateLogs: async (params: any) => { |
|||
return request.get<any, any>("/website/cert/get_certificate_logs", { params }); |
|||
}, |
|||
applyTxtCertificate: async (params: any) => { |
|||
return request.post<any, any>("/cert/apply/resolve", params); |
|||
}, |
|||
|
|||
}, |
|||
ssl: { |
|||
...createCURD<any, WebSite.ISSL>('/website/ssl'), |
|||
...createCURD<any, WebSite.ISSL>("/website/ssl"), |
|||
upload: async (params: WebSite.SSLUploadDto) => { |
|||
return request.post<any, WebSite.SSLUploadDto>('/website/ssl/upload', params) |
|||
return request.post<any, WebSite.SSLUploadDto>("/website/ssl/upload", params); |
|||
}, |
|||
download: async (params: any) => { |
|||
return request.download('/website/ssl/download', params) |
|||
return request.download("/website/ssl/download", params); |
|||
}, |
|||
}, |
|||
acme: { |
|||
...createCURD<any, WebSite.IAcmeAccount>('/website/acme') |
|||
...createCURD<any, WebSite.IAcmeAccount>("/website/acme"), |
|||
}, |
|||
dns: { |
|||
...createCURD<any, WebSite.IDnsAccount>('/cert/dns_account'), |
|||
...createCURD<any, WebSite.IDnsAccount>("/cert/dns_account"), |
|||
sync: async (id: any) => { |
|||
return request.post<any, WebSite.IDnsAccount>('/cert/dns_account/sync', { id: id }) |
|||
} |
|||
return request.post<any, WebSite.IDnsAccount>("/cert/dns_account/sync", { id: id }); |
|||
}, |
|||
}, |
|||
ca: { |
|||
...createCURD<any, WebSite.ICA>('/website/ca'), |
|||
...createCURD<any, WebSite.ICA>("/website/ca"), |
|||
obtainSsl: async (params: WebSite.ISSLObtainByCA) => { |
|||
return request.post<any, WebSite.ISSLObtainByCA>('/website/ca/obtain_ssl', params) |
|||
return request.post<any, WebSite.ISSLObtainByCA>("/website/ca/obtain_ssl", params); |
|||
}, |
|||
}, |
|||
domain: { |
|||
...createCURD<any, IWebsiteDomain>('/cert/domain'), |
|||
...createCURD<any, IWebsiteDomain>("/cert/domain"), |
|||
//remark
|
|||
remark: async (params: { id: string, remark: string }) => { |
|||
return request.post<any, any>('/cert/domain/remark', params) |
|||
remark: async (params: { id: string; remark: string }) => { |
|||
return request.post<any, any>("/cert/domain/remark", params); |
|||
}, |
|||
//tag
|
|||
tag: async (params: { id: string, tags: string }) => { |
|||
return request.post<any, any>('/cert/domain/tag', params) |
|||
tag: async (params: { id: string; tags: string }) => { |
|||
return request.post<any, any>("/cert/domain/tag", params); |
|||
}, |
|||
//binding
|
|||
binding: async (params: { id: string, user_id: string }) => { |
|||
return request.post<any, any>('/cert/domain/binding', params) |
|||
binding: async (params: { id: string; user_id: string }) => { |
|||
return request.post<any, any>("/cert/domain/binding", params); |
|||
}, |
|||
//group
|
|||
group: async (params: { id: string[], group_id: string }) => { |
|||
return request.post<any, any>('/cert/domain/group', params) |
|||
group: async (params: { id: string[]; group_id: string }) => { |
|||
return request.post<any, any>("/cert/domain/group", params); |
|||
}, |
|||
describeDomainNS: async (params: { id: number }) => { |
|||
return request.post<INameServer, any>('/cert/domain/describe_domain_ns', params) |
|||
return request.post<INameServer, any>("/cert/domain/describe_domain_ns", params); |
|||
}, |
|||
|
|||
}, |
|||
record: { |
|||
...createCURD<any, IWebsiteDnsRecords>('/cert/dns_records'), |
|||
...createCURD<any, IWebsiteDnsRecords>("/cert/dns_records"), |
|||
//
|
|||
}, |
|||
dnsAccount: { |
|||
...createCURD<any, IWebsiteDnsAccount>('/cert/dns_account'), |
|||
...createCURD<any, IWebsiteDnsAccount>("/cert/dns_account"), |
|||
sync: async (params: IWebsiteDnsAccount) => { |
|||
return request.post<any, IWebsiteDnsAccount>('/cert/dns_account/sync', params) |
|||
} |
|||
return request.post<any, IWebsiteDnsAccount>("/cert/dns_account/sync", params); |
|||
}, |
|||
}, |
|||
} |
|||
}; |
|||
|
|||
export default websitesServ |
|||
export default websitesServ; |
@ -1,185 +1,248 @@ |
|||
import { atom } from 'jotai' |
|||
import { IApiResult, IPage } from '@/global' |
|||
import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' |
|||
import { message } from 'antd' |
|||
import { t } from 'i18next' |
|||
import websitesServ from '@/service/websites.ts' |
|||
|
|||
|
|||
type SearchParams = IPage & { |
|||
name?: string |
|||
} |
|||
|
|||
import { atom } from "jotai"; |
|||
import { IApiResult, IPage } from "@/global"; |
|||
import { atomWithMutation, atomWithQuery, queryClientAtom } from "jotai-tanstack-query"; |
|||
import { message } from "antd"; |
|||
import { t } from "i18next"; |
|||
import websitesServ from "@/service/websites.ts"; |
|||
|
|||
export type Req_SearchParams = IPage & { |
|||
name?: string; |
|||
}; |
|||
|
|||
export interface Req_AddCname { |
|||
is_sync: boolean; |
|||
dns_list: ICertificate[]; |
|||
} |
|||
|
|||
export interface Req_ApplyTxtCertificate { |
|||
is_sync: boolean; |
|||
acme_type: string; |
|||
key_rsa: string; |
|||
dns_list: ICertificate[]; |
|||
remark: string; |
|||
} |
|||
//=========================证书列表
|
|||
export interface Req_CertList { |
|||
order: string; |
|||
prop: string; |
|||
page: number; |
|||
pageSize: number; |
|||
} |
|||
export interface Resp_CertList { |
|||
page: number; |
|||
pageSize: number; |
|||
total: number; |
|||
rows: any; |
|||
} |
|||
//=========================证书列表
|
|||
export const bandTypes = [ |
|||
{ label: 'Google', value: 'Google' }, |
|||
{ label: 'ZeroSSL', value: 'ZeroSSL' }, |
|||
{ label: 'Let\'s Encrypt', value: 'Let\'s Encrypt' }, |
|||
] |
|||
{ |
|||
label: "LetsEncrypt", |
|||
value: "LetsEncrypt", |
|||
}, |
|||
{ |
|||
label: "ZeroSsl", |
|||
value: "ZeroSsl", |
|||
}, |
|||
{ |
|||
label: "Google", |
|||
value: "Google", |
|||
}, |
|||
]; |
|||
|
|||
export const algorithmTypes = [ |
|||
{ label: 'RSA', value: 'RSA' }, |
|||
{ label: 'ECC', value: 'ECC' }, |
|||
] |
|||
|
|||
{ label: "RSA", value: "RSA" }, |
|||
{ label: "ECC", value: "ECC" }, |
|||
]; |
|||
|
|||
export const StatusText = { |
|||
1: [ '已签发', 'green' ], |
|||
2: [ '申请中', 'default' ], |
|||
3: [ '申请失败', 'red' ] |
|||
} |
|||
|
|||
1: ["已签发", "green"], |
|||
2: ["申请中", "default"], |
|||
3: ["申请失败", "red"], |
|||
}; |
|||
|
|||
export const certIdAtom = atom(0) |
|||
export const certIdAtom = atom(0); |
|||
|
|||
export const certIdsAtom = atom<number[]>([]) |
|||
export const certIdsAtom = atom<number[]>([]); |
|||
|
|||
export const certAtom = atom<ICertificate>(undefined as unknown as ICertificate) |
|||
export const certAtom = atom<ICertificate>(undefined as unknown as ICertificate); |
|||
|
|||
export const certSearchAtom = atom<SearchParams>({ |
|||
export const certSearchAtom = atom<Req_SearchParams>({ |
|||
// key: '',
|
|||
pageSize: 10, |
|||
page: 1, |
|||
} as SearchParams) |
|||
} as Req_SearchParams); |
|||
|
|||
export const certPageAtom = atom<IPage>({ |
|||
pageSize: 10, |
|||
page: 1, |
|||
}) |
|||
|
|||
//certApple
|
|||
export const certAppleCertAtom = atomWithMutation<IApiResult, ICertificate>((get) => { |
|||
}); |
|||
|
|||
//=================================================================================================================================================kelis
|
|||
export const getCertConfigAtom = () => |
|||
atomWithQuery<IApiResult, any>(() => { |
|||
return { |
|||
mutationKey: [ 'appleCert' ], |
|||
mutationFn: async (data) => { |
|||
//data.status = data.status ? '1' : '0'
|
|||
return await websitesServ.cert.certApply(data) |
|||
queryKey: ["getCertConfig"], |
|||
queryFn: async () => { |
|||
return await websitesServ.cert.getCertConfig(); |
|||
}, |
|||
onSuccess: (res) => { |
|||
const isAdd = !!res.data?.id |
|||
message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) |
|||
|
|||
//更新列表
|
|||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|||
// @ts-ignore fix
|
|||
get(queryClientAtom).invalidateQueries({ queryKey: [ 'certs', get(certSearchAtom) ] }) |
|||
select: (res) => { |
|||
return res.data; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
return res |
|||
} |
|||
export const checkDomainAtom = (domains: string, isClear: boolean) => |
|||
atomWithQuery<IApiResult, any>(() => { |
|||
return { |
|||
enabled: domains.length > 0 && domains.includes("."), |
|||
queryKey: ["checkDomain", domains], |
|||
queryFn: async ({ queryKey: [, domains] }) => { |
|||
if ((domains as string).length === 0) { |
|||
return Promise.reject({ |
|||
data: [], |
|||
}); |
|||
} |
|||
}) |
|||
|
|||
return await websitesServ.cert.checkDomain({ |
|||
dns_full_list: domains, |
|||
parse: true, |
|||
is_clear: isClear, |
|||
}); |
|||
}, |
|||
select: (res) => { |
|||
return res.data; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
export const certListAtom = (params: Req_CertList) => |
|||
atomWithQuery<IApiResult, any>(() => { |
|||
return { |
|||
queryKey: ["certList", params], |
|||
queryFn: async ({ queryKey: [, params] }) => { |
|||
return await websitesServ.cert.getCertList(params); |
|||
}, |
|||
select: (res) => { |
|||
return res.data; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
export const certAddCnameAtom = atomWithMutation<IApiResult, ICertificate>(() => { |
|||
return { |
|||
mutationKey: ["certAddCname"], |
|||
mutationFn: async (data) => { |
|||
const dData: Req_AddCname = { |
|||
is_sync: true, |
|||
dns_list: [data], |
|||
}; |
|||
return await websitesServ.cert.addCnameCertificate(dData); |
|||
}, |
|||
onSuccess: (res) => { |
|||
const status = res.data?.item[0]?.status || 0; |
|||
const status_txt = res.data?.item[0]?.status_txt; |
|||
if (status || status === 5) { |
|||
message.error(status_txt); |
|||
} else { |
|||
message.success(status_txt); |
|||
} |
|||
return res; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
export const applyTxtCertificateAtom = atomWithMutation<IApiResult, Req_ApplyTxtCertificate>(() => { |
|||
return { |
|||
mutationKey: ["applyTxtCertificate"], |
|||
mutationFn: async (data: Req_ApplyTxtCertificate) => { |
|||
return await websitesServ.cert.applyTxtCertificate(data); |
|||
}, |
|||
onSuccess: (res) => { |
|||
return res; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
//==================================================================================================================================================kelis
|
|||
|
|||
// //certApple
|
|||
// export const certAppleCertAtom = atomWithMutation<IApiResult, ICertificate>((get) => {
|
|||
// return {
|
|||
// mutationKey: ["appleCert"],
|
|||
// mutationFn: async (data) => {
|
|||
// //data.status = data.status ? '1' : '0'
|
|||
// return await websitesServ.cert.certApply(data);
|
|||
// },
|
|||
// onSuccess: (res) => {
|
|||
// const isAdd = !!res.data?.id;
|
|||
// message.success(t(isAdd ? "message.saveSuccess" : "message.editSuccess", "保存成功"));
|
|||
//
|
|||
// //更新列表
|
|||
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|||
// // @ts-ignore fix
|
|||
// get(queryClientAtom).invalidateQueries({ queryKey: ["certs", get(certSearchAtom)] });
|
|||
//
|
|||
// return res;
|
|||
// },
|
|||
// };
|
|||
// });
|
|||
|
|||
export const certsAtom = atomWithQuery((get) => { |
|||
return { |
|||
queryKey: [ 'certs', get(certSearchAtom) ], |
|||
queryKey: ["certs", get(certSearchAtom)], |
|||
queryFn: async ({ queryKey: [, params] }) => { |
|||
return await websitesServ.cert.list(params as SearchParams) |
|||
return await websitesServ.cert.list(params as Req_SearchParams); |
|||
}, |
|||
select: res => { |
|||
const data = res.data |
|||
data.rows = data.rows?.map(row => { |
|||
select: (res) => { |
|||
const data = res.data; |
|||
data.rows = data.rows?.map((row) => { |
|||
return { |
|||
...row, |
|||
//status: convertToBool(row.status)
|
|||
} |
|||
}) |
|||
return data |
|||
} |
|||
} |
|||
}) |
|||
}; |
|||
}); |
|||
return data; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
//saveOrUpdateAtom
|
|||
export const saveOrUpdateCertAtom = atomWithMutation<IApiResult, ICertificate>((get) => { |
|||
|
|||
return { |
|||
mutationKey: [ 'updateCert' ], |
|||
mutationKey: ["updateCert"], |
|||
mutationFn: async (data) => { |
|||
//data.status = data.status ? '1' : '0'
|
|||
if (data.id) { |
|||
return await websitesServ.cert.update(data) |
|||
return await websitesServ.cert.update(data); |
|||
} |
|||
return await websitesServ.cert.add(data) |
|||
return await websitesServ.cert.add(data); |
|||
}, |
|||
onSuccess: (res) => { |
|||
const isAdd = !!res.data?.id |
|||
message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) |
|||
const isAdd = !!res.data?.id; |
|||
message.success(t(isAdd ? "message.saveSuccess" : "message.editSuccess", "保存成功")); |
|||
|
|||
//更新列表
|
|||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|||
// @ts-ignore fix
|
|||
get(queryClientAtom).invalidateQueries({ queryKey: [ 'certs', get(certSearchAtom) ] }) |
|||
get(queryClientAtom).invalidateQueries({ queryKey: ["certs", get(certSearchAtom)] }); |
|||
|
|||
return res |
|||
} |
|||
} |
|||
}) |
|||
return res; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
export const deleteCertAtom = atomWithMutation((get) => { |
|||
return { |
|||
mutationKey: [ 'deleteCert' ], |
|||
mutationKey: ["deleteCert"], |
|||
mutationFn: async (ids: number[]) => { |
|||
return await websitesServ.cert.batchDelete(ids ?? get(certIdsAtom)) |
|||
return await websitesServ.cert.batchDelete(ids ?? get(certIdsAtom)); |
|||
}, |
|||
onSuccess: (res) => { |
|||
message.success('message.deleteSuccess') |
|||
message.success("message.deleteSuccess"); |
|||
//更新列表
|
|||
get(queryClientAtom).invalidateQueries({ queryKey: [ 'certs', get(certSearchAtom) ] }) |
|||
return res |
|||
} |
|||
} |
|||
}) |
|||
|
|||
//dnsConfig
|
|||
export const dnsConfigAtom = (domains: string) => atomWithQuery<IApiResult, any>(() => { |
|||
|
|||
return { |
|||
enabled: domains.length > 0 && domains.includes('.'), |
|||
queryKey: [ 'dnsConfig', domains ], |
|||
queryFn: async ({ queryKey: [ , domains ] }) => { |
|||
|
|||
if ((domains as string).length === 0) { |
|||
return Promise.reject({ |
|||
data: [] |
|||
}) |
|||
} |
|||
|
|||
return await websitesServ.cert.dnsConfig({ |
|||
dns_full_list: domains, |
|||
parse: (domains as string)?.includes('*') |
|||
}) |
|||
get(queryClientAtom).invalidateQueries({ queryKey: ["certs", get(certSearchAtom)] }); |
|||
return res; |
|||
}, |
|||
select: res => { |
|||
return res.data |
|||
} |
|||
} |
|||
}) |
|||
|
|||
export const dnsVerifyOKAtom = atom<boolean>(false) |
|||
|
|||
//query dnsVerify
|
|||
export const dnsVerifyAtom = (domains: string, block: boolean) => atomWithQuery<IApiResult, any>(() => { |
|||
|
|||
return { |
|||
enabled: !block && domains.length > 0 && domains.includes('.'), |
|||
queryKey: [ 'dnsVerify', domains ], |
|||
queryFn: async ({ queryKey: [ , domains ] }) => { |
|||
|
|||
if ((domains as string).length === 0) { |
|||
return Promise.reject({ |
|||
data: [] |
|||
}) |
|||
} |
|||
|
|||
return await websitesServ.cert.dnsVerify({ |
|||
dns_list: domains, |
|||
}) |
|||
}, |
|||
select: res => { |
|||
return res.data?.dns_list |
|||
} |
|||
} |
|||
}) |
|||
|
|||
|
|||
}; |
|||
}); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue