|
|
|
@ -7,7 +7,8 @@ import styles from '../index.module.scss' |
|
|
|
|
import {formatMinute} from "@/utils/time"; |
|
|
|
|
import {userApi} from "@/api"; |
|
|
|
|
import Empty from "@/components/empty/empty"; |
|
|
|
|
import eventsIndex from "@/hooks/eventsIndex"; |
|
|
|
|
import {Profile} from "@/store"; |
|
|
|
|
import LoginView from "@/components/loginView"; |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
categoryKey: CoursesKey |
|
|
|
@ -18,11 +19,12 @@ export const VideoList: FC<Props> = ({categoryKey, setCategoryKey}) => { |
|
|
|
|
const [data, setData] = useState<Courses>({ |
|
|
|
|
is_required: [], |
|
|
|
|
is_not_required: [], |
|
|
|
|
is_finished: [], |
|
|
|
|
is_not_finished: [], |
|
|
|
|
// is_finished: [],
|
|
|
|
|
// is_not_finished: [],
|
|
|
|
|
}) |
|
|
|
|
const [page, setPage] = useState(1) |
|
|
|
|
const [records, setRecords] = useState<LearnRecord[]>([]) |
|
|
|
|
const {token} = Profile.useContainer() |
|
|
|
|
|
|
|
|
|
function screen(oldData: Curriculum[], data: Curriculum[]): Curriculum[] { |
|
|
|
|
return data.reduce((pre, cur) => { |
|
|
|
@ -43,8 +45,8 @@ export const VideoList: FC<Props> = ({categoryKey, setCategoryKey}) => { |
|
|
|
|
setData({ |
|
|
|
|
is_required: screen(old.is_required, res.is_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 || []), |
|
|
|
|
// is_finished: screen(old.is_finished, res.is_finished || []),
|
|
|
|
|
// is_not_finished: screen(old.is_not_finished, res.is_not_finished || []),
|
|
|
|
|
}) |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
@ -63,7 +65,6 @@ export const VideoList: FC<Props> = ({categoryKey, setCategoryKey}) => { |
|
|
|
|
switch (categoryKey) { |
|
|
|
|
case "is_required": |
|
|
|
|
case "is_not_required": |
|
|
|
|
case "is_not_finished": |
|
|
|
|
const find = records.find(d => d?.course_id === id) |
|
|
|
|
if (find) { |
|
|
|
|
if (class_hour === find.finished_count) { |
|
|
|
@ -72,21 +73,19 @@ export const VideoList: FC<Props> = ({categoryKey, setCategoryKey}) => { |
|
|
|
|
return (<View>{`共${class_hour}节/已学${find.finished_count}节`}</View>) |
|
|
|
|
} |
|
|
|
|
return (<View>{`共${class_hour}节/已学0节`}</View>) |
|
|
|
|
case "is_finished": |
|
|
|
|
return <View>已完成</View> |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
eventsIndex.on(({id}) => { |
|
|
|
|
if (id == null) return; |
|
|
|
|
for (const [index, notFinished] of data.is_not_finished.entries()) { |
|
|
|
|
if (notFinished.id === id) { |
|
|
|
|
data.is_finished.push(notFinished) |
|
|
|
|
data.is_not_finished.splice(index, 1) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
// eventsIndex.on(({id}) => {
|
|
|
|
|
// if (id == null) return;
|
|
|
|
|
// for (const [index, notFinished] of data.is_not_finished.entries()) {
|
|
|
|
|
// if (notFinished.id === id) {
|
|
|
|
|
// data.is_finished.push(notFinished)
|
|
|
|
|
// data.is_not_finished.splice(index, 1)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
useDidShow(() => { |
|
|
|
|
getData().then() |
|
|
|
@ -115,11 +114,16 @@ export const VideoList: FC<Props> = ({categoryKey, setCategoryKey}) => { |
|
|
|
|
onChange={changeSwiper} |
|
|
|
|
current={categoryIndex}> |
|
|
|
|
{ |
|
|
|
|
Object.values(data).map((value) => <SwiperItem> |
|
|
|
|
<ScrollView scrollY className={styles.swiper} onScrollToLower={() => setPage(page + 1)}> |
|
|
|
|
Object.entries(data).map(([key, value]) => <SwiperItem> |
|
|
|
|
<ScrollView scrollY className={styles.swiper} onScrollToLower={() => setPage(page + 1)} enhanced |
|
|
|
|
showScrollbar={false}> |
|
|
|
|
<View className='py-2 flex justify-between flex-wrap'> |
|
|
|
|
{ |
|
|
|
|
value?.length ? value?.map(c => |
|
|
|
|
!token |
|
|
|
|
&& key === 'is_required' |
|
|
|
|
? <LoginView/> : value?.length ? |
|
|
|
|
<> |
|
|
|
|
{value?.map(c => |
|
|
|
|
<VideoCover |
|
|
|
|
thumb={c.thumb} |
|
|
|
|
title={c.title} |
|
|
|
@ -128,7 +132,9 @@ export const VideoList: FC<Props> = ({categoryKey, setCategoryKey}) => { |
|
|
|
|
key={c.id} |
|
|
|
|
time={formatMinute(c.course_duration)} |
|
|
|
|
content={rateOfLearning(c.id, c.class_hour)} |
|
|
|
|
/>) |
|
|
|
|
/>)} |
|
|
|
|
<View className='text-center text-muted'>暂无更多</View> |
|
|
|
|
</> |
|
|
|
|
: <Empty name='暂无课程'/> |
|
|
|
|
} |
|
|
|
|
</View> |
|
|
|
|