|
|
@@ -1,6 +1,7 @@
|
|
|
-import { YTAvoid } from "basic"
|
|
|
-import { BasicDataSource } from "../models/BasicDataSource"
|
|
|
-import { DateInfo } from "../models/DateInfo"
|
|
|
+import { YTAvoid } from 'basic'
|
|
|
+import { DateInfo } from '../models/DateInfo'
|
|
|
+import { RecodeViewModel } from '../viewModels/RecodeViewModel'
|
|
|
+import { DiaryDatePicker } from '../components/DiaryDatePicker'
|
|
|
|
|
|
/**
|
|
|
* 记录页面
|
|
|
@@ -9,24 +10,15 @@ import { DateInfo } from "../models/DateInfo"
|
|
|
export struct RecodView {
|
|
|
@StorageProp(YTAvoid.SAFE_BOTTOM_KEY) bottom: number = 0
|
|
|
@StorageProp(YTAvoid.SAFE_TOP_KEY) safeTop: number = 0
|
|
|
-
|
|
|
- @State weekLoop: BasicDataSource<DateInfo> = new BasicDataSource()
|
|
|
-
|
|
|
- private swiperController: SwiperController = new SwiperController();
|
|
|
-
|
|
|
- private weeks: ResourceStr[] = [
|
|
|
- $r('app.string.hm_calendar_sunday'),
|
|
|
- $r('app.string.hm_calendar_monday'),
|
|
|
- $r('app.string.hm_calendar_tuesday'),
|
|
|
- $r('app.string.hm_calendar_wednesday'),
|
|
|
- $r('app.string.hm_calendar_thursday'),
|
|
|
- $r('app.string.hm_calendar_friday'),
|
|
|
- $r('app.string.hm_calendar_saturday'),
|
|
|
- ]
|
|
|
-
|
|
|
+ // ViewModel
|
|
|
+ @State Vm: RecodeViewModel = new RecodeViewModel()
|
|
|
|
|
|
aboutToAppear(): void {
|
|
|
- // this.swiperController.changeIndex(19)
|
|
|
+ this.Vm.selectedDateChange = this.selectDateChange
|
|
|
+ }
|
|
|
+
|
|
|
+ selectDateChange = (index: number) => {
|
|
|
+ this.Vm.selectedDate = index
|
|
|
}
|
|
|
|
|
|
build() {
|
|
|
@@ -38,38 +30,82 @@ export struct RecodView {
|
|
|
Image($r("app.media.calendar"))
|
|
|
.width(30)
|
|
|
.aspectRatio(1)
|
|
|
+ .onClick(() => {
|
|
|
+ animateToImmediately({
|
|
|
+ duration: 200
|
|
|
+ }, () => {
|
|
|
+ this.Vm.showTimePicker = !this.Vm.showTimePicker;
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
.width("100%")
|
|
|
.justifyContent(FlexAlign.SpaceBetween)
|
|
|
|
|
|
- /**
|
|
|
- * 日历组件
|
|
|
- * 1. 懒加载用上
|
|
|
- * 2. 纵向list, 最右边(今天)作为列表头
|
|
|
- * 3. 一次加载一个月数据(待定), 是否可以添加触底刷新机制(到已加载的第一天触发)
|
|
|
- *
|
|
|
- * question
|
|
|
- * 1. 使用日历选择器选择的时间跨度 大于 30 天时,怎么加载?
|
|
|
- *
|
|
|
- */
|
|
|
- Column(){
|
|
|
- Swiper(this.swiperController){
|
|
|
- ForEach(new Array(20).fill(0), (item: number, index: number) => {
|
|
|
- Column() {
|
|
|
- Text("星期")
|
|
|
- Text("日期" + index.toString())
|
|
|
+ Stack({alignContent: Alignment.TopEnd}){
|
|
|
+ /**
|
|
|
+ * 日历组件
|
|
|
+ * 1. 懒加载用上
|
|
|
+ * 2. 纵向 swiper, 最右边(今天)作为头
|
|
|
+ *
|
|
|
+ * 加载方式
|
|
|
+ * 1. 通过监听 swiper index 的变化来触发相应逻辑
|
|
|
+ *
|
|
|
+ * * 未通过日历进行跳转日期
|
|
|
+ * 1. 向左滑动时, 如果日期剩余 < 10,则加载下一周 ( index == list.length - 10 )
|
|
|
+ *
|
|
|
+ * * 通过日历进行跳转日期
|
|
|
+ * * *
|
|
|
+ */
|
|
|
+
|
|
|
+ // 小 《 《 《 大
|
|
|
+ Column(){
|
|
|
+ Swiper(this.Vm.swiperController){
|
|
|
+ LazyForEach(this.Vm.weekLoop, (item: DateInfo, index: number) => {
|
|
|
+ Column() {
|
|
|
+ Text(item.week)
|
|
|
+ Text(`${item.month}-${item.day}`)
|
|
|
+ }
|
|
|
+ .border({
|
|
|
+ width: this.Vm.selectedDate === index ? 1 : 0
|
|
|
+ })
|
|
|
+ .onClick(() => {
|
|
|
+ this.Vm.selectedDate = index
|
|
|
+ })
|
|
|
+ }, (item: DateInfo, index: number) => { return item.id.toString() })
|
|
|
+ }
|
|
|
+ .loop(false)
|
|
|
+ .displayCount(7)
|
|
|
+ .indicator(false)
|
|
|
+ .direction(Direction.Rtl)
|
|
|
+ .onChange((index: number) => {
|
|
|
+ this.Vm.swiperOnChange(index)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if(this.Vm.showTimePicker) {
|
|
|
+ DiaryDatePicker({
|
|
|
+ selectedDate: this.Vm.weekLoop.getData(this.Vm.swiperCurrentIndex).id,
|
|
|
+ selectDateBack: (date: Date) => {
|
|
|
+ this.Vm.showTimePicker = false
|
|
|
+ this.Vm.jumpToDate(date)
|
|
|
}
|
|
|
})
|
|
|
+ .width("80%")
|
|
|
}
|
|
|
- .loop(false)
|
|
|
- .displayCount(7)
|
|
|
- .direction(Direction.Rtl)
|
|
|
- .indicator(false)
|
|
|
}
|
|
|
+ .width("100%")
|
|
|
+ .layoutWeight(1)
|
|
|
|
|
|
+ Button("check")
|
|
|
+ .onClick(() => {
|
|
|
+ for (let index = 0; index < this.Vm.weekLoop.totalCount(); index++) {
|
|
|
+ console.log(`${ this.Vm.swiperCurrentIndex == index ? 'ToDay' : '' } ${this.Vm.weekLoop.getData(index).month} 月 ${this.Vm.weekLoop.getData(index).day} 日 `)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
.width("100%")
|
|
|
.height("100%")
|
|
|
.padding({ top: this.safeTop + 22, left: 16, right: 16 })
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|