• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {Log} from '@ohos/common'
17import ViewModel from '../../vm/dateTimeViewModel'
18import Constants from '../../common/constants'
19import deviceInfo from '@ohos.deviceInfo';
20import i18n from '@ohos.i18n';
21
22const DEVICETYPE = deviceInfo.deviceType;
23const DEFAULTLANG: string = "zh-Hans";
24const TAG = 'ScreenLock-DateTime';
25
26
27@Component
28export default struct DateTime {
29  @State mViewModel: ViewModel = new ViewModel()
30  @State isShowDate: boolean = true
31  @State isPhone: boolean = false
32  @State currentLanguage: string = DEFAULTLANG
33
34  aboutToAppear() {
35    Log.showInfo(TAG, `aboutToAppear`)
36    this.mViewModel.ViewModelInit()
37    this.currentLanguage = i18n.getSystemLanguage()
38    if (DEVICETYPE == 'phone') {
39      this.isPhone = true
40    }
41  }
42
43  aboutToDisappear() {
44    Log.showInfo(TAG, `aboutToDisappear`)
45    this.mViewModel.stopPolling()
46  }
47
48  build() {
49    Column() {
50      Text(this.mViewModel.timeVal)
51        .fontSize($r('app.float.time_fontsize'))
52        .fontColor($r('app.color.date_time_color'))
53        .margin({ top: $r('app.float.time_top_margin'), bottom: $r('app.float.time_bottom_margin') })
54        .fontWeight(300)
55        .fontFamily("Digit")
56      if (this.isShowDate) {
57        Row() {
58          if (this.isPhone) {
59            Text($r("app.string.mm_dd", this.mViewModel.dateVal.month, this.mViewModel.dateVal.day))
60              .fontSize($r('app.float.date_fontsize'))
61              .fontColor($r('app.color.date_time_color'))
62          } else {
63            Text($r('app.string.yyyy_mm_dd', this.mViewModel.dateVal.year, this.mViewModel.dateVal.month,
64              this.mViewModel.dateVal.day))
65              .fontSize($r('app.float.date_fontsize'))
66              .fontColor($r('app.color.date_time_color'))
67          }
68          Text(this.mViewModel.weekVal).fontSize($r('app.float.date_fontsize'))
69            .fontColor($r('app.color.date_time_color'))
70        }.height($r('app.float.date_week_area_height'))
71
72        Row() {
73          Text(this.mViewModel.calendarVal.calendarYear + '年' + this.mViewModel.calendarVal.calendarMonth + '月' + this.mViewModel.calendarVal.calendarDay)
74            .height($r("app.float.date_lunar_calendar_height"))
75            .fontColor(Color.White)
76            .fontSize($r("app.float.date_lunar_calendar_fontSize"))
77            .margin({ top: 6 })
78        }
79        .visibility(this.currentLanguage === DEFAULTLANG ? Visibility.Visible : Visibility.None)
80      }
81    }
82    .width(Constants.FULL_CONTAINER_WIDTH)
83  }
84}