From e0c6aa46d02709c39842f54300c5384be98eef48 Mon Sep 17 00:00:00 2001 From: Yang Yongquan Date: Sun, 13 Sep 2026 16:44:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BA=86=E6=97=A5=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=EF=BC=8C=E6=84=9F=E8=A7=89=E8=B7=9F=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=E5=B7=AE=E4=B8=8D=E5=A4=9A=EF=BC=8C=E6=9C=89?= =?UTF-8?q?=E7=82=B9=E9=B8=A1=E8=82=8B=E3=80=82=E5=91=A8=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=92=8C=E6=9C=88=E8=A7=86=E5=9B=BE=E4=B8=80?= =?UTF-8?q?=E6=A0=B7=EF=BC=8C=E5=B7=A6=E5=8F=B3=E6=BB=91=E5=8A=A8=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=88=87=E6=8D=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 79 ++++++++++++------------------ 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 3baf575..58f1117 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -27,7 +27,7 @@ const WEEK_LABELS: string[] = ['一', '二', '三', '四', '五', '六', '日']; @Entry @Component struct Index { - @State mode: string = 'month'; // month | week | day | agenda + @State mode: string = 'month'; // month | week | agenda | todo @State displayYear: number = 2026; @State displayMonth: number = 0; // 0-11 @State selectedDate: number = 0; // 当天 0 点毫秒 @@ -393,8 +393,6 @@ struct Index { this.monthBody() } else if (this.mode === 'week') { this.weekBody() - } else if (this.mode === 'day') { - this.dayBody() } else if (this.mode === 'todo') { this.todoBody() } else { @@ -571,7 +569,6 @@ struct Index { Row({ space: 4 }) { this.modeTab('month', '月') this.modeTab('week', '周') - this.modeTab('day', '日') this.modeTab('agenda', '列表') this.modeTab('todo', '待办') Blank() @@ -762,28 +759,35 @@ struct Index { .layoutWeight(1) } + /** 周视图整周切换(左滑下一周、右滑上一周);跨月时自动重载数据 */ + private switchWeek(delta: number): void { + this.selectedDate += delta * 7 * 86400000; + const d = new Date(this.selectedDate); + if (d.getFullYear() !== this.displayYear || d.getMonth() !== this.displayMonth) { + this.displayYear = d.getFullYear(); + this.displayMonth = d.getMonth(); + this.reloadEvents(); + } + } + + /** 回到本周(含今天) */ + private goThisWeek(): void { + this.selectedDate = this.startOfDay(Date.now()); + } + @Builder weekBody() { Column() { Row({ space: 16 }) { - Text('‹') - .fontSize(22) - .fontColor($r('app.color.brand')) - .onClick(() => { - this.selectedDate -= 7 * 86400000; - }) Blank() Text('本周') .fontSize(15) .fontWeight(FontWeight.Bold) .fontColor($r('app.color.text_primary')) - Blank() - Text('›') - .fontSize(22) - .fontColor($r('app.color.brand')) .onClick(() => { - this.selectedDate += 7 * 86400000; + this.goThisWeek(); }) + Blank() } .width('100%') .padding({ left: 20, right: 20, top: 4, bottom: 4 }) @@ -804,41 +808,20 @@ struct Index { } .width('100%') .layoutWeight(1) + .gesture( + SwipeGesture({ direction: SwipeDirection.Horizontal }) + .onAction((event: GestureEvent) => { + // 左滑角度约 ±180(|angle|>90)→ 下一周;右滑约 0° → 上一周(与月视图 Swiper 方向一致) + if (Math.abs(event.angle) > 90) { + this.switchWeek(1); + } else { + this.switchWeek(-1); + } + }) + ) } - @Builder - dayBody() { - Column() { - Row({ space: 16 }) { - Text('‹') - .fontSize(22) - .fontColor($r('app.color.brand')) - .onClick(() => { - this.selectedDate -= 86400000; - }) - Blank() - Text(this.fmtDateCn(this.selectedDate)) - .fontSize(16) - .fontWeight(FontWeight.Bold) - .fontColor($r('app.color.text_primary')) - Blank() - Text('›') - .fontSize(22) - .fontColor($r('app.color.brand')) - .onClick(() => { - this.selectedDate += 86400000; - }) - } - .width('100%') - .padding({ left: 20, right: 20, top: 6, bottom: 6 }) - - this.eventList() - } - .width('100%') - .layoutWeight(1) - } - - /** 单日日程列表(月/周/日共用) */ + /** 单日日程列表(周视图使用) */ @Builder eventList() { Scroll() {