课程类型

main
king 1 year ago
parent 87a1c4e833
commit 66b99de2ba
  1. 6
      src/api/course.ts
  2. 2
      src/api/login.ts
  3. 1
      src/app.config.ts
  4. 4
      src/pages/business/courType/courType.config.ts
  5. 74
      src/pages/business/courType/courType.tsx
  6. 2
      src/pages/business/videoInfo/videoInfo.tsx
  7. 18
      src/pages/my/components/header/time.tsx
  8. 6
      types/curriculum.d.ts

@ -25,5 +25,11 @@ export const courseApi = {
/** 删除公司课程 */ /** 删除公司课程 */
delCourse(course_id: number) { delCourse(course_id: number) {
return request(`/api/v1/course/del/${course_id}`, "DELETE") 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)
} }
} }

@ -14,7 +14,7 @@ export const loginApi = {
return request<LoginParams>("/api/v1/auth/login/meeting", "GET"); return request<LoginParams>("/api/v1/auth/login/meeting", "GET");
}, },
testLogin() { testLogin() {
return request('/token/15882685759', "GET") return request('/token/18708100736', "GET")
}, },
meetingInfo(id: string) { meetingInfo(id: string) {
return request(`/api/v1/meetings/meeting/${id}/info`, "GET") return request(`/api/v1/meetings/meeting/${id}/info`, "GET")

@ -50,6 +50,7 @@ export default defineAppConfig({
'history/history', 'history/history',
'curHistory/curHistory', 'curHistory/curHistory',
'hourHistory/hourHistory', 'hourHistory/hourHistory',
'courType/courType',
] ]
}, },
{ {

@ -0,0 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '课程',
onReachBottomDistance: 30
})

@ -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<Curriculum[]>([])
const [page, setPage] = useState<Pages>({
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 (
<View className='py-2 flex justify-between flex-wrap '>
{data.length > 0 ? data.map(c =>
<VideoCover
thumb={c.thumb}
title={c.title}
id={c.id}
depId={c.id}
key={c.id}
time={formatMinute(c.course_duration)}
/>) : <Empty name='暂无数据'/>}
</View>
)
}
export default CourType

@ -18,6 +18,7 @@ const VideoInfo: FC = () => {
const [playing, setPlaying] = useState(false) // 学习中 const [playing, setPlaying] = useState(false) // 学习中
const getData = useCallback(async (playing: boolean) => { const getData = useCallback(async (playing: boolean) => {
console.log({id})
const res = await curriculum.courseDep(id, depId) const res = await curriculum.courseDep(id, depId)
if (res) { if (res) {
setData(res) setData(res)
@ -35,7 +36,6 @@ const VideoInfo: FC = () => {
} }
function setHors(preview: boolean, play_id: number) { function setHors(preview: boolean, play_id: number) {
console.log(preview)
setPlaying(true) setPlaying(true)
setPreview(preview) setPreview(preview)
setPlayId(play_id) setPlayId(play_id)

@ -14,17 +14,18 @@ import incomplete from '@/static/img/incomplete.png'
interface List { interface List {
title: string title: string
time: string | number time: string | number
src: string src: string,
type?: number
} }
const Time: FC = () => { const Time: FC = () => {
const [list, setList] = useState<List[]>([ const [list, setList] = useState<List[]>([
{title: '今日时长', time: '00:00', src: time1}, {title: '今日时长', time: '00:00', src: time1},
{title: '累计时长', time: '00:00', src: time2}, {title: '累计时长', time: '00:00', src: time2},
{title: '必修课', time: '0/0', src: curriculum1}, {title: '必修课', time: '0/0', src: curriculum1, type: 1},
{title: '选修课', time: '0/0', src: curriculum2}, {title: '选修课', time: '0/0', src: curriculum2, type: 2},
{title: '已完成', time: '0', src: over}, {title: '已完成', time: '0', src: over, type: 3},
{title: '未完成', time: '0', src: incomplete}, {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 ( return (
<View className='flex mt-3 justify-between flex-wrap' style={{padding: '0 10px'}}> <View className='flex mt-3 justify-between flex-wrap' style={{padding: '0 10px'}}>
{ {
list.map(d => { list.map(d => {
return ( return (
<View className={styles.timeBox} key={d.title}> <View className={styles.timeBox} key={d.title} onClick={() => jump(d.type)}>
<View className={styles.timeBoxFlex}> <View className={styles.timeBoxFlex}>
<View> <View>
<View className='mb-2'>{d.title}</View> <View className='mb-2'>{d.title}</View>

@ -109,3 +109,9 @@ interface HourCacheParam {
user_id: number; user_id: number;
unique_ident: number unique_ident: number
} }
interface Pages {
page: number
page_size: number
}

Loading…
Cancel
Save