/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useEffect, useState, useContext } from 'react'; import { Banner, Button, Card, Col, Form, Row, Switch, Typography, } from '@/components/ui'; import { API, showError, showSuccess } from '../../../helpers'; import { useTranslation } from 'react-i18next'; import { StatusContext } from '../../../context/Status'; import { getOrgUserDefaultNavModules, normalizeOrgUserNavModules, isHeaderModuleEnabled, } from '../../../constants/headerNavModules'; const { Text } = Typography; const OPTION_KEY = 'HeaderNavModulesOrgUser'; // 中部一级导航模块 const moduleKeys = [ 'home', 'experienceCenter', 'userCenter', 'console', 'pricing', 'skillMarket', 'docs', 'weyai', 'about', ]; // 右侧按钮 / 头像菜单入口 const rightActionKeys = [ 'tutorial', 'promotion', 'recharge', // 下面 rightActionConfigs 每多一项,这里必须同步登记,否则开关只显示不落库 'weyaiDownload', 'notifications', 'theme', 'newYear', 'userSettings', 'keyManagement', 'orgCenter', ]; export default function SettingsOrgUserNavModules(props) { const { t } = useTranslation(); const [loading, setLoading] = useState(false); const [statusState, statusDispatch] = useContext(StatusContext); const [modules, setModules] = useState({}); const [rightActions, setRightActions] = useState({}); // 仅展示对企业员工真实生效的开关: // - home/about 在顶栏导航中无对应链接(全仓无 isHeaderModuleEnabled 消费点); // - console 链接带 adminOnly 且 /console 不在企业员工路由放行清单,开了也进不去; // - rightActions.orgCenter 全仓无读取点。 // 上述死开关从 UI 移除(保存结构仍保留 key,由预设默认值兜底), // 避免"打开对应开关并保存"的承诺对这些项不成立。 const moduleConfigs = [ { key: 'experienceCenter', title: t('体验中心') }, { key: 'userCenter', title: t('用户中心') }, { key: 'pricing', title: t('模型广场') }, // 技能超市是企业员工基线里唯一默认开启的 C 端入口(方案决策点 3): // 纯只读、不产生 C 端消费,且是员工理解「我有哪些技能可用」的唯一途径。 // 其路由已在 App.jsx 的 ORG_USER_NAV_PATHS 中放行,开关与可达性一致。 { key: 'skillMarket', title: t('技能超市') }, { key: 'docs', title: t('文档') }, { key: 'weyai', title: t('WeyAi') }, ]; const rightActionConfigs = [ { key: 'tutorial', title: t('新手教程按钮') }, { key: 'promotion', title: t('推广按钮') }, { key: 'recharge', title: t('充值按钮') }, { key: 'weyaiDownload', title: t('下载 WeyAi 按钮') }, { key: 'notifications', title: t('公告按钮') }, { key: 'theme', title: t('主题按钮') }, { key: 'newYear', title: t('新年按钮') }, { key: 'userSettings', title: t('个人设置快捷入口') }, { key: 'keyManagement', title: t('密钥管理快捷入口') }, ]; // 以企业硬性默认预设为基线,叠加已保存配置 → 反映实际生效状态 useEffect(() => { const eff = normalizeOrgUserNavModules(props.options?.[OPTION_KEY] || ''); const m = {}; moduleKeys.forEach((k) => (m[k] = isHeaderModuleEnabled(eff, k))); setModules(m); const r = {}; rightActionKeys.forEach((k) => (r[k] = eff.rightActions?.[k] !== false)); setRightActions(r); }, [props.options]); // 恢复企业默认(隐藏 C 端入口的预设) const applyRecommended = () => { const preset = getOrgUserDefaultNavModules(); const m = {}; moduleKeys.forEach((k) => (m[k] = isHeaderModuleEnabled(preset, k))); setModules(m); const r = {}; rightActionKeys.forEach((k) => (r[k] = preset.rightActions?.[k] !== false)); setRightActions(r); showSuccess(t('已恢复企业默认配置,记得点击保存')); }; const onSubmit = async () => { setLoading(true); try { const out = {}; moduleKeys.forEach((k) => (out[k] = { enabled: !!modules[k] })); out.rightActions = {}; rightActionKeys.forEach((k) => (out.rightActions[k] = !!rightActions[k])); const value = JSON.stringify(out); const res = await API.put('/api/option/', { key: OPTION_KEY, value }); if (res.data.success) { showSuccess(t('保存成功')); statusDispatch({ type: 'set', payload: { ...statusState.status, [OPTION_KEY]: value }, }); if (props.refresh) await props.refresh(); } else { showError(res.data.message); } } catch { showError(t('保存失败,请重试')); } finally { setLoading(false); } }; const renderSwitchCard = (cfg, checked, onChange) => (
{cfg.title}
); return (
{t('中部导航')}
{moduleConfigs.map((cfg) => renderSwitchCard(cfg, !!modules[cfg.key], (v) => setModules((prev) => ({ ...prev, [cfg.key]: v })), ), )}
{t('右侧按钮 / 头像菜单')}
{rightActionConfigs.map((cfg) => renderSwitchCard(cfg, !!rightActions[cfg.key], (v) => setRightActions((prev) => ({ ...prev, [cfg.key]: v })), ), )}
{t( '提示:本设置仅控制顶栏显隐;个人资源访问由企业「仅企业资源」模式在后端拦截。', )}
); }