diff --git a/src/api/course.ts b/src/api/course.ts index 87dedc4..3c55ecb 100644 --- a/src/api/course.ts +++ b/src/api/course.ts @@ -34,8 +34,8 @@ export function storeCourse( isRequired: number, depIds: number[], categoryIds: number[], - chapters: number[], - hours: number[], + chapters: any[], + hours: any[], attachments: any[] ) { return client.post("/backend/v1/course/create", { diff --git a/src/pages/course/compenents/attachment-update.tsx b/src/pages/course/compenents/attachment-update.tsx index 76a4541..4d77bed 100644 --- a/src/pages/course/compenents/attachment-update.tsx +++ b/src/pages/course/compenents/attachment-update.tsx @@ -22,8 +22,10 @@ export const CourseAttachmentUpdate: React.FC = ({ const [form] = Form.useForm(); const [init, setInit] = useState(true); const [attachmentVisible, setAttachmentVisible] = useState(false); - const [attachmentData, setAttachmentData] = useState([]); - const [attachments, setAttachments] = useState([]); + const [attachmentData, setAttachmentData] = useState( + [] + ); + const [attachments, setAttachments] = useState([]); useEffect(() => { setInit(true); diff --git a/src/pages/course/compenents/attachments.tsx b/src/pages/course/compenents/attachments.tsx index 5a0aa58..216d48c 100644 --- a/src/pages/course/compenents/attachments.tsx +++ b/src/pages/course/compenents/attachments.tsx @@ -1,20 +1,20 @@ -import { message, Tree, Tooltip } from "antd"; +import { Tree, Tooltip } from "antd"; import { useState, useEffect } from "react"; import type { DataNode, TreeProps } from "antd/es/tree"; -interface Option { - id: number; - name: string; -} - interface PropInterface { - data: Option[]; + data: AttachmentDataModel[]; onRemoveItem: (id: number) => void; onUpdate: (arr: any[]) => void; } +interface Option { + key: string | number; + title: any; +} + export const TreeAttachments = (props: PropInterface) => { - const [treeData, setTreeData] = useState([]); + const [treeData, setTreeData] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const hours = props.data; diff --git a/src/pages/course/compenents/create.tsx b/src/pages/course/compenents/create.tsx index cb1d9b0..38836ef 100644 --- a/src/pages/course/compenents/create.tsx +++ b/src/pages/course/compenents/create.tsx @@ -57,16 +57,18 @@ export const CourseCreate: React.FC = ({ const [thumb, setThumb] = useState(""); const [type, setType] = useState("open"); const [chapterType, setChapterType] = useState(0); - const [chapters, setChapters] = useState([]); - const [hours, setHours] = useState([]); + const [chapters, setChapters] = useState([]); + const [hours, setHours] = useState([]); const [chapterHours, setChapterHours] = useState([]); const [videoVisible, setVideoVisible] = useState(false); - const [treeData, setTreeData] = useState([]); + const [treeData, setTreeData] = useState([]); const [addvideoCurrent, setAddvideoCurrent] = useState(0); const [showDrop, setShowDrop] = useState(false); const [attachmentVisible, setAttachmentVisible] = useState(false); - const [attachmentData, setAttachmentData] = useState([]); - const [attachments, setAttachments] = useState([]); + const [attachmentData, setAttachmentData] = useState( + [] + ); + const [attachments, setAttachments] = useState([]); useEffect(() => { if (open) { @@ -265,6 +267,7 @@ export const CourseCreate: React.FC = ({ setHours(keys); setTreeData(data); setVideoVisible(false); + console.log(keys, data); }; const selectChapterData = (arr: any, videos: any) => { @@ -444,7 +447,6 @@ export const CourseCreate: React.FC = ({ const keys = [...chapterHours]; keys[index] = arr; setChapterHours(keys); - const data = [...chapters]; const newArr: any = []; for (let i = 0; i < arr.length; i++) { diff --git a/src/pages/course/compenents/hour-update.tsx b/src/pages/course/compenents/hour-update.tsx index e3d5361..3a86d03 100644 --- a/src/pages/course/compenents/hour-update.tsx +++ b/src/pages/course/compenents/hour-update.tsx @@ -22,11 +22,11 @@ export const CourseHourUpdate: React.FC = ({ const [form] = Form.useForm(); const [init, setInit] = useState(true); const [chapterType, setChapterType] = useState(0); - const [chapters, setChapters] = useState([]); - const [hours, setHours] = useState([]); + const [chapters, setChapters] = useState([]); + const [hours, setHours] = useState([]); const [chapterHours, setChapterHours] = useState([]); const [videoVisible, setVideoVisible] = useState(false); - const [treeData, setTreeData] = useState([]); + const [treeData, setTreeData] = useState([]); const [addvideoCurrent, setAddvideoCurrent] = useState(0); useEffect(() => { @@ -234,7 +234,7 @@ export const CourseHourUpdate: React.FC = ({ const arr = [...chapters]; if (arr[index].id) { courseChapter - .updateCourseChapter(id, arr[index].id, value, arr.length) + .updateCourseChapter(id, Number(arr[index].id), value, arr.length) .then((res: any) => { console.log("ok"); getDetail(); @@ -262,7 +262,7 @@ export const CourseHourUpdate: React.FC = ({ onOk() { if (arr[index].id) { courseChapter - .destroyCourseChapter(id, arr[index].id) + .destroyCourseChapter(id, Number(arr[index].id)) .then((res: any) => { console.log("ok"); getDetail(); diff --git a/src/pages/course/compenents/hours.tsx b/src/pages/course/compenents/hours.tsx index c8e7c34..8765df8 100644 --- a/src/pages/course/compenents/hours.tsx +++ b/src/pages/course/compenents/hours.tsx @@ -3,18 +3,18 @@ import { useState, useEffect } from "react"; import type { DataNode, TreeProps } from "antd/es/tree"; interface Option { - id: number; - name: string; + key: string | number; + title: any; } interface PropInterface { - data: Option[]; + data: CourseHourModel[]; onRemoveItem: (id: number) => void; onUpdate: (arr: any[]) => void; } export const TreeHours = (props: PropInterface) => { - const [treeData, setTreeData] = useState([]); + const [treeData, setTreeData] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const hours = props.data; diff --git a/src/playedu.d.ts b/src/playedu.d.ts index 910e705..48babd2 100644 --- a/src/playedu.d.ts +++ b/src/playedu.d.ts @@ -116,6 +116,27 @@ declare global { interface RoleIdsModel { [key: number]: number[]; } + + interface CourseChaptersModel { + id?: number; + hours: CourseHourModel[]; + name: string; + } + + interface CourseHourModel { + id?: number; + duration: number; + name: string; + rid: number; + type: string; + } + + interface AttachmentDataModel { + id?: number; + name: string; + rid: number; + type: string; + } } export {};