import { useEffect, useState } from "react"; import { Row, Col, Spin, Tree, Popover, Space, Image } from "antd"; import type { MenuProps } from "antd"; import { user } from "../../api/index"; import styles from "./index.module.scss"; import { useSelector } from "react-redux"; import { CoursesModel } from "./compenents/courses-model"; import { Empty } from "../../compenents"; import myLesoon from "../../assets/images/commen/icon-mylesoon.png"; import studyTime from "../../assets/images/commen/icon-studytime.png"; import iconRoute from "../../assets/images/commen/icon-route.png"; import { studyTimeFormat } from "../../utils/index"; const IndexPage = () => { const systemConfig = useSelector((state: any) => state.systemConfig.value); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const [tabKey, setTabKey] = useState(0); const [coursesList, setCoursesList] = useState([]); const [categories, setCategories] = useState([]); const [categoryId, setCategoryId] = useState(0); const [categoryText, setCategoryText] = useState("所有分类"); const [learnCourseRecords, setLearnCourseRecords] = useState({}); const [learnCourseHourCount, setLearnCourseHourCount] = useState({}); const [stats, setStats] = useState({}); const departments = useSelector( (state: any) => state.loginUser.value.departments ); const currentDepId = useSelector( (state: any) => state.loginUser.value.currentDepId ); useEffect(() => { getParams(); }, []); useEffect(() => { if (currentDepId === 0) { return; } getData(); }, [tabKey, currentDepId, categoryId]); useEffect(() => { document.title = systemConfig.systemName || "首页"; }, [systemConfig]); const hide = () => { setOpen(false); }; const getData = () => { setLoading(true); user.courses(currentDepId, categoryId).then((res: any) => { const records = res.data.learn_course_records; setStats(res.data.stats); setLearnCourseRecords(records); setLearnCourseHourCount(res.data.user_course_hour_count); if (tabKey === 0) { setCoursesList(res.data.courses); } else if (tabKey === 1) { const arr: any = []; res.data.courses.map((item: any) => { if (item.is_required === 1) { arr.push(item); } }); setCoursesList(arr); } else if (tabKey === 2) { const arr: any = []; res.data.courses.map((item: any) => { if (item.is_required === 0) { arr.push(item); } }); setCoursesList(arr); } else if (tabKey === 3) { const arr: any = []; res.data.courses.map((item: any) => { if (records[item.id] && records[item.id].progress >= 10000) { arr.push(item); } }); setCoursesList(arr); } else if (tabKey === 4) { const arr: any = []; res.data.courses.map((item: any) => { if ( !records[item.id] || (records[item.id] && records[item.id].progress < 10000) ) { arr.push(item); } }); setCoursesList(arr); } setLoading(false); }); }; const getParams = () => { user.coursesCategories().then((res: any) => { const categories = res.data.categories; if (JSON.stringify(categories) !== "{}") { const new_arr: any[] = checkArr(categories, 0); new_arr.unshift({ key: 0, title: "所有分类", }); setCategories(new_arr); } }); }; const checkArr = (categories: any[], id: number) => { const arr = []; for (let i = 0; i < categories[id].length; i++) { if (!categories[categories[id][i].id]) { arr.push({ title: ( {categories[id][i].name} ), key: categories[id][i].id, }); } else { const new_arr: any[] = checkArr(categories, categories[id][i].id); arr.push({ title: ( {categories[id][i].name} ), key: categories[id][i].id, children: new_arr, }); } } return arr; }; const items = [ { key: 0, label: `全部`, }, { key: 1, label: `必修课`, }, { key: 2, label: `选修课`, }, { key: 3, label: `已学完`, }, { key: 4, label: `未学完`, }, ]; const onChange = (key: number) => { setTabKey(key); }; const onSelect = (selectedKeys: any, info: any) => { setCategoryId(selectedKeys[0]); setCategoryText(info.node.title); hide(); }; const handleOpenChange = (newOpen: boolean) => { setOpen(newOpen); }; const dropItem = (
setOpen(false)} onMouseOver={() => setOpen(true)} >
); return (
课程进度
必修课:已学完课程 {stats.required_finished_course_count || 0} / {stats.required_course_count || 0}
{stats.nun_required_course_count > 0 && (
选修课:已学完课程 {" "} {stats.nun_required_finished_course_count || 0}{" "} / {stats.nun_required_course_count || 0}
)}
学习时长
今日: {studyTimeFormat(stats.today_learn_duration)[0] !== 0 && ( <> {" "} {studyTimeFormat(stats.today_learn_duration)[0] || 0}{" "} 天 )} {studyTimeFormat(stats.today_learn_duration)[1] !== 0 && ( <> {" "} {studyTimeFormat(stats.today_learn_duration)[1] || 0}{" "} 小时 )} {" "} {studyTimeFormat(stats.today_learn_duration)[2] || 0}{" "} 分钟 {" "} {studyTimeFormat(stats.today_learn_duration)[3] || 0}{" "}
累计: {studyTimeFormat(stats.learn_duration || 0)[0] !== 0 && ( <> {" "} {studyTimeFormat(stats.learn_duration || 0)[0] || 0}{" "} 天 )} {studyTimeFormat(stats.learn_duration || 0)[1] !== 0 && ( <> {" "} {studyTimeFormat(stats.learn_duration || 0)[1] || 0}{" "} 小时 )} {" "} {studyTimeFormat(stats.learn_duration || 0)[2] || 0}{" "} 分钟 {" "} {studyTimeFormat(stats.learn_duration || 0)[3] || 0}{" "}
{items.map((item: any) => (
{ onChange(item.key); }} >
{item.label}
{item.key === tabKey && ( )}
))} setOpen(true)} > {categoryText}
{loading && (
)} {!loading && coursesList.length === 0 && ( )} {!loading && coursesList.length > 0 && (
{coursesList.map((item: any) => (
{learnCourseRecords[item.id] && ( )} {!learnCourseRecords[item.id] && learnCourseHourCount[item.id] && learnCourseHourCount[item.id] > 0 && ( )} {!learnCourseRecords[item.id] && !learnCourseHourCount[item.id] && ( )}
))}
)}
{systemConfig.pcIndexFooterMsg}
); }; export default IndexPage;