• 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 AboutDeviceModel from '../model/aboutDeviceImpl/AboutDeviceModel';
17import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
18import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
19import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent';
20import {
21  SubEntryComponentWithEndText
22} from '../../../../../../common/component/src/main/ets/default/subEntryComponent';
23import deviceInfo from '@ohos.deviceInfo';
24import { BaseData } from '../../../../../../common/utils/src/main/ets/default/bean/BaseData';
25
26/**
27 * about phone
28 */
29@Entry
30@Component
31struct AboutDevice {
32  @StorageLink("systemName") systemName: string = AboutDeviceModel.getSystemName();
33  private aboutDeviceList: BaseData[] = [];
34
35  build() {
36    Column() {
37      GridContainer({ gutter: ConfigData.GRID_CONTAINER_GUTTER_24, margin: ConfigData.GRID_CONTAINER_MARGIN_24 }) {
38        Column() {
39          HeadComponent({ headName: $r('app.string.aboutTab'), isActive: true })
40
41          SubEntryComponentWithEndText({
42            targetPage: "pages/deviceName",
43            title: $r("app.string.deviceName"),
44            endText: $systemName
45          })
46            .width(ConfigData.WH_100_100)
47            .margin({ bottom: $r("app.float.distance_12"), top: $r("app.float.distance_8") })
48
49          List() {
50            ForEach(this.aboutDeviceList, (item: BaseData) => {
51              ListItem() {
52                Flex({ justifyContent: FlexAlign.SpaceBetween }) {
53                  Text(item.settingTitle)
54                    .fontSize($r("app.float.font_16"))
55                    .lineHeight($r("app.float.wh_value_22"))
56                    .fontWeight(FontWeight.Medium)
57                    .fontColor($r('sys.color.ohos_id_color_text_primary'))
58                    .padding({ top: $r('app.float.distance_12'), bottom: $r('app.float.distance_12') })
59                    .textAlign(TextAlign.Start);
60
61                  Text(item.settingValue)
62                    .fontSize($r("app.float.font_16"))
63                    .lineHeight($r("app.float.wh_value_22"))
64                    .fontWeight(FontWeight.Regular)
65                    .fontColor($r('sys.color.ohos_id_color_text_secondary'))
66                    .padding({ top: $r('app.float.distance_12'), bottom: $r('app.float.distance_12') })
67                    .textAlign(TextAlign.End);
68                }
69                .width(ConfigData.WH_100_100)
70              }
71            })
72          }
73          .divider({ strokeWidth: $r('app.float.divider_wh'), color: $r('sys.color.ohos_id_color_list_separator') })
74          .padding({
75            left: $r('sys.float.ohos_id_card_margin_start'),
76            right: $r('sys.float.ohos_id_card_margin_start'),
77            top: $r('app.float.distance_4'),
78            bottom: $r('app.float.distance_4')
79          })
80          .borderRadius($r('app.float.distance_24'))
81          .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary"))
82        }
83        .useSizeType({
84          sm: { span: 4, offset: 0 },
85          md: { span: 6, offset: 1 },
86          lg: { span: 8, offset: 2 }
87        })
88      }
89      .width(ConfigData.WH_100_100)
90      .height(ConfigData.WH_100_100)
91    }
92    .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
93    .width(ConfigData.WH_100_100)
94    .height(ConfigData.WH_100_100)
95  }
96
97  aboutToAppear(): void {
98    LogUtil.info(ConfigData.TAG + 'settings get device info come in');
99    this.aboutDeviceList = AboutDeviceModel.getAboutDeviceInfoListener();
100    this.getDeviceInfo();
101    LogUtil.info(ConfigData.TAG + 'settings get device info' +
102    JSON.stringify(AboutDeviceModel.setOnAboutDeviceListener()));
103
104    LogUtil.info(ConfigData.TAG + 'settings get device info end in');
105  }
106
107  onPageShow() {
108    AppStorage.SetOrCreate("systemName", AboutDeviceModel.getSystemName())
109  }
110
111  private getDeviceInfo(): void {
112    for (let item of this.aboutDeviceList) {
113      let value = item.settingAlias;
114
115      if ('model' === value) {
116        item.settingValue = deviceInfo.productModel;
117        item.settingTitle = $r('app.string.model');
118      }
119      ;
120
121      if ('companyInfo' === value) {
122        item.settingValue = deviceInfo.manufacture;
123        item.settingTitle = $r('app.string.companyInfo');
124      }
125      ;
126
127      if ('deviceId' === value) {
128        item.settingValue = deviceInfo.serial;
129        item.settingTitle = $r('app.string.deviceId');
130      }
131      ;
132
133      if ('softwareVersion' === value) {
134        item.settingValue = deviceInfo.displayVersion;
135        item.settingTitle = $r('app.string.softwareVersion');
136      }
137      ;
138    }
139  }
140}
141