|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
import {FC, useEffect, useState} from "react"; |
|
|
|
|
import {useDidShow, useReachBottom} from "@tarojs/taro"; |
|
|
|
|
import {View} from "@tarojs/components"; |
|
|
|
|
import {useDidShow} from "@tarojs/taro"; |
|
|
|
|
import {ScrollView, Swiper, SwiperItem, View} from "@tarojs/components"; |
|
|
|
|
import {Courses, CoursesKey, publicApi} from "@/api/public"; |
|
|
|
|
import VideoCover from "@/components/videoCover/videoCover"; |
|
|
|
|
import styles from '../index.module.scss' |
|
|
|
@ -11,14 +11,15 @@ import eventsIndex from "@/hooks/eventsIndex"; |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
categoryKey: CoursesKey |
|
|
|
|
setCategoryKey: (categoryKey: CoursesKey) => void |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const VideoList: FC<Props> = ({categoryKey}) => { |
|
|
|
|
export const VideoList: FC<Props> = ({categoryKey, setCategoryKey}) => { |
|
|
|
|
const [data, setData] = useState<Courses>({ |
|
|
|
|
is_finished: [], |
|
|
|
|
is_not_required: [], |
|
|
|
|
is_required: [], |
|
|
|
|
is_not_finished: [], |
|
|
|
|
is_not_required: [] |
|
|
|
|
}) |
|
|
|
|
const [page, setPage] = useState(1) |
|
|
|
|
const [records, setRecords] = useState<LearnRecord[]>([]) |
|
|
|
@ -38,13 +39,12 @@ export const VideoList: FC<Props> = ({categoryKey}) => { |
|
|
|
|
async function getData() { |
|
|
|
|
try { |
|
|
|
|
const res = await publicApi.course({page: page, pageSize: 10}) |
|
|
|
|
|
|
|
|
|
const old: Courses = JSON.parse(JSON.stringify(data)) |
|
|
|
|
setData({ |
|
|
|
|
is_finished: screen(old.is_finished, res.is_finished || []), |
|
|
|
|
is_required: screen(old.is_required, res.is_required || []), |
|
|
|
|
is_not_finished: screen(old.is_not_finished, res.is_not_finished || []), |
|
|
|
|
is_not_required: screen(old.is_not_required, res.is_not_required || []), |
|
|
|
|
is_finished: screen(old.is_finished, res.is_finished || []), |
|
|
|
|
is_not_finished: screen(old.is_not_finished, res.is_not_finished || []), |
|
|
|
|
}) |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
@ -77,10 +77,6 @@ export const VideoList: FC<Props> = ({categoryKey}) => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useReachBottom(() => { |
|
|
|
|
setPage(page + 1) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
eventsIndex.on(({id}) => { |
|
|
|
|
if (id == null) return; |
|
|
|
|
for (const [index, notFinished] of data.is_not_finished.entries()) { |
|
|
|
@ -101,9 +97,23 @@ export const VideoList: FC<Props> = ({categoryKey}) => { |
|
|
|
|
getData().then() |
|
|
|
|
getRecords().then() |
|
|
|
|
}, [page]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function changeSwiper(e) { |
|
|
|
|
const index = e.detail.current |
|
|
|
|
const categoryKeys: CoursesKey[] = Object.keys(data) as CoursesKey[] |
|
|
|
|
setCategoryKey(categoryKeys[index]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<View className={'py-2 flex justify-between flex-wrap ' + styles.videoListBox}> |
|
|
|
|
{data?.[categoryKey]?.length ? data?.[categoryKey]?.map(c => |
|
|
|
|
<Swiper className={styles.swiper} onChange={changeSwiper} |
|
|
|
|
current={Object.keys(data).findIndex(d => d === categoryKey)}> |
|
|
|
|
{ |
|
|
|
|
Object.values(data).map((value) => <SwiperItem> |
|
|
|
|
<ScrollView scrollY className={styles.swiper} onScrollToLower={() => setPage(page + 1)}> |
|
|
|
|
<View className='py-2 flex justify-between flex-wrap'> |
|
|
|
|
{ |
|
|
|
|
value?.length ? value?.map(c => |
|
|
|
|
<VideoCover |
|
|
|
|
thumb={c.thumb} |
|
|
|
|
title={c.title} |
|
|
|
@ -112,8 +122,14 @@ export const VideoList: FC<Props> = ({categoryKey}) => { |
|
|
|
|
key={c.id} |
|
|
|
|
time={formatMinute(c.course_duration)} |
|
|
|
|
content={rateOfLearning(c.id, c.class_hour)} |
|
|
|
|
/>) : <Empty name='暂无数据'/>} |
|
|
|
|
/>) |
|
|
|
|
: <Empty name='暂无课程'/> |
|
|
|
|
} |
|
|
|
|
</View> |
|
|
|
|
</ScrollView> |
|
|
|
|
</SwiperItem>) |
|
|
|
|
} |
|
|
|
|
</Swiper> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|