feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
"""
|
||||
日历页面
|
||||
|
||||
Uniapp日历页面的页面对象模型。
|
||||
"""
|
||||
|
||||
from playwright.sync_api import Page
|
||||
from ..base_page import BasePage
|
||||
|
||||
|
||||
class CalendarPage(BasePage):
|
||||
"""日历页面"""
|
||||
|
||||
# 页面路径
|
||||
PATH = "/pages/calendar/index"
|
||||
|
||||
# 元素定位器
|
||||
LOCATORS = {
|
||||
"page": ".page",
|
||||
"calendar_grid": ".calendar-grid-container",
|
||||
"calendar_card": ".calendar-card",
|
||||
"month_title": ".month-title",
|
||||
"year_display": ".year-display",
|
||||
"prev_month_btn": ".nav-button",
|
||||
"next_month_btn": ".nav-button",
|
||||
"today_btn": ".today-button",
|
||||
"day_number": ".day-number",
|
||||
"day_lunar": ".day-lunar",
|
||||
"selected_date": ".calendar-card-selected",
|
||||
"current_date": ".calendar-card-today",
|
||||
"weekday_header": ".weekday",
|
||||
"tab_calendar": ".nav-item:nth-child(1)",
|
||||
"tab_almanac": ".nav-item:nth-child(2)",
|
||||
"tab_user": ".nav-item:nth-child(3)",
|
||||
}
|
||||
|
||||
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["calendar_grid"])
|
||||
|
||||
def get_month_display(self) -> str:
|
||||
"""获取月份显示"""
|
||||
return self.get_text(self.LOCATORS["month_title"])
|
||||
|
||||
def get_year_display(self) -> str:
|
||||
"""获取年份显示"""
|
||||
month_text = self.get_text(self.LOCATORS["month_title"])
|
||||
if month_text:
|
||||
import re
|
||||
match = re.search(r'(\d{4})年', month_text)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return ""
|
||||
|
||||
def click_prev_month(self) -> None:
|
||||
"""点击上一月"""
|
||||
nav_buttons = self.page.locator(self.LOCATORS["prev_month_btn"]).all()
|
||||
if len(nav_buttons) > 0:
|
||||
nav_buttons[0].click()
|
||||
|
||||
def click_next_month(self) -> None:
|
||||
"""点击下一月"""
|
||||
nav_buttons = self.page.locator(self.LOCATORS["next_month_btn"]).all()
|
||||
if len(nav_buttons) > 1:
|
||||
nav_buttons[1].click()
|
||||
|
||||
def click_today(self) -> None:
|
||||
"""点击今天按钮"""
|
||||
self.click_element(self.LOCATORS["today_btn"])
|
||||
|
||||
def click_date(self, day: int) -> None:
|
||||
"""点击指定日期"""
|
||||
calendar_cards = self.page.locator(self.LOCATORS["calendar_card"]).all()
|
||||
for card in calendar_cards:
|
||||
day_number = card.locator(self.LOCATORS["day_number"]).text_content()
|
||||
if day_number and int(day_number) == day:
|
||||
card.click()
|
||||
break
|
||||
|
||||
def get_date_cells_count(self) -> int:
|
||||
"""获取日期单元格数量"""
|
||||
return self.get_elements_count(self.LOCATORS["calendar_card"])
|
||||
|
||||
def get_selected_date(self) -> str:
|
||||
"""获取选中的日期"""
|
||||
import time
|
||||
time.sleep(1)
|
||||
selected = self.page.locator(self.LOCATORS["selected_date"]).first
|
||||
if selected and selected.count() > 0:
|
||||
day_number = selected.locator(self.LOCATORS["day_number"])
|
||||
if day_number.count() > 0:
|
||||
return day_number.text_content() or ""
|
||||
return ""
|
||||
|
||||
def has_lunar_text(self, day: int) -> bool:
|
||||
"""检查指定日期是否有农历显示"""
|
||||
calendar_cards = self.page.locator(self.LOCATORS["calendar_card"]).all()
|
||||
for card in calendar_cards:
|
||||
day_number = card.locator(self.LOCATORS["day_number"]).text_content()
|
||||
if day_number and int(day_number) == day:
|
||||
return card.locator(self.LOCATORS["day_lunar"]).count() > 0
|
||||
return False
|
||||
|
||||
def get_lunar_text(self, day: int) -> str:
|
||||
"""获取指定日期的农历文本"""
|
||||
calendar_cards = self.page.locator(self.LOCATORS["calendar_card"]).all()
|
||||
for card in calendar_cards:
|
||||
day_number = card.locator(self.LOCATORS["day_number"]).text_content()
|
||||
if day_number and int(day_number) == day:
|
||||
return card.locator(self.LOCATORS["day_lunar"]).text_content() or ""
|
||||
return ""
|
||||
|
||||
def click_tab_calendar(self) -> None:
|
||||
"""点击万年历Tab"""
|
||||
self.click_element(self.LOCATORS["tab_calendar"])
|
||||
|
||||
def click_tab_almanac(self) -> None:
|
||||
"""点击黄历Tab"""
|
||||
self.click_element(self.LOCATORS["tab_almanac"])
|
||||
|
||||
def click_tab_user(self) -> None:
|
||||
"""点击我的Tab"""
|
||||
self.click_element(self.LOCATORS["tab_user"])
|
||||
|
||||
def has_holiday_mark(self, day: int) -> bool:
|
||||
"""检查指定日期是否有节假日标记"""
|
||||
calendar_cards = self.page.locator(self.LOCATORS["calendar_card"]).all()
|
||||
for card in calendar_cards:
|
||||
day_number = card.locator(self.LOCATORS["day_number"]).text_content()
|
||||
if day_number and int(day_number) == day:
|
||||
return card.locator(self.LOCATORS["current_date"]).count() > 0
|
||||
return False
|
||||
|
||||
def wait_for_calendar_load(self, timeout: int = 10000) -> None:
|
||||
"""等待日历加载完成"""
|
||||
self.wait_for_selector(self.LOCATORS["calendar_card"], timeout=timeout)
|
||||
Reference in New Issue
Block a user