Skip to main content

yggdrasil/pages/admin/settings/
trash_section.rs

1//! 回收站分区:已删除文章的自动清理开关与保留天数。
2//!
3//! 调度任务每小时读取 DB 值执行清理。
4
5use leptos::prelude::*;
6
7use super::kit::{use_section, SettingRow, SettingsCard, SwitchRow};
8use super::SettingsSection;
9use crate::api::error::ApiError;
10use crate::api::settings::{get_trash_settings, update_trash_settings};
11use crate::components::forms::NumberInput;
12use crate::models::settings::TrashSettings;
13
14async fn save(d: TrashSettings) -> Result<TrashSettings, ApiError> {
15    update_trash_settings(d.auto_purge_enabled, d.retention_days).await
16}
17
18/// 回收站分区组件。
19#[component]
20pub fn TrashSection() -> impl IntoView {
21    let st = use_section(SettingsSection::Trash, get_trash_settings, save);
22    view! {
23        <SettingsCard
24            section=SettingsSection::Trash
25            description="已删除的文章超过保留天数后,由后台任务彻底删除。"
26            ready=st.ready()
27            load_failed=st.load_failed()
28            failed=st.failed()
29        >
30            <SwitchRow
31                label="启用自动清理"
32                hint="关闭后需要在回收站手动彻底删除。"
33                checked=st.field(|d| d.auto_purge_enabled)
34                ontoggle=move |()| st.edit(|d| d.auto_purge_enabled = !d.auto_purge_enabled)
35            />
36            <SettingRow label="保留天数" html_for="trash-days">
37                <NumberInput
38                    id="trash-days"
39                    value=st.field(|d| i64::from(d.retention_days))
40                    min=1
41                    max=365
42                    unit="天"
43                    hint="回收站列表据此显示每篇的剩余天数。"
44                    onchange=move |v: i64| st.edit(|d| d.retention_days = v as i32)
45                />
46            </SettingRow>
47        </SettingsCard>
48    }
49}