Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
export const HEADER_NAV_AUTH_MODULES = [
|
||||
'experienceCenter',
|
||||
'keyManagement',
|
||||
'userCenter',
|
||||
'pricing',
|
||||
'skillMarket',
|
||||
'docs',
|
||||
];
|
||||
|
||||
// 说明:以下导出统一使用「函数声明」而非 const 箭头函数。
|
||||
// 函数声明会被提升到模块工厂顶部,可避免在 esbuild/rollup 压缩 + manualChunks
|
||||
// 分包的某些版本下出现 “getHeaderModuleRequireAuth is not defined” 这类
|
||||
// 导出被误删 / 引用未正确链接的运行时 ReferenceError。
|
||||
export function getDefaultHeaderNavModules() {
|
||||
return {
|
||||
home: true,
|
||||
experienceCenter: {
|
||||
enabled: true,
|
||||
requireAuth: false,
|
||||
},
|
||||
keyManagement: {
|
||||
enabled: true,
|
||||
requireAuth: false,
|
||||
},
|
||||
userCenter: {
|
||||
enabled: true,
|
||||
requireAuth: false,
|
||||
},
|
||||
console: true,
|
||||
pricing: {
|
||||
enabled: true,
|
||||
requireAuth: false,
|
||||
},
|
||||
skillMarket: {
|
||||
enabled: true,
|
||||
requireAuth: false,
|
||||
},
|
||||
docs: {
|
||||
enabled: true,
|
||||
requireAuth: false,
|
||||
},
|
||||
// WeyAi 网页端入口(外链,固定需要登录;是否显示还取决于开放范围)
|
||||
weyai: true,
|
||||
about: true,
|
||||
rightActions: {
|
||||
tutorial: true,
|
||||
promotion: true,
|
||||
recharge: true,
|
||||
notifications: true,
|
||||
theme: true,
|
||||
newYear: true,
|
||||
userSettings: true,
|
||||
keyManagement: true,
|
||||
orgCenter: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function parseConfig(config) {
|
||||
if (!config) {
|
||||
return {};
|
||||
}
|
||||
if (typeof config === 'string') {
|
||||
return JSON.parse(config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
// 企业员工(org_only)顶栏硬性默认:隐藏 C 端入口,仅保留企业相关。
|
||||
// 这是「开箱即生效」的基线;管理员在运营设置里的配置会覆盖于其上。
|
||||
export function getOrgUserDefaultNavModules() {
|
||||
return {
|
||||
home: { enabled: false },
|
||||
experienceCenter: { enabled: false, requireAuth: false },
|
||||
keyManagement: { enabled: false, requireAuth: false },
|
||||
userCenter: { enabled: false, requireAuth: false },
|
||||
console: { enabled: true },
|
||||
pricing: { enabled: false, requireAuth: false },
|
||||
// 技能超市是这条基线里唯一保留的「C 端」入口(方案决策点 3,已拍板默认开)。
|
||||
// 刻意偏离「隐藏全部 C 端入口」的原因:它是员工理解「我有哪些技能可用」的
|
||||
// 唯一途径,且纯只读、不产生任何 C 端消费行为。
|
||||
// ⚠️ 默认开就必须同步放行路由:见 App.jsx 的 ORG_USER_NAV_PATHS,
|
||||
// 少加一处就会出现「按钮显示了、点了却被踢回 /org」的死按钮。
|
||||
skillMarket: { enabled: true, requireAuth: false },
|
||||
docs: { enabled: true, requireAuth: false },
|
||||
// WeyAi 网页端对企业员工同样默认开放(可在「企业员工顶栏」里关闭)
|
||||
weyai: { enabled: true },
|
||||
about: { enabled: false },
|
||||
rightActions: {
|
||||
tutorial: false,
|
||||
promotion: false,
|
||||
recharge: false,
|
||||
// 桌面端下载按钮:与 weyai 网页端入口一样默认对企业员工开放
|
||||
weyaiDownload: true,
|
||||
notifications: true,
|
||||
theme: true,
|
||||
newYear: true,
|
||||
userSettings: true,
|
||||
keyManagement: false,
|
||||
orgCenter: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeHeaderNavModules(config, baseOverride) {
|
||||
const defaults = baseOverride || getDefaultHeaderNavModules();
|
||||
let modules;
|
||||
|
||||
try {
|
||||
modules = parseConfig(config);
|
||||
} catch (_error) {
|
||||
modules = {};
|
||||
}
|
||||
|
||||
const normalized = {
|
||||
...defaults,
|
||||
...modules,
|
||||
rightActions: {
|
||||
...defaults.rightActions,
|
||||
...(modules?.rightActions || {}),
|
||||
},
|
||||
};
|
||||
|
||||
HEADER_NAV_AUTH_MODULES.forEach((key) => {
|
||||
const current = modules?.[key];
|
||||
if (typeof current === 'boolean') {
|
||||
normalized[key] = {
|
||||
enabled: current,
|
||||
requireAuth: false,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
normalized[key] = {
|
||||
...defaults[key],
|
||||
...(current || {}),
|
||||
};
|
||||
});
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
// 企业员工顶栏归一化:以企业默认预设为基线,叠加管理员保存的覆盖配置。
|
||||
export function normalizeOrgUserNavModules(config) {
|
||||
return normalizeHeaderNavModules(config, getOrgUserDefaultNavModules());
|
||||
}
|
||||
|
||||
export function isHeaderModuleEnabled(modules, key) {
|
||||
const module = modules?.[key];
|
||||
if (typeof module === 'object') {
|
||||
return module.enabled !== false;
|
||||
}
|
||||
return module === true;
|
||||
}
|
||||
|
||||
export function getHeaderModuleRequireAuth(modules, key) {
|
||||
const module = modules?.[key];
|
||||
if (typeof module === 'object') {
|
||||
return module.requireAuth === true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user