feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
"""
|
||||
仪表盘页面
|
||||
|
||||
Admin后台仪表盘页面的页面对象模型。
|
||||
"""
|
||||
|
||||
from playwright.sync_api import Page
|
||||
from ..base_page import BasePage
|
||||
|
||||
|
||||
class DashboardPage(BasePage):
|
||||
"""仪表盘页面"""
|
||||
|
||||
# 页面路径
|
||||
PATH = "/dashboard"
|
||||
|
||||
# 元素定位器
|
||||
LOCATORS = {
|
||||
"page_title": ".dashboard h1, .dashboard-title",
|
||||
"sidebar_menu": ".el-menu, .sidebar",
|
||||
"menu_items": ".el-menu-item",
|
||||
"user_info": ".user-info, .user-avatar",
|
||||
"logout_button": ".user-info",
|
||||
"stat_cards": ".stat-card, .el-card",
|
||||
"charts": ".chart-container",
|
||||
}
|
||||
|
||||
def __init__(self, page: Page, base_url: str = ""):
|
||||
super().__init__(page, base_url)
|
||||
|
||||
def navigate(self, path: str = "") -> None:
|
||||
"""导航到仪表盘页面"""
|
||||
target_path = path if path else self.PATH
|
||||
self.page.goto(f"{self.base_url}{target_path}")
|
||||
self.wait_for_load()
|
||||
|
||||
def is_loaded(self) -> bool:
|
||||
"""检查页面是否加载完成"""
|
||||
return self.is_element_visible(self.LOCATORS["stat_cards"], timeout=5000)
|
||||
|
||||
def get_page_title(self) -> str:
|
||||
"""获取页面标题"""
|
||||
return self.get_text(self.LOCATORS["page_title"])
|
||||
|
||||
def get_menu_items(self) -> list:
|
||||
"""获取菜单项列表"""
|
||||
items = self.page.locator(self.LOCATORS["menu_items"]).all()
|
||||
return [item.text_content() for item in items]
|
||||
|
||||
def click_menu_item(self, menu_text: str) -> None:
|
||||
"""点击菜单项"""
|
||||
self.page.locator(self.LOCATORS["menu_items"]).filter(
|
||||
has_text=menu_text
|
||||
).click()
|
||||
|
||||
def is_menu_item_visible(self, menu_text: str) -> bool:
|
||||
"""检查菜单项是否可见"""
|
||||
try:
|
||||
self.page.locator(self.LOCATORS["menu_items"]).filter(
|
||||
has_text=menu_text
|
||||
).wait_for(timeout=5000)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def click_logout(self) -> None:
|
||||
"""点击登出按钮"""
|
||||
try:
|
||||
user_info = self.page.locator(self.LOCATORS["user_info"])
|
||||
if user_info.is_visible():
|
||||
user_info.click()
|
||||
self.wait_for_timeout(500)
|
||||
logout_option = self.page.locator('.el-dropdown-menu__item:has-text("退出"), .el-dropdown-menu__item:has-text("logout"), .el-dropdown-menu__item:has-text("登出")')
|
||||
if logout_option.count() > 0:
|
||||
logout_option.first.click()
|
||||
return
|
||||
self.page.evaluate('localStorage.clear(); sessionStorage.clear();')
|
||||
self.page.goto(f"{self.base_url}/login")
|
||||
except Exception as e:
|
||||
self.page.evaluate('localStorage.clear(); sessionStorage.clear();')
|
||||
self.page.goto(f"{self.base_url}/login")
|
||||
|
||||
def get_stat_cards_count(self) -> int:
|
||||
"""获取统计卡片数量"""
|
||||
return self.get_elements_count(self.LOCATORS["stat_cards"])
|
||||
|
||||
def get_charts_count(self) -> int:
|
||||
"""获取图表数量"""
|
||||
return self.get_elements_count(self.LOCATORS["charts"])
|
||||
|
||||
def wait_for_data_load(self, timeout: int = 10000) -> None:
|
||||
"""等待数据加载完成"""
|
||||
self.wait_for_timeout(2000) # 等待数据加载动画
|
||||
|
||||
def refresh_data(self) -> None:
|
||||
"""刷新数据"""
|
||||
self.reload()
|
||||
self.wait_for_load()
|
||||
Reference in New Issue
Block a user