chenyang 5 months ago
parent
commit
f632a89333
  1. 298
      src/pages/websites/ssl/domain/index.tsx
  2. 26
      src/pages/websites/ssl/domain/style.ts
  3. 5
      src/service/websites.ts
  4. 92
      src/store/websites/domain.ts
  5. 14
      src/types/website/domain.d.ts

298
src/pages/websites/ssl/domain/index.tsx

@ -0,0 +1,298 @@
import { useTranslation } from '@/i18n.ts'
import { Button, Form, Popconfirm, Divider, Space, Tooltip, Badge } from 'antd'
import { useAtom, useAtomValue } from 'jotai'
import {
deleteWebsiteDomainAtom,
saveOrUpdateWebsiteDomainAtom, websiteDomainAtom, websiteDomainsAtom, websiteDomainSearchAtom,
} from '@/store/websites/domain'
import { useEffect, useMemo, useState } from 'react'
import Action from '@/components/action/Action.tsx'
import {
BetaSchemaForm,
ProColumns,
ProFormColumnsType,
} from '@ant-design/pro-components'
import ListPageLayout from '@/layout/ListPageLayout.tsx'
import { useStyle } from './style'
import { FilterOutlined } from '@ant-design/icons'
import { getValueCount } from '@/utils'
import { Table as ProTable } from '@/components/table'
const i18nPrefix = 'websiteDomains.list'
const WebsiteDomain = () => {
const { styles, cx } = useStyle()
const { t } = useTranslation()
const [ form ] = Form.useForm()
const [ filterForm ] = Form.useForm()
const { mutate: saveOrUpdate, isPending: isSubmitting, isSuccess } = useAtomValue(saveOrUpdateWebsiteDomainAtom)
const [ search, setSearch ] = useAtom(websiteDomainSearchAtom)
const [ currentWebsiteDomain, setWebsiteDomain ] = useAtom(websiteDomainAtom)
const { data, isFetching, isLoading, refetch } = useAtomValue(websiteDomainsAtom)
const { mutate: deleteWebsiteDomain, isPending: isDeleting } = useAtomValue(deleteWebsiteDomainAtom)
const [ open, setOpen ] = useState(false)
const [ openFilter, setFilterOpen ] = useState(false)
const [ searchKey, setSearchKey ] = useState(search?.title)
const columns = useMemo(() => {
return [
{
title: 'ID',
dataIndex: 'id',
hideInTable: true,
hideInSearch: true,
formItemProps: { hidden: true }
},
{
title: t(`${i18nPrefix}.columns.name`, 'name'),
dataIndex: 'name',
},
{
title: t(`${i18nPrefix}.columns.dns_account_id`, 'dns_account_id'),
dataIndex: 'dns_account_id',
},
{
title: t(`${i18nPrefix}.columns.status`, 'status'),
dataIndex: 'status',
},
{
title: t(`${i18nPrefix}.columns.created`, 'created'),
dataIndex: 'created',
},
{
title: t(`${i18nPrefix}.columns.modified`, 'modified'),
dataIndex: 'modified',
},
{
title: t(`${i18nPrefix}.columns.nameservers`, 'nameservers'),
dataIndex: 'nameservers',
},
{
title: t(`${i18nPrefix}.columns.tag`, 'tag'),
dataIndex: 'tag',
},
{
title: t(`${i18nPrefix}.columns.remark`, 'remark'),
dataIndex: 'remark',
},
{
title: t(`${i18nPrefix}.columns.option`, '操作'),
key: 'option',
valueType: 'option',
fixed: 'right',
render: (_, record) => [
<Action key="edit"
as={'a'}
onClick={() => {
form.setFieldsValue(record)
setOpen(true)
}}>{t('actions.edit')}</Action>,
<Popconfirm
key={'del_confirm'}
disabled={isDeleting}
onConfirm={() => {
deleteWebsiteDomain([ record.id ])
}}
title={t('message.deleteConfirm')}>
<a key="del">
{t('actions.delete', '删除')}
</a>
</Popconfirm>
]
}
] as ProColumns[]
}, [ isDeleting, currentWebsiteDomain, search ])
useEffect(() => {
setSearchKey(search?.title)
filterForm.setFieldsValue(search)
}, [ search ])
useEffect(() => {
if (isSuccess) {
setOpen(false)
}
}, [ isSuccess ])
return (
<ListPageLayout className={styles.container}>
<ProTable
rowKey="id"
headerTitle={t(`${i18nPrefix}.title`, '域名管理管理')}
toolbar={{
search: {
loading: isFetching && !!search?.title,
onSearch: (value: string) => {
setSearch(prev => ({
...prev,
title: value
}))
},
allowClear: true,
onChange: (e) => {
setSearchKey(e.target?.value)
},
value: searchKey,
placeholder: t(`${i18nPrefix}.placeholder`, '输入域名管理名称')
},
actions: [
<Tooltip key={'filter'} title={t(`${i18nPrefix}.filter.tooltip`, '高级查询')}>
<Badge count={getValueCount(search)}>
<Button
onClick={() => {
setFilterOpen(true)
}}
icon={<FilterOutlined/>} shape={'circle'} size={'small'}/>
</Badge>
</Tooltip>,
<Divider type={'vertical'} key={'divider'}/>,
<Button key={'add'}
onClick={() => {
form.resetFields()
form.setFieldsValue({
id: 0,
})
setOpen(true)
}}
type={'primary'}>{t(`${i18nPrefix}.add`, '添加')}</Button>
]
}}
scroll={{
x: 2500, y: 'calc(100vh - 290px)'
}}
search={false}
onRow={(record) => {
return {
className: cx({
'ant-table-row-selected': currentWebsiteDomain?.id === record.id
}),
onClick: () => {
setWebsiteDomain(record)
}
}
}}
dateFormatter="string"
loading={isLoading || isFetching}
dataSource={data?.rows ?? []}
columns={columns}
options={{
reload: () => {
refetch()
},
}}
pagination={{
total: data?.total,
pageSize: search.pageSize,
current: search.page,
onShowSizeChange: (current: number, size: number) => {
setSearch({
...search,
pageSize: size,
page: current
})
},
onChange: (current, pageSize) => {
setSearch(prev => {
return {
...prev,
page: current,
pageSize: pageSize,
}
})
},
}}
/>
<BetaSchemaForm
grid={true}
shouldUpdate={false}
width={1000}
form={form}
layout={'vertical'}
scrollToFirstError={true}
title={t(`${i18nPrefix}.title_${form.getFieldValue('id') !== 0 ? 'edit' : 'add'}`, form.getFieldValue('id') !== 0 ? '域名管理编辑' : '域名管理添加')}
layoutType={'DrawerForm'}
open={open}
drawerProps={{
maskClosable: false,
}}
onOpenChange={(open) => {
setOpen(open)
}}
loading={isSubmitting}
onFinish={async (values) => {
saveOrUpdate(values)
}}
columns={columns as ProFormColumnsType[]}/>
<BetaSchemaForm
title={t(`${i18nPrefix}.filter.title`, '域名管理高级查询')}
grid={true}
shouldUpdate={false}
width={500}
form={filterForm}
open={openFilter}
onOpenChange={open => {
setFilterOpen(open)
}}
layout={'vertical'}
scrollToFirstError={true}
layoutType={'DrawerForm'}
drawerProps={{
maskClosable: false,
mask: false,
}}
submitter={{
searchConfig: {
resetText: t(`${i18nPrefix}.filter.reset`, '清空'),
submitText: t(`${i18nPrefix}.filter.submit`, '查询'),
},
onReset: () => {
filterForm.resetFields()
},
render: (props,) => {
return (
<div style={{ textAlign: 'right' }}>
<Space>
<Button onClick={() => {
props.reset()
}}>{props.searchConfig?.resetText}</Button>
<Button type="primary"
onClick={() => {
props.submit()
}}
>{props.searchConfig?.submitText}</Button>
</Space>
</div>
)
},
}}
onFinish={async (values) => {
//处理,变成数组
Object.keys(values).forEach(key => {
if (typeof values[key] === 'string' && values[key].includes(',')) {
values[key] = values[key].split(',')
}
})
setSearch(values)
}}
columns={columns.filter(item => !item.hideInSearch) as ProFormColumnsType[]}/>
</ListPageLayout>
)
}
export default WebsiteDomain

