From 06f04deace116fe6d7d5dbea64caea5624190582 Mon Sep 17 00:00:00 2001 From: chenyang Date: Sat, 29 Jun 2024 05:32:20 +0700 Subject: [PATCH] Edit --- src/pages/websites/ssl/account/index.tsx | 300 +++++++++++++++++++++++++++++++ src/pages/websites/ssl/account/style.ts | 26 +++ src/service/websites.ts | 18 +- src/store/websites/dns_account.ts | 91 ++++++++++ src/types/website/dns_account.d.ts | 13 ++ 5 files changed, 443 insertions(+), 5 deletions(-) create mode 100644 src/pages/websites/ssl/account/index.tsx create mode 100644 src/pages/websites/ssl/account/style.ts create mode 100644 src/store/websites/dns_account.ts create mode 100644 src/types/website/dns_account.d.ts diff --git a/src/pages/websites/ssl/account/index.tsx b/src/pages/websites/ssl/account/index.tsx new file mode 100644 index 0000000..a933271 --- /dev/null +++ b/src/pages/websites/ssl/account/index.tsx @@ -0,0 +1,300 @@ +import { useTranslation } from '@/i18n.ts' +import { Button, Form, Popconfirm, Divider, Space, Tooltip, Badge } from 'antd' +import { useAtom, useAtomValue } from 'jotai' +import { + deleteWebsiteDnsAccountAtom, + saveOrUpdateWebsiteDnsAccountAtom, websiteDnsAccountAtom, websiteDnsAccountsAtom, websiteDnsAccountSearchAtom, +} from '@/store/websites/dns_account.ts' +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.ts' +import { FilterOutlined } from '@ant-design/icons' +import { getValueCount } from '@/utils' +import { Table as ProTable } from '@/components/table' + +const i18nPrefix = 'websiteDnsAccounts.list' + +const WebsiteDnsAccount = () => { + + const { styles, cx } = useStyle() + const { t } = useTranslation() + const [ form ] = Form.useForm() + const [ filterForm ] = Form.useForm() + const { mutate: saveOrUpdate, isPending: isSubmitting, isSuccess } = useAtomValue(saveOrUpdateWebsiteDnsAccountAtom) + const [ search, setSearch ] = useAtom(websiteDnsAccountSearchAtom) + const [ currentWebsiteDnsAccount, setWebsiteDnsAccount ] = useAtom(websiteDnsAccountAtom) + const { data, isFetching, isLoading, refetch } = useAtomValue(websiteDnsAccountsAtom) + const { mutate: deleteWebsiteDnsAccount, isPending: isDeleting } = useAtomValue(deleteWebsiteDnsAccountAtom) + + 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.updated_at`, 'updated_at'), + dataIndex: 'updated_at', + }, + + { + title: t(`${i18nPrefix}.columns.name`, 'name'), + dataIndex: 'name', + }, + + { + title: t(`${i18nPrefix}.columns.type`, 'type'), + dataIndex: 'type', + }, + + { + title: t(`${i18nPrefix}.columns.authorization`, 'authorization'), + dataIndex: 'authorization', + }, + + { + title: t(`${i18nPrefix}.columns.status`, 'status'), + dataIndex: 'status', + }, + + { + title: t(`${i18nPrefix}.columns.remark`, 'remark'), + dataIndex: 'remark', + }, + + { + title: t(`${i18nPrefix}.columns.tag`, 'tag'), + dataIndex: 'tag', + }, + + { + title: t(`${i18nPrefix}.columns.option`, '操作'), + key: 'option', + valueType: 'option', + fixed: 'right', + render: (_, record) => [ + { + form.setFieldsValue(record) + setOpen(true) + }}>{t('actions.edit')}, + { + deleteWebsiteDnsAccount([ record.id ]) + }} + title={t('message.deleteConfirm')}> + + {t('actions.delete', '删除')} + + + ] + } + ] as ProColumns[] + }, [ isDeleting, currentWebsiteDnsAccount, search ]) + + useEffect(() => { + + setSearchKey(search?.title) + filterForm.setFieldsValue(search) + + }, [ search ]) + + useEffect(() => { + if (isSuccess) { + setOpen(false) + } + }, [ isSuccess ]) + + return ( + + { + setSearch(prev => ({ + ...prev, + title: value + })) + }, + allowClear: true, + onChange: (e) => { + setSearchKey(e.target?.value) + }, + value: searchKey, + placeholder: t(`${i18nPrefix}.placeholder`, '输入账号管理名称') + }, + actions: [ + + + + ] + }} + scroll={{ + x: 2500, y: 'calc(100vh - 290px)' + }} + search={false} + onRow={(record) => { + return { + className: cx({ + 'ant-table-row-selected': currentWebsiteDnsAccount?.id === record.id + }), + onClick: () => { + setWebsiteDnsAccount(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, + } + }) + }, + }} + /> + { + setOpen(open) + }} + loading={isSubmitting} + // onValuesChange={(values) => { + // + // }} + onFinish={async (values) => { + saveOrUpdate(values) + }} + columns={columns as ProFormColumnsType[]}/> + { + 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 ( +
+ + + + +
+ ) + }, + + }} + // onValuesChange={(values) => { + // + // }} + + 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[]}/> +
+ ) +} + +export default WebsiteDnsAccount \ No newline at end of file diff --git a/src/pages/websites/ssl/account/style.ts b/src/pages/websites/ssl/account/style.ts new file mode 100644 index 0000000..7852918 --- /dev/null +++ b/src/pages/websites/ssl/account/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}-websiteDnsAccount-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), + } +}) \ No newline at end of file diff --git a/src/service/websites.ts b/src/service/websites.ts index 17f9ddd..4f80ac6 100644 --- a/src/service/websites.ts +++ b/src/service/websites.ts @@ -1,7 +1,9 @@ import { createCURD } from '@/service/base.ts' import { WebSite } from '@/types' import request from '@/request.ts' -import { Websites } from '@/types/website/domain' +import { IWebsiteDomain } from '@/types/website/domain' +import { IWebsiteDnsRecords } from '@/types/website/record' +import { IWebsiteDnsAccount } from '@/types/website/dns_account' const websitesServ = { ssl: { @@ -17,7 +19,7 @@ const websitesServ = { ...createCURD('/website/acme') }, dns: { - ...createCURD('/website/dns_account'), + ...createCURD('/website/account'), sync: async (params: WebSite.IDnsAccount) => { return request.post('/website/dns_account/sync', params) } @@ -29,11 +31,17 @@ const websitesServ = { }, }, domain: { - ...createCURD('/website/domain'), + ...createCURD('/website/domain'), }, record: { - ...createCURD('/website/dns_records'), - } + ...createCURD('/website/dns_records'), + }, + dnsAccount: { + ...createCURD('/website/dns_account'), + sync: async (params:IWebsiteDnsAccount) => { + return request.post('/website/dns_account/sync', params) + } + }, } export default websitesServ \ No newline at end of file diff --git a/src/store/websites/dns_account.ts b/src/store/websites/dns_account.ts new file mode 100644 index 0000000..f91c4a8 --- /dev/null +++ b/src/store/websites/dns_account.ts @@ -0,0 +1,91 @@ +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 { IWebsiteDnsAccount } from '@/types/website/dns_account' +import websitesServ from '@/service/websites.ts' + + +type SearchParams = IPage & { + key?: string + + [key: string]: any +} + +export const websiteDnsAccountIdAtom = atom(0) + +export const websiteDnsAccountIdsAtom = atom([]) + +export const websiteDnsAccountAtom = atom(undefined as unknown as IWebsiteDnsAccount ) + +export const websiteDnsAccountSearchAtom = atom({ + key: '', + pageSize: 10, + page: 1, +} as SearchParams) + +export const websiteDnsAccountPageAtom = atom({ + pageSize: 10, + page: 1, +}) + +export const websiteDnsAccountsAtom = atomWithQuery((get) => { + return { + queryKey: [ 'websiteDnsAccounts', get(websiteDnsAccountSearchAtom) ], + queryFn: async ({ queryKey: [ , params ] }) => { + return await websitesServ.dnsAccount.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 saveOrUpdateWebsiteDnsAccountAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'updateWebsiteDnsAccount' ], + mutationFn: async (data) => { + //data.status = data.status ? '1' : '0' + if (data.id === 0) { + return await websitesServ.dnsAccount.add(data) + } + return await websitesServ.dnsAccount.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: [ 'websiteDnsAccounts', get(websiteDnsAccountSearchAtom) ] }) + + return res + } + } +}) + +export const deleteWebsiteDnsAccountAtom = atomWithMutation((get) => { + return { + mutationKey: [ 'deleteWebsiteDnsAccount' ], + mutationFn: async (ids: number[]) => { + return await websitesServ.dnsAccount.batchDelete(ids ?? get(websiteDnsAccountIdsAtom)) + }, + onSuccess: (res) => { + message.success('message.deleteSuccess') + //更新列表 + get(queryClientAtom).invalidateQueries({ queryKey: [ 'websiteDnsAccounts', get(websiteDnsAccountSearchAtom) ] }) + return res + } + } +}) diff --git a/src/types/website/dns_account.d.ts b/src/types/website/dns_account.d.ts new file mode 100644 index 0000000..d3f2155 --- /dev/null +++ b/src/types/website/dns_account.d.ts @@ -0,0 +1,13 @@ +export interface IWebsiteDnsAccount { + id: number; + created_at: string; + created_by: number; + updated_at: string; + updated_by: number; + name: string; + type: string; + authorization: string; + status: number; + remark: string; + tag: string; +}