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 */ 15import { LitTable, RedrawTreeForm } from '../../../../../base-ui/table/lit-table'; 16 17//并行度逻辑处理 18export function HanldParalLogic( 19 func: (dumpObj: unknown, value?: unknown, param?: unknown) => unknown, 20 value: unknown, 21 param?: unknown): unknown { 22 // @ts-ignore 23 let arr = value.stateItem; 24 let waitArr: unknown = []; 25 let globalTs: number = 0; 26 let index: number = 0; 27 // @ts-ignore 28 while (index < arr.length || waitArr.length > 0) { 29 // @ts-ignore 30 let minEndTs = Math.min(...waitArr.map((item: unknown) => item.endTs)); 31 // @ts-ignore 32 let minIndex = waitArr.findIndex((item: unknown) => item.endTs === minEndTs); 33 //当waitArr为空时 34 // @ts-ignore 35 if (waitArr.length === 0) { 36 globalTs = arr[index].ts; 37 // @ts-ignore 38 waitArr.push(arr[index]); 39 index++; 40 continue; 41 } 42 //当全局Ts等于minEndTs时,只做删除处理 43 if (globalTs === minEndTs) { 44 // @ts-ignore 45 if (minIndex !== -1) { waitArr.splice(minIndex, 1) }; 46 continue; 47 } 48 let list = JSON.parse(JSON.stringify(waitArr)); 49 let dumpObj = { 50 ts: 0, 51 endTs: 0, 52 listSlice: [], 53 len: 0 54 }; 55 //判断原队列的数据是否被用完,即是否为空 56 if (index < arr.length) { 57 if (arr[index].ts < minEndTs) { 58 if (globalTs === arr[index].ts) { 59 // @ts-ignore 60 waitArr.push(arr[index]); 61 index++; 62 continue; 63 } else { 64 dumpObj = { 65 ts: globalTs, 66 endTs: arr[index].ts, 67 listSlice: list, 68 len: list.length 69 }; 70 // @ts-ignore 71 waitArr.push(arr[index]); 72 globalTs = arr[index].ts; 73 index++; 74 } 75 } else if (arr[index].ts >= minEndTs) { 76 dumpObj = { 77 ts: globalTs, 78 endTs: minEndTs, 79 listSlice: list, 80 len: list.length 81 }; 82 globalTs = minEndTs; 83 // @ts-ignore 84 if (minIndex !== -1) { waitArr.splice(minIndex, 1) }; 85 } 86 } else { 87 dumpObj = { 88 ts: globalTs, 89 endTs: minEndTs, 90 listSlice: list, 91 len: list.length 92 }; 93 globalTs = minEndTs; 94 // @ts-ignore 95 if (minIndex !== -1) { waitArr.splice(minIndex, 1) }; 96 } 97 param = func(dumpObj, value, param); 98 } 99 return param; 100} 101 102//表头点击事件 103export function MeterHeaderClick(tab: LitTable | null | undefined, data: Array<unknown>): void { 104 let labels = tab?.shadowRoot 105 ?.querySelector('.th > .td')! 106 .querySelectorAll('label'); 107 if (labels) { 108 for (let i = 0; i < labels.length; i++) { 109 let label = labels[i].innerHTML; 110 labels[i].addEventListener('click', (e) => { 111 if (label.includes('Process') && i === 0) { 112 tab!.setStatus(data, false); 113 tab!.recycleDs = 114 tab!.meauseTreeRowElement( 115 data, 116 RedrawTreeForm.Retract 117 ); 118 } else if (label.includes('Core') && i === 1) { 119 tab!.setStatus(data, true); 120 tab!.recycleDs = 121 tab!.meauseTreeRowElement( 122 data, 123 RedrawTreeForm.Expand 124 ); 125 } 126 }); 127 } 128 } 129}