26
src/pages/websites/ssl/domain/style.ts

@ -0,0 +1,26 @@
import { createStyles } from '@/theme'
export const useStyle = createStyles(({ token, css, cx, prefixCls }, props: any) => {
const prefix = `${prefixCls}-${token?.proPrefix}-websiteDomain-list-page`
const container = css`
.ant-table-cell{
.ant-tag{
padding-inline: 3px;
margin-inline-end: 3px;
}
}
.ant-table-empty {
.ant-table-body{
height: calc(100vh - 350px)
}
}
.ant-pro-table-highlight{
}
`
return {
container: cx(prefix, props?.className, container),
}
})

5
src/service/websites.ts

@ -1,6 +1,7 @@
import { createCURD } from '@/service/base.ts' import { createCURD } from '@/service/base.ts'
import { WebSite } from '@/types' import { WebSite } from '@/types'
import request from '@/request.ts' import request from '@/request.ts'
import { Websites } from '@/types/website/domain'
const websitesServ = { const websitesServ = {
ssl: { ssl: {
@ -26,8 +27,10 @@ const websitesServ = {
obtainSsl: async (params: WebSite.ISSLObtainByCA) => { 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, Websites.IWebsiteDomain>('/website/domain'),
} }
} }
export default websitesServ export default websitesServ

92
src/store/websites/domain.ts

@ -0,0 +1,92 @@
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'
import { Websites } from '@/types/website/domain'
type SearchParams = IPage & {
key?: string
[key: string]: any
}
export const websiteDomainIdAtom = atom(0)
export const websiteDomainIdsAtom = atom<number[]>([])
export const websiteDomainAtom = atom<Websites.IWebsiteDomain>(undefined as unknown as Websites.IWebsiteDomain )
export const websiteDomainSearchAtom = atom<SearchParams>({
key: '',
pageSize: 10,
page: 1,
} as SearchParams)
export const websiteDomainPageAtom = atom<IPage>({
pageSize: 10,
page: 1,
})
export const websiteDomainsAtom = atomWithQuery((get) => {
return {
queryKey: [ 'websiteDomains', get(websiteDomainSearchAtom) ],
queryFn: async ({ queryKey: [ , params ] }) => {
return await websitesServ.domain.list(params as SearchParams)
},
select: res => {
const data = res.data
data.rows = data.rows?.map(row => {
return {
...row,
//status: convertToBool(row.status)
}
})
return data
}
}
})
//saveOrUpdateAtom
export const saveOrUpdateWebsiteDomainAtom = atomWithMutation<IApiResult, Websites.IWebsiteDomain>((get) => {
return {
mutationKey: [ 'updateWebsiteDomain' ],
mutationFn: async (data) => {
//data.status = data.status ? '1' : '0'
if (data.id === 0) {
return await websitesServ.domain.add(data)
}
return await websitesServ.domain.update(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: [ 'websiteDomains', get(websiteDomainSearchAtom) ] })
return res
}
}
})
export const deleteWebsiteDomainAtom = atomWithMutation((get) => {
return {
mutationKey: [ 'deleteWebsiteDomain' ],
mutationFn: async (ids: number[]) => {
return await websitesServ.domain.batchDelete(ids ?? get(websiteDomainIdsAtom))
},
onSuccess: (res) => {
message.success('message.deleteSuccess')
//更新列表
get(queryClientAtom).invalidateQueries({ queryKey: [ 'websiteDomains', get(websiteDomainSearchAtom) ] })
return res
}
}
})

14
src/types/website/domain.d.ts

@ -0,0 +1,14 @@
export namespace Websites {
export interface IWebsiteDomain {
id: number;
name: string;
dns_account_id: number;
soure_id: string;
status: string;
created: string;
modified: string;
nameservers: string;
tag: string;
remark: string;
}
}
Loading…
Cancel
Save