已开启
课程表-集美大学-赖汶俊-罗方芳 #418
课程表-集美大学-赖汶俊-罗方芳 #418
已开启
2401_87213910创建于 6月30日
5 个文件变更+228-14
@@ -11,13 +11,15 @@ import cj_res_entry.app
11 11 
12@Component12@Component
13public class BackRow {13public class BackRow {
14+ @Prop var currentWeek: Int64 = 1
15+ 
14 public func build() {16 public func build() {
15 // 返回按钮+第几周 组件17 // 返回按钮+第几周 组件
16 Row {18 Row {
17 Image(@r(app.media.back))19 Image(@r(app.media.back))
18 .width(42)20 .width(42)
19 .margin(right: 8)21 .margin(right: 8)
20- Text('第8周')22+ Text('第${currentWeek}周')
21 .fontSize(22)23 .fontSize(22)
22 .fontWeight(FontWeight.W800)24 .fontWeight(FontWeight.W800)
23 .lineHeight(27)25 .lineHeight(27)
@@ -13,7 +13,7 @@ import ohos_app_cangjie_entry.dataModel.CourseItem
13import ohos_app_cangjie_entry.dataModel.CourseEntity13import ohos_app_cangjie_entry.dataModel.CourseEntity
14 14 
15@Builder15@Builder
16-public func courseBuilder(msg: CJResource, curHeight: Int64, curWidth: Int64, curBackgroundColor: Color, curFontColor: Color) {16+public func courseBuilder(msg: CJResource, curHeight: Int64, curWidth: Int64, curBackgroundColor: Color, curFontColor: Color, isCurrentDay: Bool) {
17 Row {17 Row {
18 Column {18 Column {
19 Stack {19 Stack {
@@ -38,7 +38,9 @@ public func courseBuilder(msg: CJResource, curHeight: Int64, curWidth: Int64, cu
38 .justifyContent(FlexAlign.Center)38 .justifyContent(FlexAlign.Center)
39 .width(curWidth)39 .width(curWidth)
40 .height(curHeight)40 .height(curHeight)
41- .backgroundColor(Color.WHITE)41+ .backgroundColor(isCurrentDay ? Color(0x0A007DFF) : Color.WHITE)
42+ .border(isCurrentDay ? Border(width: 0.5, color: Color(0x1A007DFF)) : Border(width: 0.5, color: Color(0xFFE8E8E8)))
43+ .borderRadius(4)
42 }44 }
43}45}
44 46 
@@ -49,6 +51,7 @@ public class Course {
49 @Prop var classScroller: Scroller51 @Prop var classScroller: Scroller
50 @Prop var timeScroller: Scroller52 @Prop var timeScroller: Scroller
51 @Prop var weekdaysScroller: Scroller53 @Prop var weekdaysScroller: Scroller
54+ @Prop var currentWeekday: Int64 = 1
52 let data = CourseEntity().data55 let data = CourseEntity().data
53 let arr = CourseEntity().arr56 let arr = CourseEntity().arr
54 57 
@@ -60,8 +63,8 @@ public class Course {
60 Column {63 Column {
61 ForEach(arr, { index: Int64, idx: Int64 =>64 ForEach(arr, { index: Int64, idx: Int64 =>
62 Row {65 Row {
63- ForEach(data[arr[index]], { item: CourseItem, idx: Int64 =>66+ ForEach(data[arr[index]], { item: CourseItem, colIdx: Int64 =>
64- courseBuilder(item.name, 100, 120, item.backColor, Color.BLACK)67+ courseBuilder(item.name, 100, 120, item.backColor, Color.BLACK, colIdx + 1 == currentWeekday)
65 })68 })
66 }69 }
67 })70 })
@@ -31,6 +31,7 @@ public class SectionRow {
31 @Prop var weekdaysScroller: Scroller31 @Prop var weekdaysScroller: Scroller
32 @Prop var classificationNames: Array<String>32 @Prop var classificationNames: Array<String>
33 @Prop var horizontalScroller: Scroller33 @Prop var horizontalScroller: Scroller
34+ @Prop var currentWeekday: Int64 = 1
34 35 
35 public func build() {36 public func build() {
36 Row {37 Row {
@@ -45,14 +46,14 @@ public class SectionRow {
45 Column {46 Column {
46 Scroll (this.weekdaysScroller) {47 Scroll (this.weekdaysScroller) {
47 Row {48 Row {
48- ForEach(this.classificationNames, { item: String, _: Int64 =>49+ ForEach(this.classificationNames, { item: String, index: Int64 =>
49 Column {50 Column {
50 Row {51 Row {
51 Text(item)52 Text(item)
52 .fontSize(14)53 .fontSize(14)
53 .fontWeight(FontWeight.W400)54 .fontWeight(FontWeight.W400)
54 .textAlign(TextAlign.Center)55 .textAlign(TextAlign.Center)
55- .fontColor(Color.BLACK)56+ .fontColor(index + 1 == currentWeekday ? Color(0xFF007DFF) : Color.BLACK)
56 .width(100.percent)57 .width(100.percent)
57 }58 }
58 }59 }
@@ -60,7 +61,7 @@ public class SectionRow {
60 .justifyContent(FlexAlign.Center)61 .justifyContent(FlexAlign.Center)
61 .width(120)62 .width(120)
62 .height(42)63 .height(42)
63- .backgroundColor(Color.WHITE)64+ .backgroundColor(index + 1 == currentWeekday ? Color(0x14007DFF) : Color.WHITE)
64 })65 })
65 }66 }
66 }67 }
@@ -9,6 +9,8 @@ import ohos.state_manage.*
9import ohos.state_macro_manage.*9import ohos.state_macro_manage.*
10import cj_res_entry.*10import cj_res_entry.*
11import std.collection.*11import std.collection.*
12+import std.time.*
13+import std.math.*
12 14 
13let COURSE_MODEL = ArrayList<CourseItem>([15let COURSE_MODEL = ArrayList<CourseItem>([
14 CourseItem(@r(app.string.empty), Color.WHITE),16 CourseItem(@r(app.string.empty), Color.WHITE),
@@ -26,6 +28,11 @@ let COURSE_MODEL = ArrayList<CourseItem>([
26 CourseItem(@r(app.string.course9), Color(0xECDC96))28 CourseItem(@r(app.string.course9), Color(0xECDC96))
27])29])
28 30 
31+// 2026年春季学期:2026年2月23日(周一)开学
32+let SEMESTER_START_YEAR = 2026
33+let SEMESTER_START_MONTH = 2
34+let SEMESTER_START_DAY = 23
35+ 
29func createCourseTable(indexMatrix: Array<Array<Int64>>) {36func createCourseTable(indexMatrix: Array<Array<Int64>>) {
30 var courseTable = ArrayList<ArrayList<CourseItem>>()37 var courseTable = ArrayList<ArrayList<CourseItem>>()
31 for (rowIndices in indexMatrix) {38 for (rowIndices in indexMatrix) {
@@ -38,6 +45,23 @@ func createCourseTable(indexMatrix: Array<Array<Int64>>) {
38 return courseTable45 return courseTable
39}46}
40 47 
48+// 计算当前是第几教学周
49+func calculateCurrentWeek(): Int64 {
50+ let now = DateTime.now()
51+ let semesterStart = DateTime(SEMESTER_START_YEAR, SEMESTER_START_MONTH, SEMESTER_START_DAY, 0, 0, 0)
52+ let diff = now.ticks() - semesterStart.ticks()
53+ let daysPerTick = 86400000000000
54+ let diffDays = diff / daysPerTick
55+ let weekNum = diffDays / 7 + 1
56+ return max(1, weekNum)
57+}
58+ 
59+// 获取指定日期的星期几(调整dayOfWeek.value():1=周一...7=周日)
60+func getCurrentWeekday(): Int64 {
61+ let now = DateTime.now()
62+ return now.dayOfWeek.value()
63+}
64+ 
41public class CourseEntity {65public class CourseEntity {
42 let courseIndexMatrix = [66 let courseIndexMatrix = [
43 [0, 1, 4, 1, 10, 2, 0],67 [0, 1, 4, 1, 10, 2, 0],
@@ -51,4 +75,19 @@ public class CourseEntity {
51 ]75 ]
52 public let data = createCourseTable(courseIndexMatrix)76 public let data = createCourseTable(courseIndexMatrix)
53 public let arr = ArrayList<Int64>([0, 1, 2, 3, 4, 5, 6, 7])77 public let arr = ArrayList<Int64>([0, 1, 2, 3, 4, 5, 6, 7])
78+ 
79+ // 获取指定星期几的所有课程(dayIndex: 0=周一...6=周日)
80+ public static func getCoursesByDay(dayIndex: Int64): ArrayList<CourseItem> {
81+ let entity = CourseEntity()
82+ var result = ArrayList<CourseItem>()
83+ for (i in entity.arr) {
84+ if (i < entity.data.size) {
85+ let row = entity.data[i]
86+ if (dayIndex < row.size) {
87+ result.append(row[dayIndex])
88+ }
89+ }
90+ }
91+ return result
92+ }
54}93}
@@ -27,6 +27,36 @@ extend Column {
27 }27 }
28}28}
29 29 
30+extend Text {
31+ func homeTitleStyle() {
32+ this.fontSize(24)
33+ .fontWeight(FontWeight.W800)
34+ .fontColor(Color.BLACK)
35+ }
36+ 
37+ func homeSubtitleStyle() {
38+ this.fontSize(14)
39+ .fontWeight(FontWeight.W400)
40+ .fontColor(Color(0xFF999999))
41+ }
42+ 
43+ func courseCardTitle() {
44+ this.fontSize(15)
45+ .fontWeight(FontWeight.W600)
46+ .fontColor(Color.BLACK)
47+ .maxLines(1)
48+ .textOverflow(overflow: TextOverflow.Ellipsis)
49+ }
50+ 
51+ func courseCardDesc() {
52+ this.fontSize(12)
53+ .fontWeight(FontWeight.W400)
54+ .fontColor(Color(0xFF666666))
55+ .maxLines(2)
56+ .textOverflow(overflow: TextOverflow.Ellipsis)
57+ }
58+}
59+ 
30@Entry60@Entry
31@Component61@Component
32class EntryView {62class EntryView {
@@ -59,33 +89,173 @@ class EntryView {
59 @State var verticalScroller: Scroller = Scroller()89 @State var verticalScroller: Scroller = Scroller()
60 @State var horizontalScroller: Scroller = Scroller()90 @State var horizontalScroller: Scroller = Scroller()
61 91 
92+ // 当前周数和星期
93+ @State var currentWeek: Int64 = calculateCurrentWeek()
94+ @State var currentWeekday: Int64 = getCurrentWeekday()
95+ @State var todayCourses: ArrayList<CourseItem> = CourseEntity.getCoursesByDay(getCurrentWeekday() - 1)
96+ 
97+ // 星期名称映射
98+ let weekdayNames = ArrayList<String>(["一", "二", "三", "四", "五", "六", "日"])
99+ 
62 func build() {100 func build() {
63 Column {101 Column {
64 Tabs(BarPosition.End, this.controller, this.currentIndex) {102 Tabs(BarPosition.End, this.controller, this.currentIndex) {
103+ // ========== 主页 Tab ==========
65 TabContent {104 TabContent {
66- Column().tabColStyle(topRectHeight)105+ Column {
106+ // 顶部欢迎区域
107+ Row {
108+ Column {
109+ Text('课程表')
110+ .homeTitleStyle()
111+ .margin(bottom: 4)
112+ Text('第${currentWeek}周 · 星期${weekdayNames[currentWeekday - 1]}')
113+ .homeSubtitleStyle()
114+ }
115+ .alignItems(HorizontalAlign.Start)
116+ }
117+ .width(100.percent)
118+ .padding(left: 20, right: 20, top: 12, bottom: 8)
119+ .backgroundColor(Color.WHITE)
120+ 
121+ // 分隔线
122+ Divider()
123+ .width(100.percent)
124+ .height(1)
125+ .color(Color(0xFFF0F0F0))
126+ 
127+ // 今日课程标题
128+ Row {
129+ Text('今日课程')
130+ .fontSize(18)
131+ .fontWeight(FontWeight.W700)
132+ .fontColor(Color.BLACK)
133+ }
134+ .width(100.percent)
135+ .padding(left: 20, top: 16, bottom: 8)
136+ 
137+ // 课程列表
138+ Column {
139+ let courseList = todayCourses
140+ if (courseList.size == 0) {
141+ Column {
142+ Text('今日无课程安排~')
143+ .fontSize(14)
144+ .fontColor(Color(0xFFBBBBBB))
145+ .textAlign(TextAlign.Center)
146+ .width(100.percent)
147+ .margin(top: 40)
148+ }
149+ } else {
150+ ForEach(courseList, { item: CourseItem, index: Int64 =>
151+ // 对于值为 "-" 的空课程项进行过滤显示
152+ let hasContent = true
153+ Row {
154+ // 时间指示条
155+ Column {
156+ }
157+ .width(3)
158+ .height(60)
159+ .backgroundColor(item.backColor)
160+ .borderRadius(2)
161+ .margin(right: 12)
162+ 
163+ // 课程信息
164+ Column {
165+ Text(item.name)
166+ .courseCardTitle()
167+ Text('第${index + 1}节 · ${classTime[index]}')
168+ .courseCardDesc()
169+ .margin(top: 4)
170+ }
171+ .alignItems(HorizontalAlign.Start)
172+ }
173+ .width(100.percent)
174+ .padding(left: 20, right: 20, top: 8, bottom: 8)
175+ .backgroundColor(Color.WHITE)
176+ 
177+ // 卡片间分隔
178+ if (index < courseList.size - 1) {
179+ Divider()
180+ .width(90.percent)
181+ .height(0.5)
182+ .color(Color(0xFFF5F5F5))
183+ .margin(left: 20)
184+ }
185+ })
186+ }
187+ }
188+ .width(100.percent)
189+ .backgroundColor(Color.WHITE)
190+ .padding(bottom: 20)
191+ }
192+ .tabColStyle(topRectHeight)
193+ .backgroundColor(Color(0xFFF8F8F8))
194+ .width(100.percent)
67 }195 }
68 .tabBar(icon: "/resources/base/media/main_page.svg", text: "主页")196 .tabBar(icon: "/resources/base/media/main_page.svg", text: "主页")
69 197 
198+ // ========== 消息 Tab ==========
70 TabContent {199 TabContent {
71- Column().tabColStyle(topRectHeight)200+ Column {
201+ // 顶部
202+ Row {
203+ Text('消息')
204+ .fontSize(22)
205+ .fontWeight(FontWeight.W800)
206+ .fontColor(Color.BLACK)
207+ }
208+ .width(100.percent)
209+ .padding(left: 20, right: 20, top: 12, bottom: 8)
210+ .backgroundColor(Color.WHITE)
211+ 
212+ Divider()
213+ .width(100.percent)
214+ .height(1)
215+ .color(Color(0xFFF0F0F0))
216+ 
217+ // 空消息占位
218+ Column {
219+ Image("/resources/base/media/message.svg")
220+ .width(80)
221+ .height(80)
222+ .opacity(0.3)
223+ .margin(bottom: 16)
224+ Text('暂无消息')
225+ .fontSize(16)
226+ .fontWeight(FontWeight.W500)
227+ .fontColor(Color(0xFFBBBBBB))
228+ Text('课程通知和提醒将显示在这里')
229+ .fontSize(13)
230+ .fontColor(Color(0xFFCCCCCC))
231+ .margin(top: 6)
232+ }
233+ .width(100.percent)
234+ .alignItems(HorizontalAlign.Center)
235+ .justifyContent(FlexAlign.Center)
236+ .height(70.percent)
237+ }
238+ .tabColStyle(topRectHeight)
239+ .backgroundColor(Color(0xFFF8F8F8))
240+ .width(100.percent)
72 }241 }
73 .tabBar(icon: "/resources/base/media/message.svg", text: "消息")242 .tabBar(icon: "/resources/base/media/message.svg", text: "消息")
74 243 
244+ // ========== 课表 Tab ==========
75 TabContent {245 TabContent {
76 Column {246 Column {
77- BackRow()247+ BackRow(currentWeek: currentWeek)
78 // 节行以下248 // 节行以下
79 Column {249 Column {
80 // 节行250 // 节行
81- SectionRow(weekdaysScroller: weekdaysScroller, classificationNames: classificationNames, horizontalScroller: horizontalScroller)251+ SectionRow(weekdaysScroller: weekdaysScroller, classificationNames: classificationNames, horizontalScroller: horizontalScroller, currentWeekday: currentWeekday)
82 252 
83 // 第几节,时间,课程253 // 第几节,时间,课程
84 Row {254 Row {
85 // 第几节 + 上课时间255 // 第几节 + 上课时间
86 SectionTime(classIndex: classIndex, classScroller: classScroller, verticalScroller: verticalScroller, timeScroller: timeScroller, classTime: classTime)256 SectionTime(classIndex: classIndex, classScroller: classScroller, verticalScroller: verticalScroller, timeScroller: timeScroller, classTime: classTime)
87 // 课表257 // 课表
88- Course(horizontalScroller: horizontalScroller, verticalScroller: verticalScroller, classScroller: classScroller, timeScroller: timeScroller, weekdaysScroller: weekdaysScroller)258+ Course(horizontalScroller: horizontalScroller, verticalScroller: verticalScroller, classScroller: classScroller, timeScroller: timeScroller, weekdaysScroller: weekdaysScroller, currentWeekday: currentWeekday)
89 }259 }
90 .position(x: 0, y: 42)260 .position(x: 0, y: 42)
91 .width(100.percent)261 .width(100.percent)
@@ -94,7 +264,6 @@ class EntryView {
94 }264 }
95 .height(88.percent)265 .height(88.percent)
96 .width(100.percent)266 .width(100.percent)
97- // todo onAppear
98 .onAppear({ =>267 .onAppear({ =>
99 if(this.weekDay > 1) {268 if(this.weekDay > 1) {
100 this.weekdaysScroller.scrollTo(xOffset: (this.weekDay - 1) * 120, yOffset: 0)269 this.weekdaysScroller.scrollTo(xOffset: (this.weekDay - 1) * 120, yOffset: 0)