import React, { useState, useEffect } from 'react'; import SvgIcon from './SvgIcon'; // 部门和组别的映射关系 const departmentGroups = { 达人部门: ['达人'], 商务部门: ['商务'], 样本中心: ['样本'], 产品部门: ['产品'], AI自媒体: ['AI自媒体'], HR: ['HR'], 技术部门: ['技术'], }; // 部门列表 const departments = Object.keys(departmentGroups); /** * 创建知识库模态框组件 * @param {Object} props * @param {boolean} props.show - 是否显示弹窗 * @param {Object} props.formData - 表单数据 * @param {Object} props.formErrors - 表单错误信息 * @param {boolean} props.isSubmitting - 是否正在提交 * @param {Function} props.onClose - 关闭弹窗的回调函数 * @param {Function} props.onChange - 表单输入变化的回调函数 * @param {Function} props.onSubmit - 提交表单的回调函数 * @param {Object} props.currentUser - 当前用户信息 */ const CreateKnowledgeBaseModal = ({ show, formData, formErrors, isSubmitting, onClose, onChange, onSubmit, currentUser, }) => { // 根据用户角色确定可以创建的知识库类型 const isAdmin = currentUser?.role === 'admin'; const isLeader = currentUser?.role === 'leader'; // 获取当前用户的部门和组别 const userDepartment = currentUser?.department || ''; // 可选的组别列表 const [availableGroups, setAvailableGroups] = useState([]); // 当部门变化时更新可用的组别 useEffect(() => { if (formData.department && departmentGroups[formData.department]) { setAvailableGroups(departmentGroups[formData.department]); } else { setAvailableGroups([]); } }, [formData.department]); // 提前返回需要放在所有 Hooks 之后 if (!show) return null; // 获取当前用户可以创建的知识库类型 const getAvailableTypes = () => { if (isAdmin) { return [ { value: 'admin', label: '公共知识库' }, { value: 'leader', label: '组长级知识库' }, { value: 'member', label: '组内知识库' }, { value: 'private', label: '私有知识库' }, { value: 'secret', label: '私密知识库' }, ]; } else if (isLeader) { return [ { value: 'admin', label: '公共知识库' }, { value: 'member', label: '组内知识库' }, { value: 'private', label: '私有知识库' }, ]; } else { return [ { value: 'admin', label: '公共知识库' }, { value: 'private', label: '私有知识库' }, ]; } }; const availableTypes = getAvailableTypes(); // 判断是否需要选择组别 const needDepartmentAndGroup = formData.type === 'member' || formData.type === 'leader'; const needSelectGroup = needDepartmentAndGroup; return (