diff --git a/src/compenents/select-resource/index.tsx b/src/compenents/select-resource/index.tsx index 75cc814..c5f5654 100644 --- a/src/compenents/select-resource/index.tsx +++ b/src/compenents/select-resource/index.tsx @@ -12,8 +12,9 @@ interface VideoItem { } interface PropsInterface { + defaultKeys: any[]; open: boolean; - onSelected: (arr: any[], label: any[]) => void; + onSelected: (arr: any[], videos: any[]) => void; onCancel: () => void; } @@ -21,7 +22,7 @@ export const SelectResource = (props: PropsInterface) => { const [refresh, setRefresh] = useState(true); const [tabKey, setTabKey] = useState(1); const [selectKeys, setSelectKeys] = useState([]); - const [selectLabel, setSelectLabel] = useState([]); + const [selectVideos, setSelectVideos] = useState([]); const items: TabsProps["items"] = [ { @@ -31,11 +32,11 @@ export const SelectResource = (props: PropsInterface) => {
{ + onSelected={(arr: any[], videos: any[]) => { setSelectKeys(arr); - setSelectLabel(label); + setSelectVideos(videos); }} />
@@ -60,7 +61,7 @@ export const SelectResource = (props: PropsInterface) => { open={props.open} width={800} maskClosable={false} - onOk={() => props.onSelected(selectKeys, selectLabel)} + onOk={() => props.onSelected(selectKeys, selectVideos)} > diff --git a/src/compenents/upload-video-sub/index.tsx b/src/compenents/upload-video-sub/index.tsx index e083a71..055f562 100644 --- a/src/compenents/upload-video-sub/index.tsx +++ b/src/compenents/upload-video-sub/index.tsx @@ -20,7 +20,7 @@ interface PropsInterface { defaultCheckedList: any[]; label: string; open: boolean; - onSelected: (arr: any[], label: any) => void; + onSelected: (arr: any[], videos: []) => void; } export const UploadVideoSub = (props: PropsInterface) => { @@ -36,9 +36,7 @@ export const UploadVideoSub = (props: PropsInterface) => { const [categoryCount, setCategoryCount] = useState({}); const [plainOptions, setPlainOptions] = useState([]); - const [checkedList, setCheckedList] = useState( - props.defaultCheckedList - ); + const [checkedList, setCheckedList] = useState([]); const [indeterminate, setIndeterminate] = useState(false); const [checkAll, setCheckAll] = useState(false); @@ -89,6 +87,10 @@ export const UploadVideoSub = (props: PropsInterface) => { setVideoList([]); setRefresh(!refresh); }; + //重置选中的key + useEffect(() => { + setCheckedList(props.defaultCheckedList); + }, [props.defaultCheckedList]); // 加载列表 useEffect(() => { @@ -99,16 +101,21 @@ export const UploadVideoSub = (props: PropsInterface) => { setCheckedList(list); setIndeterminate(!!list.length && list.length < plainOptions.length); setCheckAll(list.length === plainOptions.length); - let arrLabel: any = []; + let arrVideos: any = []; for (let i = 0; i < list.length; i++) { videoList.map((item: any) => { if (item.id === list[i]) { - arrLabel.push(item.name); + arrVideos.push({ + name: item.name, + type: item.type, + rid: item.id, + duration: videosExtra[item.id].duration, + }); } }); } - props.onSelected(list, arrLabel); + props.onSelected(list, arrVideos); }; const onCheckAllChange = (e: CheckboxChangeEvent) => { @@ -116,9 +123,17 @@ export const UploadVideoSub = (props: PropsInterface) => { setCheckedList(e.target.checked ? arr : []); setIndeterminate(false); setCheckAll(e.target.checked); - const arrLabel = videoList.map((item: any) => item.name); + let arrVideos: any = []; + videoList.map((item: any) => { + arrVideos.push({ + name: item.name, + type: item.type, + rid: item.id, + duration: videosExtra[item.id].duration, + }); + }); if (e.target.checked) { - props.onSelected(arr, arrLabel); + props.onSelected(arr, arrVideos); } else { props.onSelected([], []); } diff --git a/src/index.less b/src/index.less index 6999e33..102d671 100644 --- a/src/index.less +++ b/src/index.less @@ -526,3 +526,11 @@ textarea.ant-input { flex-direction: row-reverse; } } + +.tree-video-title { + margin-left: 4px; + width: 346px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} diff --git a/src/pages/course/compenents/create.module.less b/src/pages/course/compenents/create.module.less index cc71a68..b60bf60 100644 --- a/src/pages/course/compenents/create.module.less +++ b/src/pages/course/compenents/create.module.less @@ -32,7 +32,7 @@ /* Firefox */ -webkit-box-sizing: border-box; /* Safari */ - padding: 16px; + padding: 16px 16px 16px 0; margin-left: 42px; .no-hours { height: 24px; @@ -40,5 +40,6 @@ font-weight: 400; color: rgba(0, 0, 0, 0.25); line-height: 24px; + margin-left: 16px; } } diff --git a/src/pages/course/compenents/create.tsx b/src/pages/course/compenents/create.tsx index 77c8477..e416177 100644 --- a/src/pages/course/compenents/create.tsx +++ b/src/pages/course/compenents/create.tsx @@ -16,6 +16,7 @@ import { course, department } from "../../../api/index"; import { UploadImageButton, SelectResource } from "../../../compenents"; import { ExclamationCircleFilled } from "@ant-design/icons"; import { getHost } from "../../../utils/index"; +import { TreeHours } from "./hours"; const { confirm } = Modal; @@ -44,6 +45,7 @@ export const CourseCreate: React.FC = ({ open, onCancel }) => { const [chapters, setChapters] = useState([]); const [hours, setHours] = useState([]); const [videoVisible, setVideoVisible] = useState(false); + const [treeData, setTreeData] = useState([]); useEffect(() => { getParams(); @@ -61,8 +63,10 @@ export const CourseCreate: React.FC = ({ open, onCancel }) => { hasChapter: 0, }); setThumb(defaultThumb1); + setChapterType(0); setChapters([]); setHours([]); + setTreeData([]); }, [form, open]); const getParams = () => { @@ -107,8 +111,10 @@ export const CourseCreate: React.FC = ({ open, onCancel }) => { const onFinish = (values: any) => { let dep_ids: any[] = []; - for (let i = 0; i < values.dep_ids.length; i++) { - dep_ids.push(values.dep_ids[i][values.dep_ids[i].length - 1]); + if (type === "elective") { + for (let i = 0; i < values.dep_ids.length; i++) { + dep_ids.push(values.dep_ids[i][values.dep_ids[i].length - 1]); + } } let category_ids: any[] = []; for (let j = 0; j < values.category_ids.length; j++) { @@ -117,7 +123,15 @@ export const CourseCreate: React.FC = ({ open, onCancel }) => { ); } course - .storeCourse(values.title, values.thumb, 1, dep_ids, category_ids, [], []) + .storeCourse( + values.title, + values.thumb, + 1, + dep_ids, + category_ids, + chapters, + treeData + ) .then((res: any) => { message.success("保存成功!"); onCancel(); @@ -132,6 +146,12 @@ export const CourseCreate: React.FC = ({ open, onCancel }) => { setType(e.target.value); }; + const selectData = (arr: any, videos: any) => { + setHours(arr); + setTreeData(videos); + setVideoVisible(false); + }; + const getChapterType = (e: any) => { confirm({ title: "操作确认", @@ -153,6 +173,22 @@ export const CourseCreate: React.FC = ({ open, onCancel }) => { }); }; + const delHour = (id: number) => { + const data = [...treeData]; + const index = data.findIndex((i: any) => i.id === id); + if (index >= 0) { + data.splice(index, 1); + } + if (data.length > 0) { + setTreeData(data); + const keys = data.map((item: any) => item.rid); + setHours(keys); + } else { + setTreeData([]); + setHours([]); + } + }; + return ( <> = ({ open, onCancel }) => { >
{ setVideoVisible(false); }} - onSelected={(arr: any, label: any) => { - console.log("sel", arr, label); - setVideoVisible(false); + onSelected={(arr: any, videos: any) => { + selectData(arr, videos); }} />
= ({ open, onCancel }) => { 部门课 - - - + + {type === "elective" && ( + + + + )} + = ({ open, onCancel }) => {
- {hours.length === 0 && ( + {treeData.length === 0 && ( 请添加课时内容 )} - {hours.length > 0 && 13} + {treeData.length > 0 && ( + { + delHour(id); + }} + /> + )}
)} diff --git a/src/pages/course/compenents/hours.tsx b/src/pages/course/compenents/hours.tsx index 656656b..a0c238e 100644 --- a/src/pages/course/compenents/hours.tsx +++ b/src/pages/course/compenents/hours.tsx @@ -1,14 +1,14 @@ -import { message, Tree } from "antd"; +import { message, Tree, Tooltip } from "antd"; import { useState, useEffect } from "react"; interface Option { - id: string | number; + id: number; name: string; } interface PropInterface { data: Option[]; - onUpdate: () => void; + onRemoveItem: (id: number) => void; } export const TreeHours = (props: PropInterface) => { @@ -16,18 +16,54 @@ export const TreeHours = (props: PropInterface) => { const [loading, setLoading] = useState(true); useEffect(() => { const hours = props.data; + if (hours.length === 0) { return; } + checkTree(hours); + }, [props.data]); + + const checkTree = (hours: any) => { const arr = []; for (let i = 0; i < hours.length; i++) { arr.push({ - title: hours[i].name, + title: ( +
+
+ +
{hours[i].name}
+
+ + + + removeItem(hours[i].id)} + /> +
+ ), key: hours[i].id, }); } setTreeData(arr); - }, [props.data]); + }; + + const removeItem = (id: number) => { + if (id === 0) { + return; + } + props.onRemoveItem(id); + }; return (