线上课添加、编辑课时优化

This commit is contained in:
禺狨 2023-03-29 13:36:12 +08:00
parent 5f0c1f23de
commit 65a4045a8b
4 changed files with 64 additions and 30 deletions

View File

@ -109,10 +109,19 @@ export const UploadVideoSub = (props: PropsInterface) => {
setCheckedList(list); setCheckedList(list);
setIndeterminate(!!list.length && list.length < plainOptions.length); setIndeterminate(!!list.length && list.length < plainOptions.length);
setCheckAll(list.length === plainOptions.length); setCheckAll(list.length === plainOptions.length);
const defalut = [...props.defaultCheckedList];
let localKeys: any = [];
list.map((item: any) => {
if (defalut.indexOf(item) === -1) {
localKeys.push(item);
}
});
let arrVideos: any = []; let arrVideos: any = [];
for (let i = 0; i < list.length; i++) {
for (let i = 0; i < localKeys.length; i++) {
videoList.map((item: any, index: number) => { videoList.map((item: any, index: number) => {
if (item.id === list[i]) { if (item.id === localKeys[i]) {
arrVideos.push({ arrVideos.push({
name: item.name, name: item.name,
type: item.type, type: item.type,
@ -123,8 +132,7 @@ export const UploadVideoSub = (props: PropsInterface) => {
} }
}); });
} }
props.onSelected(localKeys, arrVideos);
props.onSelected(list, arrVideos);
}; };
const onCheckAllChange = (e: CheckboxChangeEvent) => { const onCheckAllChange = (e: CheckboxChangeEvent) => {
@ -132,18 +140,29 @@ export const UploadVideoSub = (props: PropsInterface) => {
setCheckedList(e.target.checked ? arr : []); setCheckedList(e.target.checked ? arr : []);
setIndeterminate(false); setIndeterminate(false);
setCheckAll(e.target.checked); setCheckAll(e.target.checked);
let arrVideos: any = []; const defalut = [...props.defaultCheckedList];
videoList.map((item: any, index: number) => { let localKeys: any = [];
arrVideos.push({ arr.map((item: any) => {
name: item.name, if (defalut.indexOf(item) === -1) {
type: item.type, localKeys.push(item);
rid: item.id, }
duration: videosExtra[item.id].duration,
disabled: plainOptions[index].disabled,
});
}); });
let arrVideos: any = [];
for (let i = 0; i < localKeys.length; i++) {
videoList.map((item: any, index: number) => {
if (item.id === localKeys[i]) {
arrVideos.push({
name: item.name,
type: item.type,
rid: item.id,
duration: videosExtra[item.id].duration,
disabled: plainOptions[index].disabled,
});
}
});
}
if (e.target.checked) { if (e.target.checked) {
props.onSelected(arr, arrVideos); props.onSelected(localKeys, arrVideos);
} else { } else {
props.onSelected([], []); props.onSelected([], []);
} }

View File

@ -72,6 +72,7 @@ export const CourseCreate: React.FC<PropInterface> = ({
setThumb(defaultThumb1); setThumb(defaultThumb1);
setChapterType(0); setChapterType(0);
setChapters([]); setChapters([]);
setChapterHours([]);
setHours([]); setHours([]);
setTreeData([]); setTreeData([]);
}, [form, open]); }, [form, open]);
@ -213,16 +214,20 @@ export const CourseCreate: React.FC<PropInterface> = ({
}; };
const selectData = (arr: any, videos: any) => { const selectData = (arr: any, videos: any) => {
setHours(arr); let keys = [...hours];
setTreeData(videos); let data = [...treeData];
keys = keys.concat(arr);
data = data.concat(videos);
setHours(keys);
setTreeData(data);
setVideoVisible(false); setVideoVisible(false);
}; };
const selectChapterData = (arr: any, videos: any) => { const selectChapterData = (arr: any, videos: any) => {
const data = [...chapters]; const data = [...chapters];
const keys = [...chapterHours]; const keys = [...chapterHours];
keys[addvideoCurrent] = arr; keys[addvideoCurrent] = keys[addvideoCurrent].concat(arr);
data[addvideoCurrent].hours = videos; data[addvideoCurrent].hours = data[addvideoCurrent].hours.concat(videos);
setChapters(data); setChapters(data);
setChapterHours(keys); setChapterHours(keys);
setVideoVisible(false); setVideoVisible(false);
@ -361,6 +366,16 @@ export const CourseCreate: React.FC<PropInterface> = ({
setChapters(data); setChapters(data);
}; };
const changeChapterHours = (arr: any) => {
const newArr: any = [];
for (let i = 0; i < arr.length; i++) {
arr[i].map((item: any) => {
newArr.push(item);
});
}
return newArr;
};
return ( return (
<> <>
<Drawer <Drawer
@ -381,7 +396,7 @@ export const CourseCreate: React.FC<PropInterface> = ({
<div className="float-left mt-24"> <div className="float-left mt-24">
<SelectResource <SelectResource
defaultKeys={ defaultKeys={
chapterType == 0 ? hours : chapterHours[addvideoCurrent] chapterType == 0 ? hours : changeChapterHours(chapterHours)
} }
open={videoVisible} open={videoVisible}
onCancel={() => { onCancel={() => {

View File

@ -346,6 +346,16 @@ export const CourseHourUpdate: React.FC<PropInterface> = ({
}); });
}; };
const changeChapterHours = (arr: any) => {
const newArr: any = [];
for (let i = 0; i < arr.length; i++) {
arr[i].map((item: any) => {
newArr.push(item);
});
}
return newArr;
};
return ( return (
<> <>
<Drawer <Drawer
@ -362,7 +372,7 @@ export const CourseHourUpdate: React.FC<PropInterface> = ({
<div className="float-left mt-24"> <div className="float-left mt-24">
<SelectResource <SelectResource
defaultKeys={ defaultKeys={
chapterType === 0 ? hours : chapterHours[addvideoCurrent] chapterType === 0 ? hours : changeChapterHours(chapterHours)
} }
open={videoVisible} open={videoVisible}
onCancel={() => { onCancel={() => {

View File

@ -96,16 +96,6 @@ export const CourseUpdate: React.FC<PropInterface> = ({
}); });
}; };
const checkChild = (departments: any[], id: number) => {
for (let key in departments) {
for (let i = 0; i < departments[key].length; i++) {
if (departments[key][i].id === id) {
return departments[key][i];
}
}
}
};
const checkArr = (departments: any[], id: number) => { const checkArr = (departments: any[], id: number) => {
const arr = []; const arr = [];
for (let i = 0; i < departments[id].length; i++) { for (let i = 0; i < departments[id].length; i++) {