网站负责人核验照片南京做网站群的公司
2026/4/6 5:42:56 网站建设 项目流程
网站负责人核验照片,南京做网站群的公司,建设工程合同名词解释,网站被人恶意刷流量一、项目简介 本项目基于 HarmonyOS 最新开发框架 ArkTS#xff0c;使用 DevEco Studio 开发一款轻量级但功能完整的课程表应用#xff08;ScheduleAPP#xff09;。该应用支持用户查看每日课程安排、添加/编辑课程信息、切换周视图等功能#xff0c;适用于大学或中学师生…一、项目简介本项目基于 HarmonyOS 最新开发框架 ArkTS使用 DevEco Studio 开发一款轻量级但功能完整的课程表应用ScheduleAPP。该应用支持用户查看每日课程安排、添加/编辑课程信息、切换周视图等功能适用于大学或中学师生日常使用。1.1 核心功能课程表展示以周为单位显示课程安排支持星期切换添加课程填写课程名称、教室、备注等信息编辑课程修改已有课程信息查看详情点击课程卡片查看详细信息周数计算自动计算当前学期周数1.2 技术栈开发平台HarmonyOS SDKAPI 20编程语言ArkTS工具链DevEco Studio 6.0.01.3 项目源码项目完整代码已上传至Gitee欢迎大家下载使用。ScheduleAPP项目开发源码https://gitee.com/zhen-shi_1_0/schedule.git二、开发环境搭建安装DevEco Studio 6.0 或更高版本配置 HarmonyOS SDK确保包含 API Version 20创建模拟器推荐使用 Phone 类型设备验证环境新建空白项目并成功运行 Hello World提示开发环境搭建详细步骤请看作者的其它博文。如下面这篇博文的前两节零基础使用 Flutter 编译开发 鸿蒙 HarmonyOS 项目教程——搭建环境篇三、项目创建与结构说明3.1 新建项目在 DevEco Studio 中选择File → New → Create Project模板Empty Ability项目配置Project name:ScheduleAPPBundle name:com.example.scheduleappCompile SDK:API 20Device type:Phone点击Finish完成创建。​3.2 项目目录结构创建完成后项目结构如下ScheduleAPP/ ├── AppScope/ # 应用全局配置 │ ├── app.json5 │ └── resources/ └── entry/ # 主模块 └── src/main/ ├── ets/ │ ├── entryability/ # 应用入口 │ └── pages/ # 页面代码重点 ├── resources/ # 图片、字符串等资源 └── module.json5 # 模块配置四、核心功能实现4.1 定义课程数据模型Course.ets在entry/src/main/ets/pages/class/目录下创建Course.etsexport class Course { public courseName: string ; // 课程名称 public classroom: string ; // 教室 public remark: string ; // 备注如教师姓名 public index: number 0; // 唯一位置索引0~59 constructor(courseName: string, classroom: string, remark: string, index: number) { this.courseName courseName; this.classroom classroom; this.remark remark; this.index index; } }代码说明使用class定义课程数据类包含课程的基本信息名称、教室、备注、索引index用于标识课程在课程表中的位置0-59表示60个时间槽4.2 主页面开发Index.ets主页面代码import router from ohos.router; import { Course } from ./class/Course const content1: string[] (() { const arr: string[] new Array(15).fill(); for (let i 0; i 15; i 1) { arr[i] i 1 ; } return arr; })() //节数 let newName: string ; Entry Component struct TableHome { StorageLink(name) name: string 课程表1; StorageLink(showDialog) showDialog: boolean false; //课程数据数组课程总数量 State content: Course[] (() { const arr: Course[] new Array(60); for (let i 0; i 60; i) { arr[i] new Course(, , ,i); } return arr; })() State currentWeekday: number new Date().getDay() || 7 // 0-6, 0周日转换为1-7 // 使用 StorageLink 监听 AppStorage 变化 StorageLink(updatedCourse) updatedCourse: Course new Course(, , , -1); StorageLink(showDetails) showDetails: boolean false; // 在 TableHome 组件中添加状态 StorageLink(selectedCourse) selectedCourse: Course new Course(, , , -1); // 获取指定星期几的日期 getWeekDate(dayOfWeek: number): string { let date new Date(); // 计算目标日期0周日1周一... let targetDay dayOfWeek - 1; // 调整为JavaScript的星期索引0周日 let diff targetDay - date.getDay(); // 当前星期几与目标星期几的差值 date.setDate(date.getDate() diff); let month date.getMonth() 1; let day date.getDate(); return ${month}/${day}; } // 计算从指定日期到当前日期经过的周数 getWeeksSinceStart(startYear: number, startMonth: number, startDay: number): number { let startDate new Date(startYear, startMonth - 1, startDay); // 注意月份从0开始 let currentDate new Date(); // 计算两个日期之间的毫秒差 let timeDiff currentDate.getTime() - startDate.getTime(); // 转换为天数再转换为周数 let daysDiff Math.floor(timeDiff / (1000 * 60 * 60 * 24)); let weeksDiff Math.floor(daysDiff / 7) 1; return weeksDiff; } // 获取星期名称 getWeekdayName(weekday: number): string { const names [, 周一, 周二, 周三, 周四, 周五, 周六, 周日]; return names[weekday] || ; } aboutToAppear(): void { // 初始化 AppStorage AppStorage.SetOrCreate(updatedCourse, new Course(, , , -1)); AppStorage.SetOrCreate(showDetails, false);// 控制Details组件显示/隐藏 } // 关键页面每次显示时同步 updatedCourse 到 courses onPageShow() { // console.log(onPageShow: 检查 updatedCourse 是否有更新); this.syncUpdatedCourseToLocal(); } syncUpdatedCourseToLocal(): void { const uc this.updatedCourse; if (uc.index 0 uc.index this.content.length) { // 只更新对应 index 的课程 this.content[uc.index] new Course( uc.courseName, uc.classroom, uc.remark, uc.index ); // console.log(同步第 ${uc.index} 节课成功:, JSON.stringify(uc)); } } Builder hingeBody(contNumber: number) { Sidebar({ inputValue: content1[contNumber] }) ForEach(this.content.slice(contNumber*51, contNumber*56), (item: Course) { GridItemCase({ course: item }); }) } Builder mainBody() { ForEach([0,1,2,3], (item: number) { this.hingeBody(item) }) GridItem() { Text(午休); } .GridItemRestFn() ForEach([4,5,6,7], (index: number) { this.hingeBody(index) }) GridItem() { Text(晚休); } .GridItemRestFn() ForEach([8,9,10], (index: number) { this.hingeBody(index) }) } build() { //层叠布局 Stack({ alignContent: Alignment.BottomStart }) { Column() { // 导航栏 Row() { Image($r(app.media.chevron_left)) .height(40) .onClick(() { router.back() }) .margin({ right: 10 }) if (this.showDialog) { Dialog() /*.position({ top: 100, left: 0, right: 0 })*/ }else { Text(this.name) .fontSize(18) .fontWeight(FontWeight.Bold) .alignSelf(ItemAlign.Center) .onClick(() {this.showDialog true;}) } /*Blank() Image($r(app.media.menu_01)) .height(30) .onClick(() { //跳转到全部课程表 }) .margin({ right: 10 })*/ } .width(100%) .height(60) .padding(5) .backgroundColor(#F2F2F4) .alignItems(VerticalAlign.Center) Row() { //表头——星期 Grid() { //网格布局 GridItem(){ Column() { Text(){ Span(this.getWeeksSinceStart(2025,9,8).toString()) //周数 Span(周) } .fontSize(12) .fontWeight(FontWeight.Bolder) Image($r(app.media.chevron_down)) .height(20) } .onClick(() { //跳转到周数选择页面 /*router.pushUrl({ url: pages/WeekSelectPage })*/ }) } .height(100%) // 星期选择器 ForEach([1,2,3,4,5,6,7],(weekday: number){ GridItem(){ Column() { Text(this.getWeekdayName(weekday)) .fontSize(14) .fontColor(this.currentWeekday weekday ? #FFFFFF : #666666) .fontWeight(this.currentWeekday weekday ? FontWeight.Bold : FontWeight.Normal) .fontWeight(FontWeight.Bold) .margin({ bottom: 2 }) Text(this.getWeekDate(weekday 1)) //获取星期几的日期 .fontSize(10) } .justifyContent(FlexAlign.Center) } .height(40) .backgroundColor(this.currentWeekday weekday ? #007DFF : #F5F5F5) .borderRadius(8) .onClick(() { this.currentWeekday weekday; }) }) } .columnsTemplate(13fr 18fr 18fr 18fr 18fr 18fr) .padding({ left: 8, right: 8, top: 8, bottom: 8 }) .columnsGap(1) // 设置列间距 } .height(8%) .backgroundColor(#F2F2F4) .margin({bottom:2}) // 底部间距 //主体内容 Grid() { this.mainBody() GridItem() { Row() { // 你的内容 } .height(90) .width(100%) } } .width(100%) .height(100%) .columnsTemplate(13fr 18fr 18fr 18fr 18fr 18fr) .scrollBar(BarState.Off) .edgeEffect(EdgeEffect.Spring) // 边缘效果 } .height(100%) .width(100%) .alignItems(HorizontalAlign.Start) if (this.showDetails) { Details() } } .height(100%) .width(100%) } } Component struct GridItemCase { State isSelected: boolean false; // 是否被选中 Prop course: Course new Course(,,,0); State isCourse: boolean false; //课程是否被用户填写 State params: Course router.getParams() as Course; //获取用户填写的课程信息 // 构造函数方式接收参数 constructor(courseProp: Course) { super(); this.course courseProp; } aboutToAppear(): void { // 在组件即将出现时进行一次初始化判断 if (this.course.courseName ) { this.isCourse false; } else { this.isCourse true; } } build() { GridItem(){ Row(){ Column(){ if (this.isCourse) //课程被用户填写 { Text(this.course.courseName) .fontSize(13) .fontWeight(FontWeight.Bold) Text(this.course.classroom) .TextFn() Text(this.course.remark) .TextFn() }else { if (this.isSelected) { //用户点击 被选中 Text() .fontSize(24) .fontWeight(FontWeight.Bold) .foregroundColor(Color.Black) } } } .width(100%) .height(100%) .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) } .onClick((){ if (this.isCourse) { //课程被用户填写 AppStorage.Set(selectedCourse, this.course) // 保存选中的课程 AppStorage.Set(showDetails, true) //显示课程信息 }else { if (this.isSelected) { router.pushUrl({ url: pages/AddCoursePage, params: this.course }) } this.isSelected !this.isSelected AppStorage.Set(showDetails, false) //隐藏课程信息 } }) .height(90) .backgroundColor(this.isSelected ? #f2f2f2 : Color.White) } .border({ width: 1, color: #F2F2F4, style: BorderStyle.Solid }) } } //侧边栏 Component struct Sidebar { Prop inputValue: string ; // 添加输入参数 // 构造函数方式接收参数 constructor(inputValue: string) { super(); this.inputValue inputValue; } build() { GridItem(){ Column(){ Text(this.inputValue) .fontSize(14) .fontWeight(FontWeight.Bold) .margin(3) Text(08:00) .TextFn() Text(08:45) .TextFn() } .width(100%) .height(100%) .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) .height(90) .onClick((){ // 跳转到课程时间设置页面 /*router.pushUrl({ url: pages/AddCoursePage })*/ }) } .border({ width: 1, color: #F2F2F4, style: BorderStyle.Solid }) } } //课程详情 Component struct Details { StorageLink(selectedCourse) selectedCourse: Course new Course(, , , -1) build() { //课程详情 Column() { //标题 Row() { Text(课程详情) .width(65%) .fontSize(20) .fontWeight(FontWeight.Bolder) .textAlign(TextAlign.End) Blank() Image($r(app.media.x_close)) .width(30) .onClick(() { //关闭详情页面 AppStorage.Set(showDetails, false) }) } .padding({ top: 15, right: 15 }) .width(100%) Column() { //课程名 Row(){ Circle() .width(10) .height(10) .borderRadius(5) //背景颜色需要传入 .backgroundColor(Color.Black) .margin({ right: 10 }) // Text(计算机网络) Text(this.selectedCourse.courseName) //参数courseName传入 .fontSize(18) .textAlign(TextAlign.Start) Blank() Button(编辑) .size({width: 60, height: 30}) .fontColor(#2f2f2f) .backgroundColor(#f5f5f5) .onClick(() { //跳转到课程编辑页面 router.pushUrl({ url: pages/AddCoursePage, params: this.selectedCourse }) }) } .width(100%) .padding({ right: 15 }) .margin({ bottom: 10 }) /*组件测试数据 Text(教室 基础实验楼701) .margin({ bottom: 5 }) .width(100%) Text(备注 章老师) .margin({ bottom: 5 }) .width(100%)*/ if (this.selectedCourse.classroom ! ){ Text(教室 this.selectedCourse.classroom) .margin({ bottom: 5 }) .width(100%) } if (this.selectedCourse.remark ! ){ Text(备注如老师 this.selectedCourse.remark) .margin( { bottom: 5 }) .width(100%) } Text(周三 第1-2节 (8:00 - 9:40)) //参数week、section、time传入 .width(100%) .margin({ bottom: 5 }) Row() { Text(第1-18周) .margin({right: 5}) Text(单周) .fontSize(12) .backgroundColor(Color.Gray) } .width(100%) } .width(90%) .margin({ top: 15 }) .padding(20) .justifyContent(FlexAlign.Start) .backgroundColor(Color.White) .borderRadius(20) /*Text(新建课程) .fontSize(20) .fontWeight(FontWeight.Bold) .fontColor(Color.Blue) .margin({ top: 25, bottom: 10}) .onClick(() { router.pushUrl({ url: pages/AddCoursePage }) })*/ } .width(100%) .padding(12) .borderRadius({ topLeft: 50, topRight: 50, bottomLeft: 20, bottomRight: 20 }) .backgroundColor(#f7f7f7) // .backgroundColor(Color.Pink) .justifyContent(FlexAlign.Center) .position({ bottom: 0 }) } } Preview Component struct Dialog { build() { Row() { TextInput({ placeholder: 请输入课程表名称 }) .width(60%) .height(35) .onChange((value: string) { newName value; }) .margin({ right: 15 }) Button(确定) .height(35) .onClick(() { if (newName ) { newName 课程表1 } AppStorage.Set(name, newName) AppStorage.Set(showDialog, false) }) } } } Extend(GridItem) function GridItemRestFn() { .width(100%) .backgroundColor(#F2F2F2) .columnStart(0) .columnEnd(5) } Extend(Text) function TextFn() { .fontSize(11) .fontColor(#d0d0d0) }4.2.1 页面核心功能该页面实现了以下核心功能显示一周周一至周日的课程安排网格高亮当前星期并显示对应日期如“12/16”展示课程节数1~15节并分段插入“午休”“晚休”提示点击空课格 → 弹出添加课程对话框Dialog点击已有课程 → 弹出课程详情/编辑弹窗Details支持从其他页面返回时同步更新课程数据onPageShow syncUpdatedCourseToLocal顶部导航栏支持返回上一页和重命名课程表4.2.2 主要组成部分1.主页面TableHome你打开 App 第一眼看到的课程表格。2.课程格子GridItemCase表格里的每一个小方块有的是空的号有的写着“高数”“教室301”。3.课程详情弹窗Details点击一个课程后从底部滑出的详细信息窗口还能点“编辑”去修改。此外还有侧边栏Sidebar左边显示“第1节”“第2节”……和上课时间。改名对话框Dialog点击顶部“课程表1”时弹出的输入框。4.2.3 关键技术与方法解析1.State 和 StorageLinkState组件自己的共享数据比如content数组记录60节课。StorageLink连接全局共享数据叫 AppStorage多个页面都能读写同一个数据。举个例子你在详情页编辑了“高数 → 教室401”保存后返回主页面。主页面通过StorageLink(updatedCourse)立刻知道课程变了自动刷新显示。2.Course 类class Course { courseName: string; // 课程名如“计算机网络” classroom: string; // 教室如“实验楼701” remark: string; // 备注如“张老师” index: number; // 在表格中的位置编号0~59 }每个课程格子背后都有这样一个“对象”存着所有信息。3.Grid 布局 —— 做表格的“神器”HarmonyOS 用GridGridItem来画表格主页面用Grid分成6列1列节数 5列周一到周五每行用hingeBody构建一节课在5天的情况插入“午休”“晚休”时用.columnStart(0).columnEnd(5)占满整行效果整齐的课程表像 Excel 一样。4.ForEach —— 批量生成重复内容ForEach([0,1,2,3], (item) { this.hingeBody(item) })自动生成“第1节、第2节、第3节、第4节”的行不用手写4遍。5.日期计算 —— 自动显示“今天周几”“第几周”new Date().getDay()获取今天是星期几0周日1周一…getWeekDate(dayOfWeek)算出“周一对应12月16日”这样的日期getWeeksSinceStart(2025,9,8)从开学日2025-09-08算起今天是第几周效果顶部显示“第15周”每个星期按钮下显示“12/16”等日期。6.页面跳转与传参routerrouter.pushUrl({ url: pages/AddCoursePage, params: this.course // 把课程信息传过去 })点击空格子 ➜ 跳转到“添加课程页”并告诉它“你要填的是第3节周三的位置”。7.点击交互逻辑GridItemCase每个课程格子有两种状态状态显示内容点击效果空格子显示号再点一次 ➜ 跳转去添加课程有课程显示课程名、教室点击 ➜ 弹出详情页8.弹窗显示Details DialogDetails用if (this.showDetails) { Details() }控制是否显示Dialog点击顶部名称时临时替换成输入框输完点“确定”就改名9.BuilderBuilder hingeBody(contNumber: number) { ... }把“一节课的5个格子”做成一个可复用的组件哪里需要就写在哪里。4.3 添加/编辑课程页面开发AddCoursePage.ets创建entry/src/main/ets/pages/AddCoursePage.ets文件import router from ohos.router; import { Course } from ./class/Course ​ Entry Component struct AddCoursePage { StorageLink(updatedCourse) updatedCourse: Course new Course(, , , -1); ​ State course: Course new Course(,,,-1); State timeSlotCount: number 1; // 时间段数量 private weekRange: string 第9-18周; private backgroundColor1: ResourceColor #007DFF; State isEditMode: boolean false; // 是否为编辑模式 ​ aboutToAppear(): void { const params: Course router.getParams() as Course; if (params params.index 0) { this.course.index params.index; if (params.courseName ! ) { this.course params; this.isEditMode true; } } } ​ build() { Column() { // 导航栏 Row() { Text(取消) .fontColor(#0075E6) .fontSize(16) .onClick(() { router.back() AppStorage.Set(showDetails, false) }) Text(this.isEditMode ? 编辑课程 : 新建课程) .fontSize(18) .fontWeight(FontWeight.Bold) .alignSelf(ItemAlign.Center) Text(完成) .fontColor(#0075E6) .fontSize(16) .onClick(() { AppStorage.SetOrCreate(updatedCourse, this.course); AppStorage.Set(showDetails, false) router.back(); }) } .width(100%) .height(60) .padding(10) .backgroundColor(Color.White) .justifyContent(FlexAlign.SpaceBetween) .alignItems(VerticalAlign.Center) ​ // 内容区域 Scroll() { Column() { // 课程名输入 Row() { Text(课程名) .fontSize(20) .fontWeight(FontWeight.Medium) .margin({ right: 10 }) TextInput({ placeholder:必填, text:this.course.courseName }) .layoutWeight(1) .backgroundColor(Color.White) .onChange((value: string) { this.course.courseName value; }) } .height(60) .margin({ top: 20, bottom: 15 }) .borderRadius(10) .backgroundColor(Color.White) .padding(10) .width(90%) ​ // 教室输入 Row() { Text(教室) .fontSize(20) .fontWeight(FontWeight.Medium) .margin({ right: 10 }) TextInput({ placeholder: 非必填, text:this.course.classroom }) .layoutWeight(1) .backgroundColor(Color.White) .onChange((value: string) { this.course.classroom value; }) } .width(90%) .height(60) .margin({ bottom: 15 }) .borderRadius(10) .backgroundColor(Color.White) .padding(10) ​ // 备注输入 Row() { Text(备注如老师) .fontSize(20) .fontWeight(FontWeight.Medium) .margin({ right: 10 }) TextInput({ placeholder: 非必填, text:this.course.remark }) .layoutWeight(1) .backgroundColor(Color.White) .onChange((value: string) { this.course.remark value; }) } .width(90%) .height(60) .margin({ bottom: 15 }) .borderRadius(10) .backgroundColor(Color.White) .padding(10) ​ // 时段选择简化版后续可扩展 Column() { Row() { Text(时段) .fontSize(20) .fontWeight(FontWeight.Medium) .margin({ right: 10 }) Blank() Row() { Button(){ Text(-) .fontSize(30) .fontColor(Color.Black) } .width(40) .height(40) .type(ButtonType.Circle) .backgroundColor(#F3F3F3) .onClick(() { if (this.timeSlotCount 1) { this.timeSlotCount--; } }) Text(this.timeSlotCount.toString()) .textAlign(TextAlign.Center) .fontSize(16) .width(40) .height(40) ​ Button(){ Text() .fontSize(30) .fontColor(Color.Black) } .width(40) .height(40) .type(ButtonType.Circle) .backgroundColor(#F3F3F3) .onClick(() { if (this.timeSlotCount 3) { this.timeSlotCount; } }) } .margin(10) .alignItems(VerticalAlign.Center) .justifyContent(FlexAlign.SpaceBetween) } .width(100%) .height(60) } .backgroundColor(Color.White) .borderRadius(10) .width(90%) .padding({ left: 10, right: 10 }) ​ // 上课周数 Column() { Row() { Text(上课周数) .fontSize(20) .fontWeight(FontWeight.Medium) Blank() Text(this.weekRange) .fontSize(14) .fontColor(Color.Gray) .margin(5) Image($r(app.media.chevron_right)) .width(20) .height(20) } .width(100%) .height(60) .alignItems(VerticalAlign.Center) ​ // 课程背景色 Row() { Text(课程背景色) .fontSize(20) .fontWeight(FontWeight.Medium) Blank() Circle() .width(20) .height(20) .fill(this.backgroundColor1) .margin(5) Image($r(app.media.chevron_right)) .width(20) .height(20) } .width(100%) .height(60) .alignItems(VerticalAlign.Center) } .width(90%) .margin(20) .borderRadius(10) .backgroundColor(Color.White) .padding({ left: 10, right: 10 }) } .width(100%) } } .width(100%) .height(100%) .backgroundColor(#F2F2F4) } }4.3.1页面核心功能这个文件叫AddCoursePage.ets它是课程表 App 中的“添加/编辑课程”页面。就像在手机上点一个空课格子后弹出来的那个填写课程信息的界面可以输入课程名必填可以输入教室、老师备注选填可以设置这门课占几节课1节、2节或3节还能选上课周数、课程颜色颜色和周数目前只是展示还没做选择功能支持两种模式新建课程从空格子进来编辑课程从已有课程点进来4.3.2 核心功能解析1. 接收信息const params: Course router.getParams() as Course;当你从主页面点击某个课程格子时App 会把那个格子的“位置编号”比如第3节周三和课程内容一起传过来。这个页面一打开就会先看看是否有数据传入然后进行下一步操作。效果如果传过来的是空课程→ 显示“新建课程”如果传过来的是已有课程比如“高数”→ 自动填好信息标题变成“编辑课程”2. 顶部导航栏取消 / 标题 / 完成Row() { Text(取消)...onClick(() router.back()) Text(this.isEditMode ? 编辑课程 : 新建课程) Text(完成)...onClick(() { 保存并返回 }) }点取消直接返回上一页不保存点完成把填好的课程信息存到全局共享数据AppStorage然后返回关键代码AppStorage.SetOrCreate(updatedCourse, this.course);这样主页面就能知道有课程信息更新然后自动刷新显示。3. 输入框填课程信息用了 HarmonyOS 的TextInput组件输入项是否必填如何工作课程名必填用户一打字this.course.courseName value立刻记住教室选填同理自动更新到this.course.classroom备注选填比如填“张老师”存到remark字段所有信息都存在this.course“课程对象”里。4. “时段数量”调节器 / - 按钮this.timeSlotCount // 默认是1节显示一个数字1、2 或 3左边是减号按钮不能少于1右边是加号按钮最多3节虽然现在只是改数字但未来可以用来控制“这门课横跨几行”比如高数上2节就占第1-2行。5. “上课周数”和“背景色”预留功能private weekRange: string 第9-18周; private backgroundColor1: ResourceColor #007DFF;目前只是静态显示比如“第9-18周”、“蓝色小圆点”颜色数组colors准备了8种好看的颜色方便以后做“课程分类着色”。4.4 配置页面路由编辑entry/src/main/resources/base/profile/main_pages.json{ src: [ pages/Index, pages/AddCoursePage ] }4.5添加资源文件4.5.1 添加图标资源SVG图标下载地址阿里巴巴矢量图标库在entry/src/main/resources/base/media/目录下添加以下SVG图标chevron_left.svg- 左箭头chevron_right.svg- 右箭头chevron_down.svg- 下箭头x_close.svg- 关闭图标4.5.2 字符串资源编辑entry/src/main/resources/base/element/string.json{ string: [ { name: app_name, value: 课程表 }, { name: module_desc, value: 课程表模块 }, { name: EntryAbility_desc, value: 课程表应用入口 }, { name: EntryAbility_label, value: 课程表 } ] }五、核心知识点汇总5.1 状态管理State 装饰器用于组件内部状态管理状态变化会触发UI更新State currentWeekday: number 1;StorageLink 装饰器连接全局AppStorage实现跨组件状态共享StorageLink(name) name: string 课程表1;AppStorage全局状态存储类似React的ContextAppStorage.Set(name, 新课程表名); AppStorage.Get(name);5.2 组件通信父子组件传参Prop// 父组件 GridItemCase({ course: item }) // 子组件 Prop course: Course;页面跳转传参// 跳转 router.pushUrl({ url: pages/AddCoursePage, params: this.course }) // 接收参数 const params: Course router.getParams() as Course;5.3 布局组件Grid网格布局用于创建课程表网格Grid() { // 内容 } .columnsTemplate(13fr 18fr 18fr 18fr 18fr 18fr) // 6列比例布局Stack层叠布局用于叠加详情弹窗Stack() { Column() { /* 主内容 */ } if (this.showDetails) { Details() /* 详情弹窗 */ } }5.4 生命周期aboutToAppear(): 组件即将出现时调用onPageShow(): 页面显示时调用onPageHide(): 页面隐藏时调用六、运行与测试6.1 运行应用连接设备或启动模拟器点击Run按钮绿色三角形或按ShiftF10等待编译完成应用自动安装运行6.2 测试功能查看课程表启动后应看到空白课程表添加课程点击空白单元格出现号再次点击进入添加页面填写课程信息点击完成查看详情点击已有课程查看详情弹窗编辑课程在详情页点击编辑修改信息七、常见问题解决7.1 编译错误问题找不到资源文件$r(app.media.xxx)解决检查资源文件路径和名称是否正确7.2 页面跳转失败问题router.pushUrl报错解决检查main_pages.json中是否注册了页面7.3 状态更新不生效问题修改数据后UI不更新解决确保使用了State或StorageLink装饰器7.4 课程数据丢失问题应用重启后课程消失解决当前使用内存存储需要添加持久化存储后续可扩展八、学习资源ArkTS开发指南DevEco Studio使用指南阿里巴巴矢量图标库

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询