2 Commits

  1. 70
      package.json
  2. 14
      src/App.css
  3. 2
      src/layout/RootLayout.tsx
  4. 273
      src/pages/websites/cert/apply.tsx
  5. 33
      src/service/websites.ts
  6. 295
      src/store/websites/cert.ts
  7. 1
      vite.config.ts

70
package.json

@ -12,58 +12,58 @@
},
"dependencies": {
"@ant-design/cssinjs": "^1.21.1",
"@ant-design/icons": "^5.3.6",
"@ant-design/pro-components": "^2.7.0",
"@ant-design/icons": "^5.4.0",
"@ant-design/pro-components": "^2.7.15",
"@ant-design/pro-layout": "^7.19.12",
"@ant-design/pro-provider": "^2.14.9",
"@formily/antd-v5": "^1.2.0",
"@formily/core": "^2.3.1",
"@formily/react": "^2.3.1",
"@formily/antd-v5": "^1.2.3",
"@formily/core": "^2.3.2",
"@formily/react": "^2.3.2",
"@icon-park/react": "^1.4.2",
"@melloware/react-logviewer": "^5.2.0",
"@tanstack/query-core": "^5.52.0",
"@tanstack/react-query": "^5.52.1",
"@tanstack/react-router": "^1.50.0",
"antd": "^5.16.1",
"@tanstack/query-core": "^5.54.1",
"@tanstack/react-query": "^5.54.1",
"@tanstack/react-router": "^1.53.1",
"antd": "^5.20.5",
"antd-style": "^3.6.2",
"axios": "^1.6.8",
"bunshi": "^2.1.4",
"dayjs": "^1.11.10",
"axios": "^1.7.7",
"bunshi": "^2.1.5",
"dayjs": "^1.11.13",
"fast-copy": "^3.0.2",
"fast-deep-equal": "^3.1.3",
"i18next": "^23.11.2",
"i18next": "^23.14.0",
"i18next-browser-languagedetector": "^7.2.1",
"jotai": "^2.8.0",
"jotai": "^2.9.3",
"jotai-devtools": "^0.9.1",
"jotai-scope": "^0.5.1",
"jotai-tanstack-query": "^0.8.5",
"jotai-scope": "^0.5.2",
"jotai-tanstack-query": "^0.8.7",
"lodash": "^4.17.21",
"re-resizable": "^6.9.11",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^14.1.0",
"re-resizable": "^6.9.17",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^14.1.3",
"react-if": "^4.1.5",
"react-layout-kit": "^1.9.0",
"react-rnd": "^10.4.2-test2",
"react-use": "^17.5.0",
"throttle-debounce": "^5.0.0",
"react-rnd": "^10.4.12",
"react-use": "^17.5.1",
"throttle-debounce": "^5.0.2",
"use-merge-value": "^1.2.0",
"wonka": "^6.3.4"
},
"devDependencies": {
"@tanstack/router-devtools": "^1.26.20",
"@tanstack/router-vite-plugin": "^1.26.16",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"@tanstack/router-devtools": "^1.53.1",
"@tanstack/router-vite-plugin": "^1.54.0",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.11",
"mockjs": "^1.1.0",
"typescript": "^5.2.2",
"vite": "^5.2.0",
"vite-plugin-mock": "^3.0.1"
"typescript": "^5.5.4",
"vite": "^5.4.3",
"vite-plugin-mock": "^3.0.2"
}
}

14
src/App.css

@ -7,12 +7,10 @@
display: inherit;
line-height: 28px;
}
}
.top-breadcrumb {
.item {
display: flex;
align-items: center;
justify-content: center;
@ -28,7 +26,6 @@
cursor: pointer;
&:hover {
color: #1c7ed6;
}
}
@ -50,16 +47,19 @@
color: green;
}
.color-green1{
color: rgb(18 185 128 / 1 );
.color-green1 {
color: rgb(18 185 128 / 1);
}
.color-blue {
color: #1c7ed6;
}
.color-red {
color: #F56C6C;
color: #f56c6c;
}
.color-yellow {
color: rgb(250 145 0)
color: rgb(250 145 0);
}
.text-bold {

2
src/layout/RootLayout.tsx

@ -127,7 +127,7 @@ export default () => {
color: '#00000012',
size: 17,
},
zIndex: 1009,
zindex: 1009,
} as any
} style={{ width: '100vw', height: '100vh' }}>
<ProLayout

273
src/pages/websites/cert/apply.tsx

@ -2,35 +2,44 @@ import { t } from "@/i18n.ts";
import { useAtom, useAtomValue, useSetAtom } from "jotai";
import {
algorithmTypes,
dnsConfigAtom,
dnsVerifyAtom,
dnsVerifyOKAtom,
saveOrUpdateCertAtom,
certAddCnameAtom,
checkDomainAtom,
applyTxtCertificateAtom,
Req_ApplyTxtCertificate,
} from "@/store/websites/cert.ts";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {Button, Flex, Form, Input, message, Progress, Radio, Select, Space, Steps, Table, Tooltip} from "antd";
import { Button, Flex, Form, Input, message, Radio, Select, Space, Steps, Table, Tooltip } from "antd";
import google from "@/pages/websites/cert/assets/google.png";
import zerossl from "@/pages/websites/cert/assets/zerossl.png";
import lets_encrypt from "@/pages/websites/cert/assets/lets_encrypt.png";
import { useStyle } from "./style";
import ListPageLayout from "@/layout/ListPageLayout.tsx";
import { ColumnsType } from "antd/es/table";
import { atomWithStorage } from "jotai/utils";
import { atomWithStorage, RESET } from "jotai/utils";
import Copy from "@/components/copy";
import { CopyOutlined, InfoCircleOutlined, LoadingOutlined } from "@ant-design/icons";
import {
ClusterOutlined,
CopyOutlined,
InfoCircleOutlined,
LoadingOutlined,
LoginOutlined,
TagOutlined,
} from "@ant-design/icons";
import { useQueryClient } from "@tanstack/react-query";
const i18nPrefix = "cert.apply";
const BrandSelect = (props: any) => {
const BrandSelect = (props: { value: string; applyTxtCertificateData; setApplyTxtCertificateData }) => {
const { styles, cx } = useStyle();
const [value, setValue] = useState(() => props.value);
useEffect(() => {
setValue(props.value);
onChange(props.value);
}, [props.value]);
const onChange = useCallback((val: string) => {
props.onChange?.(val);
props.setApplyTxtCertificateData((prevState) => ({
...prevState,
acme_type: val,
}));
}, []);
return (
@ -40,7 +49,7 @@ const BrandSelect = (props: any) => {
vertical={true}
onClick={() => onChange("Google")}
className={cx("band-normal", {
"band-active": value === "Google" || !props.value,
"band-active": props.applyTxtCertificateData.acme_type === "Google" || !props.value,
})}
>
<img src={google} style={{ height: "2rem" }} />
@ -50,7 +59,7 @@ const BrandSelect = (props: any) => {
vertical={true}
onClick={() => onChange("ZeroSSL")}
className={cx("band-normal", {
"band-active": value === "ZeroSSL",
"band-active": props.applyTxtCertificateData.acme_type === "ZeroSSL",
})}
>
<img src={zerossl} style={{ height: "2rem" }} />
@ -60,7 +69,7 @@ const BrandSelect = (props: any) => {
vertical={true}
onClick={() => onChange("Let's Encrypt")}
className={cx("band-normal", {
"band-active": value === "Let's Encrypt",
"band-active": props.applyTxtCertificateData.acme_type === "Let's Encrypt",
})}
>
<img src={lets_encrypt} style={{ height: "2rem" }} />
@ -71,27 +80,40 @@ const BrandSelect = (props: any) => {
);
};
const StatusTable = (props: { value: string }) => {
const [data, setData] = useState<any>(null); // 临时状态来存储模拟数据
const { isFetching } = useAtomValue(useMemo(() => dnsConfigAtom(props.value), [props.value]));
const {
data: dnsVerifyStatus,
isFetching: isVerifyFetching,
refetch,
} = useAtomValue(useMemo(() => dnsVerifyAtom(props.value, isFetching), [props.value, isFetching]));
const StatusTable = (props: { value: string; setCurrentStep; setApplyTxtCertificateData }) => {
// const [data, setData] = useState<any>(null); // 临时状态来存储模拟数据
const [forceUpdate, setForceUpdate] = useState(0);
const { data, isFetching: isVerifyFetching } = useAtomValue(
useMemo(() => checkDomainAtom(props.value, forceUpdate === 0), [props.value, forceUpdate]),
);
const refetch = () => {
setForceUpdate((prev) => prev + 1);
};
const setDnsVerifyOK = useSetAtom(dnsVerifyOKAtom);
const { mutate: addCnameFun, isPending: addCnamePending, isSuccess } = useAtomValue(certAddCnameAtom);
const handleAddCname = async (info: any) => {
addCnameFun(info);
};
// const {
// data: dnsVerifyStatus,
// isFetching: isVerifyFetching,
// refetch,
// } = useAtomValue(useMemo(() => dnsVerifyAtom(props.value, isFetching), [props.value, isFetching]));
//
// const setDnsVerifyOK = useSetAtom(dnsVerifyOKAtom);
const timerRef = useRef<number>();
const handleCopy = (str:string) => {
navigator.clipboard.writeText(str).then(() => {
message.info('复制成功!');
}).catch(err => {
const handleCopy = (str: string) => {
navigator.clipboard
.writeText(str)
.then(() => {
message.info("复制成功!");
})
.catch((err) => {
message.info(err);
});
};
};
const columns = useMemo<ColumnsType>(() => {
return [
@ -105,27 +127,61 @@ const StatusTable = (props: { value: string }) => {
</>
),
dataIndex: "status",
width: 100,
width: 150,
render: (_, record) => {
if (isFetching) {
return <span>{t(`${i18nPrefix}.actions.dnsVerifyStatus.0`, "等待")}</span>;
}
if (isVerifyFetching) {
//0,等待 1,域名OK,2,域名分析错误,3:检测中 4:检测成功,匹配失败 5:检测失败,9:检测成功
return (
<span>
<LoadingOutlined style={{ paddingInlineEnd: 5 }} />
{t(`${i18nPrefix}.actions.dnsVerifyStatus.3`, "检测中")}
</span>
);
}
const dns = record.dns_name;
const info = (dnsVerifyStatus as any)?.find((item) => item.dns_name === dns) as any;
const info = (data as any)?.dns_list?.find((item) => item.dns_name === dns) as any;
if (info) {
return <span>{t(`${i18nPrefix}.actions.dnsVerifyStatus.${info.status}`, `${info?.status_txt}`)}</span>;
if (info.is_self === true) {
return (
// <Button
// size="small"
// type="text"
// className={"color-blue"}
// // icon={<ClusterOutlined />}
// style={{ width: "100%", textAlign: "left" }}
// // onClick={() => handleCopy(text)}
// >
// 自动注册
// </Button>
<span
style={{
width: "100%",
textAlign: "right",
color: "#1c7ed6",
cursor: "pointer",
}}
onClick={() => {
handleAddCname(info);
}}
>
<TagOutlined style={{ paddingInlineEnd: 5 }} />
</span>
);
} else {
if (isVerifyFetching) {
//0,等待 1,域名OK,2,域名分析错误,3:检测中 4:检测成功,匹配失败 5:检测失败,9:检测成功
return (
<span style={{ width: "100%", textAlign: "right" }}>
<LoadingOutlined style={{ paddingInlineEnd: 5 }} />
{t(`${i18nPrefix}.actions.dnsVerifyStatus.3`, "检测中")}
</span>
);
}
//0,等待 1,域名OK,2,域名分析错误,3:检测中 4:检测成功,匹配失败 5:检测失败,9:检测成功
return (
<span style={{ width: "100%", textAlign: "left" }}>
{t(`${i18nPrefix}.actions.dnsVerifyStatus.${info.status}`, `${info?.status_txt}`)}
</span>
);
}
}
return <span>{t(`${i18nPrefix}.actions.dnsVerifyStatus.0`, "等待")}</span>;
return (
<span style={{ width: "100%", textAlign: "left" }}>
{t(`${i18nPrefix}.actions.dnsVerifyStatus.0`, "等待")}
</span>
);
},
},
{
@ -147,7 +203,14 @@ const StatusTable = (props: { value: string }) => {
width: 200,
render(text) {
return (
<Button size="small" type="text" className={"color-green1"} icon={<CopyOutlined />} iconPosition={"end"} onClick={() => handleCopy(text)}>
<Button
size="small"
type="text"
className={"color-green1"}
icon={<CopyOutlined />}
iconPosition={"end"}
onClick={() => handleCopy(text)}
>
{text}
</Button>
);
@ -178,42 +241,31 @@ const StatusTable = (props: { value: string }) => {
width: 200,
render: (text) => {
return (
<Button size="small" type="text" className={"color-green1"} icon={<CopyOutlined />} iconPosition={"end"} onClick={() => handleCopy(text)}>
<Button
size="small"
type="text"
className={"color-green1"}
icon={<CopyOutlined />}
iconPosition={"end"}
onClick={() => handleCopy(text)}
>
{t(`actions.clickCopy`)}
</Button>
);
},
},
] as ColumnsType;
}, [isFetching, isVerifyFetching, dnsVerifyStatus]);
}, [isVerifyFetching, data]);
useEffect(() => {
// 模拟数据
const mockData = {
dns_list: [
{
status: 1,
name_servers: "Example NS",
dns_name: "example.com",
host: "example",
type: "A",
record_value: "192.168.1.1",
},
{
status: 3,
name_servers: "Another NS",
dns_name: "another.com",
host: "another",
type: "CNAME",
record_value: "cname.another.com",
},
],
};
setData(mockData);
if ((dnsVerifyStatus as any)?.every((item) => item.status === 9)) {
setDnsVerifyOK(true);
if ((data as any)?.check_ok === true) {
props.setCurrentStep(2);
props.setApplyTxtCertificateData((prevState) => ({
...prevState,
dns_list: (data as any).dns_list,
}));
return;
}
@ -222,8 +274,15 @@ const StatusTable = (props: { value: string }) => {
return;
}
// dnsVerifyStatus 如果所有status 为 9 则说明域名验证通过
if ((dnsVerifyStatus as any)?.every((item) => item.status === 9)) {
setDnsVerifyOK(true);
// if ((data as any)?.dns_list?.every((item) => item.status === 9)) {
// props.setCurrentStep(2);
// window.clearInterval(timerRef.current);
if ((data as any)?.check_ok === true) {
props.setCurrentStep(2);
props.setApplyTxtCertificateData((prevState) => ({
...prevState,
dns_list: (data as any).dns_list,
}));
window.clearInterval(timerRef.current);
} else {
refetch();
@ -233,7 +292,7 @@ const StatusTable = (props: { value: string }) => {
return () => {
window.clearInterval(timerRef.current);
};
}, [dnsVerifyStatus, isVerifyFetching]);
}, [data, isVerifyFetching]);
return (
<>
@ -248,7 +307,7 @@ const StatusTable = (props: { value: string }) => {
<Table
columns={columns}
dataSource={(data as any)?.dns_list}
loading={isFetching}
loading={isVerifyFetching}
size={"small"}
pagination={false}
bordered={true}
@ -276,6 +335,9 @@ const DomainsInput = (props: { setDomains; currentDomainMod; setCurrentDomainMod
<Input
disabled={props.currentStep !== 0}
placeholder="请输入域名,支持泛解析域名。如果为多个域名注册到一个证书,域名之间用<逗号(英文输入)>分割。如:a.com,*.b.com"
onBlur={(e) => {
props.setDomains(e.target.value);
}}
/>
)}
{props.currentDomainMod === "multiple" && (
@ -300,11 +362,30 @@ const domainsAtom = atomWithStorage<string>("domains", "");
const Apply = () => {
const { styles } = useStyle();
const [form] = Form.useForm();
const { mutate: saveOrUpdate, isPending: isSubmitting } = useAtomValue(saveOrUpdateCertAtom);
const {
mutate: applyTxtCertificateFun,
isPending: applyTxtCertificatePending,
isSuccess: applyTxtCertificateIsSuccess,
} = useAtomValue(applyTxtCertificateAtom);
const [domains, setDomains] = useAtom(domainsAtom);
const [currentStep, setCurrentStep] = useState(0);
const [currentDomainMod, setCurrentDomainMod] = useState<"single" | "multiple">("single");
const dnsVerifyOK = useAtomValue(dnsVerifyOKAtom);
const [applyTxtCertificateData, setApplyTxtCertificateData] = useState<Req_ApplyTxtCertificate>({
is_sync: true,
acme_type: "",
key_rsa: "",
dns_list: [],
});
const handleAlgorithmChange = (value: string) => {
setApplyTxtCertificateData((prevState) => ({
...prevState,
key_rsa: value,
}));
};
const applyTxtCertificateClick = () => {
applyTxtCertificateFun(applyTxtCertificateData);
};
useEffect(() => {
if (domains) {
@ -313,7 +394,6 @@ const Apply = () => {
});
}
}, [domains]);
return (
<ListPageLayout
childrenClassName={styles.applyContent}
@ -350,9 +430,9 @@ const Apply = () => {
}
}}
onFinish={async (values) => {
if (dnsVerifyOK) {
saveOrUpdate(values);
}
// if (dnsVerifyOK) {
// saveOrUpdate(values);
// }
}}
>
{/* <Form.Item*/}
@ -385,7 +465,11 @@ const Apply = () => {
label={t(`${i18nPrefix}.columns.type`, "域名验证")}
rules={[{ required: true, message: t(`${i18nPrefix}.columns.type`, "域名验证没有通过") }]}
>
<StatusTable value={domains} />
<StatusTable
value={domains}
setCurrentStep={setCurrentStep}
setApplyTxtCertificateData={setApplyTxtCertificateData}
/>
</Form.Item>
<Form.Item
@ -398,7 +482,11 @@ const Apply = () => {
},
]}
>
<BrandSelect value="Google" />
<BrandSelect
value="Google"
applyTxtCertificateData={applyTxtCertificateData}
setApplyTxtCertificateData={setApplyTxtCertificateData}
/>
</Form.Item>
<Form.Item
name={"algorithm"}
@ -410,7 +498,7 @@ const Apply = () => {
},
]}
>
<Select style={{ width: 120 }} options={algorithmTypes} />
<Select style={{ width: 120 }} options={algorithmTypes} onChange={handleAlgorithmChange} />
</Form.Item>
<Form.Item name={"remark"} label={t(`${i18nPrefix}.columns.remark`, "备注 ")}>
<Input style={{ width: 400 }} />
@ -420,19 +508,24 @@ const Apply = () => {
<Form.Item label={" "} colon={false}>
<Space>
{currentStep !== 0 && (
<Button type="primary" onClick={() => setCurrentStep(currentStep - 1)} htmlType={"submit"}>
<Button type="primary" onClick={() => setCurrentStep(0)} htmlType={"submit"}>
{t(`${i18nPrefix}.apply.prev`, "上一步")}
</Button>
)}
{currentStep === 0 && (
<Button type="primary" onClick={() => setCurrentStep(currentStep + 1)} htmlType={"submit"}>
<Button type="primary" onClick={() => setCurrentStep(currentStep + 1)}>
{t(`${i18nPrefix}.apply.next`, "下一步")}
</Button>
)}
{currentStep !== 0 && (
<Button type="primary" htmlType={"submit"} disabled={currentStep === 1}>
<Button
type="primary"
htmlType={"submit"}
disabled={currentStep === 1}
onClick={applyTxtCertificateClick}
>
{t(`${i18nPrefix}.apply.submit`, "提交申请")}
</Button>
)}

33
src/service/websites.ts

@ -7,19 +7,32 @@ 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);
},
// 证书续签
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);
},
//dns_verify
dnsVerify: async (params: any) => {
return request.post<any, any>('/website/cert/dns_verify', params)
// 下载证书
downloadCertificate: async (params: any) => {
return request.post<any, any>("/website/cert/download_certificate", params);
},
//cert-apply
certApply: async (params: any) => {
return request.post<any, any>('/website/cert/dns_verify', 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: {

295
src/store/websites/cert.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('*')
})
},
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
}
}
})
};
});

1
vite.config.ts

@ -13,6 +13,7 @@ const proxyMap = {
'/api/v1/movie': 'http://47.113.117.106:10000',
//'/api/v1/certold': 'http://192.168.31.41:8000',
'/api/v1/cert': 'http://127.0.0.1:8000',
//'/api/v1/cert': 'http://192.168.31.41:8000',
} as Record<any, string>
const proxyConfig = Object.keys(proxyMap).reduce((acc, key) => {

Loading…
Cancel
Save