• 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 emitter from '@ohos.events.emitter';
17import { EmptyPage } from '@ohos/common/src/main/ets/components/EmptyPage';
18import { Information } from '../model/Information';
19import { QueueDataSource } from '../components/queuecomponents/QueueDataSource';
20import { InformationItemView } from '../components/InformationItemView';
21import { Constant } from '../Constant';
22
23const MIN_LENGTH = 0;
24
25@Component
26export struct QueueView {
27  private dataSource: QueueDataSource = new QueueDataSource();
28  @State totalCount: number = MIN_LENGTH;
29
30  aboutToAppear() {
31    emitter.on({ eventId: Constant.EMITTER_ID_QUEUE }, (eventData) => {
32      this.dataSource.addData(eventData.data as Information);
33      this.totalCount = this.dataSource.totalCount();
34    });
35  }
36
37  aboutToDisappear() {
38    emitter.off(Constant.EMITTER_ID_QUEUE);
39  }
40
41  build() {
42    Column() {
43      if (this.totalCount > MIN_LENGTH) {
44        List() {
45          LazyForEach(this.dataSource, (item: Information, index: number) => {
46            ListItem() {
47              InformationItemView({ index: index, information: item, deleteAction: () => {
48                this.dataSource.deleteData();
49                this.totalCount = this.dataSource.totalCount();
50              } })
51            }
52            .height(72)
53            .width('100%')
54            .margin({ bottom: 20 })
55          }, (item: Information, index: number) => JSON.stringify(item) + index)
56        }
57        .width('100%')
58        .layoutWeight(1)
59
60      } else {
61        EmptyPage()
62      }
63    }
64    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
65  }
66}