diff --git a/src/common/components/AnswerToStudent/index.tsx b/src/common/components/AnswerToStudent/index.tsx index f4cae74..cee3def 100644 --- a/src/common/components/AnswerToStudent/index.tsx +++ b/src/common/components/AnswerToStudent/index.tsx @@ -6,7 +6,7 @@ function AnswerToStudent() { return ( 问题问题问题问题问题: - 10个回答 + 1个回答 ); } diff --git a/src/common/types/userTypes.ts b/src/common/types/userTypes.ts index e1ae997..db8e1cf 100644 --- a/src/common/types/userTypes.ts +++ b/src/common/types/userTypes.ts @@ -36,3 +36,30 @@ export type WebUserProfileVo = { using_title: string; utime?: number; }; +/** + * ginx.Result + */ +export interface GradeResponse { + /** + * 错误码,非 0 表示失败 + */ + code?: number; + data?: GradeChart[]; + /** + * 错误或成功 描述 + */ + msg?: string; +} + +/** + * web.GradeChartVo + */ +export interface GradeChart { + avg: number; + grades: Grade[]; +} + +export interface Grade { + percent?: number; + total_grades: number[]; +} diff --git a/src/custom-tab-bar/index.tsx b/src/custom-tab-bar/index.tsx index 93d56b8..808dca0 100644 --- a/src/custom-tab-bar/index.tsx +++ b/src/custom-tab-bar/index.tsx @@ -1,7 +1,7 @@ /* eslint-disable import/first */ import { View } from '@tarojs/components'; import Taro from '@tarojs/taro'; -import { memo } from 'react'; +import React, { memo } from 'react'; import { AtIcon } from 'taro-ui'; import './index.scss'; @@ -14,7 +14,7 @@ interface TabBarProps {} const TAB_LIST: Array<{ pagePath: string; name: string; icon?: string }> = [ { pagePath: '/pages/main/index', name: 'Home', icon: 'streaming' }, { pagePath: '/pages/main/index', name: 'Download', icon: 'download-cloud' }, - { pagePath: '/pages/main/index', name: '+' }, + { pagePath: '/pages/evaluate/evaluate', name: '+' }, { pagePath: '/pages/notification/index', name: 'Massage', icon: 'message' }, { pagePath: '/pages/profile/index', name: 'Profile', icon: 'user' }, ]; diff --git a/src/pages/classInfo/index.tsx b/src/pages/classInfo/index.tsx index 48ca395..9293a2c 100644 --- a/src/pages/classInfo/index.tsx +++ b/src/pages/classInfo/index.tsx @@ -15,6 +15,7 @@ import AnswerToStudent from '@/common/components/AnswerToStudent'; import LineChart from '@/common/components/chart'; import Label3 from '@/common/components/label3/label3'; import ShowStar from '@/common/components/showStar/showStar'; +import { GradeChart } from '@/common/types/userTypes'; import { get } from '@/common/utils/fetch'; const coursePropertyMap = { @@ -38,22 +39,20 @@ function translateCourseProperty(englishDescription) { export default function Index() { const [course, setCourse] = useState(null); - const [courseId, setCourseId] = useState(null); - const [comments, setComments] = useState([]); + const [grade, setGrade] = useState(); // 将 grade 的类型设置为 GradeChart | null useEffect(() => { const getParams = () => { const instance = Taro.getCurrentInstance(); - // 使用可选链操作符安全访问 router 和 params const params = instance?.router?.params || {}; if (params.course_id) setCourseId(params.course_id); }; getParams(); - }, []); // 这个 effect 仅在组件挂载时运行一次 + }, []); useEffect(() => { // eslint-disable-next-line @typescript-eslint/require-await @@ -65,7 +64,6 @@ export default function Index() { setCourse(res.data); }); } catch (error) { - // 错误处理,例如弹出提示 console.error('Failed to fetch course data:', error); } }; @@ -83,26 +81,44 @@ export default function Index() { setComments(res.data as CommentInfoType[]); }); } catch (error) { - // 错误处理,例如弹出提示 console.error('Failed to fetch course data:', error); } }; if (courseId) void getCommentData(); - }, [courseId]); // 在courseId变化时运行 + }, [courseId]); - if (!course) { + useEffect(() => { + const fetchGrades = async () => { + try { + await get(`/grades/courses/${courseId}`, true).then((res) => { + console.log(res.data); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + setGrade(res.data); // 设置 grade 数据 + }); + } catch (err) { + console.error('Failed to fetch grades data', err); + } + }; + if (courseId) void fetchGrades(); + }, [courseId]); + + if (!course || !grade) { return Loading...; // 数据加载中 } - // 检查 course.features 是否存在并且是一个数组 + const xLabels = ['0-40', '40-50', '50-60', '60-70', '70-80', '80-90', '90-100']; + + const avgScore = grade.avg; + const heightLightIndex = Math.floor(avgScore / 10) - 4; // 假设 0-40 开始对应 index 0,每个区间跨度 10 + // 处理 y 轴的数据,确保它们在 0 到 100 之间 + const yData = grade.grades.flatMap((g) => g.total_grades.map((score) => score ?? 0)); + // 计算高亮百分比 + const heightLightPercent = heightLightIndex / xLabels.length; + const featuresList = course.features && Array.isArray(course.features) ? course.features : []; - // @ts-ignore - // @ts-ignore - // @ts-ignore - // @ts-ignore return ( {course?.name} @@ -118,14 +134,19 @@ export default function Index() { 课程特点: {} - {/* @ts-ignore*/} {featuresList.map((feature, keyindex) => ( ))} - {/*<>*/} + {/* 将 grade 数据传递给 LineChart */} - + @@ -154,9 +175,9 @@ export default function Index() { url: `/pages/evaluateInfo/index?comment=${serializedComment}`, }); }} - key={comment.id} // 使用唯一key值来帮助React识别哪些元素是不同的 - {...comment} // 展开comment对象,将属性传递给Comment组件 - type="inner" // 固定属性,不需要从数组中获取 + key={comment.id} + {...comment} + type="inner" /> ))}