feat: add supplierApply permission toggle for providing compute button

- Add supplierApply module to console area in role-menu-permission config
- Add supplierApply to DEFAULT_SIDEBAR_CONFIG in useSidebar hook
- Update HeaderLogo to check sidebar module config before showing the button
- Update MobileSiteNavDropdown to check same permission for mobile entry
- Default value is enabled (backward compatible)
This commit is contained in:
xiezhouwei 2026-06-11 11:37:48 +08:00
parent 82016579db
commit d7fdbb4e18
4 changed files with 54 additions and 15 deletions

View File

@ -17,11 +17,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com For commercial licensing, please contact support@quantumnous.com
*/ */
import React, { useCallback } from 'react'; import React, { useCallback, useContext } from 'react';
import { Link, useLocation, useNavigate } from 'react-router-dom'; import { Link, useLocation, useNavigate } from 'react-router-dom';
import { Typography, Tag } from '@douyinfe/semi-ui'; import { Typography, Tag } from '@douyinfe/semi-ui';
import SkeletonWrapper from '../components/SkeletonWrapper'; import SkeletonWrapper from '../components/SkeletonWrapper';
import { userIsSupplierUser, showInfo, isAdmin } from '../../../helpers'; import { userIsSupplierUser, showInfo, isAdmin } from '../../../helpers';
import { StatusContext } from '../../../context/Status';
/** /**
* 顶栏申请入口浅色用 #409EFF * 顶栏申请入口浅色用 #409EFF
@ -49,6 +50,24 @@ const HeaderLogo = ({
const location = useLocation(); const location = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
const user = userState?.user; const user = userState?.user;
const [statusState] = useContext(StatusContext);
const isSupplierApplyEnabled = React.useMemo(() => {
try {
const roleModulesRaw = statusState?.status?.SidebarModulesByRole;
if (!roleModulesRaw) return true;
const roleConfig = JSON.parse(roleModulesRaw);
const userRole = String(user?.role ?? 0);
const config = roleConfig[userRole];
if (!config) return true;
const consoleSection = config.console;
if (!consoleSection) return true;
if (consoleSection.enabled === false) return false;
return consoleSection.supplierApply !== false;
} catch {
return true;
}
}, [statusState?.status?.SidebarModulesByRole, user?.role]);
/** 未登录且已在登录页时:提示先登录,并同步 redirect 到目标申请页 */ /** 未登录且已在登录页时:提示先登录,并同步 redirect 到目标申请页 */
const handleApplyEntryClick = useCallback( const handleApplyEntryClick = useCallback(
@ -72,7 +91,7 @@ const HeaderLogo = ({
/** 管理员不展示;已是供应商则隐藏「提供算力」 */ /** 管理员不展示;已是供应商则隐藏「提供算力」 */
const hideApplyLinks = isAdmin(); const hideApplyLinks = isAdmin();
const showSupplierApply = !hideApplyLinks && !userIsSupplierUser(user); const showSupplierApply = !hideApplyLinks && !userIsSupplierUser(user) && isSupplierApplyEnabled;
const supplierTo = user const supplierTo = user
? supplierApplyPath ? supplierApplyPath

View File

@ -22,6 +22,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { Button, Dropdown } from '@douyinfe/semi-ui'; import { Button, Dropdown } from '@douyinfe/semi-ui';
import { ChevronDown } from 'lucide-react'; import { ChevronDown } from 'lucide-react';
import SkeletonWrapper from '../components/SkeletonWrapper'; import SkeletonWrapper from '../components/SkeletonWrapper';
import { StatusContext } from '../../../context/Status';
import { isAdmin, userIsSupplierUser } from '../../../helpers'; import { isAdmin, userIsSupplierUser } from '../../../helpers';
/** 主站入口顺序(与桌面顶栏一致) */ /** 主站入口顺序(与桌面顶栏一致) */
@ -42,6 +43,7 @@ const MobileSiteNavDropdown = ({
const location = useLocation(); const location = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
const user = userState?.user; const user = userState?.user;
const [statusState] = React.useContext(StatusContext);
const byNavKey = useMemo( const byNavKey = useMemo(
() => Object.fromEntries(mainNavLinks.map((l) => [l.itemKey, l])), () => Object.fromEntries(mainNavLinks.map((l) => [l.itemKey, l])),
@ -59,17 +61,33 @@ const MobileSiteNavDropdown = ({
const applyEntries = useMemo(() => { const applyEntries = useMemo(() => {
const hideApplyLinks = isAdmin(); const hideApplyLinks = isAdmin();
const showSupplierApply = !hideApplyLinks && !userIsSupplierUser(user); if (!hideApplyLinks && !userIsSupplierUser(user)) {
try {
if (!showSupplierApply) return []; const roleModulesRaw = statusState?.status?.SidebarModulesByRole;
return [ if (roleModulesRaw) {
{ const roleConfig = JSON.parse(roleModulesRaw);
itemKey: 'supplier-apply', const userRole = String(user?.role ?? 0);
text: t('提供算力'), const config = roleConfig[userRole];
redirectPath: supplierApplyPath, if (config) {
}, const consoleSection = config.console;
]; if (consoleSection) {
}, [user, t]); if (consoleSection.enabled === false || consoleSection.supplierApply === false) {
return [];
}
}
}
}
} catch {}
return [
{
itemKey: 'supplier-apply',
text: t('提供算力'),
redirectPath: supplierApplyPath,
},
];
}
return [];
}, [user, t, statusState?.status?.SidebarModulesByRole]);
const currentPageLabel = useMemo(() => { const currentPageLabel = useMemo(() => {
const p = location.pathname; const p = location.pathname;

View File

@ -1,4 +1,4 @@
/* /*
Copyright (C) 2025 QuantumNous Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@ -40,6 +40,7 @@ export const DEFAULT_SIDEBAR_CONFIG = {
log: true, log: true,
midjourney: true, midjourney: true,
task: true, task: true,
'supplierApply': true,
}, },
personal: { personal: {
enabled: true, enabled: true,

View File

@ -1,4 +1,4 @@
/* /*
Copyright (C) 2025 QuantumNous Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@ -65,6 +65,7 @@ const sectionConfigs = [
desc_key: '绘图任务记录', desc_key: '绘图任务记录',
}, },
{ key: 'task', title_key: '任务日志', desc_key: '系统任务记录' }, { key: 'task', title_key: '任务日志', desc_key: '系统任务记录' },
{ key: 'supplierApply', title_key: '提供算力按钮', desc_key: '普通用户前端提供算力按钮显示权限' },
], ],
}, },
{ {