Integrate FileUpload component for material uploads in AIKnowledgeDetail. Update upload logic to handle file types and improve user feedback on upload success or failure. Adjust tab rendering order for better clarity.
This commit is contained in:
@@ -39,6 +39,7 @@ import {
|
||||
} from "./api";
|
||||
import { deleteKnowledgeBase } from "../list/api";
|
||||
import type { KnowledgeBase, Material, Caller } from "./data";
|
||||
import FileUpload from "@/components/Upload/FileUpload";
|
||||
|
||||
type TabType = "info" | "materials";
|
||||
|
||||
@@ -496,24 +497,32 @@ const AIKnowledgeDetail: React.FC = () => {
|
||||
<div className={style.materialSection}>
|
||||
{/* 系统预设不显示上传按钮 */}
|
||||
{!isSystemPreset && (
|
||||
<Upload
|
||||
showUploadList={false}
|
||||
beforeUpload={file => {
|
||||
handleUpload(file);
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<UploadOutlined />}
|
||||
className={style.uploadButton}
|
||||
size="large"
|
||||
>
|
||||
上传素材到此库
|
||||
</Button>
|
||||
</Upload>
|
||||
<div className={style.uploadButtonWrap}>
|
||||
<FileUpload
|
||||
maxCount={1}
|
||||
disabled={isSystemPreset}
|
||||
acceptTypes={["pdf", "txt", "doc", "docx", "md"]}
|
||||
onChange={async v => {
|
||||
// v 可能为 string 或 string[]:单传取 string
|
||||
const uploadUrl = Array.isArray(v) ? v[0] : v;
|
||||
if (uploadUrl && id) {
|
||||
try {
|
||||
await uploadMaterial({
|
||||
typeId: Number(id),
|
||||
name: uploadUrl.split("/").pop() || "已上传文件",
|
||||
label: [],
|
||||
fileUrl: uploadUrl,
|
||||
});
|
||||
message.success("上传成功");
|
||||
fetchDetail();
|
||||
} catch (e) {
|
||||
message.error("上传失败");
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={style.materialList}>
|
||||
{materials.length > 0 ? (
|
||||
materials.map(material => (
|
||||
@@ -600,7 +609,7 @@ const AIKnowledgeDetail: React.FC = () => {
|
||||
className={`${style.tab} ${activeTab === "materials" ? style.tabActive : ""}`}
|
||||
onClick={() => setActiveTab("materials")}
|
||||
>
|
||||
{knowledgeBase?.name || "知识库"}
|
||||
客户案例
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -614,8 +623,8 @@ const AIKnowledgeDetail: React.FC = () => {
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{activeTab === "info" && renderInfoTab()}
|
||||
{activeTab === "materials" && renderMaterialsTab()}
|
||||
{activeTab === "info" && renderMaterialsTab()}
|
||||
{activeTab === "materials" && renderInfoTab()}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user