Browse Source

NDS增加同步操作

main
dark 5 months ago
parent
commit
fbfc5ecdf3
  1. 227
      src/pages/websites/ssl/dns/DNSList.tsx
  2. 39
      src/service/websites.ts
  3. 15
      src/store/websites/dns.ts

227
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<ProColumns<WebSite.IDnsAccount>[]>(() => {
@ -206,17 +207,24 @@ const DNSList = () => {
return [
<Action key="edit"
as={'a'}
disabled={record.status === 2}
onClick={() => {
form.setFieldsValue(record)
setOpen(true)
}}>{t('actions.edit')}</Action>,
<Action key="sync"
as={'a'}
disabled={isAsyncing || record.status === 2}
onClick={() => {
asyncDNS(record)
}}>{t('actions.sync', '同步')}</Action>,
<Popconfirm
key={'del_confirm'}
disabled={isDeleting}
onConfirm={() => {
deleteDNS(record.id)
}}
title={t('message.deleteConfirm')}>
key={'del_confirm'}
disabled={isDeleting || record.status === 2}
onConfirm={() => {
deleteDNS(record.id)
}}
title={t('message.deleteConfirm')}>
<a key="del">
{t('actions.delete', '删除')}
</a>
@ -234,75 +242,76 @@ const DNSList = () => {
}, [ isSuccess ])
return (
<>
<ProTable<WebSite.IDnsAccount>
cardProps={{
bodyStyle: {
padding: 0,
}
}}
rowKey="id"
headerTitle={
<Button
onClick={() => {
form.setFieldsValue({
id: 0,
type: DNSTypeEnum.DnsPod,
})
setOpen(true)
}}
type={'primary'}>{t('website.ssl.dns.add', '添加DNS帐户')}</Button>
}
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,
}
})
},
<>
<ProTable<WebSite.IDnsAccount>
cardProps={{
bodyStyle: {
padding: 0,
}
}}
rowKey="id"
headerTitle={
<Button
onClick={() => {
form.resetFields()
form.setFieldsValue({
id: 0,
type: DNSTypeEnum.DnsPod,
})
setOpen(true)
}}
type={'primary'}>{t('website.ssl.dns.add', '添加DNS帐户')}</Button>
}
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,
}
})
},
}}
/>
<BetaSchemaForm<WebSite.IDnsAccount>
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[]}/>
</>
}}
/>
<BetaSchemaForm<WebSite.IDnsAccount>
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[]}/>
</>
)
}

39
src/service/websites.ts

@ -3,27 +3,30 @@ import { WebSite } from '@/types'
import request from '@/request.ts'
const websitesServ = {
ssl: {
...createCURD<any, WebSite.ISSL>('/website/ssl'),
upload: async(params: WebSite.SSLUploadDto)=>{
return request.post<any, WebSite.SSLUploadDto>('/website/ssl/upload', params)
},
download: async(params: any)=>{
return request.download('/website/ssl/download', params)
},
ssl: {
...createCURD<any, WebSite.ISSL>('/website/ssl'),
upload: async (params: WebSite.SSLUploadDto) => {
return request.post<any, WebSite.SSLUploadDto>('/website/ssl/upload', params)
},
acme: {
...createCURD<any, WebSite.IAcmeAccount>('/website/acme')
download: async (params: any) => {
return request.download('/website/ssl/download', params)
},
dns: {
...createCURD<any, WebSite.IDnsAccount>('/website/dns_account')
},
ca: {
...createCURD<any, WebSite.ICA>('/website/ca'),
obtainSsl: async (params: WebSite.ISSLObtainByCA) => {
return request.post<any, WebSite.ISSLObtainByCA>('/website/ca/obtain_ssl', params)
},
},
acme: {
...createCURD<any, WebSite.IAcmeAccount>('/website/acme')
},
dns: {
...createCURD<any, WebSite.IDnsAccount>('/website/dns_account'),
sync: async (params: WebSite.IDnsAccount) => {
return request.post<any, WebSite.IDnsAccount>('/website/dns_account/sync', params)
}
},
ca: {
...createCURD<any, WebSite.ICA>('/website/ca'),
obtainSsl: async (params: WebSite.ISSLObtainByCA) => {
return request.post<any, WebSite.ISSLObtainByCA>('/website/ca/obtain_ssl', params)
},
}
}

15
src/store/websites/dns.ts

@ -99,4 +99,17 @@ export const deleteDNSAtom = atomWithMutation<IApiResult, number>(get => ({
message.success(t('message.deleteSuccess', '删除成功'))
get(dnsListAtom).refetch()
}
}))
}))
//sync
export const syncDNSAtom = atomWithMutation<IApiResult, number>(get => ({
mutationKey: [ 'syncDNS' ],
mutationFn: async (id) => {
return await websitesServ.dns.sync(id)
},
onSuccess: () => {
message.success(t('message.syncSuccess', '同步中'))
get(dnsListAtom).refetch()
}
}))
Loading…
Cancel
Save