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 rectLeft: any; 18 static rectTop: any; 19 static rectRight: any; 20 static rectBottom: any; 21 static rectValue: 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.rectLeft = JSON.parse('[' + rectInfo[0] + ']')[0]; 39 this.rectTop = JSON.parse('[' + rectInfo[0] + ']')[1]; 40 this.rectRight = JSON.parse('[' + rectInfo[1] + ']')[0]; 41 this.rectBottom = JSON.parse('[' + rectInfo[1] + ']')[1]; 42 this.rectValue = { 43 "left": this.rectLeft, "top": this.rectTop, "right": this.rectRight, "bottom": this.rectBottom 44 }; 45 console.info(JSON.stringify(this.rectValue)); 46 return this.rectValue; 47 } 48} 49