1/* 2 * Copyright (c) 2022-2023 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 16import CommonEvent from '@ohos.commonEvent' 17import LauncherGridLayout from '../components/LauncherGridLayout' 18import { DesktopLayoutModel } from '../model/DesktopLayoutModel' 19import { EventConstants, GridLayoutItemInfo, Logger } from '@ohos/base' 20 21const TAG: string = 'WorkSpace'; 22 23@Component 24export struct WorkSpace { 25 @StorageLink('DesktopLayoutModel') desktopLayoutModel: DesktopLayoutModel | undefined = undefined; 26 @StorageLink('isRefresh') @Watch('refreshWorkSpace') isRefresh: boolean = false; 27 @State appPages: Array<Array<GridLayoutItemInfo>> | undefined = [[]]; 28 private swiperController: SwiperController = new SwiperController(); 29 30 build() { 31 Column() { 32 Swiper(this.swiperController) { 33 ForEach(this.appPages, (item: Array<GridLayoutItemInfo>) => { 34 LauncherGridLayout({ gridInfos: item }) 35 }, (item: Array<GridLayoutItemInfo>) => JSON.stringify(item)) 36 } 37 .indicatorStyle({ 38 selectedColor: Color.White 39 }) 40 .width('100%') 41 .height('95%') 42 .gesture( 43 PanGesture({ fingers: 1, direction: PanDirection.Up, distance: 20 }) 44 .onActionStart((event: GestureEvent) => { 45 console.info('Pan start'); 46 }) 47 .onActionUpdate((event: GestureEvent) => { 48 }) 49 .onActionEnd(() => { 50 console.info('Pan end') 51 CommonEvent.publish(EventConstants.EVENT_ENTER_RECENTS, () => { 52 Logger.info(TAG, 'publish EVENT_ENTER_RECENTS'); 53 }) 54 }) 55 ) 56 } 57 .width('100%') 58 .height('100%') 59 .padding({ top: 40, bottom: 40 }) 60 } 61 62 aboutToAppear() { 63 Logger.info(TAG, 'aboutToAppear'); 64 this.getData(); 65 } 66 67 refreshWorkSpace() { 68 Logger.info(TAG, 'refreshWorkSpace'); 69 if (this.isRefresh) { 70 this.appPages = this.desktopLayoutModel?.getLayoutInfoCache(); 71 AppStorage.SetOrCreate('isRefresh', false); 72 Logger.info(TAG, 'refreshWorkSpace' + JSON.stringify(this.appPages)); 73 } 74 } 75 76 async getData() { 77 this.appPages = await this.desktopLayoutModel?.getLayoutInfo(); 78 Logger.info(TAG, `getLauncherAbilityList end,appPages = ${JSON.stringify(this.appPages)}`); 79 } 80}