学习滑动

main
king 1 year ago
parent 9ba1294380
commit 98c6f8c3e5
  1. 31
      src/pages/home/home.module.scss
  2. 62
      src/pages/index/components/videoList.tsx
  3. 6
      src/pages/index/index.config.ts
  4. 19
      src/pages/index/index.module.scss
  5. 8
      src/pages/index/index.tsx

@ -1,29 +1,3 @@
.header {
font-weight: bold;
font-size: 34rpx;
position: fixed;
width: 100%;
left: 0;
top: 0;
overflow: hidden;
text-align: center;
color: #000;
&:after {
min-height: 100vh;
position: absolute;
top: 0;
left: -10%;
width: 120%;
content: '';
display: block;
background: linear-gradient(40deg, #fff 50rpx, #caf0e2, #92ecc5) no-repeat;
min-height: 100vh;
background-size: 100% 600rpx;
z-index: -1;
}
}
.tipsLogin { .tipsLogin {
padding: 24rpx; padding: 24rpx;
color: #fff; color: #fff;
@ -48,7 +22,6 @@
overflow: hidden; overflow: hidden;
&:after { &:after {
//min-height: 100vh;
position: absolute; position: absolute;
top: 0; top: 0;
left: -10%; left: -10%;
@ -56,11 +29,7 @@
height: 400rpx; height: 400rpx;
content: ''; content: '';
display: block; display: block;
//background: linear-gradient(40deg, #fff 50rpx, #caf0e2, #92ecc5) no-repeat;
background: linear-gradient(to bottom, #92ecc5, #f1f8f6) no-repeat; background: linear-gradient(to bottom, #92ecc5, #f1f8f6) no-repeat;
//min-height: 100vh;
//background-size: 100% 600rpx;
//filter: blur(50px);
z-index: -1; z-index: -1;
} }
} }

@ -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,19 +97,39 @@ 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)}>
<VideoCover {
thumb={c.thumb} Object.values(data).map((value) => <SwiperItem>
title={c.title} <ScrollView scrollY className={styles.swiper} onScrollToLower={() => setPage(page + 1)}>
id={c.id} <View className='py-2 flex justify-between flex-wrap'>
depId={c.id} {
key={c.id} value?.length ? value?.map(c =>
time={formatMinute(c.course_duration)} <VideoCover
content={rateOfLearning(c.id, c.class_hour)} thumb={c.thumb}
/>) : <Empty name='暂无数据'/>} title={c.title}
</View> id={c.id}
depId={c.id}
key={c.id}
time={formatMinute(c.course_duration)}
content={rateOfLearning(c.id, c.class_hour)}
/>)
: <Empty name='暂无课程'/>
}
</View>
</ScrollView>
</SwiperItem>)
}
</Swiper>
) )
} }

@ -1,5 +1,5 @@
export default definePageConfig({ export default definePageConfig({
navigationStyle: 'custom', navigationBarTitleText: '医学道',
navigationBarTitleText:'医学道', navigationBarBackgroundColor: '#92ecc5',
onReachBottomDistance: 30 navigationBarTextStyle: 'white',
}) })

@ -1,30 +1,31 @@
.content { .content {
position: relative; position: fixed;
top: 0;
left: 0;
padding: 0 20px; padding: 0 20px;
min-height: 90vh; min-height: 100vh;
box-sizing: border-box; box-sizing: border-box;
width: 750rpx; width: 750rpx;
overflow: hidden; overflow: hidden;
&:after { &:after {
min-height: 100vh;
position: absolute; position: absolute;
top: 0; top: 0;
left: -10%; left: -10%;
width: 120%; width: 120%;
height: 400rpx;
content: ''; content: '';
display: block; display: block;
background: linear-gradient(40deg, #fff 50rpx, #caf0e2, #92ecc5) no-repeat; background: linear-gradient(to bottom, #92ecc5, #f1f8f6) no-repeat;
min-height: 100vh;
background-size: 100% 600rpx;
filter: blur(50px);
z-index: -1; z-index: -1;
} }
} }
.swiper {
height: calc(100vh - 88rpx);
}
.videoListBox { .videoListBox {
border-radius: 20px; border-radius: 20px;
} }

@ -4,10 +4,8 @@ import styles from './index.module.scss'
import {VideoList} from "@/pages/index/components/videoList"; import {VideoList} from "@/pages/index/components/videoList";
import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs";
import {CoursesKey} from "@/api/public"; import {CoursesKey} from "@/api/public";
import Taro from '@tarojs/taro'
const Index: FC = () => { const Index: FC = () => {
const globalData = Taro.getApp().globalData
const category: TabList[] = [ const category: TabList[] = [
{title: "必修", value: 'is_required'}, {title: "必修", value: 'is_required'},
{title: "选修", value: 'is_not_required'}, {title: "选修", value: 'is_not_required'},
@ -20,12 +18,12 @@ const Index: FC = () => {
setCategoryKey(data.tab?.value as CoursesKey) setCategoryKey(data.tab?.value as CoursesKey)
} }
return ( return (
<> <>
<View className={styles.content} style={`paddingTop:${globalData.statusBarHeight}px`}> <View className={styles.content}>
{process.env.TARO_ENV !== "h5" && <View className='text-center font-weight font-34 mt-3'></View>}
<Tabs tabList={category} onChange={tabChange} current={categoryKey}/> <Tabs tabList={category} onChange={tabChange} current={categoryKey}/>
<VideoList categoryKey={categoryKey}/> <VideoList categoryKey={categoryKey} setCategoryKey={(categoryKey) => setCategoryKey(categoryKey)}/>
</View> </View>
</> </>
) )

Loading…
Cancel
Save