HarmonyOS ArkTS 实战:实现一个校园成绩查询与学分统计应用
·
HarmonyOS ArkTS 实战:实现一个校园成绩查询与学分统计应用
项目效果
本文使用 HarmonyOS 和 ArkTS 实现一个校园成绩查询与学分统计应用。
应用可以查询各学期课程成绩,计算GPA绩点,统计已修学分,查看课程排名,并提供挂科提醒、成绩分析和学分进度等功能。
项目使用 DevEco Studio 开发,适配 API 23 及以上版本。
运行效果

功能介绍
- 学期成绩查询
- GPA绩点计算
- 学分统计
- 成绩排名
- 挂科提醒
- 成绩分布分析
- 学分进度条
- 课程详情
- 按学期筛选
- 不及格课程统计
定义数据结构
interface Course {
id: number;
name: string;
credit: number;
score: number;
gradePoint: number;
semester: string;
courseType: string;
isMakeup: boolean;
}
字段:id/课程名/学分/分数/绩点/学期/课程类型/是否补考
初始化页面状态
@State private selectedSemester: string = '全部';
@State private currentStudentId: string = '2023001';
初始数据:
@State private courses: Course[] = [
{ id: 1, name: '高等数学', credit: 4, score: 92, gradePoint: 4.0, semester: '2023-2024-1', courseType: '必修', isMakeup: false },
{ id: 2, name: '大学英语', credit: 3, score: 85, gradePoint: 3.5, semester: '2023-2024-1', courseType: '必修', isMakeup: false },
{ id: 3, name: '程序设计基础', credit: 4, score: 95, gradePoint: 4.0, semester: '2023-2024-1', courseType: '必修', isMakeup: false },
{ id: 4, name: '大学物理', credit: 4, score: 58, gradePoint: 0, semester: '2023-2024-1', courseType: '必修', isMakeup: true },
{ id: 5, name: '数据结构', credit: 4, score: 88, gradePoint: 3.7, semester: '2023-2024-2', courseType: '必修', isMakeup: false }
];
GPA计算
private calculateGPA(courseList: Course[]): number {
const totalCredit = courseList.reduce((sum, c) => sum + c.credit, 0);
if (totalCredit === 0) return 0;
const totalPoint = courseList.reduce((sum, c) => sum + c.credit * c.gradePoint, 0);
return Math.round((totalPoint / totalCredit) * 100) / 100;
}
统计数据
private getTotalCredit(): number {
return this.courses.filter(c => c.score >= 60).reduce((sum, c) => sum + c.credit, 0);
}
private getFailedCount(): number {
return this.courses.filter(c => c.score < 60).length;
}
private getAverageScore(): number {
const passed = this.courses.filter(c => c.score >= 60);
if (passed.length === 0) return 0;
return Math.round(passed.reduce((sum, c) => sum + c.score, 0) / passed.length);
}
设置分数颜色
private getScoreColor(score: number): ResourceColor {
if (score >= 90) return '#7E22CE';
if (score >= 80) return '#059669';
if (score >= 60) return '#F59E0B';
return '#DC2626';
}
主题色:深紫色#7E22CE,体现学习、学术、专业的感觉。
页面设计说明
页面分为:顶部个人信息和GPA展示、统计卡片(总学分/平均分/挂科数/当前排名)、学期筛选、成绩列表。高分用紫色,及格用绿色,不及格用红色。
SDK 配置
统一使用 API 24 配置。
运行项目
entry/src/main/ets/pages/Index.ets
项目总结
实现了成绩查询、GPA计算、学分统计、挂科提醒、成绩分析等功能。掌握了绩点计算、数据统计、条件筛选、状态管理等。后续可加入成绩排名、成绩单导出、补考报名、选课推荐、培养方案对比等功能。
更多推荐


所有评论(0)