第一次
This commit is contained in:
parent
90882138f0
commit
837001779f
@ -805,12 +805,15 @@ class LongiMainPage extends BasePage {
|
||||
}
|
||||
|
||||
// 等待页面加载
|
||||
const loadResult = await this.waitForPageLoadWithRetry({text: menuPath});
|
||||
const loadResult = await this.waitForPageLoadWithRetry(menuInfo);
|
||||
if (!loadResult.success) {
|
||||
console.warn(loadResult.error);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 处理所有TAB页
|
||||
await this.handleAllTabs(menuInfo);
|
||||
|
||||
// 关闭标签页
|
||||
await this.closeActiveTab(menuPath);
|
||||
return true;
|
||||
@ -819,6 +822,81 @@ class LongiMainPage extends BasePage {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单个TAB页
|
||||
* @param {Object} tabInfo TAB页信息对象,包含text、isActive和element属性
|
||||
* @param {Object} parentMenu 父级菜单对象
|
||||
* @returns {Promise<boolean>} 处理是否成功
|
||||
* @private
|
||||
*/
|
||||
async handleSingleTab(tabInfo, parentMenu) {
|
||||
try {
|
||||
const menuPath = parentMenu.path || parentMenu.text;
|
||||
console.log(`🔹 处理TAB页: ${menuPath} > ${tabInfo.text}`);
|
||||
|
||||
// 直接使用传入的element点击
|
||||
await tabInfo.element.click();
|
||||
|
||||
// 等待页面加载
|
||||
const loadResult = await this.waitForPageLoadWithRetry(parentMenu, tabInfo.text);
|
||||
if (!loadResult.success) {
|
||||
console.warn(`TAB页 ${tabInfo.text} 加载失败: ${loadResult.error}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`处理TAB页失败 [${parentMenu.text} > ${tabInfo.text}]:`, error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理所有TAB页
|
||||
* @param {Object} menu 菜单对象
|
||||
* @returns {Promise<boolean>} 处理是否成功
|
||||
* @private
|
||||
*/
|
||||
async handleAllTabs(menu) {
|
||||
try {
|
||||
// 等待TAB容器加载
|
||||
await this.page.waitForTimeout(1000);
|
||||
|
||||
// 使用更精确的选择器获取工作区的TAB页
|
||||
const tabs = await this.page.locator('.workSpaceBaseTab .el-tabs__item').all();
|
||||
if (tabs.length === 0) {
|
||||
console.log(`📝 ${menu.text} 没有TAB页`);
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log(`📑 ${menu.text} 找到 ${tabs.length} 个TAB页`);
|
||||
|
||||
// 获取所有TAB页的完整信息(文本、激活状态和元素引用)
|
||||
const tabInfos = await Promise.all(
|
||||
tabs.map(async element => ({
|
||||
text: (await element.textContent()).trim(),
|
||||
isActive: await element.evaluate(el => el.classList.contains('is-active')),
|
||||
element: element // 保存元素引用
|
||||
}))
|
||||
);
|
||||
|
||||
// 处理每个非激活的TAB页
|
||||
for (const tabInfo of tabInfos) {
|
||||
// 跳过当前激活的TAB页,因为它已经是默认加载的
|
||||
if (!tabInfo.isActive) {
|
||||
await this.handleSingleTab(tabInfo, menu);
|
||||
} else {
|
||||
console.log(`⏭️ 跳过当前激活的TAB页: ${menu.text} > ${tabInfo.text}`);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`处理TAB页失败 [${menu.text}]:`, error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LongiMainPage;
|
||||
Loading…
Reference in New Issue
Block a user