diff --git a/web/src/pages/Setting/Operation/SettingsLog.jsx b/web/src/pages/Setting/Operation/SettingsLog.jsx index dcd17081..067e968b 100644 --- a/web/src/pages/Setting/Operation/SettingsLog.jsx +++ b/web/src/pages/Setting/Operation/SettingsLog.jsx @@ -18,7 +18,7 @@ For commercial licensing, please contact support@quantumnous.com */ import React, { useEffect, useState, useRef } from 'react'; -import { Button, Col, Form, Row, Spin, DatePicker } from '@douyinfe/semi-ui'; +import { Button, Col, Form, Row, Spin, DatePicker, Typography, Modal } from '@douyinfe/semi-ui'; import dayjs from 'dayjs'; import { useTranslation } from 'react-i18next'; import { @@ -29,6 +29,8 @@ import { showWarning, } from '../../../helpers'; +const { Text } = Typography; + export default function SettingsLog(props) { const { t } = useTranslation(); const [loading, setLoading] = useState(false); @@ -78,24 +80,75 @@ export default function SettingsLog(props) { }); } async function onCleanHistoryLog() { - try { - setLoadingCleanHistoryLog(true); - if (!inputs.historyTimestamp) throw new Error(t('请选择日志记录时间')); - const res = await API.delete( - `/api/log/?target_timestamp=${Date.parse(inputs.historyTimestamp) / 1000}`, - ); - const { success, message, data } = res.data; - if (success) { - showSuccess(`${data} ${t('条日志已清理!')}`); - return; - } else { - throw new Error(t('日志清理失败:') + message); - } - } catch (error) { - showError(error.message); - } finally { - setLoadingCleanHistoryLog(false); + if (!inputs.historyTimestamp) { + showError(t('请选择日志记录时间')); + return; } + + const now = dayjs(); + const targetDate = dayjs(inputs.historyTimestamp); + const targetTime = targetDate.format('YYYY-MM-DD HH:mm:ss'); + const currentTime = now.format('YYYY-MM-DD HH:mm:ss'); + const daysDiff = now.diff(targetDate, 'day'); + + Modal.confirm({ + title: t('确认清除历史日志'), + content: ( +
+

+ {t('当前时间')}: + {currentTime} +

+

+ {t('选择时间')}: + {targetTime} + {daysDiff > 0 && ( + ({t('约')} {daysDiff} {t('天前')}) + )} +

+
+ ⚠️ {t('注意')}: + {t('将删除')} + {targetTime} + {daysDiff > 0 && ( + ({t('约')} {daysDiff} {t('天前')}) + )} + {t('之前的所有日志')} +
+

+ {t('此操作不可恢复,请仔细确认时间后再操作!')} +

+
+ ), + okText: t('确认删除'), + cancelText: t('取消'), + okType: 'danger', + onOk: async () => { + try { + setLoadingCleanHistoryLog(true); + const res = await API.delete( + `/api/log/?target_timestamp=${Date.parse(inputs.historyTimestamp) / 1000}`, + ); + const { success, message, data } = res.data; + if (success) { + showSuccess(`${data} ${t('条日志已清理!')}`); + return; + } else { + throw new Error(t('日志清理失败:') + message); + } + } catch (error) { + showError(error.message); + } finally { + setLoadingCleanHistoryLog(false); + } + }, + }); } useEffect(() => { @@ -138,7 +191,7 @@ export default function SettingsLog(props) { -