学习记录

main
king 1 year ago
parent 5b9c976e78
commit aee74e0418
  1. 7
      src/api/user.ts
  2. 30
      src/pages/index/components/videoList.tsx

@ -31,6 +31,10 @@ interface DepListData {
user: User user: User
} }
interface LearningRecord {
user_course_records: LearnRecord[]
}
export const userApi = { export const userApi = {
login(code: string) { login(code: string) {
@ -51,5 +55,8 @@ export const userApi = {
}, },
code(catch_key: string) { code(catch_key: string) {
return request<{ code: Code }>(`/api/v1/auth/login/code`, "POST", {openid: catch_key}) return request<{ code: Code }>(`/api/v1/auth/login/code`, "POST", {openid: catch_key})
},
learningRecord(courseId = 0) {
return request<LearningRecord>(`/api/v1/user/record/course`, "GET", {courseId})
} }
} }

@ -5,6 +5,7 @@ import {CoursesKey, Cur, 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'
import {formatMinute} from "@/utils/time"; import {formatMinute} from "@/utils/time";
import {userApi} from "@/api";
interface Props { interface Props {
categoryId: CoursesKey categoryId: CoursesKey
@ -13,6 +14,7 @@ interface Props {
export const VideoList: FC<Props> = ({categoryId}: Props) => { export const VideoList: FC<Props> = ({categoryId}: Props) => {
const [data, setDta] = useState<Cur[] | null>(null) const [data, setDta] = useState<Cur[] | null>(null)
const [index, setIndex] = useState(3) const [index, setIndex] = useState(3)
const [records, setRecords] = useState<LearnRecord[]>([])
async function getData() { async function getData() {
try { try {
@ -35,10 +37,29 @@ export const VideoList: FC<Props> = ({categoryId}: Props) => {
Taro.hideLoading() Taro.hideLoading()
} }
async function getRecords() {
try {
const {user_course_records} = await userApi.learningRecord()
setRecords(user_course_records)
} catch (e) {
}
}
function rateOfLearning(id: number, class_hour: number): JSX.Element { function rateOfLearning(id: number, class_hour: number): JSX.Element {
console.log(id) switch (categoryId) {
return (<View>{`${class_hour}节/已学${0}`}</View>) case "is_finished":
case "is_not_required":
const find = records.find(d => d.course_id === id)
if (find) {
return (<View>{`${class_hour}节/已学${find.finished_count}`}</View>)
}
return (<View>{`${class_hour}节/已学0节`}</View>)
case "is_not_finished":
return (<View>{`${class_hour}节/已学0节`}</View>)
case "is_required":
return (<View>{`${class_hour}节/已学${class_hour}`}</View>)
}
} }
function jumpCategoryCur(id: number) { function jumpCategoryCur(id: number) {
@ -51,7 +72,10 @@ export const VideoList: FC<Props> = ({categoryId}: Props) => {
} }
}) })
Taro.useDidShow(getData) Taro.useDidShow(() => {
getData()
getRecords()
})
return ( return (
<> <>
{data?.slice(0, index).map(d => ( {data?.slice(0, index).map(d => (

Loading…
Cancel
Save