From 80718dfc8b0f41f4476292486ebdc2c781b6f6fa Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Wed, 22 Oct 2025 21:11:59 +0800 Subject: [PATCH] add anc --- src/App.tsx | 2 + .../SiteInformation/SiteInformation.tsx | 24 +++++- src/component/Common/AnnouncementDialog.tsx | 75 +++++++++++++++++++ src/redux/thunks/site.ts | 7 ++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/component/Common/AnnouncementDialog.tsx diff --git a/src/App.tsx b/src/App.tsx index 47f0e4e..279ee19 100755 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,6 +15,7 @@ import { GrowDialogTransition } from "./component/FileManager/Search/SearchPopup import Warning from "./component/Icons/Warning.tsx"; import { useAppSelector } from "./redux/hooks.ts"; import { changeThemeColor } from "./util"; +import AnnouncementDialog from "./component/Common/AnnouncementDialog.tsx"; export const applyThemeWithOverrides = (themeConfig: ThemeOptions): ThemeOptions => { return { @@ -374,6 +375,7 @@ const AppContent = () => { }} > + diff --git a/src/component/Admin/Settings/SiteInformation/SiteInformation.tsx b/src/component/Admin/Settings/SiteInformation/SiteInformation.tsx index 9db5596..dbf1ba0 100755 --- a/src/component/Admin/Settings/SiteInformation/SiteInformation.tsx +++ b/src/component/Admin/Settings/SiteInformation/SiteInformation.tsx @@ -64,9 +64,29 @@ const SiteInformation = () => { {t("settings.customFooterHTMLDes")} - + - + + setSettings({ + announcement_enabled: e.target.checked ? "1" : "0", + }) + } + /> + {t("settings.announcementEnabledDes")} + + + + + setSettings({ announcement: e.target.value })} + disabled={!isTrueVal(values.announcement_enabled)} + /> {t("settings.announcementDes")} diff --git a/src/component/Common/AnnouncementDialog.tsx b/src/component/Common/AnnouncementDialog.tsx new file mode 100644 index 0000000..c55b36a --- /dev/null +++ b/src/component/Common/AnnouncementDialog.tsx @@ -0,0 +1,75 @@ +import { useEffect, useState } from "react"; +import { + Dialog, + DialogContent, + DialogTitle, + Checkbox, + FormControlLabel, + Button, + Paper, + Typography, +} from "@mui/material"; +import { useTranslation } from "react-i18next"; +import { useAppDispatch, useAppSelector } from "../../redux/hooks.ts"; +import { getAnnouncement } from "../../redux/thunks/site.ts"; +import SessionManager from "../../session"; + +const AnnouncementDialog = () => { + const { t } = useTranslation(); + const dispatch = useAppDispatch(); + const announcement = useAppSelector((state) => state.siteConfig.basic.config.announcement || ""); + const announcementEnabled = useAppSelector((state) => state.siteConfig.basic.config.announcement_enabled || false); + const [open, setOpen] = useState(false); + const [dontShowAgain, setDontShowAgain] = useState(false); + + useEffect(() => { + // 加载公告 + dispatch(getAnnouncement()); + }, [dispatch]); + + useEffect(() => { + // 检查是否应该显示公告 + const shouldShow = + announcementEnabled && + announcement && + announcement.trim() !== "" && + !SessionManager.get("announcement_dismissed"); + + if (shouldShow) { + // 延迟显示,让页面加载完成 + const timer = setTimeout(() => setOpen(true), 1000); + return () => clearTimeout(timer); + } + }, [announcement, announcementEnabled]); + + const handleClose = () => { + if (dontShowAgain) { + // 保存用户选择不再显示 + SessionManager.set("announcement_dismissed", "true"); + } + setOpen(false); + }; + + return ( + + + {t("common:announcement")} + + + + {announcement} + + setDontShowAgain(e.target.checked)} />} + label={t("common:dontShowAgain")} + sx={{ mt: 2 }} + /> + + + + ); +}; + +export default AnnouncementDialog; diff --git a/src/redux/thunks/site.ts b/src/redux/thunks/site.ts index fd8fb44..c6bdcfb 100755 --- a/src/redux/thunks/site.ts +++ b/src/redux/thunks/site.ts @@ -27,3 +27,10 @@ export function updateSiteConfig(): AppThunk { } }; } + +export function getAnnouncement(): AppThunk { + return async (dispatch, _getState) => { + // 获取基本配置,其中包含公告信息 + await dispatch(loadSiteConfig("basic")); + }; +}