1/** 2 * Copyright (c) 2021-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 */ 15 16import { Log } from '../utils/Log'; 17import { AppName } from './AppName'; 18import { AppMenu } from './AppMenu'; 19import { FormModel } from '../model/FormModel'; 20import { StyleConstants } from '../constants/StyleConstants'; 21import { PresetStyleConstants } from '../constants/PresetStyleConstants'; 22import { CommonConstants } from '../constants/CommonConstants'; 23import { localEventManager } from '../manager/LocalEventManager'; 24import { EventConstants } from '../constants/EventConstants'; 25 26const TAG = 'FormItemComponent'; 27 28@Component 29export struct FormItemComponent { 30 @State showFormName: boolean = true; 31 @State isAllowUpdate: boolean = true; 32 @State isShow: boolean = true; 33 @State isHover: boolean = false; 34 formNameHeight: number; 35 formNameSize: number; 36 nameFontColor: string; 37 iconNameMargin: number = PresetStyleConstants.DEFAULT_ICON_NAME_GAP; 38 private formItemWidth; 39 private formItemHeight; 40 private menuInfo; 41 private formItem; 42 private formId; 43 private mFormModel: FormModel; 44 private nameLines: number = PresetStyleConstants.DEFAULT_APP_NAME_LINES; 45 mPaddingTop: number = StyleConstants.DEFAULT_10; 46 getFormId: (id: number) => void; 47 clickForm?: Function = null; 48 dragStart: Function; 49 50 aboutToAppear(): void { 51 this.mFormModel = FormModel.getInstance(); 52 } 53 54 @Builder MenuBuilder() { 55 Column() { 56 AppMenu({ 57 menuInfoList: this.menuInfo, 58 }) 59 } 60 .alignItems(HorizontalAlign.Center) 61 .justifyContent(FlexAlign.Center) 62 .width(StyleConstants.CONTEXT_MENU_WIDTH) 63 } 64 65 build() { 66 Column() { 67 FormComponent({ 68 id: this.formItem.cardId, 69 name: this.formItem.cardName, 70 bundle: this.formItem.bundleName, 71 ability: this.formItem.abilityName, 72 module: this.formItem.moduleName, 73 dimension: this.formItem.cardDimension 74 }) 75 .clip(new Rect({ width: this.formItemWidth, height: this.formItemHeight, radius: 24})) 76 .size({ width: this.formItemWidth, height: this.formItemHeight }) 77 .allowUpdate(this.isAllowUpdate) 78 .visibility(this.isShow ? Visibility.Visible : Visibility.None) 79 .onAcquired((form) => { 80 Log.showInfo(TAG, `FormComponent card id is: ${form.id}`); 81 this.formId = form.id; 82 if (this.getFormId) { 83 this.getFormId(form.id); 84 } 85 }) 86 .onClick((event: ClickEvent) => { 87 Log.showInfo(TAG, `FormComponent onClick`); 88 }) 89 .onError((error) => { 90 Log.showInfo(TAG, `FormComponent error msg: ${error.msg}`); 91 this.mFormModel.deleteForm(this.formItem.cardId); 92 localEventManager.sendLocalEventSticky(EventConstants.EVENT_REQUEST_PAGEDESK_ITEM_UPDATE, null); 93 }) 94 .onTouch(event => { 95 if (event.type === CommonConstants.TOUCH_TYPE_UP) { 96 this.clickForm(event, this.formItem); 97 } 98 }) 99 100 Column() { 101 AppName({ 102 bundleName: this.formItem.bundleName, 103 moduleName: this.formItem.moduleName, 104 labelId: this.formItem.appLabelId, 105 nameHeight: this.formNameHeight, 106 nameSize: this.formNameSize, 107 nameFontColor: this.nameFontColor, 108 appName: this.formItem.appName, 109 nameLines: this.nameLines, 110 marginTop: this.iconNameMargin 111 }) 112 } 113 .visibility(this.showFormName ? Visibility.Visible : Visibility.Hidden) 114 } 115 .onHover((isHover: boolean) => { 116 Log.showInfo(TAG, `Form onHover isHover: ${isHover}`); 117 this.isHover = isHover; 118 }) 119 .onDisAppear(() => { 120 Log.showInfo(TAG, `formItemComponent onDisAppear: ${this.formId}`); 121 }) 122 .padding({top : this.mPaddingTop}) 123 .height(StyleConstants.PERCENTAGE_100) 124 .width(StyleConstants.PERCENTAGE_100) 125 .bindContextMenu(this.MenuBuilder, ResponseType.LongPress) 126 .bindContextMenu(this.MenuBuilder, ResponseType.RightClick) 127 .onDragStart((event: DragEvent, extraParams: string) => { 128 return this.dragStart(event); 129 }) 130 } 131}