lk
3 months ago
7 changed files with 414 additions and 274 deletions
-
70package.json
-
14src/App.css
-
2src/layout/RootLayout.tsx
-
259src/pages/websites/cert/apply.tsx
-
33src/service/websites.ts
-
295src/store/websites/cert.ts
-
1vite.config.ts
@ -1,185 +1,218 @@ |
|||
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 type Req_AddCname = { |
|||
is_sync: boolean; |
|||
dns_list: ICertificate[]; |
|||
}; |
|||
|
|||
export type Req_ApplyTxtCertificate = { |
|||
is_sync: boolean; |
|||
acme_type: string; |
|||
key_rsa: string; |
|||
dns_list: ICertificate[]; |
|||
}; |
|||
|
|||
export const bandTypes = [ |
|||
{ label: 'Google', value: 'Google' }, |
|||
{ label: 'ZeroSSL', value: 'ZeroSSL' }, |
|||
{ label: 'Let\'s Encrypt', value: 'Let\'s Encrypt' }, |
|||
] |
|||
{ label: "Google", value: "Google" }, |
|||
{ label: "ZeroSSL", value: "ZeroSSL" }, |
|||
{ label: "Let's Encrypt", value: "Let's Encrypt" }, |
|||
]; |
|||
|
|||
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, |
|||
}) |
|||
}); |
|||
|
|||
//=================================================================================================================================================kelis
|
|||
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: [], |
|||
}); |
|||
} |
|||
|
|||
//certApple
|
|||
export const certAppleCertAtom = atomWithMutation<IApiResult, ICertificate>((get) => { |
|||
return await websitesServ.cert.checkDomain({ |
|||
dns_full_list: domains, |
|||
parse: true, |
|||
is_clear: isClear, |
|||
}); |
|||
}, |
|||
select: (res) => { |
|||
return res.data; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
export const certListAtom = atomWithQuery((get) => { |
|||
return { |
|||
queryKey: ["certList", get(certSearchAtom)], |
|||
queryFn: async ({ queryKey: [, params] }) => { |
|||
return await websitesServ.cert.list(params as Req_SearchParams); |
|||
}, |
|||
select: (res) => { |
|||
const data = res.data; |
|||
data.rows = data.rows?.map((row) => { |
|||
return { |
|||
...row, |
|||
//status: convertToBool(row.status)
|
|||
}; |
|||
}); |
|||
return data; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
export const certAddCnameAtom = atomWithMutation<IApiResult, ICertificate>(() => { |
|||
return { |
|||
mutationKey: [ 'appleCert' ], |
|||
mutationKey: ["certAddCname"], |
|||
mutationFn: async (data) => { |
|||
//data.status = data.status ? '1' : '0'
|
|||
return await websitesServ.cert.certApply(data) |
|||
const dData: Req_AddCname = { |
|||
is_sync: true, |
|||
dns_list: [data], |
|||
}; |
|||
return await websitesServ.cert.addCnameCertificate(dData); |
|||
}, |
|||
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 |
|||
} |
|||
} |
|||
}) |
|||
|
|||
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) ], |
|||
queryFn: async ({ queryKey: [ , params ] }) => { |
|||
return await websitesServ.cert.list(params as SearchParams) |
|||
queryKey: ["certs", get(certSearchAtom)], |
|||
queryFn: async ({ queryKey: [, params] }) => { |
|||
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