• 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 router from '@ohos.router'
16import { create, all, MathJsStatic } from 'mathjs'
17import { TitleBar } from '../Component/TitleBar'
18import { TextShow } from '../Component/TextShow'
19
20const math: MathJsStatic = create(all)
21
22@Entry
23@Component
24struct Index {
25  @State value: string = ''
26  onClickButton = () => {
27    let context = getContext(this) as any
28    context.terminateSelf()
29  }
30
31  build() {
32    Column() {
33      TitleBar({ handleButtonClick: this.onClickButton })
34      Scroll() {
35        Column() {
36          TextShow({ text: $r('app.string.first_mathjs'), fontSize: 25 })
37          Button($r('app.string.generate_captcha'))
38            .fontSize(20)
39            .width(200)
40            .height(50)
41            .type(ButtonType.Normal)
42            .margin('5%')
43            .key('getCode')
44            .onClick(() => {
45              this.value = ''
46              for (let i = 0; i < 6; i++) {
47                let number = Math.trunc(math.chain(Math.random()).multiply(10).done())
48                this.value = this.value + number
49              }
50            })
51          Text(this.value)
52            .fontSize(35)
53            .backgroundColor('#ffe5d9d9')
54            .fontColor('#ffc81c1c')
55            .fontStyle(FontStyle.Italic)
56            .margin({ top: 20 })
57          Button($r('app.string.next_page'))
58            .fontSize(20)
59            .width(150)
60            .height(50)
61            .type(ButtonType.Normal)
62            .key('indexNextPage')
63            .margin({ top: '25%', left: '2%' })
64            .onClick(() => {
65              this.value = ''
66              router.push({
67                url: 'pages/DatePage'
68              })
69            })
70        }
71        .height('100%')
72        .width('100%')
73      }
74      .constraintSize({ maxHeight: '85%' })
75    }
76  }
77}