You've already forked DataMate
refactor(KnowledgeManagement): 优化知识集详情页面文件记录渲染逻辑
- 将重复的条件判断提取为变量 isFileRecord - 使用立即执行函数简化 JSX 结构 - 统一文件类型记录的操作按钮渲染方式 - 提高代码可读性和维护性
This commit is contained in:
@@ -335,41 +335,54 @@ const KnowledgeSetDetail = () => {
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
{(record.contentType === KnowledgeContentType.FILE ||
|
||||
record.sourceType === KnowledgeSourceType.FILE_UPLOAD) && (
|
||||
<Tooltip title="预览">
|
||||
<Button
|
||||
type="text"
|
||||
icon={<EyeOutlined />}
|
||||
onClick={() => handlePreviewItemFile(record)}
|
||||
loading={previewLoadingItemId === record.id}
|
||||
aria-label="预览"
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
{(record.contentType === KnowledgeContentType.FILE ||
|
||||
record.sourceType === KnowledgeSourceType.FILE_UPLOAD) && (
|
||||
<Tooltip title="下载文件">
|
||||
<Button
|
||||
type="text"
|
||||
icon={<DownloadOutlined />}
|
||||
onClick={() => handleDownloadItem(record)}
|
||||
aria-label="下载文件"
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Button
|
||||
type="text"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => {
|
||||
setCurrentItem({
|
||||
...(record as unknown as KnowledgeItem),
|
||||
status: record.rawStatus,
|
||||
});
|
||||
setItemEditorOpen(true);
|
||||
}}
|
||||
disabled={isReadOnly || record.rawStatus === KnowledgeStatusType.ARCHIVED || record.rawStatus === KnowledgeStatusType.DEPRECATED}
|
||||
/>
|
||||
{(() => {
|
||||
const isFileRecord =
|
||||
record.contentType === KnowledgeContentType.FILE ||
|
||||
record.sourceType === KnowledgeSourceType.FILE_UPLOAD;
|
||||
return (
|
||||
<>
|
||||
{isFileRecord && (
|
||||
<Tooltip title="预览">
|
||||
<Button
|
||||
type="text"
|
||||
icon={<EyeOutlined />}
|
||||
onClick={() => handlePreviewItemFile(record)}
|
||||
loading={previewLoadingItemId === record.id}
|
||||
aria-label="预览"
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
{isFileRecord && (
|
||||
<Tooltip title="下载文件">
|
||||
<Button
|
||||
type="text"
|
||||
icon={<DownloadOutlined />}
|
||||
onClick={() => handleDownloadItem(record)}
|
||||
aria-label="下载文件"
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
{isFileRecord && (
|
||||
<Button
|
||||
type="text"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => {
|
||||
setCurrentItem({
|
||||
...(record as unknown as KnowledgeItem),
|
||||
status: record.rawStatus,
|
||||
});
|
||||
setItemEditorOpen(true);
|
||||
}}
|
||||
disabled={
|
||||
isReadOnly ||
|
||||
record.rawStatus === KnowledgeStatusType.ARCHIVED ||
|
||||
record.rawStatus === KnowledgeStatusType.DEPRECATED
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
})()}
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
|
||||
Reference in New Issue
Block a user