|
@@ -2,10 +2,12 @@ import TimeUtil from "../common/util/TimeUtil"
|
|
|
@Component
|
|
|
export struct TimeAndTitle {
|
|
|
@State currentTime: string = TimeUtil.getHourAndMinute(); // 响应式时间数据
|
|
|
+ @State timePeriod: string = TimeUtil.getTimePeriod();
|
|
|
+ @State dateAndWeek: string = TimeUtil.getDateAndWeek();
|
|
|
private timerID: number | undefined; // 定时器ID
|
|
|
aboutToAppear() {
|
|
|
this.timerID = setInterval(() => {
|
|
|
- this.currentTime = TimeUtil.getHourAndMinute(); // 每秒更新
|
|
|
+ this.updateAllTime(); // 每秒更新
|
|
|
}, 1000);
|
|
|
}
|
|
|
aboutToDisappear() {
|
|
@@ -13,19 +15,24 @@ export struct TimeAndTitle {
|
|
|
clearInterval(this.timerID);
|
|
|
}
|
|
|
}
|
|
|
+ private updateAllTime() {
|
|
|
+ this.currentTime = TimeUtil.getHourAndMinute();
|
|
|
+ this.timePeriod = TimeUtil.getTimePeriod();
|
|
|
+ this.dateAndWeek = TimeUtil.getDateAndWeek();
|
|
|
+ }
|
|
|
|
|
|
build() {
|
|
|
Row() {
|
|
|
Row(){
|
|
|
- Text(TimeUtil.getDateAndWeek())
|
|
|
+ Text(this.dateAndWeek)
|
|
|
.fontSize($r('app.float.fontSize_16'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
|
- Text(' ' + TimeUtil.getTimePeriod())
|
|
|
+ Text(' ' + this.timePeriod)
|
|
|
.fontSize($r('app.float.fontSize_16'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
|
- Text(' ' + TimeUtil.getHourAndMinute())
|
|
|
+ Text(' ' + this.currentTime)
|
|
|
.fontSize($r('app.float.fontSize_16'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|