feat(*): 插件中心与模型协议 - 完善声明式协议运行时并增加功能开放控制
This commit is contained in:
@@ -7,21 +7,24 @@ import { WorkspaceErrorState, WorkspaceLoadingState, WorkspaceState } from "@/co
|
||||
import { refreshFeatureAvailability } from "@/lib/user-session";
|
||||
import { useUserStore } from "@/stores/use-user-store";
|
||||
|
||||
type FeatureKey = "shortDramaEnabled" | "taskCenterEnabled" | "creditsEnabled" | "frontendModelsEnabled";
|
||||
type FeatureKey = "shortDramaEnabled" | "taskCenterEnabled" | "creditsEnabled" | "frontendModelsEnabled" | "pluginCenterEnabled";
|
||||
|
||||
const featureNames: Record<FeatureKey, string> = {
|
||||
shortDramaEnabled: "短剧创作",
|
||||
taskCenterEnabled: "任务中心",
|
||||
creditsEnabled: "积分中心",
|
||||
frontendModelsEnabled: "前台模型",
|
||||
pluginCenterEnabled: "插件中心",
|
||||
};
|
||||
|
||||
let featureAvailabilityCheckedOnce = false;
|
||||
|
||||
export function RequireFeature({ feature, children }: { feature: FeatureKey; children: ReactNode }) {
|
||||
const navigate = useNavigate();
|
||||
const user = useUserStore((state) => state.user);
|
||||
const features = useUserStore((state) => state.features);
|
||||
const [checking, setChecking] = useState(() => !useUserStore.getState().features[feature]);
|
||||
const adminBypass = feature === "pluginCenterEnabled" && user?.role === "admin";
|
||||
const [checking, setChecking] = useState(() => !adminBypass && !useUserStore.getState().features[feature]);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
@@ -43,9 +46,9 @@ export function RequireFeature({ feature, children }: { feature: FeatureKey; chi
|
||||
|
||||
if (checking) return <WorkspacePage><WorkspaceLoadingState label="正在确认功能状态" detail={featureNames[feature]} rows={3} /></WorkspacePage>;
|
||||
if (error) return <WorkspacePage><WorkspaceErrorState title="无法确认功能状态" description={error} actionLabel="返回创作台" onRetry={() => navigate("/create", { replace: true })} /></WorkspacePage>;
|
||||
if (!features[feature]) {
|
||||
if (!adminBypass && !features[feature]) {
|
||||
// 管理员页面返回到管理后台首页,用户页面返回到创作台
|
||||
const isAdminFeature = feature === "frontendModelsEnabled";
|
||||
const isAdminFeature = feature === "frontendModelsEnabled" || (feature === "pluginCenterEnabled" && user?.role === "admin");
|
||||
const backPath = isAdminFeature ? "/admin" : "/create";
|
||||
const backLabel = isAdminFeature ? "返回管理后台" : "返回创作台";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user