diff --git a/src/assets/css/pages/system/settings.scss b/src/assets/css/pages/system/settings.scss index 5af3198..032a7dc 100644 --- a/src/assets/css/pages/system/settings.scss +++ b/src/assets/css/pages/system/settings.scss @@ -5,9 +5,13 @@ padding: 30px; gap: 20px; - .root-row { + .root-col { gap: 20px; + > * { + flex: 0 0 auto; + } + .settings-card { padding: 20px; gap: 20px; diff --git a/src/pages/system/settings/BaseSettings.tsx b/src/pages/system/settings/BaseSettings.tsx new file mode 100644 index 0000000..62402f6 --- /dev/null +++ b/src/pages/system/settings/BaseSettings.tsx @@ -0,0 +1,81 @@ +import React from 'react' +import { useUpdatedEffect } from '@/util/hooks' +import { hasPermission } from '@/util/auth' +import { r_sys_settings_base_get, r_sys_settings_base_update } from '@/services/system' +import { SettingsCard } from '@/pages/system/settings' + +const BaseSettings: React.FC = () => { + const [baseForm] = AntdForm.useForm() + const baseFormValues = AntdForm.useWatch([], baseForm) + const [loading, setLoading] = useState(false) + + const handleOnReset = () => { + getBaseSettings() + } + + const handleOnSave = () => { + void r_sys_settings_base_update(baseFormValues).then((res) => { + const response = res.data + if (response.success) { + void message.success('保存设置成功') + getBaseSettings() + } else { + void message.error('保存设置失败,请稍后重试') + } + }) + } + + const getBaseSettings = () => { + if (loading) { + return + } + + setLoading(true) + void r_sys_settings_base_get().then((res) => { + const response = res.data + if (response.success) { + const data = response.data + data && baseForm.setFieldsValue(data) + setLoading(false) + } + }) + } + + useUpdatedEffect(() => { + getBaseSettings() + }, []) + + return ( + <> + + + + + + + + + + + + + + + + + + ) +} + +export default BaseSettings diff --git a/src/pages/system/Settings.tsx b/src/pages/system/settings/MailSettings.tsx similarity index 52% rename from src/pages/system/Settings.tsx rename to src/pages/system/settings/MailSettings.tsx index f78bc9c..cd0fd51 100644 --- a/src/pages/system/Settings.tsx +++ b/src/pages/system/settings/MailSettings.tsx @@ -1,55 +1,13 @@ import React from 'react' import Icon from '@ant-design/icons' -import '@/assets/css/pages/system/settings.scss' import { useUpdatedEffect } from '@/util/hooks' import { hasPermission } from '@/util/auth' import { - r_sys_settings_base_get, - r_sys_settings_base_update, r_sys_settings_mail_get, r_sys_settings_mail_send, r_sys_settings_mail_update } from '@/services/system' -import FitFullscreen from '@/components/common/FitFullscreen' -import HideScrollbar from '@/components/common/HideScrollbar' -import Card from '@/components/common/Card' -import FlexBox from '@/components/common/FlexBox' -import LoadingMask from '@/components/common/LoadingMask' -import Permission from '@/components/common/Permission' - -interface SettingsCardProps extends React.PropsWithChildren { - icon: IconComponent - title: string - loading?: boolean - modifyOperationCode?: string - expand?: React.ReactNode - onReset?: () => void - onSave?: () => void -} -const SettingsCard: React.FC = (props) => { - return ( - - - - -
{props.title}
- {!props.loading ? ( - - {props.expand} - - - - - - - - ) : undefined} -
- -
-
- ) -} +import { SettingsCard } from '@/pages/system/settings' const MailSettings: React.FC = () => { const [modal, contextHolder] = AntdModal.useModal() @@ -194,99 +152,4 @@ const MailSettings: React.FC = () => { ) } -const BaseSettings: React.FC = () => { - const [baseForm] = AntdForm.useForm() - const baseFormValues = AntdForm.useWatch([], baseForm) - const [loading, setLoading] = useState(false) - - const handleOnReset = () => { - getBaseSettings() - } - - const handleOnSave = () => { - void r_sys_settings_base_update(baseFormValues).then((res) => { - const response = res.data - if (response.success) { - void message.success('保存设置成功') - getBaseSettings() - } else { - void message.error('保存设置失败,请稍后重试') - } - }) - } - - const getBaseSettings = () => { - if (loading) { - return - } - - setLoading(true) - void r_sys_settings_base_get().then((res) => { - const response = res.data - if (response.success) { - const data = response.data - data && baseForm.setFieldsValue(data) - setLoading(false) - } - }) - } - - useUpdatedEffect(() => { - getBaseSettings() - }, []) - - return ( - <> - - - - - - - - - - - - - - - - - - ) -} - -const Settings: React.FC = () => { - return ( - <> - - - - - - - - - - - - - - - - ) -} - -export default Settings +export default MailSettings diff --git a/src/pages/system/settings/index.tsx b/src/pages/system/settings/index.tsx new file mode 100644 index 0000000..7da663d --- /dev/null +++ b/src/pages/system/settings/index.tsx @@ -0,0 +1,70 @@ +import React from 'react' +import Icon from '@ant-design/icons' +import '@/assets/css/pages/system/settings.scss' +import FitFullscreen from '@/components/common/FitFullscreen' +import HideScrollbar from '@/components/common/HideScrollbar' +import Card from '@/components/common/Card' +import FlexBox from '@/components/common/FlexBox' +import LoadingMask from '@/components/common/LoadingMask' +import Permission from '@/components/common/Permission' +import BaseSettings from '@/pages/system/settings/BaseSettings' +import MailSettings from '@/pages/system/settings/MailSettings' + +interface SettingsCardProps extends React.PropsWithChildren { + icon: IconComponent + title: string + loading?: boolean + modifyOperationCode?: string + expand?: React.ReactNode + onReset?: () => void + onSave?: () => void +} +export const SettingsCard: React.FC = (props) => { + return ( + + + + +
{props.title}
+ {!props.loading ? ( + + {props.expand} + + + + + + + + ) : undefined} +
+ +
+
+ ) +} + +const Settings: React.FC = () => { + return ( + <> + + + + + + + + + + + + + + + + + + ) +} + +export default Settings