diff --git a/src/compenents/select-resource/index.tsx b/src/compenents/select-resource/index.tsx index 5754c3f..b0f74f7 100644 --- a/src/compenents/select-resource/index.tsx +++ b/src/compenents/select-resource/index.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from "react"; -import { Button, Row, Col, Modal, message, Tabs } from "antd"; +import { Button, Row, Modal, message, Tabs } from "antd"; import styles from "./index.module.less"; import { UploadVideoSub } from "../../compenents"; import type { TabsProps } from "antd"; diff --git a/src/compenents/upload-video-sub/index.tsx b/src/compenents/upload-video-sub/index.tsx index 3757d05..c93f2e4 100644 --- a/src/compenents/upload-video-sub/index.tsx +++ b/src/compenents/upload-video-sub/index.tsx @@ -25,7 +25,7 @@ interface PropsInterface { export const UploadVideoSub = (props: PropsInterface) => { const [category_ids, setCategoryIds] = useState([]); - + const [loading, setLoading] = useState(false); const [videoList, setVideoList] = useState([]); const [videosExtra, setVideoExtra] = useState([]); const [refresh, setRefresh] = useState(false); @@ -39,7 +39,7 @@ export const UploadVideoSub = (props: PropsInterface) => { const [checkAll, setCheckAll] = useState(false); // 获取列表 - const getvideoList = () => { + const getvideoList = (defaultKeys: any[]) => { let categoryIds = category_ids.join(","); resource .resourceList(page, size, "", "", "", "VIDEO", categoryIds) @@ -69,8 +69,18 @@ export const UploadVideoSub = (props: PropsInterface) => { ), value: data[i].id, + disabled: false, }); } + if (defaultKeys.length > 0 && arr.length > 0) { + for (let i = 0; i < defaultKeys.length; i++) { + for (let j = 0; j < arr.length; j++) { + if (arr[j].value === defaultKeys[i]) { + arr[j].disabled = true; + } + } + } + } setPlainOptions(arr); }) .catch((err) => { @@ -83,7 +93,8 @@ export const UploadVideoSub = (props: PropsInterface) => { setVideoList([]); setRefresh(!refresh); }; - //重置选中的key + + // 加载列表 useEffect(() => { const arr = [...props.defaultCheckedList]; setCheckedList(arr); @@ -91,12 +102,8 @@ export const UploadVideoSub = (props: PropsInterface) => { setIndeterminate(false); setCheckAll(false); } - }, [props.defaultCheckedList]); - - // 加载列表 - useEffect(() => { - getvideoList(); - }, [props.open, category_ids, refresh, page, size]); + getvideoList(arr); + }, [props.open, props.defaultCheckedList, category_ids, refresh, page, size]); const onChange = (list: CheckboxValueType[]) => { setCheckedList(list); @@ -104,13 +111,14 @@ export const UploadVideoSub = (props: PropsInterface) => { setCheckAll(list.length === plainOptions.length); let arrVideos: any = []; for (let i = 0; i < list.length; i++) { - videoList.map((item: any) => { + videoList.map((item: any, index: number) => { if (item.id === list[i]) { arrVideos.push({ name: item.name, type: item.type, rid: item.id, duration: videosExtra[item.id].duration, + disabled: plainOptions[index].disabled, }); } }); @@ -125,12 +133,13 @@ export const UploadVideoSub = (props: PropsInterface) => { setIndeterminate(false); setCheckAll(e.target.checked); let arrVideos: any = []; - videoList.map((item: any) => { + videoList.map((item: any, index: number) => { arrVideos.push({ name: item.name, type: item.type, rid: item.id, duration: videosExtra[item.id].duration, + disabled: plainOptions[index].disabled, }); }); if (e.target.checked) { @@ -184,11 +193,6 @@ export const UploadVideoSub = (props: PropsInterface) => { /> )} - {/* {videoList.map((item) => ( -
- {item.name} -
- ))} */} = ({ const selectData = (arr: any, videos: any) => { const hours: any = []; + console.log(videos); for (let i = 0; i < videos.length; i++) { - hours.push({ - chapter_id: 0, - sort: i, - title: videos[i].name, - type: videos[i].type, - duration: videos[i].duration, - rid: videos[i].rid, - }); + if (videos[i].disabled === false) { + hours.push({ + chapter_id: 0, + sort: i, + title: videos[i].name, + type: videos[i].type, + duration: videos[i].duration, + rid: videos[i].rid, + }); + } } courseHour .storeCourseHourMulti(id, hours) @@ -135,14 +138,16 @@ export const CourseHourUpdate: React.FC = ({ } const hours: any = []; for (let i = 0; i < videos.length; i++) { - hours.push({ - chapter_id: data[addvideoCurrent].id, - sort: i, - title: videos[i].name, - type: videos[i].type, - duration: videos[i].duration, - rid: videos[i].rid, - }); + if (videos[i].disabled === false) { + hours.push({ + chapter_id: data[addvideoCurrent].id, + sort: i, + title: videos[i].name, + type: videos[i].type, + duration: videos[i].duration, + rid: videos[i].rid, + }); + } } courseHour .storeCourseHourMulti(id, hours) diff --git a/src/pages/course/compenents/update.tsx b/src/pages/course/compenents/update.tsx index 24738b7..0e63799 100644 --- a/src/pages/course/compenents/update.tsx +++ b/src/pages/course/compenents/update.tsx @@ -80,7 +80,7 @@ export const CourseUpdate: React.FC = ({ let box = res.data.dep_ids; let depIds: any[] = []; let type = res.data.dep_ids.length > 0 ? "elective" : "open"; - if (box.length > 1) { + if (box.length > 0) { for (let i = 0; i < box.length; i++) { let item = checkChild(deps, box[i]); let arr: any[] = []; diff --git a/src/pages/course/index.tsx b/src/pages/course/index.tsx index 3246a7d..1e6450c 100644 --- a/src/pages/course/index.tsx +++ b/src/pages/course/index.tsx @@ -157,7 +157,6 @@ export const CoursePage = () => { { title: "必修/选修", dataIndex: "isRequired", - width: 120, render: (isRequired: number) => ( {isRequired === 1 ? "必修课" : "选修课"} ),