1/** 2 * Copyright (c) 2024 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 16export default class CommonFunc { 17 static rect_left: any; 18 static rect_top: any; 19 static rect_right: any; 20 static rect_bottom: any; 21 static rect_value: any; 22 23 static sleep(time: number){ 24 return new Promise((resolve,reject)=>{ 25 setTimeout(()=>{ 26 resolve("ok") 27 },time) 28 }).then(()=>{ 29 console.info(`sleep ${time} over...`) 30 }) 31 } 32 33 static getComponentRect(key: string) { 34 let strJson = getInspectorByKey(key); 35 let obj = JSON.parse(strJson); 36 console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj)); 37 let rectInfo = JSON.parse('[' + obj.$rect + ']'); 38 this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]; 39 this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]; 40 this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]; 41 this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]; 42 this.rect_value = { 43 "left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom 44 }; 45 console.info(JSON.stringify(this.rect_value)); 46 return this.rect_value; 47 } 48} 49