From 33eaa1adcb6e96ffc744079b221f386620687edd Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Thu, 3 Aug 2023 17:05:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E6=97=B6=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +- src/api/course.ts | 14 +++ src/api/index.ts | 1 + src/api/manage.ts | 7 -- src/api/user.ts | 4 +- .../custom-page-container.tsx | 6 ++ src/pages/business/curHistory/curHistory.tsx | 71 +++++++++------ src/pages/business/history/history.tsx | 2 +- .../hourHistory/hourHistory.module.scss | 57 ++++++++++++ .../business/hourHistory/hourHistory.tsx | 90 ++++++++++++++++++- .../videoInfo/components/catalogue.tsx | 18 ++-- src/pages/business/videoInfo/videoInfo.tsx | 3 +- src/pages/manage/addStudent/addStudent.tsx | 8 +- src/pages/manage/depAdmin/depAdmin.tsx | 4 + types/user.d.ts | 4 +- 15 files changed, 233 insertions(+), 60 deletions(-) create mode 100644 src/api/course.ts create mode 100644 src/pages/business/hourHistory/hourHistory.module.scss diff --git a/.env b/.env index 3bfcb50..692d973 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -#TARO_APP_API=https://yjx.dev.yaojiankang.top -TARO_APP_API=https://playedu.yaojiankang.top +TARO_APP_API=https://yjx.dev.yaojiankang.top +#TARO_APP_API=https://playedu.yaojiankang.top TARO_APP_LGOIN=true diff --git a/src/api/course.ts b/src/api/course.ts new file mode 100644 index 0000000..de72b94 --- /dev/null +++ b/src/api/course.ts @@ -0,0 +1,14 @@ +import {request} from "@/api/request"; + +interface HourHistorys { + course: Curriculum + data: Record + hour: Hour +} + +export const courseApi = { + /** 课时学习记录 */ + hourHistory(courseId: string, hourId: string) { + return request(`/api/v1/course/${courseId}/hour/${hourId}/info`, "GET") + } +} diff --git a/src/api/index.ts b/src/api/index.ts index a1634d3..bfc8739 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -4,3 +4,4 @@ export * from './login' export * from './meeting' export * from './public' export * from './manage' +export * from './course' diff --git a/src/api/manage.ts b/src/api/manage.ts index d79541a..d792c0a 100644 --- a/src/api/manage.ts +++ b/src/api/manage.ts @@ -117,11 +117,4 @@ export const ManageApi = { buy(data_list: number[]) { return request(`/api/v1/course/buy?data_list=${data_list}`, "POST") }, - /** 学员学习记录 */ - userRecord(curId: number) { - return request(`/api/v1/course/${curId}/user/index?page=1&size=10000`, "GET") - }, - offline(data: Offline) { - return request('/wechat/link', "GET", data) - } } diff --git a/src/api/user.ts b/src/api/user.ts index 18e6e6f..03bd5fb 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -37,7 +37,7 @@ interface LearningRecord { interface CourseRecord { course: Curriculum - data: Record + data: Record } interface HourCourse { @@ -71,7 +71,7 @@ export const userApi = { }, /** 学习记录 */ record(category_id: number) { - return request>(`/api/v1/course/${category_id}/record`, "GET") + return request>(`/api/v1/course/${category_id}/record`, "GET") }, courseRecord(course_id: string) { return request(`/api/v1/course/${course_id}/info`, "GET") diff --git a/src/components/custom-page-container/custom-page-container.tsx b/src/components/custom-page-container/custom-page-container.tsx index 4bd5c32..339f6f7 100644 --- a/src/components/custom-page-container/custom-page-container.tsx +++ b/src/components/custom-page-container/custom-page-container.tsx @@ -1,6 +1,7 @@ import {PageContainer, PageContainerProps, View} from "@tarojs/components"; import {CSSProperties, FC, useCallback, useEffect, useState} from "react"; import styles from './custom-page-container.module.scss' +import Taro from "@tarojs/taro"; const PageContainerInner: FC = (props) => { const [visible, setVisible] = useState(props.show) @@ -55,6 +56,11 @@ const PageContainerInner: FC = (props) => { } }, [props.show]) + Taro.useDidHide(() => { + props.onClickOverlay?.(null as any) + setVisible(false) + }) + return ( { const [show, setShow] = useState(false) const {course_id} = Taro.getCurrentInstance().router?.params as unknown as { course_id: string } - const [data, setData] = useState([]) + const [data, setData] = useState([]) const [course, setCourse] = useState(null) const [hours, setHours] = useState(null) const [durations, setDuration] = useState | null>(null) const [time, setTime] = useState | null>(null) Taro.useLoad(() => { - // Taro.setNavigationBarTitle({title: name}) userApi.courseRecord(course_id).then(res => { + Taro.setNavigationBarTitle({title: res.course.title}) setData(Object.values(res.data)) setCourse(res.course) }) }) async function setHour(unique_ident: number) { - const res = await userApi.hourCourse(course_id, unique_ident) - setHours(Object.values(res.courseHour)) - setDuration(res.duration) - setTime(res.date) - setShow(true) + try { + const res = await userApi.hourCourse(course_id, unique_ident) + setHours(Object.values(res.courseHour)) + setDuration(res.duration) + setTime(res.date) + setShow(true) + } catch (e) { + + } } function percent(duration: number): number { @@ -64,24 +69,33 @@ const CurHistory = () => { - - {data.map((d, index) => setHour(d.unique_ident)} className={styles.recordItem}> - 第{index + 1}次观看 - {getCurTime(d.start_at, d.end_at)} - 观看视频:{formatMinute(d.duration)} - - )} - + { + data.length ? + { + data.map((d, index) => setHour(d.unique_ident)} + className={styles.recordItem}> + 第{index + 1}次观看 + {getCurTime(d.start_at, d.end_at)} + 观看视频:{formatMinute(d.duration)} + + ) + } + + : + } + { position='bottom' onClickOverlay={() => setShow(false)}> - {hours?.map(d => + {hours?.length ? + hours?.map(d => {d.title} {getTime(d.id)} @@ -104,8 +119,8 @@ const CurHistory = () => { activeColor={'#45D4A8'} /> - - )} + ) + : } diff --git a/src/pages/business/history/history.tsx b/src/pages/business/history/history.tsx index b0a85fd..284c539 100644 --- a/src/pages/business/history/history.tsx +++ b/src/pages/business/history/history.tsx @@ -8,7 +8,7 @@ import {formatMinute} from "@/utils/time"; import Empty from "@/components/empty/empty"; const History = () => { - const [data, setData] = useState([]) + const [data, setData] = useState([]) async function getData(id: number) { const res = await userApi.record(id) diff --git a/src/pages/business/hourHistory/hourHistory.module.scss b/src/pages/business/hourHistory/hourHistory.module.scss new file mode 100644 index 0000000..406dd26 --- /dev/null +++ b/src/pages/business/hourHistory/hourHistory.module.scss @@ -0,0 +1,57 @@ +.page { + padding: 30px !important; + box-sizing: border-box; +} + +.cur { + background: #fff; + overflow: hidden; + border-radius: 16px; + font-weight: 500; + position: relative; +} + +.classHour { + background: rgba(#000, .6); + position: absolute; + top: 250rpx; + width: 100%; + font-size: 25rpx; + line-height: 50rpx; + text-align: center; + color: #fff; + font-weight: 100; + left: 0; +} + +.title { + padding: 10rpx; + height: 100rpx; +} + +.image { + width: 100%; + height: 300rpx; + display: block; + background: #ddd; +} + +.progressBox { + background: #fff; + padding: 20rpx; + margin-top: 30rpx; + border-radius: 30rpx; +} + +.recordItem { + padding: 24px 0 38rpx; + border-bottom: 1px solid #F5F8F7; + font-size: 26rpx; + color: #606563; + line-height: 1.75; +} + +.progress { + color: #45D4A8; +} + diff --git a/src/pages/business/hourHistory/hourHistory.tsx b/src/pages/business/hourHistory/hourHistory.tsx index 7e4021d..08f7578 100644 --- a/src/pages/business/hourHistory/hourHistory.tsx +++ b/src/pages/business/hourHistory/hourHistory.tsx @@ -1,9 +1,91 @@ -import {View} from "@tarojs/components"; -import {FC} from "react"; +import {Image, Progress, View} from "@tarojs/components"; +import {FC, useEffect, useState} from "react"; +import Taro from "@tarojs/taro"; +import {courseApi} from "@/api"; +import styles from './hourHistory.module.scss' +import Empty from "@/components/empty/empty"; +import {formatDateTime} from "@/utils/time"; + +const HourHistory: FC = () => { + const {courseId, hourId} = Taro.getCurrentInstance().router?.params as { courseId: string, hourId: string } + const [cur, setCur] = useState(null) + const [hour, setHour] = useState(null) + const [times, setTimes] = useState([]) + + useEffect(() => { + courseApi.hourHistory(courseId, hourId).then(res => { + if (res) { + setHour(res.hour) + setCur(res.course) + const data = Object.values(res.data).map(d => { + if (d.length === 1) { + return d[0] + } + const duration = d.reduce((pre, cur) => { + return pre + cur.duration + }, 0) + return ({ + ...d[0], + duration, + end_at: d[d.length - 1].end_at + }) + }) + setTimes(data) + } + }) + }, []) + -const HourHistory:FC = () => { return ( - sd + + + + 共{cur?.class_hour}节/已学{cur?.finished_hour_count || 0}节 + + {cur?.title} + 课时:{hour?.title} + + + + { + times.length ? + + { + times.map(d => + {formatDateTime(new Date(d.start_at), 'MM-dd')} + + ) + } + + : + } + + {/*{times.length ? times.map((d, index) =>*/} + {/* */} + {/* */} + {/* */} + {/* 共{d.total_hour_count}节/已学{d.finished_count}节*/} + {/* */} + {/* */} + {/* {d.course.title}*/} + {/* */} + {/* 观看{formatMinute(d.duration)}*/} + {/* 学习进度:{(d.finished_count / d.total_hour_count * 100).toFixed(0)}%*/} + {/* */} + {/* */} + {/* ) : }*/} + + ) } diff --git a/src/pages/business/videoInfo/components/catalogue.tsx b/src/pages/business/videoInfo/components/catalogue.tsx index e8f964f..1157383 100644 --- a/src/pages/business/videoInfo/components/catalogue.tsx +++ b/src/pages/business/videoInfo/components/catalogue.tsx @@ -13,7 +13,8 @@ import hourRecord from '@/static/img/hourRecord.png' interface Props { data: CourseDepData | null setHors: (is_complete: boolean, id: number) => void - id: number + id: number //课程 + playId: number | null } const tabList = [ @@ -23,12 +24,12 @@ const tabList = [ ] -const Catalogue: FC = ({data, setHors, id}) => { +const Catalogue: FC = ({data, setHors, id, playId}) => { const [current, setCurrent] = useState(1) const [show, setShow] = useState(false) function jumCurHistory() { - // Taro.navigateTo({url: `/pages/business/curHistory/curHistory`}) + Taro.navigateTo({url: `/pages/business/hourHistory/hourHistory?courseId=${id}&hourId=${playId}`}) } function tabChange({tab}: OnChangOpt) { @@ -133,10 +134,13 @@ const Catalogue: FC = ({data, setHors, id}) => { 课程记录 - - - 当前课时学习记录 - + { + playId != null && + + 当前课时学习记录 + + } + setShow(false)} type='default' fillet>取消 diff --git a/src/pages/business/videoInfo/videoInfo.tsx b/src/pages/business/videoInfo/videoInfo.tsx index fe38f79..711a0f3 100644 --- a/src/pages/business/videoInfo/videoInfo.tsx +++ b/src/pages/business/videoInfo/videoInfo.tsx @@ -109,9 +109,8 @@ const VideoInfo: FC = () => { 学习进度{data?.learn_hour_records.length || 0}/{data?.course.class_hour} - + - ) } diff --git a/src/pages/manage/addStudent/addStudent.tsx b/src/pages/manage/addStudent/addStudent.tsx index 6fae6aa..e2ae87c 100644 --- a/src/pages/manage/addStudent/addStudent.tsx +++ b/src/pages/manage/addStudent/addStudent.tsx @@ -19,7 +19,6 @@ const AddStudent = () => { const [department, setDepartment] = useState([]) const [depIds, setDepIds] = useState([]) const params = getCurrentInstance()?.router?.params as { id?: number } - const [disable, setDisable] = useState(false) const {company} = Profile.useContainer() @@ -34,12 +33,11 @@ const AddStudent = () => { const value: Student = event.detail.value for (const [key, value1] of Object.entries(value)) { if (!value1 && !['id_card', 'password'].includes(key)) { - Taro.showToast({title: "请填写完整", icon: 'error'}) + Taro.showToast({title: "请认真填写", icon: 'error'}) return } } Taro.showLoading() - setDisable(true) try { if (params.id) { await ManageApi.putUser(params.id, {...value, dep_ids: depIds, company_id: company?.id || 0}) @@ -54,12 +52,10 @@ const AddStudent = () => { } catch (e) { } Taro.hideLoading() - setDisable(true) } const formatDep = useCallback(() => { - console.log(depIds, 12) const selected = department.filter(d => depIds.includes(d.id)).map(d => d.title) const top4 = selected.splice(0, 3).join('、') return top4 + (selected.length ? "+" + selected.length : '') @@ -117,7 +113,7 @@ const AddStudent = () => { - + ) diff --git a/src/pages/manage/depAdmin/depAdmin.tsx b/src/pages/manage/depAdmin/depAdmin.tsx index 07392cf..1c5b055 100644 --- a/src/pages/manage/depAdmin/depAdmin.tsx +++ b/src/pages/manage/depAdmin/depAdmin.tsx @@ -80,6 +80,8 @@ const DepAdmin: FC = () => { del(item.name, item.id) break } + }, + fail() { } }) } @@ -126,6 +128,8 @@ const DepAdmin: FC = () => { setRoleType(user) break } + }, + fail() { } }) } diff --git a/types/user.d.ts b/types/user.d.ts index e961b9a..df569f7 100644 --- a/types/user.d.ts +++ b/types/user.d.ts @@ -34,6 +34,7 @@ interface Department { users: null } +/** 公司 */ interface Company { id: number company_name: string @@ -76,7 +77,8 @@ interface CueStats { } -interface userRecord { +/** 课时学习记录 */ +interface HourHistory { id: number; duration: number; course: Curriculum;