feat: 1. 本地化思源黑体的字体包并优先使用。
2. 添加权限映射表和全局查看权限的hook,便于路由控制不同权限按钮显示/隐藏。 3. 删除评查点分组的部分旧api方法。 4. 对接评查点分组接口,文档类型接口, 提示词管理接口, 入口模块管理的接口。 5. 优化角色权限管理的接口,完善不用地区的访问权限认证。 6. 优化主页交叉评查和设置的入口样式和布局。 7. 优化评查点分组,评查规则的功能权限校验。
This commit is contained in:
@@ -49,7 +49,7 @@ import type { EvaluationPointGroup } from "~/models/evaluation_point_groups";
|
||||
// 导入RuleContext上下文
|
||||
import { RuleContext } from "~/contexts/RuleContext";
|
||||
import { toastService } from '~/components/ui/Toast';
|
||||
import type { UserRole } from '~/root';
|
||||
import { usePermission } from '~/hooks/usePermission';
|
||||
import { getPromptTemplateOptions } from '~/api/prompts/prompts';
|
||||
import {
|
||||
createEvaluationPoint,
|
||||
@@ -148,26 +148,50 @@ export default function RuleNew() {
|
||||
const [isCopyMode, setIsCopyMode] = useState(false); // 添加复制模式状态
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [instanceKey, setInstanceKey] = useState<string>('new');
|
||||
// 从root路由获取用户角色和JWT token
|
||||
const rootData = useRouteLoaderData("root") as { userRole: UserRole; frontendJWT?: string };
|
||||
const userRole = rootData?.userRole || 'common';
|
||||
// 从root路由获取JWT token
|
||||
const rootData = useRouteLoaderData("root") as { frontendJWT?: string };
|
||||
const frontendJWT = rootData?.frontendJWT;
|
||||
|
||||
// ✅ 使用权限 Hook
|
||||
const { canCreate, canUpdate } = usePermission();
|
||||
const canCreateRule = canCreate('evaluation_point');
|
||||
const canUpdateRule = canUpdate('evaluation_point');
|
||||
|
||||
// ✅ 判断表单是否为只读模式
|
||||
// 从 URL 检查是否为查看模式
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
const urlMode = searchParams.get('mode');
|
||||
const isViewMode = urlMode === 'view';
|
||||
|
||||
// 根据模式和权限决定是否只读
|
||||
const hasEditPermission = isEditMode ? canUpdateRule : canCreateRule;
|
||||
const isReadOnly = isViewMode || !hasEditPermission;
|
||||
|
||||
// 使用 ref 跟踪当前加载的 URL,避免重复加载
|
||||
const loadedUrlRef = useRef<string>('');
|
||||
|
||||
const [formData, setFormData] = useState<EvaluationPoint>({});
|
||||
const [evaluationPointGroups, setEvaluationPointGroups] = useState<EvaluationPointGroup[]>([]);
|
||||
|
||||
// 判断表单是否为只读模式
|
||||
const isReadOnly = userRole === 'common';
|
||||
|
||||
// 添加用于共享的字段数据状态
|
||||
const [extractionFields, setExtractionFields] = useState<string[]>([]);
|
||||
|
||||
// VLM字段类型选项
|
||||
const [vlmFieldTypeOptions, setVlmFieldTypeOptions] = useState<Array<{ value: string; label: string }>>([]);
|
||||
|
||||
// ✅ 页面加载时检查权限并提示(仅在只读模式下提示)
|
||||
useEffect(() => {
|
||||
if (isReadOnly && !isLoading) {
|
||||
if (isViewMode) {
|
||||
// toastService.info('当前为查看模式');
|
||||
} else if (isEditMode && !canUpdateRule) {
|
||||
toastService.info('当前为查看模式,您没有编辑权限');
|
||||
} else if (!isEditMode && !canCreateRule) {
|
||||
toastService.warning('您没有创建评查点的权限');
|
||||
}
|
||||
}
|
||||
}, [isReadOnly, isViewMode, isEditMode, canUpdateRule, canCreateRule, isLoading]);
|
||||
|
||||
/**
|
||||
* 从表单数据中提取所有字段
|
||||
* 用于编辑模式下初始化字段数据
|
||||
@@ -417,6 +441,17 @@ export default function RuleNew() {
|
||||
const handleSave = async () => {
|
||||
// console.log("保存评查点", formData);
|
||||
|
||||
// ✅ Runtime permission check
|
||||
if (isEditMode && !canUpdateRule) {
|
||||
toastService.warning('您没有修改权限,无法保存更改');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isEditMode && !canCreateRule) {
|
||||
toastService.warning('您没有创建权限,无法新增评查点');
|
||||
return;
|
||||
}
|
||||
|
||||
// ========== 验证必填字段 ==========
|
||||
|
||||
// 1. 验证评查点名称
|
||||
|
||||
Reference in New Issue
Block a user