• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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*/
16
17// src/main/ets/view/BottomView.ets
18
19import { common, Want } from '@kit.AbilityKit';
20import TaskViewModel from '../viewmodel/TaskViewModel';
21import TaskListViewModel from '../viewmodel/TaskListViewModel';
22
23@Builder export function actionButton(text: string|Resource, onClick:() => void) {
24  Button(text, { buttonStyle: ButtonStyleMode.NORMAL })
25    .onClick(onClick)
26    .margin({ left: 10, right: 10, top: 5, bottom: 5 })
27}
28
29@ComponentV2
30export default struct BottomView {
31  @Param taskList: TaskListViewModel = new TaskListViewModel();
32  @Local newTaskName: string = '';
33  private context = getContext() as common.UIAbilityContext;
34
35  build() {
36    Column() {
37      Row() {
38        actionButton($r('app.string.Finish_all_tasks'), (): void => this.taskList.finishAll(true))
39        actionButton($r('app.string.Unfinish_all_tasks'), (): void => this.taskList.finishAll(false))
40        actionButton($r('app.string.Setting'), (): void => {
41          let wantInfo: Want = {
42            deviceId: '', // deviceId为空表示本设备
43            bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName
44            abilityName: 'SettingAbility',
45          };
46          this.context.startAbility(wantInfo);
47        })
48      }
49      .margin({ top: 10, bottom: 5 })
50      Row() {
51        TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName })
52          .onChange((value) => this.newTaskName = value)
53          .width('70%')
54        actionButton('+', (): void => {
55          let newTask = new TaskViewModel();
56          newTask.taskName = this.newTaskName;
57          this.taskList.addTask(newTask);
58          this.newTaskName = '';
59        })
60      }
61    }
62  }
63}