diff --git a/src/api/curriculum.ts b/src/api/curriculum.ts index 5845db6..b035d20 100644 --- a/src/api/curriculum.ts +++ b/src/api/curriculum.ts @@ -59,5 +59,8 @@ export const curriculum = { /** 课程结束 */ curEnd(courseId: number, id: number, duration: number) { return request(`/api/v1/course/${courseId}/hour/${id}/record`, "POST", {duration}) + }, + categoryCur(categoryId:number,companyId:number){ + return request(`/api/v1/category/${categoryId}/${companyId}`,"GET") } } diff --git a/src/api/public.ts b/src/api/public.ts index a34bd51..4e85c47 100644 --- a/src/api/public.ts +++ b/src/api/public.ts @@ -21,9 +21,11 @@ export interface Courses { is_not_required: Curriculum[] /** 必修 */ is_required: Curriculum[] + /** 总时长 */ + total_course_duration: number } -export type CoursesKey = keyof Courses +export type CoursesKey = keyof Omit export type Cur = Category & { courses: Courses diff --git a/src/app.config.ts b/src/app.config.ts index 6601020..27f2da6 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -30,9 +30,10 @@ export default defineAppConfig({ { root: 'pages/business', pages: [ - 'course/course', + // 'course/course', 'userInfo/userInfo', - 'videoInfo/videoInfo' + 'videoInfo/videoInfo', + 'categoryCur/categoryCur' ] }, { diff --git a/src/components/video/video.tsx b/src/components/video/video.tsx index c777610..e678e79 100644 --- a/src/components/video/video.tsx +++ b/src/components/video/video.tsx @@ -13,7 +13,7 @@ const HVideo: FC = (opt: HVideoOptions) => { function onTimeUpdate(event: BaseEventOrig) { if (opt.preview) return; - if (user?.role_type !== 0) return; + if (user?.role_type === 2) return; const time = event.detail.currentTime /** 前进回退 */ if (currentTime + deviation < time) { @@ -34,8 +34,7 @@ const HVideo: FC = (opt: HVideoOptions) => { } function onEnded() { - console.log(user) - if (user?.role_type !== 0) return; + if (user?.role_type === 2) return; if (currentTime + 1 > opt.duration) { opt.onEnded() } else { diff --git a/src/components/videoCover/videoCover.scss b/src/components/videoCover/videoCover.scss index 1e56159..ef73df6 100644 --- a/src/components/videoCover/videoCover.scss +++ b/src/components/videoCover/videoCover.scss @@ -32,10 +32,7 @@ .title{ width: 100%; - //word-break: break-word; - //white-space: pre-line; font-size: 28rpx; - word-break: break-all; overflow: hidden; display: -webkit-box; diff --git a/src/components/videoCover/videoCover.tsx b/src/components/videoCover/videoCover.tsx index 19e5226..08aed3e 100644 --- a/src/components/videoCover/videoCover.tsx +++ b/src/components/videoCover/videoCover.tsx @@ -34,7 +34,7 @@ const VideoCover: FC = (opt: VideoCoverProps) => { {opt.title} - {opt?.time} + {opt.time && 时长:{opt.time}} {opt?.schedule} diff --git a/src/pages/business/categoryCur/categoryCur.config.ts b/src/pages/business/categoryCur/categoryCur.config.ts new file mode 100644 index 0000000..2707d28 --- /dev/null +++ b/src/pages/business/categoryCur/categoryCur.config.ts @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: '更多课程' +}) diff --git a/src/pages/business/categoryCur/categoryCur.tsx b/src/pages/business/categoryCur/categoryCur.tsx new file mode 100644 index 0000000..729256b --- /dev/null +++ b/src/pages/business/categoryCur/categoryCur.tsx @@ -0,0 +1,50 @@ +import {View} from "@tarojs/components"; +import {Profile} from '@/store' +import {FC, useEffect, useState} from "react"; +import {getCurrentInstance} from "@tarojs/runtime"; +import {curriculum} from "@/api"; +import VideoCover from "@/components/videoCover/videoCover"; + +const Index: FC = () => { + const {company} = Profile.useContainer() + const {categoryId} = getCurrentInstance()?.router?.params as { categoryId: number } + const [data, setData] = useState([]) + + async function getData() { + try { + const res = await curriculum.categoryCur(categoryId!, company?.id!) + setData(res) + } catch (e) { + } + } + + + useEffect(() => { + getData() + }, []) + return ( + <> + + {data.map(d => ) + } + + - 暂无更多 - + + ) +} + + +const CategoryCur = () => { + return ( + + + + ) +} + +export default CategoryCur diff --git a/src/pages/business/course/course.config.ts b/src/pages/business/course/course.config.ts deleted file mode 100644 index 44b4321..0000000 --- a/src/pages/business/course/course.config.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default definePageConfig({ - navigationBarTitleText: '课程' -}) diff --git a/src/pages/business/videoInfo/components/catalogue.tsx b/src/pages/business/videoInfo/components/catalogue.tsx index 48d5d62..f176208 100644 --- a/src/pages/business/videoInfo/components/catalogue.tsx +++ b/src/pages/business/videoInfo/components/catalogue.tsx @@ -5,13 +5,13 @@ import {Profile} from '@/store' import {CourseDepData} from "@/api"; import Collapse from "@/components/collapse/collapse"; import Hours from "@/pages/business/videoInfo/components/hours"; -import Taro from "@tarojs/taro"; interface Props { data: CourseDepData | null + setPlayId: (id: number) => void } -const Catalogue: FC = ({data}: Props) => { +const Catalogue: FC = ({data, setPlayId}: Props) => { const {user} = Profile.useContainer() const [current, setCurrent] = useState(0) const [tabList, setTabList] = useState([ @@ -42,22 +42,15 @@ const Catalogue: FC = ({data}: Props) => { return null } - function complete(id: number): boolean { return !!data?.learn_hour_records?.[id]?.is_finished } - - function jump(id) { - Taro.navigateTo({url: `/pages/business/course/course?courseId=${data?.course.id}&id=${id}`}) - } - - return ( - {current === 0 && {data?.course.short_desc}} + {current === 0 && {data?.course.short_desc || '无'}} {current === 1 && 课程目录 {data?.chapters.length ? Object.values(data?.chapters || {}).map((d, index) => @@ -69,7 +62,7 @@ const Catalogue: FC = ({data}: Props) => { title={hor.title} duration={hor.duration} complete={complete} - click={jump} + click={() => setPlayId(d.id)} /> )} @@ -81,7 +74,7 @@ const Catalogue: FC = ({data}: Props) => { title={hor.title} duration={hor.duration} complete={complete} - click={jump} + click={() => setPlayId(hor.id)} /> )} } diff --git a/src/pages/business/course/course.tsx b/src/pages/business/videoInfo/components/course.tsx similarity index 78% rename from src/pages/business/course/course.tsx rename to src/pages/business/videoInfo/components/course.tsx index 7d4a38a..97b7eb8 100644 --- a/src/pages/business/course/course.tsx +++ b/src/pages/business/videoInfo/components/course.tsx @@ -1,25 +1,31 @@ import {CustomWrapper, PageContainer, ScrollView} from "@tarojs/components"; -import {useEffect, useState} from "react"; +import {FC, useEffect, useState} from "react"; import HVideo from "@/components/video/video"; -import {getCurrentInstance} from "@tarojs/runtime"; import {curriculum, HourPlayData} from "@/api"; import {Profile} from '@/store' import Taro from "@tarojs/taro"; -const Course = () => { - const {courseId, id, preview} = getCurrentInstance()?.router?.params as { - courseId: number, - id: number, - preview: string | null - } +interface Props { + id: number, + courseId: number + preview?: boolean + curEnd: () => void +} + +const Course: FC = ({id, courseId, preview, curEnd}: Props) => { const [breakpoint, setBreakpoint] = useState([]) const [show, setShow] = useState(false) const [data, setData] = useState(null) async function onEnded() { try { - await curriculum.curEnd(courseId, id, data?.duration || 0) - Taro.showModal({title: "学习完成"}) + await curriculum.curEnd(courseId, id, data?.duration!) + Taro.showModal({ + title: "学习完成", + success() { + curEnd() + } + }) } catch (e) { } } @@ -38,7 +44,7 @@ const Course = () => { useEffect(() => { getData() - }, []) + }, [id]) return ( @@ -52,7 +58,6 @@ const Course = () => { onBreakpoint={onBreakpoint} />} - = (opt: Props) => { return ( <> - opt.click(opt.id)} - > + opt.click(opt.id)}> {opt.index + 1}.{opt.title} diff --git a/src/pages/business/videoInfo/videoInfo.scss b/src/pages/business/videoInfo/videoInfo.scss index cf2f3c2..16cb78f 100644 --- a/src/pages/business/videoInfo/videoInfo.scss +++ b/src/pages/business/videoInfo/videoInfo.scss @@ -1,4 +1,9 @@ .content { + + &-video{ + height: 480rpx; + } + .image { width: 100%; display: block; @@ -41,7 +46,9 @@ border-bottom: 1px solid #ddd; View { + width: 630rpx; margin-bottom: 20px; + word-wrap:break-word; } } } diff --git a/src/pages/business/videoInfo/videoInfo.tsx b/src/pages/business/videoInfo/videoInfo.tsx index e599c07..317e8ad 100644 --- a/src/pages/business/videoInfo/videoInfo.tsx +++ b/src/pages/business/videoInfo/videoInfo.tsx @@ -1,15 +1,16 @@ import {Image, Text, View} from "@tarojs/components"; -import {FC, useState} from "react"; +import {FC, useEffect, useState} from "react"; import {getCurrentInstance} from "@tarojs/runtime"; import {CourseDepData, curriculum} from "@/api"; import './videoInfo.scss' -import Taro from "@tarojs/taro"; import {Profile} from '@/store' -import Catalogue from "@/pages/business/videoInfo/components/catalogue"; +import Catalogue from "./components/catalogue"; +import Course from "./components/course"; const VideoInfo: FC = () => { const {id, depId} = getCurrentInstance()?.router?.params as { id: number, depId: number | null } const [data, setData] = useState(null) + const [playId, setPlayId] = useState(null) async function getData() { const res = await curriculum.courseDep(id, depId) @@ -18,13 +19,20 @@ const VideoInfo: FC = () => { } } - Taro.useDidShow(getData) - + useEffect(() => { + getData() + }, []) return ( - + + { + playId ? + + : + } + @@ -34,11 +42,11 @@ const VideoInfo: FC = () => { {data?.course.title} {/*时长:32:10*/} - 学习进度{data?.learn_record?.finished_count || 0}/{data?.learn_record?.hour_count || Object.keys(data?.hours || {}).length} + 学习进度{data?.learn_record?.finished_count || 0}/{data?.course.class_hour} - + setPlayId(id)}/> ) diff --git a/src/pages/index/components/videoList.tsx b/src/pages/index/components/videoList.tsx index 192a9a9..0c3445c 100644 --- a/src/pages/index/components/videoList.tsx +++ b/src/pages/index/components/videoList.tsx @@ -1,9 +1,10 @@ import {FC, useState} from "react"; -import Taro from "@tarojs/taro"; -import {View} from "@tarojs/components"; +import Taro, {useReachBottom} from "@tarojs/taro"; +import {Text, View} from "@tarojs/components"; import {CoursesKey, Cur, publicApi} from "@/api/public"; import VideoCover from "@/components/videoCover/videoCover"; import styles from '../index.module.scss' +import {formatMinute} from "@/utils/time"; interface Props { categoryId: CoursesKey @@ -11,36 +12,64 @@ interface Props { export const VideoList: FC = ({categoryId}: Props) => { const [data, setDta] = useState(null) + const [index, setIndex] = useState(3) async function getData() { - const res = await publicApi.curs() - setDta(res) - } + try { + Taro.showLoading() + const res = await publicApi.curs() + const flatData = res.reduce((put, cur) => { + put.push(cur) + if (cur.resourceCategory?.length) { + put.push(...cur.resourceCategory.map(d => { + d.name = cur.name + '/' + d.name + return d + })) + } + return put + }, [] as Cur[]) + setDta(flatData) + } catch (e) { + } + Taro.hideLoading() + } - Taro.useDidShow(() => { - getData() - }) function rateOfLearning(id: number, class_hour: number): JSX.Element { console.log(id) return ({`共${class_hour}节/已学${0}节`}) } + function jumpCategoryCur(id: number) { + Taro.navigateTo({url: '/pages/business/categoryCur/categoryCur?categoryId=' + id}) + } + + useReachBottom(() => { + if (data && data?.length > index) { + setIndex(index + 1) + } + }) + + Taro.useDidShow(getData) return ( <> - {data?.map(d => ( + {data?.slice(0, index).map(d => ( <>{ d.courses?.[categoryId].length ? - {d.name} + jumpCategoryCur(d.id)}> + {d.name} + 查看更多 + - {d.courses[categoryId].map(d => ( + {d.courses[categoryId].map(c => ( ))} diff --git a/src/pages/index/index.config.ts b/src/pages/index/index.config.ts index 23c20dd..7cf42d9 100644 --- a/src/pages/index/index.config.ts +++ b/src/pages/index/index.config.ts @@ -1,3 +1,4 @@ export default definePageConfig({ - navigationStyle: 'custom' + navigationStyle: 'custom', + onReachBottomDistance: 30 }) diff --git a/src/pages/index/index.module.scss b/src/pages/index/index.module.scss index 9e0fc65..3f703d2 100644 --- a/src/pages/index/index.module.scss +++ b/src/pages/index/index.module.scss @@ -1,7 +1,10 @@ .content { position: relative; - min-height: 100vh; padding: 0 20px; + min-height: 90vh; + box-sizing: border-box; + width: 750rpx; + overflow: hidden; &:after { min-height: 100vh; diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 83f4c39..724336b 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -23,12 +23,6 @@ const Index: FC = () => { setCategoryId(data.tab?.value as CoursesKey) } - // Taro.showActionSheet({ - // alertText: '212', - // itemColor:'red', - // itemList:['删除'] - // }) - return ( diff --git a/src/pages/manage/depAdmin/depAdmin.tsx b/src/pages/manage/depAdmin/depAdmin.tsx index af4dbfb..900af1e 100644 --- a/src/pages/manage/depAdmin/depAdmin.tsx +++ b/src/pages/manage/depAdmin/depAdmin.tsx @@ -118,7 +118,7 @@ const DepAdmin: FC = () => { function managesSheet(item: Manage) { Taro.showActionSheet({ - itemList: ['查看部门课程', '修改', '删除'], + itemList: ['查看部门课程', '修改', '详情', '删除'], success({tapIndex}) { switch (tapIndex) { case 0: @@ -128,6 +128,9 @@ const DepAdmin: FC = () => { showPop(item) break case 2: + Taro.navigateTo({url: `/pages/manage/depAdmin/depAdmin?id=${item.id}&name=${item.name}`}) + break + case 3: del(item.name, item.id) break } diff --git a/src/pages/manage/studentAdmin/studentAdmin.tsx b/src/pages/manage/studentAdmin/studentAdmin.tsx index a5b42ec..fb35b54 100644 --- a/src/pages/manage/studentAdmin/studentAdmin.tsx +++ b/src/pages/manage/studentAdmin/studentAdmin.tsx @@ -114,10 +114,6 @@ const studentAdmin = () => { 手机号 {d.phone_number} - - 邮箱 - {d.email} - diff --git a/src/pages/my/components/header/service.tsx b/src/pages/my/components/header/service.tsx index 3cb0ba9..a8e6023 100644 --- a/src/pages/my/components/header/service.tsx +++ b/src/pages/my/components/header/service.tsx @@ -4,7 +4,7 @@ import Taro from "@tarojs/taro"; import {Profile} from '@/store/profile' import styles from '../../my.module.scss' import dep from '@/static/img/dep.png' -import cur from '@/static/img/cur.png' +// import cur from '@/static/img/cur.png' import student from '@/static/img/student.png' import buy from '@/static/img/buy.png' @@ -27,7 +27,7 @@ const Service = () => { oldList.unshift(...[ {title: '部门管理', src: dep, router: '/pages/manage/depAdmin/depAdmin'}, {title: '学员管理', src: student, router: '/pages/manage/studentAdmin/studentAdmin'}, - {title: '课程管理', src: cur, router: ''}, + // {title: '课程管理', src: cur, router: ''}, {title: '课程购买', src: buy, router: '/pages/manage/curriculum/curriculum'}, ]) setList(oldList)