diff --git a/app/backend/src/api/textbook.ts b/app/backend/src/api/textbook.ts index aceba71..9777f53 100644 --- a/app/backend/src/api/textbook.ts +++ b/app/backend/src/api/textbook.ts @@ -104,7 +104,7 @@ export function GetResourceListApi( //删除+ 批量删除 export function DelResourceItemApi(idList: string) { - return client.destroy(`/backend/v1/jc/softwareInfo?idList=${idList}`); + return client.destroy(`/backend/v1/jc/resource/delIds?idList=${idList}`); } //根据id查详情 @@ -258,8 +258,7 @@ export function AddResourceItemApi( txtDesc: string, extension: string, size: number, - path: string, - chapterId?: string + path: string ) { return client.post(`/jc/resource`, { bookId, @@ -269,6 +268,27 @@ export function AddResourceItemApi( extension, size, path, - chapterId, + }); +} + +export function UpdateResourceItemApi( + editId: number, + bookId: number, + name: string, + knowledgeCode: string, + txtDesc: string, + extension: string, + size: number, + path: string +) { + return client.put(`/jc/resource`, { + id: editId, + bookId, + name, + knowledgeCode, + txtDesc, + extension, + size, + path, }); } diff --git a/app/backend/src/pages/textbook/compenents/Resource/CreateResourceModal.tsx b/app/backend/src/pages/textbook/compenents/Resource/CreateResourceModal.tsx index bf5a3c6..fb14395 100644 --- a/app/backend/src/pages/textbook/compenents/Resource/CreateResourceModal.tsx +++ b/app/backend/src/pages/textbook/compenents/Resource/CreateResourceModal.tsx @@ -1,8 +1,13 @@ import React, { useState, useEffect } from 'react'; -import { Modal, Form, Input, message, Spin, Select } from 'antd'; +import { Modal, Form, Input, message, Spin, Select, SelectProps } from 'antd'; import { useTranslation } from 'react-i18next'; import TextArea from 'antd/es/input/TextArea'; -import { AddResourceItemApi } from '../../../../api/textbook'; +import { + AddResourceItemApi, + GetDetailApi, + getKnowledgeListApi, + UpdateResourceItemApi, +} from '../../../../api/textbook'; import { DraggerUpload } from '../Upload/DraggerUpload'; interface ModalPropsType { @@ -13,18 +18,95 @@ interface ModalPropsType { resourceId: number; } -interface Option { - value: string | number; - title: string; - children?: Option[]; -} +const defaultData = [ + { + createTime: '2025-11-29 16:37:08', + updateTime: '2025-12-02 15:42:09', + creator: null, + updater: null, + tenantId: '-1', + id: 1, + bookId: 46, + parentId: 0, + name: '高等数学基础', + knowledgeCode: 'MATH001', + desc: '高等数学的基础知识点,包含极限、导数、积分等', + level: 1, + type: '基础', + isReal: '1', + orderNum: 1, + extraJson: null, + children: null, + }, + { + createTime: '2025-11-29 16:37:08', + updateTime: '2025-12-02 15:42:09', + creator: null, + updater: null, + tenantId: '-1', + id: 2, + bookId: 46, + parentId: 1, + name: '极限与连续', + knowledgeCode: 'MATH001001', + desc: '函数极限的定义与性质,连续函数的特征', + level: 2, + type: '基础', + isReal: '1', + orderNum: 1, + extraJson: null, + children: null, + }, + { + createTime: '2025-11-29 16:37:08', + updateTime: '2025-12-02 15:42:09', + creator: null, + updater: null, + tenantId: '-1', + id: 3, + bookId: 46, + parentId: 1, + name: '导数与微分', + knowledgeCode: 'MATH001002', + desc: '导数的定义、计算方法及应用', + level: 2, + type: '基础', + isReal: '1', + orderNum: 2, + extraJson: null, + children: null, + }, + { + createTime: '2025-11-29 16:37:08', + updateTime: '2025-12-02 15:42:09', + creator: null, + updater: null, + tenantId: '-1', + id: 4, + bookId: 46, + parentId: 1, + name: '积分学', + knowledgeCode: 'MATH001003', + desc: '不定积分与定积分的计算方法', + level: 2, + type: '基础', + isReal: '1', + orderNum: 3, + extraJson: null, + children: null, + }, +]; const CreateResourceModal = (props: ModalPropsType) => { const { t } = useTranslation(); const { isOpen, onCancel, bookId, resourceId, isEdit } = props; const [form] = Form.useForm(); - const [loading, setLoading] = useState(false); - const [spinInit, setSpinInit] = useState(false); - const [knowledgeOption, setKnowledgeOption] = useState([]); + const [spinInit, setSpinInit] = useState(false); + const [knowledgeOption, setKnowledgeOption] = useState< + { + label: string; + value: number; + }[] + >([]); const [fileSize, setFileSize] = useState(0); const [fileName, setFileName] = useState(''); const [filePath, setFilePath] = useState(''); @@ -36,77 +118,87 @@ const CreateResourceModal = (props: ModalPropsType) => { if (isEdit && resourceId) { getDetail(); } else { + form.resetFields(); setSpinInit(false); - form.setFieldsValue({ - type: '视频', - }); } }, [isEdit, resourceId]); - /* useEffect(() => { - getChapterTreeData(); - }, []);*/ + useEffect(() => { + getKnowledgeOptionData(); + }, []); - /* const getKnowledgeOptionData = () => { - GetChapterTreeApi({ bookId }).then((res: any) => { + useEffect(() => { + return () => { + form.resetFields(); + setFileName(''); + setFilePath(''); + setFileSize(0); + setKnowledgeCode(''); + }; + }, []); + + const getKnowledgeOptionData = () => { + getKnowledgeListApi(bookId).then((res: any) => { const resData: any = res.data; - // console.log(resData, '>>>'); - setKnowledgeOption(resData); + const knowledgeOption: { label: string; value: number }[] = defaultData.map( + (item: { name: string; id: number }) => ({ + label: `${item.name}`, // 如:"极限与连续 (基础)" (${item.type}) + value: item.id, + }) + ); + setKnowledgeOption(knowledgeOption); }); - };*/ + }; const getDetail = () => { - setSpinInit(false); + GetDetailApi(resourceId) + .then((res: any) => { + if (!res || !res.data) { + message.error('获取详情失败'); + setSpinInit(false); + return; + } + }) + .catch((err) => { + message.error('获取详情失败'); + setSpinInit(false); + console.error('获取详情失败:', err); + }); }; const onFinish = (values: any) => { - console.log('表单提交:', values); - - const { name = '', txtDesc = '', chapterId = '' } = values; - + const { name = '', txtDesc = '', knowledgeCode = '' } = values; try { if (isEdit) { - /*UpdateTextbookApi( - editId, - values.title, - thumb, - values.short_desc, - values.author, - values.major, - dep_ids, - group_ids, - user_ids, - values.publish_time, - values.publish_unit, - values.create_time, - values.isbn - ) - .then((res: any) => { - setLoading(false); - message.success(t('commen.saveSuccess')); - onCancel(); - }) - .catch((e) => { - setLoading(false); - });*/ - } else { - AddResourceItemApi( + UpdateResourceItemApi( + resourceId, bookId, name, knowledgeCode, txtDesc, fileExtension, fileSize, - filePath, - chapterId + filePath ) .then((res: any) => { - setLoading(false); + setSpinInit(false); message.success(t('commen.saveSuccess')); onCancel(); }) .catch((e) => { - setLoading(false); + setSpinInit(false); + }); + } else { + console.log(bookId, name, knowledgeCode, txtDesc, fileExtension, fileSize, filePath); + AddResourceItemApi(bookId, name, knowledgeCode, txtDesc, fileExtension, fileSize, filePath) + .then((res: any) => { + setSpinInit(false); + message.success(t('commen.saveSuccess')); + onCancel(); + }) + .catch((e) => { + console.log(e, 'error'); + setSpinInit(false); }); } onCancel(); @@ -117,6 +209,7 @@ const CreateResourceModal = (props: ModalPropsType) => { const handleSelectChange = (e: any) => { console.log(e, '>>.select e'); + setKnowledgeCode(e.join(',')); }; const onFinishFailed = (errorInfo: any) => { @@ -160,14 +253,6 @@ const CreateResourceModal = (props: ModalPropsType) => { >