1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_ciimport { BaseElement, element } from '../../../../base-ui/BaseElement'; 17fb726d48Sopenharmony_ciimport { SpStatisticsHttpUtil } from '../../../../statistics/util/SpStatisticsHttpUtil'; 18fb726d48Sopenharmony_ciimport './Top10LongestRunTimeProcess.ts'; 19fb726d48Sopenharmony_ciimport './Top10ProcessSwitchCount.ts'; 20fb726d48Sopenharmony_ciimport { Top10LongestRunTimeProcess } from './Top10LongestRunTimeProcess'; 21fb726d48Sopenharmony_ciimport { Top10ProcessSwitchCount } from './Top10ProcessSwitchCount'; 22fb726d48Sopenharmony_ci 23fb726d48Sopenharmony_ci@element('tab-process-analysis') 24fb726d48Sopenharmony_ciexport class TabProcessAnalysis extends BaseElement { 25fb726d48Sopenharmony_ci private currentTabID: string | undefined; 26fb726d48Sopenharmony_ci private currentTab: BaseElement | undefined; 27fb726d48Sopenharmony_ci private btn1: HTMLDivElement | null | undefined; 28fb726d48Sopenharmony_ci private btn2: HTMLDivElement | null | undefined; 29fb726d48Sopenharmony_ci private Top10LongestRunTimeProcess: Top10LongestRunTimeProcess | undefined | null; 30fb726d48Sopenharmony_ci private Top10ProcessSwitchCount: Top10ProcessSwitchCount | undefined | null; 31fb726d48Sopenharmony_ci 32fb726d48Sopenharmony_ci /** 33fb726d48Sopenharmony_ci * 元素初始化,将html节点与内部变量进行绑定 34fb726d48Sopenharmony_ci */ 35fb726d48Sopenharmony_ci initElements(): void { 36fb726d48Sopenharmony_ci this.btn1 = this.shadowRoot!.querySelector<HTMLDivElement>('#btn1'); 37fb726d48Sopenharmony_ci this.btn2 = this.shadowRoot!.querySelector<HTMLDivElement>('#btn2'); 38fb726d48Sopenharmony_ci this.Top10LongestRunTimeProcess = this.shadowRoot!.querySelector<Top10LongestRunTimeProcess>('#top10_process_runTime'); 39fb726d48Sopenharmony_ci this.Top10ProcessSwitchCount = this.shadowRoot!.querySelector<Top10ProcessSwitchCount>('#top10_process_switchCount'); 40fb726d48Sopenharmony_ci this.btn1!.addEventListener('click', (event) => { 41fb726d48Sopenharmony_ci this.setClickTab(this.btn1!, this.Top10ProcessSwitchCount!); 42fb726d48Sopenharmony_ci }); 43fb726d48Sopenharmony_ci this.btn2!.addEventListener('click', (event) => { 44fb726d48Sopenharmony_ci this.setClickTab(this.btn2!, this.Top10LongestRunTimeProcess!); 45fb726d48Sopenharmony_ci }); 46fb726d48Sopenharmony_ci } 47fb726d48Sopenharmony_ci 48fb726d48Sopenharmony_ci /** 49fb726d48Sopenharmony_ci * 初始化操作,清空该标签页下所有面板数据,只有首次导入新trace后执行一次 50fb726d48Sopenharmony_ci */ 51fb726d48Sopenharmony_ci init(): void { 52fb726d48Sopenharmony_ci this.Top10ProcessSwitchCount?.clearData(); 53fb726d48Sopenharmony_ci this.Top10LongestRunTimeProcess?.clearData(); 54fb726d48Sopenharmony_ci this.hideCurrentTab(); 55fb726d48Sopenharmony_ci this.currentTabID = undefined; 56fb726d48Sopenharmony_ci this.setClickTab(this.btn1!, this.Top10ProcessSwitchCount!); 57fb726d48Sopenharmony_ci } 58fb726d48Sopenharmony_ci 59fb726d48Sopenharmony_ci /** 60fb726d48Sopenharmony_ci * 隐藏当前面板,将按钮样式设置为未选中状态 61fb726d48Sopenharmony_ci */ 62fb726d48Sopenharmony_ci hideCurrentTab(): void { 63fb726d48Sopenharmony_ci if (this.currentTabID) { 64fb726d48Sopenharmony_ci let clickTab = this.shadowRoot!.querySelector<HTMLDivElement>(`#${this.currentTabID}`); 65fb726d48Sopenharmony_ci if (clickTab) { 66fb726d48Sopenharmony_ci clickTab.className = 'tag_bt'; 67fb726d48Sopenharmony_ci } 68fb726d48Sopenharmony_ci } 69fb726d48Sopenharmony_ci if (this.currentTab) { 70fb726d48Sopenharmony_ci this.currentTab.style.display = 'none'; 71fb726d48Sopenharmony_ci } 72fb726d48Sopenharmony_ci } 73fb726d48Sopenharmony_ci 74fb726d48Sopenharmony_ci /** 75fb726d48Sopenharmony_ci * 76fb726d48Sopenharmony_ci * @param btn 当前点击的数据类型按钮 77fb726d48Sopenharmony_ci * @param showContent 需要展示的面板对象 78fb726d48Sopenharmony_ci */ 79fb726d48Sopenharmony_ci setClickTab(btn: HTMLDivElement, showContent: Top10ProcessSwitchCount | Top10LongestRunTimeProcess): void { 80fb726d48Sopenharmony_ci // 将前次点击的按钮样式设置为未选中样式状态 81fb726d48Sopenharmony_ci if (this.currentTabID) { 82fb726d48Sopenharmony_ci let clickTab = this.shadowRoot!.querySelector<HTMLDivElement>(`#${this.currentTabID}`); 83fb726d48Sopenharmony_ci if (clickTab) { 84fb726d48Sopenharmony_ci clickTab.className = 'tag_bt'; 85fb726d48Sopenharmony_ci } 86fb726d48Sopenharmony_ci } 87fb726d48Sopenharmony_ci // 切换当前点击按钮的类名,应用点击样式 88fb726d48Sopenharmony_ci btn.className = 'tab_click'; 89fb726d48Sopenharmony_ci // 切换记录的好的当前点击面板id,并设置其显隐 90fb726d48Sopenharmony_ci if (btn.id !== this.currentTabID) { 91fb726d48Sopenharmony_ci this.currentTabID = btn.id; 92fb726d48Sopenharmony_ci if (this.currentTab) { 93fb726d48Sopenharmony_ci this.currentTab.style.display = 'none'; 94fb726d48Sopenharmony_ci } 95fb726d48Sopenharmony_ci this.currentTab = showContent; 96fb726d48Sopenharmony_ci showContent.style.display = 'inline'; 97fb726d48Sopenharmony_ci showContent.init(); 98fb726d48Sopenharmony_ci } 99fb726d48Sopenharmony_ci } 100fb726d48Sopenharmony_ci 101fb726d48Sopenharmony_ci /** 102fb726d48Sopenharmony_ci * 用于将元素节点挂载 103fb726d48Sopenharmony_ci * @returns 返回字符串形式的元素节点 104fb726d48Sopenharmony_ci */ 105fb726d48Sopenharmony_ci initHtml(): string { 106fb726d48Sopenharmony_ci return ` 107fb726d48Sopenharmony_ci <style> 108fb726d48Sopenharmony_ci .tag_bt{ 109fb726d48Sopenharmony_ci height: 45px; 110fb726d48Sopenharmony_ci border-radius: 10px; 111fb726d48Sopenharmony_ci border: solid 1px var(--dark-border1,#e0e0e0); 112fb726d48Sopenharmony_ci line-height: 45px; 113fb726d48Sopenharmony_ci text-align: center; 114fb726d48Sopenharmony_ci color: var(--dark-color,#000000); 115fb726d48Sopenharmony_ci background-color: var(--dark-background5,#FFFFFF); 116fb726d48Sopenharmony_ci cursor: pointer; 117fb726d48Sopenharmony_ci } 118fb726d48Sopenharmony_ci :host { 119fb726d48Sopenharmony_ci width: 100%; 120fb726d48Sopenharmony_ci height: 100%; 121fb726d48Sopenharmony_ci background: var(--dark-background5,#F6F6F6); 122fb726d48Sopenharmony_ci } 123fb726d48Sopenharmony_ci .tab_click{ 124fb726d48Sopenharmony_ci height: 45px; 125fb726d48Sopenharmony_ci border-radius: 10px; 126fb726d48Sopenharmony_ci border: solid 1px var(--dark-border1,#e0e0e0); 127fb726d48Sopenharmony_ci line-height: 45px; 128fb726d48Sopenharmony_ci text-align: center; 129fb726d48Sopenharmony_ci color: #FFFFFF; 130fb726d48Sopenharmony_ci background-color: #0d47a1; 131fb726d48Sopenharmony_ci cursor: pointer; 132fb726d48Sopenharmony_ci } 133fb726d48Sopenharmony_ci #content{ 134fb726d48Sopenharmony_ci background-color: var(--dark-background,#FFFFFF); 135fb726d48Sopenharmony_ci } 136fb726d48Sopenharmony_ci .grid-box{ 137fb726d48Sopenharmony_ci display: grid;grid-template-columns: auto auto auto auto auto;grid-column-gap: 15px;padding: 10px; 138fb726d48Sopenharmony_ci background-color: var(--dark-background,#FFFFFF); 139fb726d48Sopenharmony_ci } 140fb726d48Sopenharmony_ci </style> 141fb726d48Sopenharmony_ci <div class="grid-box"> 142fb726d48Sopenharmony_ci <div class="tag_bt" id="btn1">Top10切换次数进程</div> 143fb726d48Sopenharmony_ci <div class="tag_bt" id="btn2">Top10运行超长进程</div> 144fb726d48Sopenharmony_ci </div> 145fb726d48Sopenharmony_ci <div id="content"> 146fb726d48Sopenharmony_ci <top10-process-switch-count id="top10_process_switchCount" style="display: none"></top10-process-switch-count> 147fb726d48Sopenharmony_ci <top10-longest-runtime-process id="top10_process_runTime" style="display: none"></top10-longest-runtime-process> 148fb726d48Sopenharmony_ci </div> 149fb726d48Sopenharmony_ci `; 150fb726d48Sopenharmony_ci } 151fb726d48Sopenharmony_ci}