• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 systemParameter from '@ohos.systemParameterEnhance';
17import { ColumnOperation } from '../components/ColumnOperation';
18import { BusinessError } from '@ohos.base';
19
20@Preview
21@Component
22export struct SystemParameter {
23  @State result: string = '';
24
25  build() {
26    Scroll() {
27      Column() {
28        Row() {
29          Text(this.result)
30            .fontWeight(FontWeight.Medium)
31            .fontSize(20)
32        }
33        .alignItems(VerticalAlign.Top)
34        .width('100%')
35        .backgroundColor($r("app.color.white"))
36        .height(160)
37        .padding(16)
38        .borderRadius(20)
39        .margin({ top: 16 })
40        ColumnOperation({ operationRes: $r('app.strarray.system_parameter'), doOperation: this.doOperation })
41      }
42      .width('100%')
43      .padding(4)
44    }
45    .scrollBar(BarState.Off)
46  }
47
48  doOperation = async (index: number) => {
49    switch (index) {
50      case 0:
51        try {
52          let that = this;
53          systemParameter.set("const.parameter.test_key", "test", (err: BusinessError) => {
54            if (err == undefined) {
55              that.result = `set const.parameter.test_key success`;
56            } else {
57              that.result = `set const.parameter.test_key fail:${JSON.stringify(err)}`;
58            }
59          })
60        } catch (err) {
61          this.result = `set const.parameter.test_key err:${JSON.stringify(err)}`;
62        }
63        break
64      case 1:
65        try {
66          let that = this;
67          systemParameter.get("const.parameter.test_key", (err: BusinessError, data: string) => {
68            if (err == undefined) {
69              that.result = `get const.parameter.test_key success:${data}`;
70            } else {
71              that.result = `get const.parameter.test_key fail:${JSON.stringify(err)}`;
72            }
73          })
74        } catch (err) {
75          this.result = `get const.parameter.test_key err:${JSON.stringify(err)}`;
76        }
77        break
78      default:
79        break
80    }
81  }
82}