feat(welcome): 站点外观 - 合并欢迎页开放开关与入口分包修复

# Conflicts:
#	docs/content/docs/progress/pending-test.mdx
This commit is contained in:
ddCat
2026-09-15 15:19:38 +08:00
16 changed files with 225 additions and 3 deletions

View File

@@ -368,6 +368,7 @@ function parseFeatureAvailability(value: unknown): FeatureAvailability {
if (typeof record[key] !== "boolean") throw new Error("功能开放配置响应缺少有效开关状态");
}
return {
welcomeEnabled: record.welcomeEnabled as boolean,
shortDramaEnabled: record.shortDramaEnabled as boolean,
taskCenterEnabled: record.taskCenterEnabled as boolean,
creditsEnabled: record.creditsEnabled as boolean,

View File

@@ -9,6 +9,7 @@ import { AdminStatusBadge, SettingsSectionCard } from "@/pages/admin/components/
import { cn } from "@/lib/utils";
import { cloneSkinDefinition, DEFAULT_CLASSIC_SKIN, duplicateSkinDefinition, normalizeSkinDefinition, type SkinDefinition } from "@/lib/skin-themes";
import { SkinThemeEditor } from "@/pages/admin/settings/components/skin-theme-editor";
import { WelcomeSetting } from "@/pages/admin/settings/components/welcome-setting";
import { deleteAdminResources } from "@/services/api/admin-storage";
import { getAdminAppearance, resetAdminAppearance, updateAdminAppearance, uploadAppearanceAsset, type AdminAppearance, type AppearanceAssetSlot } from "@/services/api/appearance";
import { commitPublicAppearance, DEFAULT_PUBLIC_APPEARANCE } from "@/stores/use-appearance-store";
@@ -473,6 +474,7 @@ export default function AppearanceSettingsPage() {
onChange={(event) => setBrandSlug(event.target.value.toLocaleLowerCase().replace(/[^a-z0-9-]/g, ""))}
/>
</Form.Item>
<WelcomeSetting />
</Form>
<div className="admin-appearance-brand-logo admin-appearance-logo-stack">
<AssetPicker

View File

@@ -0,0 +1,65 @@
import { useEffect, useState } from "react";
import { App, Button } from "antd";
import { Switch } from "@/components/ui/base/switch";
import { getAdminFeatureAvailability, updateAdminFeatureAvailability } from "@/services/api/auth";
import { useUserStore } from "@/stores/use-user-store";
export function WelcomeSetting() {
const { message } = App.useApp();
const [enabled, setEnabled] = useState<boolean | null>(null);
const [saving, setSaving] = useState(false);
const [error, setError] = useState("");
const [revision, setRevision] = useState(0);
const setFeatures = useUserStore((state) => state.setFeatures);
useEffect(() => {
let active = true;
setError("");
getAdminFeatureAvailability()
.then(({ features }) => {
if (typeof features.welcomeEnabled !== "boolean") throw new Error("欢迎页配置无效");
if (active) setEnabled(features.welcomeEnabled);
})
.catch(() => {
if (active) setError("读取欢迎页状态失败,请重试。");
});
return () => {
active = false;
};
}, [revision]);
async function changeWelcome(value: boolean) {
if (saving) return;
setSaving(true);
try {
const { features } = await updateAdminFeatureAvailability({ welcomeEnabled: value });
if (features.welcomeEnabled !== value) throw new Error("欢迎页状态未保存,请重试");
setEnabled(features.welcomeEnabled);
setFeatures(features);
message.success(value ? "欢迎页已启用" : "欢迎页已关闭");
} catch (error) {
message.error(error instanceof Error ? error.message : "保存欢迎页状态失败");
} finally {
setSaving(false);
}
}
return (
<div className="admin-appearance-logo-frame-option">
<div className="admin-appearance-logo-frame-copy">
<strong>启用欢迎页</strong>
<p>切换后立即保存。关闭后访问 /welcome 将跳转到首页。</p>
{error ? (
<div role="alert">
{error}
<Button onClick={() => setRevision((value) => value + 1)}>重试</Button>
</div>
) : null}
</div>
<div className="admin-appearance-logo-frame-control">
<span>{enabled === null ? "读取中" : saving ? "保存中" : enabled ? "已启用" : "已关闭"}</span>
<Switch aria-label="启用欢迎页" checked={enabled === true} disabled={enabled === null || saving || Boolean(error)} onChange={(value) => void changeWelcome(value)} />
</div>
</div>
);
}