diff --git a/src/api/course.ts b/src/api/course.ts index 913b081..ae53231 100644 --- a/src/api/course.ts +++ b/src/api/course.ts @@ -25,5 +25,11 @@ export const courseApi = { /** 删除公司课程 */ delCourse(course_id: number) { return request(`/api/v1/course/del/${course_id}`, "DELETE") + }, + /** + * 类型查询课程 + */ + courseType(type: string, data: Pages) { + return request<{ data: Curriculum[], total: number }>(`/api/v1/course/course/info/type/${type}`, 'GET', data) } } diff --git a/src/api/login.ts b/src/api/login.ts index edde65f..308f498 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -14,7 +14,7 @@ export const loginApi = { return request("/api/v1/auth/login/meeting", "GET"); }, testLogin() { - return request('/token/15882685759', "GET") + return request('/token/18708100736', "GET") }, meetingInfo(id: string) { return request(`/api/v1/meetings/meeting/${id}/info`, "GET") diff --git a/src/app.config.ts b/src/app.config.ts index 7b642d7..2de26e7 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -50,6 +50,7 @@ export default defineAppConfig({ 'history/history', 'curHistory/curHistory', 'hourHistory/hourHistory', + 'courType/courType', ] }, { diff --git a/src/pages/business/courType/courType.config.ts b/src/pages/business/courType/courType.config.ts new file mode 100644 index 0000000..0dcb3ed --- /dev/null +++ b/src/pages/business/courType/courType.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '课程', + onReachBottomDistance: 30 +}) diff --git a/src/pages/business/courType/courType.tsx b/src/pages/business/courType/courType.tsx new file mode 100644 index 0000000..cc7cba0 --- /dev/null +++ b/src/pages/business/courType/courType.tsx @@ -0,0 +1,74 @@ +import {View} from "@tarojs/components"; +import {FC, useEffect, useState} from "react"; +import Taro, {useReachBottom, useRouter} from "@tarojs/taro"; +import {courseApi} from "@/api"; +import VideoCover from "@/components/videoCover/videoCover"; +import {formatMinute} from "@/utils/time"; +import Empty from "@/components/empty/empty"; + +const CourType: FC = () => { + const params = useRouter().params + const [total, setTotal] = useState(0) + const [data, setData] = useState([]) + const [page, setPage] = useState({ + page: 1, + page_size: 10 + }) + + useReachBottom(() => { + if (data.length < total) { + setPage({ + ...page, + page: page.page + 1 + }) + } + }) + + async function getData() { + if (!params.type) return; + try { + const res = await courseApi.courseType(params.type, page) + setTotal(res.total) + + const oldData: Curriculum[] = JSON.parse(JSON.stringify(data)) + + res.data.forEach(d => { + const index = oldData.findIndex(x => x.id === d.id) + if (index === -1) { + oldData.push(d) + } else { + oldData.splice(index, 1, d) + } + }) + setData(oldData) + } catch (e) { + } + } + + + useEffect(() => { + getData() + }, [params]) + + Taro.useLoad(() => { + Taro.setNavigationBarTitle({ + title: ['课程', '必修课', '选修课', '已完成', '未完成'][params.type ? Number(params.type) : 0] + }) + }) + + return ( + + {data.length > 0 ? data.map(c => + ) : } + + ) +} + +export default CourType diff --git a/src/pages/business/videoInfo/videoInfo.tsx b/src/pages/business/videoInfo/videoInfo.tsx index aa121e5..e26c2b4 100644 --- a/src/pages/business/videoInfo/videoInfo.tsx +++ b/src/pages/business/videoInfo/videoInfo.tsx @@ -18,6 +18,7 @@ const VideoInfo: FC = () => { const [playing, setPlaying] = useState(false) // 学习中 const getData = useCallback(async (playing: boolean) => { + console.log({id}) const res = await curriculum.courseDep(id, depId) if (res) { setData(res) @@ -35,7 +36,6 @@ const VideoInfo: FC = () => { } function setHors(preview: boolean, play_id: number) { - console.log(preview) setPlaying(true) setPreview(preview) setPlayId(play_id) diff --git a/src/pages/my/components/header/time.tsx b/src/pages/my/components/header/time.tsx index 7973587..c542e33 100644 --- a/src/pages/my/components/header/time.tsx +++ b/src/pages/my/components/header/time.tsx @@ -14,17 +14,18 @@ import incomplete from '@/static/img/incomplete.png' interface List { title: string time: string | number - src: string + src: string, + type?: number } const Time: FC = () => { const [list, setList] = useState([ {title: '今日时长', time: '00:00', src: time1}, {title: '累计时长', time: '00:00', src: time2}, - {title: '必修课', time: '0/0', src: curriculum1}, - {title: '选修课', time: '0/0', src: curriculum2}, - {title: '已完成', time: '0', src: over}, - {title: '未完成', time: '0', src: incomplete}, + {title: '必修课', time: '0/0', src: curriculum1, type: 1}, + {title: '选修课', time: '0/0', src: curriculum2, type: 2}, + {title: '已完成', time: '0', src: over, type: 3}, + {title: '未完成', time: '0', src: incomplete, type: 4}, ]) @@ -43,13 +44,18 @@ const Time: FC = () => { } }) + function jump(type?: number) { + if (!type) return; + Taro.navigateTo({url: "/pages/business/courType/courType?type=" + type}) + } + return ( { list.map(d => { return ( - + jump(d.type)}> {d.title} diff --git a/types/curriculum.d.ts b/types/curriculum.d.ts index bb7f0b1..31cb7df 100644 --- a/types/curriculum.d.ts +++ b/types/curriculum.d.ts @@ -109,3 +109,9 @@ interface HourCacheParam { user_id: number; unique_ident: number } + + +interface Pages { + page: number + page_size: number +}