|
|
@ -9,44 +9,66 @@ const CurHistory = () => { |
|
|
|
const [show, setShow] = useState(false) |
|
|
|
const [show, setShow] = useState(false) |
|
|
|
const {course_id, name} = Taro.getCurrentInstance().preloadData as { course_id: number, name: string } |
|
|
|
const {course_id, name} = Taro.getCurrentInstance().preloadData as { course_id: number, name: string } |
|
|
|
const [data, setData] = useState<userRecord[]>([]) |
|
|
|
const [data, setData] = useState<userRecord[]>([]) |
|
|
|
|
|
|
|
const [course, setCourse] = useState<Curriculum | null>(null) |
|
|
|
|
|
|
|
const [hours, setHours] = useState<Hour[] | null>(null) |
|
|
|
|
|
|
|
const [durations, setDuration] = useState<Record<number, number> | null>(null) |
|
|
|
|
|
|
|
const [time, setTime] = useState<Record<number, { start: number, end: number }> | null>(null) |
|
|
|
|
|
|
|
|
|
|
|
Taro.useLoad(() => { |
|
|
|
Taro.useLoad(() => { |
|
|
|
Taro.setNavigationBarTitle({title: name}) |
|
|
|
Taro.setNavigationBarTitle({title: name}) |
|
|
|
userApi.courseRecord(course_id).then(res => { |
|
|
|
userApi.courseRecord(course_id).then(res => { |
|
|
|
setData(Object.values(res)) |
|
|
|
setData(Object.values(res.data)) |
|
|
|
|
|
|
|
setCourse(res.course) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
function setHour() { |
|
|
|
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) |
|
|
|
setShow(true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function percent(duration: number): number { |
|
|
|
|
|
|
|
if (!course?.course_duration) return 0 |
|
|
|
|
|
|
|
return Number((duration / course.course_duration * 100).toFixed(2)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getTime(id: number): string { |
|
|
|
|
|
|
|
const start = formatDateTime(new Date(time?.[id].start || 0), 'MM/dd HH:mm') |
|
|
|
|
|
|
|
const end = formatDateTime(new Date(time?.[id].end || 0), 'MM/dd HH:mm') |
|
|
|
|
|
|
|
return `${start} - ${end}` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function hourPercent(id: number, duration: number): number { |
|
|
|
|
|
|
|
const viewingTime = durations?.[id] || 0 |
|
|
|
|
|
|
|
console.log(viewingTime,duration) |
|
|
|
|
|
|
|
return Number((viewingTime / duration * 100).toFixed(2)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<View> |
|
|
|
<View> |
|
|
|
<View className={styles.cur}> |
|
|
|
<View className={styles.cur}> |
|
|
|
<Image src={''} mode='aspectFit'/> |
|
|
|
<Image src={course?.thumb || ''} mode='widthFix'/> |
|
|
|
<View>{name}</View> |
|
|
|
<View>{name}</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<View className={styles.record}> |
|
|
|
<View className={styles.record}> |
|
|
|
|
|
|
|
{data.map(d => <View onClick={() => setHour(d.unique_ident)} className={styles.recordItem}> |
|
|
|
{ |
|
|
|
<View>{formatDateTime(new Date(d.start_at), "MM/dd HH:ss")} - {formatDateTime(new Date(d.end_at), "MM/dd HH:ss")}</View> |
|
|
|
data.map(d => <View onClick={() => setHour()} className={styles.recordItem}> |
|
|
|
<View>观看视频:{formatMinute(d.duration)}</View> |
|
|
|
<View>{formatDateTime(new Date(d.start_at), "MM-dd HH:ss")} - {formatDateTime(new Date(d.end_at), "MM-dd HH:ss")}</View> |
|
|
|
|
|
|
|
<View>观看:{formatMinute(d.duration)}</View> |
|
|
|
|
|
|
|
<Progress |
|
|
|
<Progress |
|
|
|
percent={d.duration} |
|
|
|
percent={percent(d.duration)} |
|
|
|
showInfo |
|
|
|
showInfo |
|
|
|
borderRadius={10} |
|
|
|
borderRadius={10} |
|
|
|
active |
|
|
|
active |
|
|
|
|
|
|
|
duration={10} |
|
|
|
strokeWidth={10} |
|
|
|
strokeWidth={10} |
|
|
|
color={'#45D4A8'} |
|
|
|
color={'#45D4A8'} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</View>) |
|
|
|
</View>)} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
|
|
<PageContainer |
|
|
|
<PageContainer |
|
|
@ -54,12 +76,16 @@ const CurHistory = () => { |
|
|
|
round |
|
|
|
round |
|
|
|
onAfterLeave={() => setShow(false)}> |
|
|
|
onAfterLeave={() => setShow(false)}> |
|
|
|
{show && <View className={styles.hourRecord}> |
|
|
|
{show && <View className={styles.hourRecord}> |
|
|
|
<View> |
|
|
|
|
|
|
|
<View onClick={() => setHour()} className={styles.recordItem}> |
|
|
|
{ |
|
|
|
<View>2023-6-19</View> |
|
|
|
hours?.map(d => <View> |
|
|
|
|
|
|
|
<View className={styles.recordItem}> |
|
|
|
|
|
|
|
<View>{d.title}</View> |
|
|
|
|
|
|
|
<View>{getTime(d.id)}</View> |
|
|
|
<Progress |
|
|
|
<Progress |
|
|
|
percent={10} |
|
|
|
percent={hourPercent(d.id, d.duration)} |
|
|
|
showInfo |
|
|
|
showInfo |
|
|
|
|
|
|
|
duration={10} |
|
|
|
borderRadius={10} |
|
|
|
borderRadius={10} |
|
|
|
active |
|
|
|
active |
|
|
|
strokeWidth={10} |
|
|
|
strokeWidth={10} |
|
|
@ -67,6 +93,8 @@ const CurHistory = () => { |
|
|
|
/> |
|
|
|
/> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
</View>} |
|
|
|
</View>} |
|
|
|
</PageContainer> |
|
|
|
</PageContainer> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|