From 359c5fc4421278264bf6c2d08e4270c2ee21db2f Mon Sep 17 00:00:00 2001 From: dark Date: Sat, 4 May 2024 21:44:58 +0800 Subject: [PATCH] =?UTF-8?q?types=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Auth.tsx | 2 +- src/components/avatar/index.tsx | 2 +- .../department-tree/DepartmentCascader.tsx | 2 +- src/components/department-tree/DepartmentTree.tsx | 4 +- src/components/error/404.tsx | 2 +- src/components/role-picker/RolePicker.tsx | 2 +- src/components/user-picker/UserPicker.tsx | 2 +- src/components/user-picker/store.ts | 2 +- src/global.d.ts | 2 +- src/layout/RootLayout.tsx | 2 +- src/pages/login/index.tsx | 2 +- .../departments/components/DepartmentTree.tsx | 4 +- .../departments/components/TreeNodeRender.tsx | 2 +- src/pages/system/departments/index.tsx | 2 +- src/pages/system/logs/login/index.tsx | 2 +- src/pages/system/menus/components/BatchButton.tsx | 2 +- src/pages/system/menus/components/MenuTree.tsx | 2 +- .../system/menus/components/TreeNodeRender.tsx | 2 +- src/pages/system/menus/index.tsx | 2 +- src/pages/system/roles/index.tsx | 6 +- src/pages/system/users/index.tsx | 2 +- src/pages/websites/ssl/components/AcmeList.tsx | 8 +- src/pages/websites/ssl/components/CAList.tsx | 8 +- src/pages/websites/ssl/components/DNSList.tsx | 8 +- src/pages/websites/ssl/index.tsx | 8 +- src/routes.tsx | 2 +- src/service/system.ts | 24 ++- src/service/websites.ts | 13 +- src/store/department.ts | 84 ----------- src/store/logs.ts | 58 ------- src/store/menu.ts | 88 ----------- src/store/role.ts | 88 ----------- src/store/system/department.ts | 84 +++++++++++ src/store/system/logs.ts | 58 +++++++ src/store/system/menu.ts | 89 +++++++++++ src/store/system/role.ts | 88 +++++++++++ src/store/system/user.ts | 164 ++++++++++++++++++++ src/store/user.ts | 166 --------------------- src/store/websites/acme.ts | 6 +- src/store/websites/ca.ts | 6 +- src/store/websites/dns.ts | 6 +- src/store/websites/ssl.ts | 5 - src/types/department.d.ts | 17 --- src/types/index.d.ts | 14 ++ src/types/index.ts | 5 - src/types/login.d.ts | 22 --- src/types/logs.d.ts | 11 -- src/types/menus.d.ts | 66 -------- src/types/roles.d.ts | 30 ---- src/types/system/department.d.ts | 17 +++ src/types/system/login.d.ts | 14 ++ src/types/system/logs.d.ts | 11 ++ src/types/system/menus.d.ts | 34 +++++ src/types/system/roles.d.ts | 10 ++ src/types/system/user.d.ts | 26 ++++ src/types/user.d.ts | 26 ---- src/utils/index.ts | 2 +- src/utils/uuid.ts | 2 - 58 files changed, 676 insertions(+), 742 deletions(-) delete mode 100644 src/store/department.ts delete mode 100644 src/store/logs.ts delete mode 100644 src/store/menu.ts delete mode 100644 src/store/role.ts create mode 100644 src/store/system/department.ts create mode 100644 src/store/system/logs.ts create mode 100644 src/store/system/menu.ts create mode 100644 src/store/system/role.ts create mode 100644 src/store/system/user.ts delete mode 100644 src/store/user.ts delete mode 100644 src/types/department.d.ts create mode 100644 src/types/index.d.ts delete mode 100644 src/types/index.ts delete mode 100644 src/types/login.d.ts delete mode 100644 src/types/logs.d.ts delete mode 100644 src/types/menus.d.ts delete mode 100644 src/types/roles.d.ts create mode 100644 src/types/system/department.d.ts create mode 100644 src/types/system/login.d.ts create mode 100644 src/types/system/logs.d.ts create mode 100644 src/types/system/menus.d.ts create mode 100644 src/types/system/roles.d.ts create mode 100644 src/types/system/user.d.ts delete mode 100644 src/types/user.d.ts diff --git a/src/Auth.tsx b/src/Auth.tsx index a21f5cc..9481707 100644 --- a/src/Auth.tsx +++ b/src/Auth.tsx @@ -1,7 +1,7 @@ import React from 'react' import { Props } from './global' import { useAtomValue } from 'jotai' -import { authAtom } from './store/user.ts' +import { authAtom } from './store/system/user.ts' export type AuthProps = Props & { diff --git a/src/components/avatar/index.tsx b/src/components/avatar/index.tsx index d272a21..bba548d 100644 --- a/src/components/avatar/index.tsx +++ b/src/components/avatar/index.tsx @@ -1,6 +1,6 @@ import Icon from '@/components/icon' import { useTranslation } from '@/i18n.ts' -import { currentUserAtom, logoutAtom } from '@/store/user.ts' +import { currentUserAtom, logoutAtom } from '@/store/system/user.ts' import { Avatar as AntAvatar, Dropdown, Spin } from 'antd' import { useAtomValue } from 'jotai' import { useNavigate } from '@tanstack/react-router' diff --git a/src/components/department-tree/DepartmentCascader.tsx b/src/components/department-tree/DepartmentCascader.tsx index 90724be..135f64e 100644 --- a/src/components/department-tree/DepartmentCascader.tsx +++ b/src/components/department-tree/DepartmentCascader.tsx @@ -1,6 +1,6 @@ import { Cascader, CascaderProps } from '@/components/cascader' import { useAtomValue } from 'jotai/index' -import { departTreeAtom } from '@/store/department.ts' +import { departTreeAtom } from '@/store/system/department.ts' import { usePageStoreOptions } from '@/store' import { Spin } from 'antd' import { useTranslation } from '@/i18n.ts' diff --git a/src/components/department-tree/DepartmentTree.tsx b/src/components/department-tree/DepartmentTree.tsx index 832f947..48d6216 100644 --- a/src/components/department-tree/DepartmentTree.tsx +++ b/src/components/department-tree/DepartmentTree.tsx @@ -2,12 +2,12 @@ import { usePageStoreOptions } from '@/store' import { Empty, Spin, Tree, TreeDataNode, TreeProps } from 'antd' import { useStyle } from './style.ts' import { useTranslation } from '@/i18n.ts' -import { departTreeAtom, } from '@/store/department.ts' +import { departTreeAtom, } from '@/store/system/department.ts' import { useAtomValue } from 'jotai' import { useRef } from 'react' import { flattenTree } from '@/utils' import { useDeepCompareEffect } from 'react-use' -import { IDepartment } from '@/types/department' +import { IDepartment } from '@/types/system/department' export interface DepartmentTreeProps extends TreeProps { root?: TreeDataNode | boolean | string diff --git a/src/components/error/404.tsx b/src/components/error/404.tsx index 7145e55..e2b69bb 100644 --- a/src/components/error/404.tsx +++ b/src/components/error/404.tsx @@ -2,7 +2,7 @@ import { useTranslation } from '@/i18n.ts' import { useNavigate } from '@tanstack/react-router' import { Button, Result } from 'antd' import { useAtomValue } from 'jotai' -import { userMenuDataAtom } from '@/store/user.ts' +import { userMenuDataAtom } from '@/store/system/user.ts' const NotFound = () => { diff --git a/src/components/role-picker/RolePicker.tsx b/src/components/role-picker/RolePicker.tsx index b763dc4..82cc480 100644 --- a/src/components/role-picker/RolePicker.tsx +++ b/src/components/role-picker/RolePicker.tsx @@ -1,7 +1,7 @@ import { convertToBool } from '@/utils' import { Select, SelectProps } from 'antd' import { useAtomValue } from 'jotai' -import { rolesAtom } from '@/store/role.ts' +import { rolesAtom } from '@/store/system/role.ts' import { memo } from 'react' import { useTranslation } from '@/i18n.ts' diff --git a/src/components/user-picker/UserPicker.tsx b/src/components/user-picker/UserPicker.tsx index e849ac2..2853679 100644 --- a/src/components/user-picker/UserPicker.tsx +++ b/src/components/user-picker/UserPicker.tsx @@ -7,7 +7,7 @@ import { useTranslation } from '@/i18n.ts' import DepartmentTree from '@/components/department-tree/DepartmentTree.tsx' import { DraggablePanel } from '@/components/draggable-panel' import { useAtom, useAtomValue } from 'jotai' -import { userListAtom, userSearchAtom, } from '@/store/user.ts' +import { userListAtom, userSearchAtom, } from '@/store/system/user.ts' import { IUser } from '@/types' import EmptyWrap from '@/components/empty/EmptyWrap.tsx' diff --git a/src/components/user-picker/store.ts b/src/components/user-picker/store.ts index 3ec8af6..66597c2 100644 --- a/src/components/user-picker/store.ts +++ b/src/components/user-picker/store.ts @@ -1,4 +1,4 @@ -import { IUser } from '@/types/user' +import { IUser } from '@/types/system/user' import { atom } from 'jotai' export const userSelectedAtom = atom([]) diff --git a/src/global.d.ts b/src/global.d.ts index a21d1db..a33ae76 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,4 +1,4 @@ -import { IMenu } from '@/types/menus' +import { IMenu } from '@/types/system/menus' import { QueryClient } from '@tanstack/react-query' import { Router } from '@tanstack/react-router' import { RouteOptions } from '@tanstack/react-router/src/route.ts' diff --git a/src/layout/RootLayout.tsx b/src/layout/RootLayout.tsx index 9b6f639..45ef9bd 100644 --- a/src/layout/RootLayout.tsx +++ b/src/layout/RootLayout.tsx @@ -3,7 +3,7 @@ import PageBreadcrumb from '@/components/breadcrumb' import ErrorPage from '@/components/error/error.tsx' import SelectLang from '@/components/select-lang' import { appAtom } from '@/store/system.ts' -import { userMenuDataAtom } from '@/store/user.ts' +import { userMenuDataAtom } from '@/store/system/user.ts' import { MenuItem } from '@/global' import { ProConfigProvider, ProLayout, } from '@ant-design/pro-components' import { zhCNIntl, enUSIntl } from '@ant-design/pro-provider/es/intl' diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 9262330..b61c222 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -3,7 +3,7 @@ import { createFileRoute } from '@tanstack/react-router' import { Button, Form, Input, Space } from 'antd' import { useAtom, useAtomValue } from 'jotai' import { useTranslation } from '@/i18n.ts' -import { loginAtom, loginFormAtom } from '@/store/user.ts' +import { loginAtom, loginFormAtom } from '@/store/system/user.ts' import { memo, useLayoutEffect } from 'react' import { useStyles } from './style.ts' diff --git a/src/pages/system/departments/components/DepartmentTree.tsx b/src/pages/system/departments/components/DepartmentTree.tsx index ef8b87f..2a553f5 100644 --- a/src/pages/system/departments/components/DepartmentTree.tsx +++ b/src/pages/system/departments/components/DepartmentTree.tsx @@ -3,14 +3,14 @@ import { Empty, Spin, Tree } from 'antd' import { useStyle } from '../style.ts' import { useTranslation } from '@/i18n.ts' import { useSetAtom } from 'jotai' -import { selectedDepartAtom, departTreeAtom, batchIdsAtom } from '@/store/department.ts' +import { selectedDepartAtom, departTreeAtom, batchIdsAtom } from '@/store/system/department.ts' import { FormInstance } from 'antd/lib' import { useAtomValue } from 'jotai' import { TreeNodeRender } from './TreeNodeRender.tsx' import { useEffect, useRef } from 'react' import { flattenTree } from '@/utils' import { useDeepCompareEffect } from 'react-use' -import { IDepartment } from '@/types/department' +import { IDepartment } from '@/types/system/department' export const DepartmentTree = ({ form }: { form: FormInstance }) => { diff --git a/src/pages/system/departments/components/TreeNodeRender.tsx b/src/pages/system/departments/components/TreeNodeRender.tsx index 0365b53..2554c82 100644 --- a/src/pages/system/departments/components/TreeNodeRender.tsx +++ b/src/pages/system/departments/components/TreeNodeRender.tsx @@ -6,7 +6,7 @@ import { FormInstance } from 'antd/lib' import { useTranslation } from '@/i18n.ts' import { useStyle } from '../style.ts' import { useAtomValue, useSetAtom } from 'jotai' -import { selectedDepartAtom, deleteDepartAtom, defaultDepart } from '@/store/department.ts' +import { selectedDepartAtom, deleteDepartAtom, defaultDepart } from '@/store/system/department.ts' import { PlusOutlined } from '@ant-design/icons' import ActionIcon, { DeleteAction } from '@/components/icon/action' diff --git a/src/pages/system/departments/index.tsx b/src/pages/system/departments/index.tsx index 3f6f384..a6b7abc 100644 --- a/src/pages/system/departments/index.tsx +++ b/src/pages/system/departments/index.tsx @@ -4,7 +4,7 @@ import { useStyle } from './style.ts' import DepartmentTree from './components/DepartmentTree.tsx' import { Alert, Button, Divider, Form, Input, InputNumber, InputRef, notification, TreeSelect } from 'antd' import { PlusOutlined } from '@ant-design/icons' -import { defaultDepart, selectedDepartAtom, departTreeAtom, saveOrUpdateDepartAtom } from '@/store/department.ts' +import { defaultDepart, selectedDepartAtom, departTreeAtom, saveOrUpdateDepartAtom } from '@/store/system/department.ts' import { useAtom, useAtomValue, } from 'jotai' import Glass from '@/components/glass' import { useEffect, useRef } from 'react' diff --git a/src/pages/system/logs/login/index.tsx b/src/pages/system/logs/login/index.tsx index 1fce3cf..43feaeb 100644 --- a/src/pages/system/logs/login/index.tsx +++ b/src/pages/system/logs/login/index.tsx @@ -11,7 +11,7 @@ import { useAtom, useAtomValue } from 'jotai' import { useTranslation } from '@/i18n.ts' import { Button, Space, Table, Popconfirm } from 'antd' -import { deleteLoginLogAtom, loginLogPageAtom, loginLogsAtom, loginLogSearchAtom } from '@/store/logs.ts' +import { deleteLoginLogAtom, loginLogPageAtom, loginLogsAtom, loginLogSearchAtom } from '@/store/system/logs.ts' const LoginLog = memo(() => { diff --git a/src/pages/system/menus/components/BatchButton.tsx b/src/pages/system/menus/components/BatchButton.tsx index 4d31e46..0a918ab 100644 --- a/src/pages/system/menus/components/BatchButton.tsx +++ b/src/pages/system/menus/components/BatchButton.tsx @@ -1,7 +1,7 @@ import { Button, Popconfirm } from 'antd' import { useAtomValue } from 'jotai' -import { batchIdsAtom, deleteMenuAtom } from '@/store/menu.ts' +import { batchIdsAtom, deleteMenuAtom } from '@/store/system/menu.ts' import { useTranslation } from '@/i18n.ts' const BatchButton = () => { diff --git a/src/pages/system/menus/components/MenuTree.tsx b/src/pages/system/menus/components/MenuTree.tsx index c23adb2..29623a9 100644 --- a/src/pages/system/menus/components/MenuTree.tsx +++ b/src/pages/system/menus/components/MenuTree.tsx @@ -4,7 +4,7 @@ import { MenuItem } from '@/global' import { useStyle } from '../style.ts' import { useTranslation } from '@/i18n.ts' import { useSetAtom } from 'jotai' -import { batchIdsAtom, menuDataAtom, selectedMenuAtom } from '@/store/menu.ts' +import { batchIdsAtom, menuDataAtom, selectedMenuAtom } from '@/store/system/menu.ts' import { FormInstance } from 'antd/lib' import { useAtomValue } from 'jotai' import { TreeNodeRender } from './TreeNodeRender.tsx' diff --git a/src/pages/system/menus/components/TreeNodeRender.tsx b/src/pages/system/menus/components/TreeNodeRender.tsx index 1525d21..8b0e319 100644 --- a/src/pages/system/menus/components/TreeNodeRender.tsx +++ b/src/pages/system/menus/components/TreeNodeRender.tsx @@ -6,7 +6,7 @@ import { FormInstance } from 'antd/lib' import { useTranslation } from '@/i18n.ts' import { useStyle } from '../style.ts' import { useAtomValue, useSetAtom } from 'jotai' -import { defaultMenu, deleteMenuAtom, selectedMenuAtom } from '@/store/menu.ts' +import { defaultMenu, deleteMenuAtom, selectedMenuAtom } from '@/store/system/menu.ts' import { PlusOutlined } from '@ant-design/icons' import ActionIcon, { DeleteAction } from '@/components/icon/action' diff --git a/src/pages/system/menus/index.tsx b/src/pages/system/menus/index.tsx index c03ccb6..2ee36b5 100644 --- a/src/pages/system/menus/index.tsx +++ b/src/pages/system/menus/index.tsx @@ -4,7 +4,7 @@ import { PlusOutlined } from '@ant-design/icons' import { ProCard } from '@ant-design/pro-components' import { Button, Form, Input, Radio, TreeSelect, InputNumber, notification, Alert, InputRef, Divider } from 'antd' import { useAtom, useAtomValue } from 'jotai' -import { defaultMenu, menuDataAtom, saveOrUpdateMenuAtom, selectedMenuAtom } from '@/store/menu.ts' +import { defaultMenu, menuDataAtom, saveOrUpdateMenuAtom, selectedMenuAtom } from '@/store/system/menu.ts' import IconPicker from '@/components/icon/picker' import ButtonTable from './components/ButtonTable.tsx' import { useStyle } from './style.ts' diff --git a/src/pages/system/roles/index.tsx b/src/pages/system/roles/index.tsx index 5a4f44f..0ded53b 100644 --- a/src/pages/system/roles/index.tsx +++ b/src/pages/system/roles/index.tsx @@ -1,6 +1,6 @@ import Switch from '@/components/switch' -import { IMenu } from '@/types/menus' +import { IMenu } from '@/types/system/menus' import { ActionType, PageContainer, @@ -19,11 +19,11 @@ import { rolesAtom, saveOrUpdateRoleAtom, searchAtom -} from '@/store/role.ts' +} from '@/store/system/role.ts' import { useTranslation } from '@/i18n.ts' import { Button, Form, Space, Spin, Table, Tree, Popconfirm } from 'antd' import { PlusOutlined } from '@ant-design/icons' -import { menuDataAtom } from '@/store/menu.ts' +import { menuDataAtom } from '@/store/system/menu.ts' import { getTreeCheckedStatus } from '@/utils/tree.ts' const MenuTree = (props: any) => { diff --git a/src/pages/system/users/index.tsx b/src/pages/system/users/index.tsx index dd80e62..699137e 100644 --- a/src/pages/system/users/index.tsx +++ b/src/pages/system/users/index.tsx @@ -19,7 +19,7 @@ import { userPageAtom, userSearchAtom, userSelectedAtom -} from '@/store/user.ts' +} from '@/store/system/user.ts' import { useMemo, useRef, useState } from 'react' import Switch from '@/components/switch' import { DepartmentCascader } from '@/components/department-tree' diff --git a/src/pages/websites/ssl/components/AcmeList.tsx b/src/pages/websites/ssl/components/AcmeList.tsx index 7d1a293..1f685c0 100644 --- a/src/pages/websites/ssl/components/AcmeList.tsx +++ b/src/pages/websites/ssl/components/AcmeList.tsx @@ -1,12 +1,12 @@ import { useMemo, useState } from 'react' import { BetaSchemaForm, ProColumns, ProFormColumnsType, ProTable } from '@ant-design/pro-components' -import { IAcmeAccount } from '@/types/website/acme' import { useTranslation } from '@/i18n.ts' import { AcmeAccountTypes, acmeListAtom, acmePageAtom, AcmeType, saveOrUpdateAcmeAtom } from '@/store/websites/acme.ts' import { useAtom, useAtomValue } from 'jotai' import { Alert, Button, Form, Popconfirm } from 'antd' import { KeyTypeEnum, KeyTypes } from '@/store/websites/ssl.ts' import { deleteDNSAtom } from '@/store/websites/dns.ts' +import { WebSite } from '@/types' const AcmeList = () => { @@ -18,7 +18,7 @@ const AcmeList = () => { const { mutate: deleteDNS, isPending: isDeleting } = useAtomValue(deleteDNSAtom) const [ open, setOpen ] = useState(false) - const columns = useMemo[]>(() => { + const columns = useMemo[]>(() => { return [ { title: 'ID', @@ -95,7 +95,7 @@ const AcmeList = () => { return ( <> - + cardProps={{ bodyStyle: { padding: 0, @@ -139,7 +139,7 @@ const AcmeList = () => { }} /> - + shouldUpdate={false} width={600} form={form} diff --git a/src/pages/websites/ssl/components/CAList.tsx b/src/pages/websites/ssl/components/CAList.tsx index 99a9e45..e0ded30 100644 --- a/src/pages/websites/ssl/components/CAList.tsx +++ b/src/pages/websites/ssl/components/CAList.tsx @@ -1,12 +1,12 @@ import { useMemo, useState } from 'react' import { BetaSchemaForm, ProColumns, ProFormColumnsType, ProTable } from '@ant-design/pro-components' -import { ICA, } from '@/types/website/ca' import { useTranslation } from '@/i18n.ts' import { deleteCaAtom } from '@/store/websites/ca.ts' import { useAtom, useAtomValue } from 'jotai' import { Button, Form, Popconfirm } from 'antd' import { KeyTypeEnum, KeyTypes } from '@/store/websites/ssl.ts' import { caListAtom, caPageAtom, saveOrUpdateCaAtom } from '@/store/websites/ca.ts' +import { WebSite } from '@/types' const CAList = () => { @@ -18,7 +18,7 @@ const CAList = () => { const { mutate: deleteCA, isPending: isDeleting } = useAtomValue(deleteCaAtom) const [ open, setOpen ] = useState(false) - const columns = useMemo[]>(() => { + const columns = useMemo[]>(() => { return [ { title: 'ID', @@ -145,7 +145,7 @@ const CAList = () => { return ( <> - + cardProps={{ bodyStyle: { padding: 0, @@ -189,7 +189,7 @@ const CAList = () => { }} /> - + shouldUpdate={false} width={600} form={form} diff --git a/src/pages/websites/ssl/components/DNSList.tsx b/src/pages/websites/ssl/components/DNSList.tsx index aa5d055..ef25654 100644 --- a/src/pages/websites/ssl/components/DNSList.tsx +++ b/src/pages/websites/ssl/components/DNSList.tsx @@ -11,7 +11,7 @@ import { DNSTypes, saveOrUpdateDNSAtom } from '@/store/websites/dns.ts' -import { IDnsAccount } from '@/types/website/dns' +import { WebSite } from '@/types' const getKeyColumn = (type: string, t) => { const columns: ProColumns[] = [] @@ -155,7 +155,7 @@ const DNSList = () => { const { mutate: deleteDNS, isPending: isDeleting } = useAtomValue(deleteDNSAtom) const [ open, setOpen ] = useState(false) - const columns = useMemo[]>(() => { + const columns = useMemo[]>(() => { return [ { title: 'ID', @@ -221,7 +221,7 @@ const DNSList = () => { return ( <> - + cardProps={{ bodyStyle: { padding: 0, @@ -264,7 +264,7 @@ const DNSList = () => { }} /> - + shouldUpdate={false} width={600} form={form} diff --git a/src/pages/websites/ssl/index.tsx b/src/pages/websites/ssl/index.tsx index 0df9e08..13a2dce 100644 --- a/src/pages/websites/ssl/index.tsx +++ b/src/pages/websites/ssl/index.tsx @@ -15,13 +15,13 @@ import { memo, useMemo, useState } from 'react' import { useTranslation } from '@/i18n.ts' import { Button, Form, Popconfirm } from 'antd' import { PlusOutlined } from '@ant-design/icons' -import { ISSL } from '@/types/website/ssl' import DrawerPicker from '@/components/drawer-picker/DrawerPicker.tsx' import AcmeList from './components/AcmeList.tsx' import { acmeListAtom, AcmeType, getAcmeAccountTypeName } from '@/store/websites/acme.ts' import { dnsListAtom, getDNSTypeName } from '@/store/websites/dns.ts' import DNSList from './components/DNSList.tsx' import CAList from '@/pages/websites/ssl/components/CAList.tsx' +import { WebSite } from '@/types' const SSL = () => { @@ -38,7 +38,7 @@ const SSL = () => { const [ open, setOpen ] = useState(false) - const columns = useMemo[]>(() => { + const columns = useMemo[]>(() => { return [ { title: 'ID', @@ -216,7 +216,7 @@ const SSL = () => { return ( - + headerTitle={t('website.ssl.title', '证书列表')} search={false} loading={isLoading || isFetching} @@ -303,7 +303,7 @@ const SSL = () => { > - + shouldUpdate={false} width={600} form={form} diff --git a/src/routes.tsx b/src/routes.tsx index 87c7f46..7c0adc0 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -27,7 +27,7 @@ import RootLayout from './layout/RootLayout' import { IRootContext, MenuItem } from './global' import { DevTools } from 'jotai-devtools' import { useAtomValue } from 'jotai' -import { userMenuDataAtom } from '@/store/user.ts' +import { userMenuDataAtom } from '@/store/system/user.ts' const PageRootLayout = () => { return diff --git a/src/service/system.ts b/src/service/system.ts index 0b9fcc9..9b7fc02 100644 --- a/src/service/system.ts +++ b/src/service/system.ts @@ -1,42 +1,38 @@ import { IPageResult } from '@/global' -import { IUser, IUserInfo } from '@/types/user' import request from '../request.ts' -import { LoginRequest, LoginResponse } from '@/types/login' import { createCURD } from '@/service/base.ts' -import { IMenu } from '@/types/menus' -import { IRole } from '@/types/roles' -import { IDepartment } from '@/types/department' +import { System } from '@/types' const systemServ = { dept: { - ...createCURD('/sys/dept'), + ...createCURD('/sys/dept'), tree: () => { - return request.get<{ tree: IDepartment }>('/sys/dept/tree') + return request.get<{ tree: System.IDepartment }>('/sys/dept/tree') } }, menus: { - ...createCURD('/sys/menu') + ...createCURD('/sys/menu') }, - login: (data: LoginRequest) => { - return request.post('/sys/login', data) + login: (data: System.LoginRequest) => { + return request.post('/sys/login', data) }, logout:()=>{ // }, user: { - ...createCURD('/sys/user'), + ...createCURD('/sys/user'), current: () => { - return request.get('/sys/user/info') + return request.get('/sys/user/info') }, menus: () => { - return request.get>('/sys/user/menus') + return request.get>('/sys/user/menus') }, resetPassword: (id: number) => { return request.post(`/sys/user/reset/password`, { id }) } }, role: { - ...createCURD('/sys/role') + ...createCURD('/sys/role') }, logs: { login: { diff --git a/src/service/websites.ts b/src/service/websites.ts index f3cf596..0191bd7 100644 --- a/src/service/websites.ts +++ b/src/service/websites.ts @@ -1,21 +1,18 @@ import { createCURD } from '@/service/base.ts' -import { ISSL } from '@/types/website/ssl' -import { IAcmeAccount } from '@/types/website/acme' -import { IDnsAccount } from '@/types/website/dns' -import { ICA } from '@/types/website/ca' +import { WebSite } from '@/types' const websitesServ = { ssl: { - ...createCURD('/website/ssl') + ...createCURD('/website/ssl') }, acme:{ - ...createCURD('/website/acme') + ...createCURD('/website/acme') }, dns:{ - ...createCURD('/website/dns') + ...createCURD('/website/dns') }, ca:{ - ...createCURD('/website/ca') + ...createCURD('/website/ca') } } diff --git a/src/store/department.ts b/src/store/department.ts deleted file mode 100644 index 48479d1..0000000 --- a/src/store/department.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' -import systemServ from '@/service/system.ts' -import { IApiResult, IPage } from '@/global' -import { IDepartment } from '@/types/department' -import { atom, createStore } from 'jotai' -import { t } from 'i18next' -import { message } from 'antd' - - -const store = createStore() - -export const departPageAtom = atom({}) - -export const defaultDepart = { - id: 0, - parent_id: 0, - name: '', - manager_user_id: 0, - phone: '', - sort: 0, -} as IDepartment - -export const batchIdsAtom = atom([]) - -export const selectedDepartAtom = atom({} as IDepartment) - -export const departTreeAtom = atomWithQuery(() => { - - return { - queryKey: [ 'departTree' ], - queryFn: async () => { - return await systemServ.dept.tree() - }, - select: (res) => { - return res.data.tree ?? [] - } - } -}) - -export const saveOrUpdateDepartAtom = atomWithMutation((get) => { - - return { - mutationKey: [ 'saveOrUpdateDepart' ], - mutationFn: async (data: IDepartment) => { - if (data.id) { - return await systemServ.dept.update(data) - } - return await systemServ.dept.add(data) - }, - onSuccess: (res) => { - const isAdd = !!res.data?.id - message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) - - if (isAdd) { - store.set(selectedDepartAtom, prev => ({ - ...prev, - id: res.data.id - })) - } - - get(queryClientAtom).invalidateQueries({ queryKey: [ 'departTree' ] }).then() - } - } - -}) - - -export const deleteDepartAtom = atomWithMutation((get) => { - - return { - mutationKey: [ 'deleteDepart', get(batchIdsAtom) ], - mutationFn: async (ids: number[]) => { - return await systemServ.dept.batchDelete(ids) - }, - onSuccess: () => { - message.success(t('message.deleteSuccess', '删除成功')) - store.set(batchIdsAtom, []) - get(queryClientAtom).invalidateQueries({ queryKey: [ 'departTree' ] }).then() - - } - } - -}) - diff --git a/src/store/logs.ts b/src/store/logs.ts deleted file mode 100644 index ae40ea6..0000000 --- a/src/store/logs.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { atomWithMutation, atomWithQuery } from 'jotai-tanstack-query' -import { atom } from 'jotai/index' -import { IPage } from '@/global' -import systemServ from '@/service/system.ts' -import { message } from 'antd' -import { t } from '@/i18n.ts' - - -export const loginLogPageAtom = atom({ - page: 1, - pageSize: 10, -}) - -type LogSearch = { - key?: string, -} - -export const loginLogSearchAtom = atom({ - key: '' -}) - -export const loginLogsAtom = atomWithQuery((get) => ({ - queryKey: [ 'loginLogs', get(loginLogPageAtom), get(loginLogSearchAtom) ], - queryFn: async ({ queryKey: [ , page, search ] }) => { - return await systemServ.logs.login.list({ - ...page as any, - ...search as any, - }) - }, - select: (data) => { - return data.data - }, -})) - -export const loginLogIdsAtom = atom([]) - -export const deleteLoginLogAtom = atomWithMutation((get) => ({ - mutationKey: [ 'deleteLoginLog' ], - mutationFn: async (ids) => { - return await systemServ.logs.login.batchDelete(ids) - }, - onSuccess: () => { - message.success(t('message.deleteSuccess', '删除成功')) - get(loginLogsAtom).refetch() - }, -})) - -//clear -export const clearLoginLogAtom = atomWithMutation((get) => ({ - mutationKey: [ 'clearLoginLog' ], - mutationFn: async (params) => { - return await systemServ.logs.login.clear(params) - }, - onSuccess: () => { - message.success(t('message.deleteSuccess', '删除成功')) - get(loginLogsAtom).refetch() - } -})) \ No newline at end of file diff --git a/src/store/menu.ts b/src/store/menu.ts deleted file mode 100644 index 27bf08a..0000000 --- a/src/store/menu.ts +++ /dev/null @@ -1,88 +0,0 @@ -import systemServ from '@/service/system.ts' -import { IApiResult, IPage, MenuItem } from '@/global' -import { IMenu } from '@/types/menus' -import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' -import { atom, createStore } from 'jotai' -import { message } from 'antd' -import { t } from '@/i18n.ts' - - -export const defaultMenu = { - parent_id: 0, - type: 'menu', - name: '', - title: '', - icon: '', - path: '', - component: '', - sort: 0, - id: 0, - button: [], -} as unknown as MenuItem - -export const menuPageAtom = atom({}) - -const store = createStore() - -export const menuDataAtom = atomWithQuery((get) => { - - return { - queryKey: [ 'menus', get(menuPageAtom) ], - queryFn: async ({ queryKey: [ , page ] }) => { - return await systemServ.menus.list(page) - }, - select: (res) => { - return res.data.rows ?? [] - } - } -}) - - -export const selectedMenuIdAtom = atom(0) -export const selectedMenuAtom = atom({} as MenuItem) -export const byIdMenuAtom = atomWithQuery((get) => ({ - queryKey: [ 'selectedMenu', get(selectedMenuIdAtom) ], - queryFn: async ({ queryKey: [ , id ] }) => { - return await systemServ.menus.info(id as number) - }, - select: data => data.data, -})) - - -export const saveOrUpdateMenuAtom = atomWithMutation((get) => { - - return { - mutationKey: [ 'updateMenu', get(selectedMenuIdAtom) ], - mutationFn: async (data: IMenu) => { - if (data.id === 0) { - return await systemServ.menus.add(data) - } - return await systemServ.menus.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: [ 'menus', get(menuPageAtom) ] }).then() - } - } -}) - -export const batchIdsAtom = atom([]) - -export const deleteMenuAtom = atomWithMutation((get) => { - return { - mutationKey: [ 'deleteMenu', get(batchIdsAtom) ], - mutationFn: async (ids?: number[]) => { - return await systemServ.menus.batchDelete(ids ?? get(batchIdsAtom)) - }, - onSuccess: () => { - message.success(t('message.deleteSuccess', '删除成功')) - store.set(batchIdsAtom, []) - get(queryClientAtom).invalidateQueries({ queryKey: [ 'menus', get(menuPageAtom) ] }).then() - } - } -}) \ No newline at end of file diff --git a/src/store/role.ts b/src/store/role.ts deleted file mode 100644 index a6b7952..0000000 --- a/src/store/role.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { convertToBool } from '@/utils' -import { atom } from 'jotai/index' -import { IRole } from '@/types/roles' -import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' -import { IApiResult, IPage } from '@/global' -import systemServ from '@/service/system.ts' -import { message } from 'antd' -import { t } from '@/i18n.ts' - -type SearchParams = IPage & { - key?: string -} - -export const idAtom = atom(0) - -export const roleIdsAtom = atom([]) - -export const roleAtom = atom(undefined as unknown as IRole) - -export const searchAtom = atom({ - key: '' -} as SearchParams) - -export const pageAtom = atom({ - pageSize: 10, - page: 1, -}) - -export const rolesAtom = atomWithQuery((get) => { - return { - queryKey: [ 'roles', get(searchAtom) ], - queryFn: async ({ queryKey: [ , params ] }) => { - return await systemServ.role.list(params as SearchParams) - }, - select: res => { - const data = res.data - data.rows = data.rows?.map(row => { - return { - ...row, - status: convertToBool(row.status) - } - }) - return data - } - } -}) - -//saveOrUpdateRoleAtom - -export const saveOrUpdateRoleAtom = atomWithMutation((get) => { - - return { - mutationKey: [ 'updateMenu' ], - mutationFn: async (data) => { - data.status = data.status ? '1' : '0' - if (data.id === 0) { - return await systemServ.role.add(data) - } - return await systemServ.role.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: [ 'roles', get(searchAtom) ] }) - - return res - } - } -}) - -export const deleteRoleAtom = atomWithMutation((get) => { - return { - mutationKey: [ 'deleteMenu' ], - mutationFn: async (ids: number[]) => { - return await systemServ.role.batchDelete(ids ?? get(roleIdsAtom)) - }, - onSuccess: (res) => { - message.success('message.deleteSuccess') - //更新列表 - get(queryClientAtom).invalidateQueries({ queryKey: [ 'roles', get(searchAtom) ] }) - return res - } - } -}) \ No newline at end of file diff --git a/src/store/system/department.ts b/src/store/system/department.ts new file mode 100644 index 0000000..443a313 --- /dev/null +++ b/src/store/system/department.ts @@ -0,0 +1,84 @@ +import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' +import systemServ from '@/service/system.ts' +import { IApiResult, IPage } from '@/global' +import { atom, createStore } from 'jotai' +import { t } from 'i18next' +import { message } from 'antd' +import { System } from '@/types' + + +const store = createStore() + +export const departPageAtom = atom({}) + +export const defaultDepart = { + id: 0, + parent_id: 0, + name: '', + manager_user_id: 0, + phone: '', + sort: 0, +} as System.IDepartment + +export const batchIdsAtom = atom([]) + +export const selectedDepartAtom = atom({} as System.IDepartment) + +export const departTreeAtom = atomWithQuery(() => { + + return { + queryKey: [ 'departTree' ], + queryFn: async () => { + return await systemServ.dept.tree() + }, + select: (res) => { + return res.data.tree ?? [] + } + } +}) + +export const saveOrUpdateDepartAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'saveOrUpdateDepart' ], + mutationFn: async (data: System.IDepartment) => { + if (data.id) { + return await systemServ.dept.update(data) + } + return await systemServ.dept.add(data) + }, + onSuccess: (res) => { + const isAdd = !!res.data?.id + message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) + + if (isAdd) { + store.set(selectedDepartAtom, prev => ({ + ...prev, + id: res.data.id + })) + } + + get(queryClientAtom).invalidateQueries({ queryKey: [ 'departTree' ] }).then() + } + } + +}) + + +export const deleteDepartAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'deleteDepart', get(batchIdsAtom) ], + mutationFn: async (ids: number[]) => { + return await systemServ.dept.batchDelete(ids) + }, + onSuccess: () => { + message.success(t('message.deleteSuccess', '删除成功')) + store.set(batchIdsAtom, []) + get(queryClientAtom).invalidateQueries({ queryKey: [ 'departTree' ] }).then() + + } + } + +}) + diff --git a/src/store/system/logs.ts b/src/store/system/logs.ts new file mode 100644 index 0000000..ae40ea6 --- /dev/null +++ b/src/store/system/logs.ts @@ -0,0 +1,58 @@ +import { atomWithMutation, atomWithQuery } from 'jotai-tanstack-query' +import { atom } from 'jotai/index' +import { IPage } from '@/global' +import systemServ from '@/service/system.ts' +import { message } from 'antd' +import { t } from '@/i18n.ts' + + +export const loginLogPageAtom = atom({ + page: 1, + pageSize: 10, +}) + +type LogSearch = { + key?: string, +} + +export const loginLogSearchAtom = atom({ + key: '' +}) + +export const loginLogsAtom = atomWithQuery((get) => ({ + queryKey: [ 'loginLogs', get(loginLogPageAtom), get(loginLogSearchAtom) ], + queryFn: async ({ queryKey: [ , page, search ] }) => { + return await systemServ.logs.login.list({ + ...page as any, + ...search as any, + }) + }, + select: (data) => { + return data.data + }, +})) + +export const loginLogIdsAtom = atom([]) + +export const deleteLoginLogAtom = atomWithMutation((get) => ({ + mutationKey: [ 'deleteLoginLog' ], + mutationFn: async (ids) => { + return await systemServ.logs.login.batchDelete(ids) + }, + onSuccess: () => { + message.success(t('message.deleteSuccess', '删除成功')) + get(loginLogsAtom).refetch() + }, +})) + +//clear +export const clearLoginLogAtom = atomWithMutation((get) => ({ + mutationKey: [ 'clearLoginLog' ], + mutationFn: async (params) => { + return await systemServ.logs.login.clear(params) + }, + onSuccess: () => { + message.success(t('message.deleteSuccess', '删除成功')) + get(loginLogsAtom).refetch() + } +})) \ No newline at end of file diff --git a/src/store/system/menu.ts b/src/store/system/menu.ts new file mode 100644 index 0000000..6da3723 --- /dev/null +++ b/src/store/system/menu.ts @@ -0,0 +1,89 @@ +import systemServ from '@/service/system.ts' +import { IApiResult, IPage, MenuItem } from '@/global' +import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' +import { atom, createStore } from 'jotai' +import { message } from 'antd' +import { t } from '@/i18n.ts' +import { System } from '@/types' + + + +export const defaultMenu = { + parent_id: 0, + type: 'menu', + name: '', + title: '', + icon: '', + path: '', + component: '', + sort: 0, + id: 0, + button: [], +} as unknown as MenuItem + +export const menuPageAtom = atom({}) + +const store = createStore() + +export const menuDataAtom = atomWithQuery((get) => { + + return { + queryKey: [ 'menus', get(menuPageAtom) ], + queryFn: async ({ queryKey: [ , page ] }) => { + return await systemServ.menus.list(page) + }, + select: (res) => { + return res.data.rows ?? [] + } + } +}) + + +export const selectedMenuIdAtom = atom(0) +export const selectedMenuAtom = atom({} as MenuItem) +export const byIdMenuAtom = atomWithQuery((get) => ({ + queryKey: [ 'selectedMenu', get(selectedMenuIdAtom) ], + queryFn: async ({ queryKey: [ , id ] }) => { + return await systemServ.menus.info(id as number) + }, + select: data => data.data, +})) + + +export const saveOrUpdateMenuAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'updateMenu', get(selectedMenuIdAtom) ], + mutationFn: async (data: System.IMenu) => { + if (data.id === 0) { + return await systemServ.menus.add(data) + } + return await systemServ.menus.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: [ 'menus', get(menuPageAtom) ] }).then() + } + } +}) + +export const batchIdsAtom = atom([]) + +export const deleteMenuAtom = atomWithMutation((get) => { + return { + mutationKey: [ 'deleteMenu', get(batchIdsAtom) ], + mutationFn: async (ids?: number[]) => { + return await systemServ.menus.batchDelete(ids ?? get(batchIdsAtom)) + }, + onSuccess: () => { + message.success(t('message.deleteSuccess', '删除成功')) + store.set(batchIdsAtom, []) + get(queryClientAtom).invalidateQueries({ queryKey: [ 'menus', get(menuPageAtom) ] }).then() + } + } +}) \ No newline at end of file diff --git a/src/store/system/role.ts b/src/store/system/role.ts new file mode 100644 index 0000000..4ac38eb --- /dev/null +++ b/src/store/system/role.ts @@ -0,0 +1,88 @@ +import { convertToBool } from '@/utils' +import { atom } from 'jotai/index' +import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' +import { IApiResult, IPage } from '@/global' +import systemServ from '@/service/system.ts' +import { message } from 'antd' +import { t } from '@/i18n.ts' +import { System } from '@/types' + +type SearchParams = IPage & { + key?: string +} + +export const idAtom = atom(0) + +export const roleIdsAtom = atom([]) + +export const roleAtom = atom(undefined as unknown as System.IRole) + +export const searchAtom = atom({ + key: '' +} as SearchParams) + +export const pageAtom = atom({ + pageSize: 10, + page: 1, +}) + +export const rolesAtom = atomWithQuery((get) => { + return { + queryKey: [ 'roles', get(searchAtom) ], + queryFn: async ({ queryKey: [ , params ] }) => { + return await systemServ.role.list(params as SearchParams) + }, + select: res => { + const data = res.data + data.rows = data.rows?.map(row => { + return { + ...row, + status: convertToBool(row.status) + } + }) + return data + } + } +}) + +//saveOrUpdateRoleAtom + +export const saveOrUpdateRoleAtom = atomWithMutation((get) => { + + return { + mutationKey: [ 'updateMenu' ], + mutationFn: async (data) => { + data.status = data.status ? '1' : '0' + if (data.id === 0) { + return await systemServ.role.add(data) + } + return await systemServ.role.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: [ 'roles', get(searchAtom) ] }) + + return res + } + } +}) + +export const deleteRoleAtom = atomWithMutation((get) => { + return { + mutationKey: [ 'deleteMenu' ], + mutationFn: async (ids: number[]) => { + return await systemServ.role.batchDelete(ids ?? get(roleIdsAtom)) + }, + onSuccess: (res) => { + message.success('message.deleteSuccess') + //更新列表 + get(queryClientAtom).invalidateQueries({ queryKey: [ 'roles', get(searchAtom) ] }) + return res + } + } +}) \ No newline at end of file diff --git a/src/store/system/user.ts b/src/store/system/user.ts new file mode 100644 index 0000000..8f482d6 --- /dev/null +++ b/src/store/system/user.ts @@ -0,0 +1,164 @@ +import { appAtom, setToken } from '@/store/system.ts' +import { atom } from 'jotai/index' +import { IApiResult, IAuth, IPage, IPageResult, MenuItem } from '@/global' +import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' +import systemServ from '@/service/system.ts' +import { formatMenuData, isDev } from '@/utils' +import { message } from 'antd' +import { t } from 'i18next' +import { System } from '@/types' + +export const authAtom = atom({ + isLogin: false, + authKey: [] +}) + +const devLogin = { + username: 'SupperAdmin', + password: 'kk123456', + code: '123456' +} +export const loginFormAtom = atom({ + ...(isDev ? devLogin : {}) +} as System.LoginRequest) + +export const loginAtom = atomWithMutation((get) => ({ + mutationKey: [ 'login' ], + mutationFn: async (params) => { + return await systemServ.login(params) + }, + onSuccess: (res) => { + message.success(t('login.success')) + // console.log('login success', res) + get(userMenuDataAtom).refetch().then() + return res.data + }, + retry: false, +})) + +export const logoutAtom = atomWithMutation(() => ({ + mutationKey: [ 'logout' ], + mutationFn: async () => { + setToken('') + return true + }, +})) + +export const currentUserAtom = atomWithQuery, any, System.IUserInfo>((get) => { + return { + queryKey: [ 'user_info', get(appAtom).token ], + queryFn: async () => { + return await systemServ.user.current() + }, + select: (data) => { + return data.data + } + } +}) + +export const userMenuDataAtom = atomWithQuery>, any, MenuItem[]>((get) => ({ + enabled: false, + queryKey: [ 'user_menus', get(appAtom).token ], + queryFn: async () => { + return await systemServ.user.menus() + }, + select: (data) => { + return formatMenuData(data.data.rows as any ?? []) + }, + retry: false, +})) + +export type UserSearch = { + dept_id?: any, + key?: string +} + +export const userSearchAtom = atom({} as UserSearch) + +//=======user page store====== + +export const userPageAtom = atom({ + pageSize: 10, + page: 1 +}) + +// user list +export const userListAtom = atomWithQuery((get) => { + return { + queryKey: [ 'user_list', get(userSearchAtom), get(userPageAtom) ], + queryFn: async ({ queryKey: [ , params, page ] }) => { + return await systemServ.user.list({ + ...params as any, + ...page as any, + }) + }, + select: (data) => { + return data.data + }, + + } +}) + +// user selected +export const userSelectedAtom = atom({} as System.IUser) + +export const defaultUserData = { + id: 0, + dept_id: 0, + role_id: 0, +} as System.IUser + +//save or update user +export const saveOrUpdateUserAtom = atomWithMutation((get) => ({ + mutationKey: [ 'save_user' ], + mutationFn: async (params) => { + params.status = params.status ? '1' : '0' + const isAdd = 0 === params.id + if (isAdd) { + return await systemServ.user.add(params) + } + return await systemServ.user.update(params) + }, + onSuccess: (res) => { + const isAdd = !!res.data?.id + message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) + + //刷新userList + get(queryClientAtom).invalidateQueries({ queryKey: [ 'user_list' ] }) + + return res + }, +})) + +//delete user + +export const batchUserIdsAtom = atom([]) +export const deleteUserAtom = atomWithMutation((get) => ({ + mutationKey: [ 'delete_user' ], + mutationFn: async (params) => { + return await systemServ.user.batchDelete(params) + }, + onSuccess: () => { + message.success(t('message.deleteSuccess', '删除成功')) + //刷新userList + get(queryClientAtom).invalidateQueries({ queryKey: [ 'user_list' ] }) + return true + }, +})) + +//reset password +export const resetPasswordAtom = atomWithMutation(() => ({ + mutationKey: [ 'reset_password' ], + mutationFn: async (id) => { + return await systemServ.user.resetPassword(id) + }, + onSuccess: () => { + message.success(t('message.resetSuccess', '重置成功')) + //刷新userList + // get(queryClientAtom).invalidateQueries({ queryKey: [ 'user_list' ] }) + return true + }, + onError: () => { + message.error(t('message.resetError', '重置失败')) + }, +})) diff --git a/src/store/user.ts b/src/store/user.ts deleted file mode 100644 index 0d9ca11..0000000 --- a/src/store/user.ts +++ /dev/null @@ -1,166 +0,0 @@ -import { appAtom, setToken } from '@/store/system.ts' -import { IMenu } from '@/types/menus' -import { IUser, IUserInfo } from '@/types/user' -import { atom } from 'jotai/index' -import { IApiResult, IAuth, IPage, IPageResult, MenuItem } from '@/global' -import { LoginRequest } from '@/types/login' -import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' -import systemServ from '@/service/system.ts' -import { formatMenuData, isDev } from '@/utils' -import { message } from 'antd' -import { t } from 'i18next' - -export const authAtom = atom({ - isLogin: false, - authKey: [] -}) - -const devLogin = { - username: 'SupperAdmin', - password: 'kk123456', - code: '123456' -} -export const loginFormAtom = atom({ - ...(isDev ? devLogin : {}) -} as LoginRequest) - -export const loginAtom = atomWithMutation((get) => ({ - mutationKey: [ 'login' ], - mutationFn: async (params) => { - return await systemServ.login(params) - }, - onSuccess: (res) => { - message.success(t('login.success')) - // console.log('login success', res) - get(userMenuDataAtom).refetch().then() - return res.data - }, - retry: false, -})) - -export const logoutAtom = atomWithMutation(() => ({ - mutationKey: [ 'logout' ], - mutationFn: async () => { - setToken('') - return true - }, -})) - -export const currentUserAtom = atomWithQuery, any, IUserInfo>((get) => { - return { - queryKey: [ 'user_info', get(appAtom).token ], - queryFn: async () => { - return await systemServ.user.current() - }, - select: (data) => { - return data.data - } - } -}) - -export const userMenuDataAtom = atomWithQuery>, any, MenuItem[]>((get) => ({ - enabled: false, - queryKey: [ 'user_menus', get(appAtom).token ], - queryFn: async () => { - return await systemServ.user.menus() - }, - select: (data) => { - return formatMenuData(data.data.rows as any ?? []) - }, - retry: false, -})) - -export type UserSearch = { - dept_id?: any, - key?: string -} - -export const userSearchAtom = atom({} as UserSearch) - -//=======user page store====== - -export const userPageAtom = atom({ - pageSize: 10, - page: 1 -}) - -// user list -export const userListAtom = atomWithQuery((get) => { - return { - queryKey: [ 'user_list', get(userSearchAtom), get(userPageAtom) ], - queryFn: async ({ queryKey: [ , params, page ] }) => { - return await systemServ.user.list({ - ...params as any, - ...page as any, - }) - }, - select: (data) => { - return data.data - }, - - } -}) - -// user selected -export const userSelectedAtom = atom({} as IUser) - -export const defaultUserData = { - id: 0, - dept_id: 0, - role_id: 0, -} as IUser - -//save or update user -export const saveOrUpdateUserAtom = atomWithMutation((get) => ({ - mutationKey: [ 'save_user' ], - mutationFn: async (params) => { - params.status = params.status ? '1' : '0' - const isAdd = 0 === params.id - if (isAdd) { - return await systemServ.user.add(params) - } - return await systemServ.user.update(params) - }, - onSuccess: (res) => { - const isAdd = !!res.data?.id - message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) - - //刷新userList - get(queryClientAtom).invalidateQueries({ queryKey: [ 'user_list' ] }) - - return res - }, -})) - -//delete user - -export const batchUserIdsAtom = atom([]) -export const deleteUserAtom = atomWithMutation((get) => ({ - mutationKey: [ 'delete_user' ], - mutationFn: async (params) => { - return await systemServ.user.batchDelete(params) - }, - onSuccess: () => { - message.success(t('message.deleteSuccess', '删除成功')) - //刷新userList - get(queryClientAtom).invalidateQueries({ queryKey: [ 'user_list' ] }) - return true - }, -})) - -//reset password -export const resetPasswordAtom = atomWithMutation(() => ({ - mutationKey: [ 'reset_password' ], - mutationFn: async (id) => { - return await systemServ.user.resetPassword(id) - }, - onSuccess: () => { - message.success(t('message.resetSuccess', '重置成功')) - //刷新userList - // get(queryClientAtom).invalidateQueries({ queryKey: [ 'user_list' ] }) - return true - }, - onError: () => { - message.error(t('message.resetError', '重置失败')) - }, -})) diff --git a/src/store/websites/acme.ts b/src/store/websites/acme.ts index f163984..676724a 100644 --- a/src/store/websites/acme.ts +++ b/src/store/websites/acme.ts @@ -1,10 +1,10 @@ import { atomWithMutation, atomWithQuery } from 'jotai-tanstack-query' -import { IAcmeAccount } from '@/types/website/acme' import websitesServ from '@/service/websites.ts' import { message } from 'antd' import { t } from 'i18next' import { IApiResult, IPage } from '@/global' import { atom } from 'jotai' +import { WebSite } from '@/types' export enum AcmeType { LetsEncrypt = 'letsencrypt', @@ -43,9 +43,9 @@ export const acmeListAtom = atomWithQuery(get => ({ })) //saveOrUpdate -export const saveOrUpdateAcmeAtom = atomWithMutation(get => ({ +export const saveOrUpdateAcmeAtom = atomWithMutation(get => ({ mutationKey: [ 'saveOrUpdateAcme' ], - mutationFn: async (data: IAcmeAccount) => { + mutationFn: async (data: WebSite.IAcmeAccount) => { if (data.id > 0) { return await websitesServ.acme.update(data) } diff --git a/src/store/websites/ca.ts b/src/store/websites/ca.ts index 7421360..e8c0898 100644 --- a/src/store/websites/ca.ts +++ b/src/store/websites/ca.ts @@ -4,7 +4,7 @@ import { atomWithMutation, atomWithQuery } from 'jotai-tanstack-query' import websitesServ from '@/service/websites.ts' import { message, } from 'antd' import { t } from 'i18next' -import { ICA } from '@/types/website/ca' +import { WebSite } from '@/types' export const caPageAtom = atom({ page: 1, pageSize: 10, @@ -22,9 +22,9 @@ export const caListAtom = atomWithQuery(get => ({ })) //saveOrUpdate -export const saveOrUpdateCaAtom = atomWithMutation(get => ({ +export const saveOrUpdateCaAtom = atomWithMutation(get => ({ mutationKey: [ 'saveOrUpdateCA' ], - mutationFn: async (data: ICA) => { + mutationFn: async (data: WebSite.ICA) => { if (data.id > 0) { return await websitesServ.ca.update(data) } diff --git a/src/store/websites/dns.ts b/src/store/websites/dns.ts index c27af6a..1f7d804 100644 --- a/src/store/websites/dns.ts +++ b/src/store/websites/dns.ts @@ -4,7 +4,7 @@ import { IApiResult, IPage } from '@/global' import { atomWithMutation, atomWithQuery } from 'jotai-tanstack-query' import websitesServ from '@/service/websites.ts' import { message } from 'antd' -import { IDnsAccount } from '@/types/website/dns' +import { WebSite } from '@/types' export const DNSTypeEnum = { AliYun: 'AliYun', @@ -73,9 +73,9 @@ export const dnsListAtom = atomWithQuery(get => ({ })) //saveOrUpdate -export const saveOrUpdateDNSAtom = atomWithMutation(get => ({ +export const saveOrUpdateDNSAtom = atomWithMutation(get => ({ mutationKey: [ 'saveOrUpdatedDNS' ], - mutationFn: async (data: IDnsAccount) => { + mutationFn: async (data: WebSite.IDnsAccount) => { if (data.id > 0) { return await websitesServ.dns.update(data) } diff --git a/src/store/websites/ssl.ts b/src/store/websites/ssl.ts index c3b1297..017923d 100644 --- a/src/store/websites/ssl.ts +++ b/src/store/websites/ssl.ts @@ -59,11 +59,6 @@ export const saveOrUpdateSslAtom = atomWithMutation(get => ({ return await websitesServ.ssl.update(data) } }, - // onError: (error: any) => { - // const msg = error?.data?.message ||t('message.saveFailed', '保存失败') - // message.error(msg) - // return error - // }, onSuccess: (res) => { const isAdd = !!res.data?.id message.success(t(isAdd ? 'message.saveSuccess' : 'message.editSuccess', '保存成功')) diff --git a/src/types/department.d.ts b/src/types/department.d.ts deleted file mode 100644 index 835c1ba..0000000 --- a/src/types/department.d.ts +++ /dev/null @@ -1,17 +0,0 @@ - -export interface IDepartment { - id: number, - parent_id: number, - manager_user_id: number, - phone: string, - name: string, - sort: number, - status: string, - remark: string - - children?: IDepartment[] -} - -export interface DepartmentRequest extends IDepartment { - -} diff --git a/src/types/index.d.ts b/src/types/index.d.ts new file mode 100644 index 0000000..0272155 --- /dev/null +++ b/src/types/index.d.ts @@ -0,0 +1,14 @@ +export namespace System { + export { IDepartment } from './system/department' + export { IUser, IUserInfo } from './system/user' + export { LoginRequest, LoginResponse } from './system/login' + export { IRole } from './system/roles' + export { IMenu } from './system/menus' +} + +export namespace WebSite { + export { IAcmeAccount } from './website/acme' + export { ICA } from './website/ca' + export { IDnsAccount } from './website/dns' + export { ISSL, ProviderType, SSLSearchParam } from './website/ssl' +} \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts deleted file mode 100644 index ebe95fa..0000000 --- a/src/types/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './department' -export * from './user' -export * from './login' -export * from './roles' -export * from './menus' diff --git a/src/types/login.d.ts b/src/types/login.d.ts deleted file mode 100644 index b22a93e..0000000 --- a/src/types/login.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -export interface LoginLogRequest { - key: string, - start: string, - end: string, - order: string, - prop: string, - page: number, - pageSize: number -} - -export interface LoginRequest { - 'mfa_status': boolean; - 'username': string; - 'password': string; - 'code': string; -} - -export interface LoginResponse { - 'token': string; - 'mfa_status': boolean; -} - diff --git a/src/types/logs.d.ts b/src/types/logs.d.ts deleted file mode 100644 index ed5285a..0000000 --- a/src/types/logs.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -interface ILoginLog { - id: string; - username: string; - ip: string; - user_agent: string; - os: string; - browser: string; - status: string; - note: string; - created_at: string; -} \ No newline at end of file diff --git a/src/types/menus.d.ts b/src/types/menus.d.ts deleted file mode 100644 index fa746ab..0000000 --- a/src/types/menus.d.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { ReactNode } from 'react' - -export interface MenuButton { - code: string, - label: string -} - - -interface Meta { -} - -export interface IMenu { - id: number, - key: string, - parent_id: number, - sort: number, - code: string, - name: string, - title: string, - component: string, - icon: string | ReactNode, - description: string, - sequence: number, - type: string, - path: string, - properties: string, - status: string, - parent_path: string, - affix: boolean, - redirect: string, - button: MenuButton[], - meta: Meta, - - children: IMenu[] -} - -export interface MenuRequest extends IMenu { - -} - -export interface MenuResponse { - id: number, -} - - -export interface MenuDropRequest { - source: number, - target: number, - action: string -} - - -export interface MenuListRequest { - order: string, - prop: string, - page: number, - pageSize: number -} - - -export interface MenuListResponse { - page: number, - pageSize: number, - total: number, - rows: IMenu[] -} \ No newline at end of file diff --git a/src/types/roles.d.ts b/src/types/roles.d.ts deleted file mode 100644 index 286cd6c..0000000 --- a/src/types/roles.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -export interface IRole { - id: number, - sort: number, - code: string, - name: string, - description: string, - sequence: number, - status: string | boolean, - menu_ids: number[] -} - -export interface RoleRequest extends IRole { - -} - -export interface RoleListResponse { - key: string, - order: string, - prop: string, - page: number, - pageSize: number - -} - -export interface RoleListResponse { - page: number, - pageSize: number, - total: number, - rows: IRole[] -} \ No newline at end of file diff --git a/src/types/system/department.d.ts b/src/types/system/department.d.ts new file mode 100644 index 0000000..835c1ba --- /dev/null +++ b/src/types/system/department.d.ts @@ -0,0 +1,17 @@ + +export interface IDepartment { + id: number, + parent_id: number, + manager_user_id: number, + phone: string, + name: string, + sort: number, + status: string, + remark: string + + children?: IDepartment[] +} + +export interface DepartmentRequest extends IDepartment { + +} diff --git a/src/types/system/login.d.ts b/src/types/system/login.d.ts new file mode 100644 index 0000000..d874235 --- /dev/null +++ b/src/types/system/login.d.ts @@ -0,0 +1,14 @@ + + +export interface LoginRequest { + 'mfa_status': boolean; + 'username': string; + 'password': string; + 'code': string; +} + +export interface LoginResponse { + 'token': string; + 'mfa_status': boolean; +} + diff --git a/src/types/system/logs.d.ts b/src/types/system/logs.d.ts new file mode 100644 index 0000000..ed5285a --- /dev/null +++ b/src/types/system/logs.d.ts @@ -0,0 +1,11 @@ +interface ILoginLog { + id: string; + username: string; + ip: string; + user_agent: string; + os: string; + browser: string; + status: string; + note: string; + created_at: string; +} \ No newline at end of file diff --git a/src/types/system/menus.d.ts b/src/types/system/menus.d.ts new file mode 100644 index 0000000..7d512ba --- /dev/null +++ b/src/types/system/menus.d.ts @@ -0,0 +1,34 @@ + +export interface MenuButton { + code: string, + label: string +} + + +export interface Meta { +} + +export interface IMenu { + id: number, + key: string, + parent_id: number, + sort: number, + code: string, + name: string, + title: string, + component: string, + icon: string | any, + description: string, + sequence: number, + type: string, + path: string, + properties: string, + status: string, + parent_path: string, + affix: boolean, + redirect: string, + button: MenuButton[], + meta: Meta, + + children: IMenu[] +} diff --git a/src/types/system/roles.d.ts b/src/types/system/roles.d.ts new file mode 100644 index 0000000..ad87345 --- /dev/null +++ b/src/types/system/roles.d.ts @@ -0,0 +1,10 @@ +export interface IRole { + id: number, + sort: number, + code: string, + name: string, + description: string, + sequence: number, + status: string | boolean, + menu_ids: number[] +} diff --git a/src/types/system/user.d.ts b/src/types/system/user.d.ts new file mode 100644 index 0000000..923c5ce --- /dev/null +++ b/src/types/system/user.d.ts @@ -0,0 +1,26 @@ + + +export interface IUser { + id: number, + created_at: string, + created_by: number, + updated_at: string, + updated_by: number, + username: string, + role_id: number, + dept_id: number, + dept_name: string, + name: string, + phone: string, + email: string, + remark: string, + status: string, + mfa_status: boolean, +} + +export interface IUserInfo { + info: IUser, + buttons: string[], + nickname: string, + avatar: string +} \ No newline at end of file diff --git a/src/types/user.d.ts b/src/types/user.d.ts deleted file mode 100644 index 923c5ce..0000000 --- a/src/types/user.d.ts +++ /dev/null @@ -1,26 +0,0 @@ - - -export interface IUser { - id: number, - created_at: string, - created_by: number, - updated_at: string, - updated_by: number, - username: string, - role_id: number, - dept_id: number, - dept_name: string, - name: string, - phone: string, - email: string, - remark: string, - status: string, - mfa_status: boolean, -} - -export interface IUserInfo { - info: IUser, - buttons: string[], - nickname: string, - avatar: string -} \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index 69dd807..954ceb7 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,4 @@ -import { IMenu } from '@/types/menus' +import { IMenu } from '@/types/system/menus' import { FiledNames, FlattenData, MenuItem, TreeItem } from '@/global' import { getIcon } from '@/components/icon' import { TreeDataNode } from 'antd' diff --git a/src/utils/uuid.ts b/src/utils/uuid.ts index 6f32f94..86a7598 100644 --- a/src/utils/uuid.ts +++ b/src/utils/uuid.ts @@ -1,5 +1,3 @@ -import { MenuItem } from '@/global' -import { TreeDataNode } from 'antd' export function generateUUID() { if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {