cs
3 months ago
15 changed files with 1031 additions and 621 deletions
-
71package.json
-
14src/App.css
-
24src/components/action/Action.tsx
-
100src/components/r-form/index.tsx
-
26src/components/r-form/utils/index.tsx
-
89src/i18n.ts
-
6src/locales/lang/zh-CN.ts
-
179src/pages/login/index.tsx
-
60src/pages/r-form/index.tsx
-
650src/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,97 +1,102 @@ |
|||
import SelectLang from '@/components/select-lang' |
|||
import { createFileRoute } from '@tanstack/react-router' |
|||
import { Button, Form, Input, Space } from 'antd' |
|||
import { useAtom, useAtomValue } from 'jotai' |
|||
import { useTranslation } from '@/i18n.ts' |
|||
import { loginAtom, loginFormAtom } from '@/store/system/user.ts' |
|||
import { memo, useLayoutEffect } from 'react' |
|||
import { useStyles } from './style.ts' |
|||
import SelectLang from "@/components/select-lang"; |
|||
import { createFileRoute } from "@tanstack/react-router"; |
|||
import { Button, Form, Input, Radio, Space } from "antd"; |
|||
import { useAtom, useAtomValue } from "jotai"; |
|||
import { useTranslation } from "@/i18n.ts"; |
|||
import { loginAtom, loginFormAtom } from "@/store/system/user.ts"; |
|||
import React, {memo, useLayoutEffect, useState} from "react"; |
|||
import { useStyles } from "./style.ts"; |
|||
|
|||
const Login = memo(() => { |
|||
const { styles } = useStyles(); |
|||
const { t } = useTranslation(); |
|||
const [values, setValues] = useAtom(loginFormAtom); |
|||
const { isPending, mutate } = useAtomValue(loginAtom); |
|||
const [form] = Form.useForm(); |
|||
|
|||
const { styles } = useStyles() |
|||
const { t } = useTranslation() |
|||
const [ values, setValues ] = useAtom(loginFormAtom) |
|||
const { isPending, mutate } = useAtomValue(loginAtom) |
|||
const [ form ] = Form.useForm() |
|||
const handleSubmit = () => { |
|||
form.validateFields().then(() => { |
|||
mutate(values); |
|||
}); |
|||
}; |
|||
|
|||
const handleSubmit = () => { |
|||
form.validateFields().then(() => { |
|||
mutate(values) |
|||
}) |
|||
} |
|||
const [loginMod, setLoginMod] = useState([ |
|||
{ value: "single", info: "帐号密码登录" }, |
|||
{ value: "multiple-email", info: "邮箱登录" }, |
|||
{ value: "multiple-plane", info: "飞机登录" }, |
|||
]); |
|||
|
|||
const [selectedMode, setSelectedMode] = useState(loginMod[0].value); |
|||
|
|||
useLayoutEffect(() => { |
|||
const handleModeChange = (e: any) => { |
|||
setSelectedMode(e.target.value); |
|||
}; |
|||
|
|||
document.body.className = 'login' |
|||
return () => { |
|||
document.body.className = document.body.className.replace('login', '') |
|||
} |
|||
useLayoutEffect(() => { |
|||
document.body.className = "login"; |
|||
return () => { |
|||
document.body.className = document.body.className.replace("login", ""); |
|||
}; |
|||
}, []); |
|||
|
|||
}, []) |
|||
return ( |
|||
<div className={styles.container}> |
|||
<div className={styles.language}> |
|||
<SelectLang /> |
|||
</div> |
|||
<div className={styles.loginBlock}> |
|||
<div className={styles.innerBlock}> |
|||
<Radio.Group style={{ marginBottom: 8 }} value={selectedMode} onChange={handleModeChange}> |
|||
{loginMod.map((mod) => ( |
|||
<Radio.Button key={mod.value} value={mod.value}> |
|||
{mod.info} |
|||
</Radio.Button> |
|||
))} |
|||
</Radio.Group> |
|||
<Form |
|||
form={form} |
|||
disabled={isPending} |
|||
initialValues={values} |
|||
onValuesChange={(_, allValues) => { |
|||
setValues(allValues); |
|||
}} |
|||
size="large" |
|||
> |
|||
<Form.Item name={"username"} rules={[{ required: true, message: t("login.usernameMsg") }]}> |
|||
<Input maxLength={20} placeholder={t("login.username")} /> |
|||
</Form.Item> |
|||
<Form.Item name={"password"} rules={[{ required: true, message: t("login.passwordMsg") }]}> |
|||
<Input.Password placeholder={t("login.password")} /> |
|||
</Form.Item> |
|||
<Form.Item noStyle> |
|||
<Space direction="horizontal"> |
|||
<Form.Item name={"code"} rules={[{ required: true, message: t("login.codeMsg") }]}> |
|||
<Input placeholder={t("login.code")} /> |
|||
{/*<img src="https://img.alicdn.com/tfs/TB1KtN6mKH2gK0jSZJnXXaT1FXa-1014-200.png" alt="验证码" />*/} |
|||
</Form.Item> |
|||
</Space> |
|||
</Form.Item> |
|||
<Form.Item style={{ marginBottom: 10 }}> |
|||
<Button |
|||
htmlType={"submit"} |
|||
type="primary" |
|||
onClick={handleSubmit} |
|||
className={"submitBtn"} |
|||
loading={isPending} |
|||
disabled={isPending} |
|||
> |
|||
{t("login.submit")} |
|||
</Button> |
|||
</Form.Item> |
|||
</Form> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
); |
|||
}); |
|||
|
|||
return ( |
|||
<div className={styles.container}> |
|||
<div className={styles.language}> |
|||
<SelectLang/> |
|||
</div> |
|||
<div className={styles.loginBlock}> |
|||
<div className={styles.innerBlock}> |
|||
export const Route = createFileRoute("/login")({ |
|||
component: Login, |
|||
}); |
|||
|
|||
<div className={styles.desc}> |
|||
<span className={styles.active}> |
|||
{t('login.title')} |
|||
</span> |
|||
|
|||
</div> |
|||
|
|||
<Form form={form} |
|||
disabled={isPending} |
|||
initialValues={values} |
|||
onValuesChange={(_, allValues) => { |
|||
setValues(allValues) |
|||
}} |
|||
size="large"> |
|||
<Form.Item name={'username'} |
|||
rules={[ { required: true, message: t('login.usernameMsg') } ]}> |
|||
<Input maxLength={20} placeholder={t('login.username')}/> |
|||
</Form.Item> |
|||
<Form.Item name={'password'} |
|||
rules={[ { required: true, message: t('login.passwordMsg') } ]}> |
|||
<Input.Password placeholder={t('login.password')}/> |
|||
</Form.Item> |
|||
<Form.Item noStyle> |
|||
<Space direction="horizontal"> |
|||
<Form.Item name={'code'} |
|||
rules={[ { required: true, message: t('login.codeMsg') } ]}> |
|||
<Input placeholder={t('login.code')}/> |
|||
{/*<img src="https://img.alicdn.com/tfs/TB1KtN6mKH2gK0jSZJnXXaT1FXa-1014-200.png" alt="验证码" />*/} |
|||
</Form.Item> |
|||
</Space> |
|||
</Form.Item> |
|||
<Form.Item style={{ marginBottom: 10 }}> |
|||
<Button |
|||
htmlType={'submit'} |
|||
type="primary" |
|||
onClick={handleSubmit} |
|||
className={'submitBtn'} |
|||
loading={isPending} |
|||
disabled={isPending} |
|||
> |
|||
{t('login.submit')} |
|||
</Button> |
|||
</Form.Item> |
|||
</Form> |
|||
</div> |
|||
</div> |
|||
|
|||
</div> |
|||
) |
|||
}) |
|||
|
|||
export const Route = createFileRoute('/login')({ |
|||
component: Login |
|||
}) |
|||
|
|||
export default Login |
|||
export default Login; |
@ -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 { |
|||
queryKey: ["getCertConfig"], |
|||
queryFn: async () => { |
|||
return await websitesServ.cert.getCertConfig(); |
|||
}, |
|||
select: (res) => { |
|||
return res.data; |
|||
}, |
|||
}; |
|||
}); |
|||
|
|||
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: [ '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('*') |
|||
}) |
|||
}, |
|||
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, |
|||
}) |
|||
get(queryClientAtom).invalidateQueries({ queryKey: ["certs", get(certSearchAtom)] }); |
|||
return res; |
|||
}, |
|||
select: res => { |
|||
return res.data?.dns_list |
|||
} |
|||
} |
|||
}) |
|||
|
|||
|
|||
}; |
|||
}); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue