diff --git a/src/pages/websites/ssl/dns/DNSList.tsx b/src/pages/websites/ssl/dns/DNSList.tsx index 6ccde0b..2bb95d3 100644 --- a/src/pages/websites/ssl/dns/DNSList.tsx +++ b/src/pages/websites/ssl/dns/DNSList.tsx @@ -10,7 +10,7 @@ import { dnsPageAtom, DNSTypeEnum, DNSTypes, - saveOrUpdateDNSAtom + saveOrUpdateDNSAtom, syncDNSAtom } from '@/store/websites/dns.ts' import { WebSite } from '@/types' @@ -74,20 +74,20 @@ const getKeyColumn = (type: string, t) => { } case DNSTypeEnum.CloudFlare: { columns.push(...[ - { - title: t('website.ssl.dns.columns.email', 'Email'), - dataIndex: 'email', - formItemProps: { - rules: [ { required: true, message: t('message.required') } ] - } - }, { - title: t('website.ssl.dns.columns.apiKey', 'API ToKen'), - dataIndex: 'apiKey', - formItemProps: { - rules: [ { required: true, message: t('message.required') } ] - } - }, - ] + { + title: t('website.ssl.dns.columns.email', 'Email'), + dataIndex: 'email', + formItemProps: { + rules: [ { required: true, message: t('message.required') } ] + } + }, { + title: t('website.ssl.dns.columns.apiKey', 'API ToKen'), + dataIndex: 'apiKey', + formItemProps: { + rules: [ { required: true, message: t('message.required') } ] + } + }, + ] ) break } @@ -95,12 +95,12 @@ const getKeyColumn = (type: string, t) => { case DNSTypeEnum.NameCheap: case DNSTypeEnum.NameSilo: columns.push({ - title: t('website.ssl.dns.columns.apiKey', 'API Key'), - dataIndex: 'apiKey', - formItemProps: { - rules: [ { required: true, message: t('message.required') } ] - } - }, + title: t('website.ssl.dns.columns.apiKey', 'API Key'), + dataIndex: 'apiKey', + formItemProps: { + rules: [ { required: true, message: t('message.required') } ] + } + }, ) if (type === DNSTypeEnum.NameCheap) { columns.push({ @@ -122,20 +122,20 @@ const getKeyColumn = (type: string, t) => { break case DNSTypeEnum.NameCom: { columns.push( - { - title: t('website.ssl.dns.columns.apiUser', 'UserName'), - dataIndex: 'apiUser', - formItemProps: { - rules: [ { required: true, message: t('message.required') } ] - } - }, - { - title: t('website.ssl.dns.columns.token', 'Token'), - dataIndex: 'token', - formItemProps: { - rules: [ { required: true, message: t('message.required') } ] - } - } + { + title: t('website.ssl.dns.columns.apiUser', 'UserName'), + dataIndex: 'apiUser', + formItemProps: { + rules: [ { required: true, message: t('message.required') } ] + } + }, + { + title: t('website.ssl.dns.columns.token', 'Token'), + dataIndex: 'token', + formItemProps: { + rules: [ { required: true, message: t('message.required') } ] + } + } ) break } @@ -154,6 +154,7 @@ const DNSList = () => { const { data, isLoading, isFetching, refetch } = useAtomValue(dnsListAtom) const { mutate: saveOrUpdate, isPending: isSubmitting, isSuccess } = useAtomValue(saveOrUpdateDNSAtom) const { mutate: deleteDNS, isPending: isDeleting } = useAtomValue(deleteDNSAtom) + const { mutate: asyncDNS, isPending: isAsyncing } = useAtomValue(syncDNSAtom) const [ open, setOpen ] = useState(false) const columns = useMemo[]>(() => { @@ -206,17 +207,24 @@ const DNSList = () => { return [ { form.setFieldsValue(record) setOpen(true) }}>{t('actions.edit')}, + { + asyncDNS(record) + }}>{t('actions.sync', '同步')}, { - deleteDNS(record.id) - }} - title={t('message.deleteConfirm')}> + key={'del_confirm'} + disabled={isDeleting || record.status === 2} + onConfirm={() => { + deleteDNS(record.id) + }} + title={t('message.deleteConfirm')}> {t('actions.delete', '删除')} @@ -234,75 +242,76 @@ const DNSList = () => { }, [ isSuccess ]) return ( - <> - - cardProps={{ - bodyStyle: { - padding: 0, - } - }} - rowKey="id" - headerTitle={ - - } - loading={isLoading || isFetching} - dataSource={data?.rows ?? []} - columns={columns} - search={false} - options={{ - reload: () => { - refetch() - }, - }} - pagination={{ - total: data?.total, - pageSize: page.pageSize, - current: page.page, - onChange: (current, pageSize) => { - setPage(prev => { - return { - ...prev, - page: current, - pageSize: pageSize, - } - }) - }, + <> + + cardProps={{ + bodyStyle: { + padding: 0, + } + }} + rowKey="id" + headerTitle={ + + } + loading={isLoading || isFetching} + dataSource={data?.rows ?? []} + columns={columns} + search={false} + options={{ + reload: () => { + refetch() + }, + }} + pagination={{ + total: data?.total, + pageSize: page.pageSize, + current: page.page, + onChange: (current, pageSize) => { + setPage(prev => { + return { + ...prev, + page: current, + pageSize: pageSize, + } + }) + }, - }} - /> - - shouldUpdate={false} - width={600} - form={form} - layout={'horizontal'} - scrollToFirstError={true} - title={t(`website.ssl.dns.title_${form.getFieldValue('id') !== 0 ? 'edit' : 'add'}`, form.getFieldValue('id') !== 0 ? 'DNS帐号编辑' : 'DNS帐号添加')} - // colProps={{ span: 24 }} - labelCol={{ span: 6 }} - wrapperCol={{ span: 14 }} - layoutType={'ModalForm'} - open={open} - modalProps={{ - maskClosable: false, - }} - onOpenChange={(open) => { - setOpen(open) - }} - loading={isSubmitting} - onFinish={async (values) => { - // console.log('values', values) - saveOrUpdate(values) - }} - columns={columns as ProFormColumnsType[]}/> - + }} + /> + + shouldUpdate={false} + width={600} + form={form} + layout={'horizontal'} + scrollToFirstError={true} + title={t(`website.ssl.dns.title_${form.getFieldValue('id') !== 0 ? 'edit' : 'add'}`, form.getFieldValue('id') !== 0 ? 'DNS帐号编辑' : 'DNS帐号添加')} + // colProps={{ span: 24 }} + labelCol={{ span: 6 }} + wrapperCol={{ span: 14 }} + layoutType={'ModalForm'} + open={open} + modalProps={{ + maskClosable: false, + }} + onOpenChange={(open) => { + setOpen(open) + }} + loading={isSubmitting} + onFinish={async (values) => { + // console.log('values', values) + saveOrUpdate(values) + }} + columns={columns as ProFormColumnsType[]}/> + ) } diff --git a/src/service/websites.ts b/src/service/websites.ts index 5b5cbb7..6a70d78 100644 --- a/src/service/websites.ts +++ b/src/service/websites.ts @@ -3,27 +3,30 @@ import { WebSite } from '@/types' import request from '@/request.ts' const websitesServ = { - ssl: { - ...createCURD('/website/ssl'), - upload: async(params: WebSite.SSLUploadDto)=>{ - return request.post('/website/ssl/upload', params) - }, - download: async(params: any)=>{ - return request.download('/website/ssl/download', params) - }, + ssl: { + ...createCURD('/website/ssl'), + upload: async (params: WebSite.SSLUploadDto) => { + return request.post('/website/ssl/upload', params) }, - acme: { - ...createCURD('/website/acme') + download: async (params: any) => { + return request.download('/website/ssl/download', params) }, - dns: { - ...createCURD('/website/dns_account') - }, - ca: { - ...createCURD('/website/ca'), - obtainSsl: async (params: WebSite.ISSLObtainByCA) => { - return request.post('/website/ca/obtain_ssl', params) - }, + }, + acme: { + ...createCURD('/website/acme') + }, + dns: { + ...createCURD('/website/dns_account'), + sync: async (params: WebSite.IDnsAccount) => { + return request.post('/website/dns_account/sync', params) } + }, + ca: { + ...createCURD('/website/ca'), + obtainSsl: async (params: WebSite.ISSLObtainByCA) => { + return request.post('/website/ca/obtain_ssl', params) + }, + } } diff --git a/src/store/websites/dns.ts b/src/store/websites/dns.ts index 1f7d804..411142a 100644 --- a/src/store/websites/dns.ts +++ b/src/store/websites/dns.ts @@ -99,4 +99,17 @@ export const deleteDNSAtom = atomWithMutation(get => ({ message.success(t('message.deleteSuccess', '删除成功')) get(dnsListAtom).refetch() } -})) \ No newline at end of file +})) + +//sync +export const syncDNSAtom = atomWithMutation(get => ({ + mutationKey: [ 'syncDNS' ], + mutationFn: async (id) => { + return await websitesServ.dns.sync(id) + }, + onSuccess: () => { + message.success(t('message.syncSuccess', '同步中')) + get(dnsListAtom).refetch() + } +})) +