HarmonyOS ArkTS 实战:实现一个校园心理测评预约咨询应用

HarmonyOS ArkTS 实战:实现一个校园心理测评预约咨询应用 HarmonyOS ArkTS 实战实现一个校园心理测评预约咨询应用项目效果本文使用 HarmonyOS 和 ArkTS 实现一个校园心理测评预约咨询应用。应用可以进行心理测评预约心理咨询查看测评报告咨询记录并提供心理科普、情绪打卡、咨询师介绍、危机干预等完整功能。项目使用 DevEco Studio 开发适配 API 23 及以上版本。运行效果功能介绍心理测评量表在线测评答题测评报告生成心理咨询预约咨询师选择时间段选择我的预约咨询记录心理科普文章情绪打卡危机干预热线心情日记定义数据结构interfaceScale{id:number;name:string;description:string;questionCount:number;duration:number;category:string;}interfaceCounselor{id:number;name:string;title:string;specialty:string;avatar:string;available:boolean;introduction:string;}interfaceAppointment{id:number;counselorId:number;counselorName:string;date:string;time:string;type:string;// 线上/线下status:string;// 待确认/已确认/已完成/已取消problem:string;}interfaceAssessmentResult{id:number;scaleId:number;scaleName:string;score:number;level:string;suggestion:string;testTime:string;}初始化页面状态StateprivatetabIndex:number0;Stateprivatescales:Scale[][{id:1,name:SCL-90症状自评量表,description:从多个角度反映心理健康状况,questionCount:90,duration:15,category:综合},{id:2,name:抑郁自评量表SDS,description:评估抑郁程度的常用量表,questionCount:20,duration:5,category:情绪},{id:3,name:焦虑自评量表SAS,description:评估焦虑程度的常用量表,questionCount:20,duration:5,category:情绪},{id:4,name:大学生人格问卷UPI,description:大学生心理健康筛查,questionCount:60,duration:10,category:人格},];Stateprivatecounselors:Counselor[][{id:1,name:陈老师,title:心理咨询中心主任,specialty:情绪管理、人际关系,avatar:,available:true,introduction:从事心理咨询15年},{id:2,name:刘老师,title:专职心理咨询师,specialty:学业压力、恋爱心理,avatar:,available:true,introduction:国家二级心理咨询师},{id:3,name:周老师,title:兼职心理咨询师,specialty:职业规划、自我成长,avatar:,available:false,introduction:心理学博士},];Stateprivateappointments:Appointment[][{id:1,counselorId:1,counselorName:陈老师,date:2026-07-25,time:14:00-15:00,type:线下,status:已确认,problem:学业压力咨询},];Stateprivateresults:AssessmentResult[][];StateprivatenextId:number10;预约咨询privatebookAppointment(counselorId:number,date:string,time:string,type:string,problem:string):void{constcounselorthis.counselors.find(cc.idcounselorId);if(!counselor)return;constapp:Appointment{id:this.nextId,counselorId,counselorName:counselor.name,date,time,type,status:待确认,problem};this.appointments[app,...this.appointments];this.nextId1;}取消预约privatecancelAppointment(appointmentId:number):void{this.appointmentsthis.appointments.map(aa.idappointmentId?{...a,status:已取消}:a);}咨询师卡片组件BuilderCounselorCard(counselor:Counselor){Row({space:12}){Column().width(60).height(60).backgroundColor(#FEF9C3).borderRadius(30)Column({space:4}){Row(){Text(counselor.name).fontSize(16).fontWeight(FontWeight.Medium).fontColor(#451A03)Text(counselor.title).fontSize(11).fontColor(#A16207).margin({left:8})}Text(擅长${counselor.specialty}).fontSize(12).fontColor(#854D0E)Text(counselor.introduction).fontSize(11).fontColor(#A16207).maxLines(1)if(counselor.available){Button(预约咨询).fontSize(12).height(32).backgroundColor(#451A03).margin({top:4}).onClick(()this.bookAppointment(counselor.id,2026-07-28,15:00-16:00,线下,心理咨询))}else{Text(已约满).fontSize(12).fontColor(#94A3B8).margin({top:4})}}.layoutWeight(1).alignItems(HorizontalAlign.Start)}.width(100%).padding(16).backgroundColor(#FEFCE8).borderRadius(12)}页面布局build(){Column(){// 顶部温馨提示Column({space:8}){Text( 心灵驿站).fontSize(24).fontWeight(FontWeight.Bold).fontColor(#451A03)Text(关爱自己从心开始。咨询保密安全放心。).fontSize(13).fontColor(#A16207)}.width(100%).padding(20).backgroundColor(#FEF9C3)// 危机热线Row(){Text( 24小时心理危机热线400-161-9995).fontSize(13).fontColor(Color.White)}.width(100%).padding(12).backgroundColor(#DC2626).justifyContent(FlexAlign.Center)// TabRow({space:20}){Text(心理测评).fontSize(16).fontWeight(this.tabIndex0?FontWeight.Bold:FontWeight.Normal).fontColor(this.tabIndex0?#451A03:#94A3B8).onClick(()this.tabIndex0)Text(预约咨询).fontSize(16).fontWeight(this.tabIndex1?FontWeight.Bold:FontWeight.Normal).fontColor(this.tabIndex1?#451A03:#94A3B8).onClick(()this.tabIndex1)Text(我的预约).fontSize(16).fontWeight(this.tabIndex2?FontWeight.Bold:FontWeight.Normal).fontColor(this.tabIndex2?#451A03:#94A3B8).onClick(()this.tabIndex2)}.width(100%).padding({left:20,right:20,top:16})if(this.tabIndex0){List({space:12}){ForEach(this.scales,(s:Scale){ListItem(){Column({space:8}){Text(s.name).fontSize(15).fontWeight(FontWeight.Medium).fontColor(#451A03)Text(s.description).fontSize(12).fontColor(#854D0E)Row(){Text(${s.questionCount}题 | 约${s.duration}分钟).fontSize(11).fontColor(#A16207)Blank()Button(开始测评).fontSize(12).height(32).backgroundColor(#451A03)}.width(100%).margin({top:4})}.width(100%).padding(16).backgroundColor(#FEFCE8).borderRadius(12)}})}.width(100%).padding(20).layoutWeight(1)}elseif(this.tabIndex1){List({space:12}){ForEach(this.counselors,(c:Counselor){ListItem(){this.CounselorCard(c)}})}.width(100%).padding(20).layoutWeight(1)}else{List({space:12}){ForEach(this.appointments,(a:Appointment){ListItem(){Column({space:8}){Row(){Text(${a.counselorName}老师).fontSize(15).fontWeight(FontWeight.Medium)Blank()Text(a.status).fontSize(12).fontColor(a.status已确认?#059669:#F59E0B)}Text(${a.date}${a.time}|${a.type}).fontSize(12).fontColor(#854D0E)Text(a.problem).fontSize(12).fontColor(#A16207)if(a.status!已取消a.status!已完成){Button(取消预约).width(100%).height(34).fontSize(13).backgroundColor(#DC2626).onClick(()this.cancelAppointment(a.id))}}.width(100%).padding(16).backgroundColor(#FEFCE8).borderRadius(12)}})}.width(100%).padding(20).layoutWeight(1)}}.width(100%).height(100%).backgroundColor(Color.White)}页面设计说明主题色采用yellow-950#451A03深黄色体现心理咨询的温暖、关怀、治愈。黄色系背景给人温馨感红色危机热线醒目突出整体氛围温暖安全。SDK配置API 24compatibleSdkVersion: “6.1.1(24)”运行项目将代码复制到 entry/src/main/ets/pages/Index.ets 即可运行。项目总结实现了心理测评、咨询师预约、预约管理、危机干预等功能。掌握了温馨配色、卡片布局、状态管理、热线提示等。后续可加入在线答题、测评报告生成、心情日记、情绪打卡、线上咨询、心理科普文章推送等功能。