From e7798329a2c87cc04fdae978ab751152e98e7f14 Mon Sep 17 00:00:00 2001 From: dengqichen Date: Fri, 7 Mar 2025 18:30:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E6=89=B9=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=82=B9=E5=87=BB=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/LongiMainPage.js | 80 ++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/src/pages/LongiMainPage.js b/src/pages/LongiMainPage.js index 58b8855..0f24f72 100644 --- a/src/pages/LongiMainPage.js +++ b/src/pages/LongiMainPage.js @@ -35,7 +35,9 @@ class LongiMainPage extends BasePage { // Tab相关 tabContainer: '.workSpaceBaseTab .el-tabs__item', activeTab: '.vab-tabs .el-tabs--card .el-tabs__item.is-active', - closeButton: '.el-icon.is-icon-close' + closeButton: '.el-icon.is-icon-close', + tabItems: '.workSpaceBaseTab .el-tabs__item', + nextTabButton: '.el-icon.is-icon-next' }); } @@ -380,19 +382,30 @@ class LongiMainPage extends BasePage { } /** - * 处理单个TAB页 - * @param {Object} tabInfo TAB页信息对象 - * @param {Object} parentMenu 父级菜单对象 + * 查找标签页信息 + * @param {Object} menu 菜单对象 + * @returns {Promise} 标签页信息数组 + * @private */ - async handleSingleTab(tabInfo, parentMenu) { - try { - const menuPath = parentMenu.path || parentMenu.text; - const tabPath = `${menuPath} > ${tabInfo.text}`; - await tabInfo.element.click(); - await this.waitForIBPPageLoadWithRetry(tabPath); - } catch (error) { - console.error(`处理TAB页失败 [${parentMenu.text} > ${tabInfo.text}]:`, error.message); + async findTabInfos(menu) { + const tabs = await this.page.locator(this.selectors.tabContainer).all(); + if (tabs.length === 0) { + console.log(`📝 ${menu.text} 没有TAB页`); + return []; } + + console.log(`📑 ${menu.text} 找到 ${tabs.length} 个TAB页`); + const tabInfos = []; + for (const tab of tabs) { + const text = await tab.textContent(); + const isActive = await tab.evaluate(el => el.classList.contains('is-active')); + tabInfos.push({ + text: text.trim(), + element: tab, + isActive: isActive + }); + } + return tabInfos; } /** @@ -403,21 +416,19 @@ class LongiMainPage extends BasePage { try { await this.waitForTimeout(1000); - const tabs = await this.page.locator(this.selectors.tabContainer).all(); - if (tabs.length === 0) { - console.log(`📝 ${menu.text} 没有TAB页`); + const tabInfos = await this.findTabInfos(menu); + if (tabInfos.length === 0) { return; } - console.log(`📑 ${menu.text} 找到 ${tabs.length} 个TAB页`); - const tabInfos = await this.findTabInfos(tabs); - + let hasSkippedActiveTab = false; for (const tabInfo of tabInfos) { - if (!tabInfo.isActive) { - await this.handleSingleTab(tabInfo, menu); - } else { + if (tabInfo.isActive && !hasSkippedActiveTab) { console.log(`⏭️ 跳过当前激活的TAB页: ${menu.text} > ${tabInfo.text}`); + hasSkippedActiveTab = true; + continue; } + await this.handleSingleTab(tabInfo, menu); } } catch (error) { console.error(`处理TAB页失败 [${menu.text}]:`, error.message); @@ -425,19 +436,22 @@ class LongiMainPage extends BasePage { } /** - * 获取TAB页信息 - * @param {Array} tabs TAB页元素数组 - * @returns {Promise} TAB页信息数组 - * @private + * 处理单个TAB页 + * @param {Object} tabInfo TAB页信息对象 + * @param {Object} parentMenu 父级菜单对象 */ - async findTabInfos(tabs) { - return Promise.all( - tabs.map(async element => ({ - text: await this.getTextByElement(element), - isActive: await element.evaluate(el => el.classList.contains('is-active')), - element: element - })) - ); + async handleSingleTab(tabInfo, parentMenu) { + try { + const menuPath = parentMenu.path || parentMenu.text; + const tabPath = `${menuPath} > ${tabInfo.text}`; + + console.log(`等待页面 ${tabPath} 数据加载...`); + await tabInfo.element.click(); + await this.waitForIBPPageLoadWithRetry(tabPath); + console.log(`✅ 页面 ${tabPath} 加载完成`); + } catch (error) { + console.error(`处理TAB页失败 [${tabPath}]:`, error.message); + } } /**