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