• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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 */
15import { ThirdTitleBar, MathString, Logger } from '@ohos/library'
16import { TextAreaShow } from '../Component/TextAreaShow'
17import { TextShow } from '../Component/TextShow'
18import { AlertShow } from '../Component/AlertShow'
19
20const TAG: string = 'LocalLibrary'
21
22@Entry
23@Component
24struct LocalLibrary {
25  @State firstString: string = ''
26  @State secondString: string = ''
27  @State resultString: string = ''
28  private mathString: MathString = new MathString()
29  private logger: Logger = new Logger('[npm]')
30  private pinDialogController: CustomDialogController | undefined = undefined
31
32  build() {
33    Column() {
34      ThirdTitleBar()
35      Scroll() {
36        Column() {
37          TextShow({ text: $r('app.string.third_string_splicing'), fontSize: 25 })
38          TextShow({ text: $r('app.string.input_first_string'), fontSize: 20 })
39          TextAreaShow({ placeholder: '', value: $firstString, inputNumber: 3 })
40          TextShow({ text: $r('app.string.input_second_string'), fontSize: 20 })
41          TextAreaShow({ placeholder: '', value: $secondString, inputNumber: 4 })
42          Button('确定')
43            .fontSize(20)
44            .width(100)
45            .height(50)
46            .type(ButtonType.Normal)
47            .margin({ top: 20 })
48            .key('confirmBtn')
49            .onClick(() => {
50              if (this.firstString === '') {
51                this.pinDialogController = new CustomDialogController({
52                  builder: AlertShow({ text: $r('app.string.input_first_string') }),
53                })
54                this.pinDialogController.open()
55                return
56              }
57              if (this.secondString === '') {
58                this.pinDialogController = new CustomDialogController({
59                  builder: AlertShow({ text: $r('app.string.input_second_string') }),
60                })
61                this.pinDialogController.open()
62                return
63              }
64              this.resultString = this.mathString.add(this.firstString, this.secondString)
65              this.logger.info(TAG, `onClick resultString = ${this.resultString}`)
66            })
67          if (this.firstString != '' && this.secondString != '') {
68            Text(`拼接后字符串:${this.resultString}`)
69              .fontSize(20)
70              .alignSelf(ItemAlign.Start)
71              .margin({ top: '3%', left: '5%' })
72          }
73        }.width('100%')
74      }
75      .constraintSize({ maxHeight: '85%' })
76    }
77  }
78}