feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Uniapp端页面对象模型
|
||||
|
||||
提供黄历小程序的页面对象封装。
|
||||
"""
|
||||
|
||||
from .almanac_page import AlmanacPage
|
||||
from .calendar_page import CalendarPage
|
||||
from .user_page import UserPage
|
||||
|
||||
__all__ = [
|
||||
"AlmanacPage",
|
||||
"CalendarPage",
|
||||
"UserPage",
|
||||
]
|
||||
@@ -0,0 +1,149 @@
|
||||
"""
|
||||
黄历页面
|
||||
|
||||
Uniapp黄历页面的页面对象模型。
|
||||
"""
|
||||
|
||||
from playwright.sync_api import Page
|
||||
from ..base_page import BasePage
|
||||
|
||||
|
||||
class AlmanacPage(BasePage):
|
||||
"""黄历页面"""
|
||||
|
||||
# 页面路径
|
||||
PATH = "/pages/almanac/index"
|
||||
|
||||
# 元素定位器
|
||||
LOCATORS = {
|
||||
"page_title": ".page-title",
|
||||
"date_display": ".date-display",
|
||||
"solar_date": ".solar-date",
|
||||
"lunar_date": ".lunar-date",
|
||||
"ganzhi": ".ganzhi",
|
||||
"shengxiao": ".shengxiao",
|
||||
"yi_list": ".yi-list",
|
||||
"ji_list": ".ji-list",
|
||||
"yi_items": ".yi-item",
|
||||
"ji_items": ".ji-item",
|
||||
"shichen_table": ".shichen-table",
|
||||
"shichen_rows": ".shichen-row",
|
||||
"chongsha": ".chongsha",
|
||||
"wuxing": ".wuxing",
|
||||
"taishen": ".taishen",
|
||||
"caishen": ".caishen",
|
||||
"prev_date_btn": ".prev-date",
|
||||
"next_date_btn": ".next-date",
|
||||
"date_picker": ".date-picker",
|
||||
"search_btn": ".search-btn",
|
||||
"tab_calendar": ".tab-calendar",
|
||||
"tab_almanac": ".tab-almanac",
|
||||
"tab_user": ".tab-user",
|
||||
}
|
||||
|
||||
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["date_display"])
|
||||
|
||||
def get_solar_date(self) -> str:
|
||||
"""获取公历日期"""
|
||||
return self.get_text(self.LOCATORS["solar_date"])
|
||||
|
||||
def get_lunar_date(self) -> str:
|
||||
"""获取农历日期"""
|
||||
return self.get_text(self.LOCATORS["lunar_date"])
|
||||
|
||||
def get_ganzhi(self) -> str:
|
||||
"""获取干支"""
|
||||
return self.get_text(self.LOCATORS["ganzhi"])
|
||||
|
||||
def get_shengxiao(self) -> str:
|
||||
"""获取生肖"""
|
||||
return self.get_text(self.LOCATORS["shengxiao"])
|
||||
|
||||
def get_yi_items(self) -> list:
|
||||
"""获取宜事项列表"""
|
||||
items = self.page.locator(self.LOCATORS["yi_items"]).all()
|
||||
return [item.text_content() for item in items]
|
||||
|
||||
def get_ji_items(self) -> list:
|
||||
"""获取忌事项列表"""
|
||||
items = self.page.locator(self.LOCATORS["ji_items"]).all()
|
||||
return [item.text_content() for item in items]
|
||||
|
||||
def get_yi_count(self) -> int:
|
||||
"""获取宜事项数量"""
|
||||
return self.get_elements_count(self.LOCATORS["yi_items"])
|
||||
|
||||
def get_ji_count(self) -> int:
|
||||
"""获取忌事项数量"""
|
||||
return self.get_elements_count(self.LOCATORS["ji_items"])
|
||||
|
||||
def click_prev_date(self) -> None:
|
||||
"""点击前一天"""
|
||||
self.click_element(self.LOCATORS["prev_date_btn"])
|
||||
|
||||
def click_next_date(self) -> None:
|
||||
"""点击后一天"""
|
||||
self.click_element(self.LOCATORS["next_date_btn"])
|
||||
|
||||
def click_date_picker(self) -> None:
|
||||
"""点击日期选择器"""
|
||||
self.click_element(self.LOCATORS["date_picker"])
|
||||
|
||||
def click_search(self) -> None:
|
||||
"""点击搜索按钮"""
|
||||
self.click_element(self.LOCATORS["search_btn"])
|
||||
|
||||
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 get_chongsha(self) -> str:
|
||||
"""获取冲煞信息"""
|
||||
return self.get_text(self.LOCATORS["chongsha"])
|
||||
|
||||
def get_wuxing(self) -> str:
|
||||
"""获取五行信息"""
|
||||
return self.get_text(self.LOCATORS["wuxing"])
|
||||
|
||||
def get_taishen(self) -> str:
|
||||
"""获取胎神信息"""
|
||||
return self.get_text(self.LOCATORS["taishen"])
|
||||
|
||||
def get_caishen(self) -> str:
|
||||
"""获取财神方位"""
|
||||
return self.get_text(self.LOCATORS["caishen"])
|
||||
|
||||
def get_shichen_count(self) -> int:
|
||||
"""获取时辰数量"""
|
||||
return self.get_elements_count(self.LOCATORS["shichen_rows"])
|
||||
|
||||
def has_yi_section(self) -> bool:
|
||||
"""检查是否有宜事项区域"""
|
||||
return self.is_element_visible(self.LOCATORS["yi_list"])
|
||||
|
||||
def has_ji_section(self) -> bool:
|
||||
"""检查是否有忌事项区域"""
|
||||
return self.is_element_visible(self.LOCATORS["ji_list"])
|
||||
|
||||
def wait_for_data_load(self, timeout: int = 10000) -> None:
|
||||
"""等待数据加载完成"""
|
||||
self.wait_for_selector(self.LOCATORS["solar_date"], timeout=timeout)
|
||||
@@ -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)
|
||||
@@ -0,0 +1,103 @@
|
||||
"""
|
||||
用户页面
|
||||
|
||||
Uniapp用户页面的页面对象模型。
|
||||
"""
|
||||
|
||||
from playwright.sync_api import Page
|
||||
from ..base_page import BasePage
|
||||
|
||||
|
||||
class UserPage(BasePage):
|
||||
"""用户页面"""
|
||||
|
||||
# 页面路径
|
||||
PATH = "/pages/user/index"
|
||||
|
||||
# 元素定位器
|
||||
LOCATORS = {
|
||||
"page_title": ".page-title",
|
||||
"user_avatar": ".user-avatar",
|
||||
"user_name": ".user-name",
|
||||
"user_stats": ".user-stats",
|
||||
"stat_days": ".stat-days",
|
||||
"stat_favorites": ".stat-favorites",
|
||||
"stat_important": ".stat-important",
|
||||
"menu_favorites": ".menu-favorites",
|
||||
"menu_important": ".menu-important",
|
||||
"menu_feedback": ".menu-feedback",
|
||||
"menu_settings": ".menu-settings",
|
||||
"menu_about": ".menu-about",
|
||||
"tab_calendar": ".tab-calendar",
|
||||
"tab_almanac": ".tab-almanac",
|
||||
"tab_user": ".tab-user",
|
||||
}
|
||||
|
||||
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["user_avatar"])
|
||||
|
||||
def get_user_name(self) -> str:
|
||||
"""获取用户名"""
|
||||
return self.get_text(self.LOCATORS["user_name"])
|
||||
|
||||
def get_stat_days(self) -> str:
|
||||
"""获取使用天数"""
|
||||
return self.get_text(self.LOCATORS["stat_days"])
|
||||
|
||||
def get_stat_favorites(self) -> str:
|
||||
"""获取收藏数"""
|
||||
return self.get_text(self.LOCATORS["stat_favorites"])
|
||||
|
||||
def get_stat_important(self) -> str:
|
||||
"""获取重要日期数"""
|
||||
return self.get_text(self.LOCATORS["stat_important"])
|
||||
|
||||
def click_menu_favorites(self) -> None:
|
||||
"""点击我的收藏菜单"""
|
||||
self.click_element(self.LOCATORS["menu_favorites"])
|
||||
|
||||
def click_menu_important(self) -> None:
|
||||
"""点击重要日期菜单"""
|
||||
self.click_element(self.LOCATORS["menu_important"])
|
||||
|
||||
def click_menu_feedback(self) -> None:
|
||||
"""点击意见反馈菜单"""
|
||||
self.click_element(self.LOCATORS["menu_feedback"])
|
||||
|
||||
def click_menu_settings(self) -> None:
|
||||
"""点击设置菜单"""
|
||||
self.click_element(self.LOCATORS["menu_settings"])
|
||||
|
||||
def click_menu_about(self) -> None:
|
||||
"""点击关于我们菜单"""
|
||||
self.click_element(self.LOCATORS["menu_about"])
|
||||
|
||||
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_user_avatar(self) -> bool:
|
||||
"""检查是否有用户头像"""
|
||||
return self.is_element_visible(self.LOCATORS["user_avatar"])
|
||||
|
||||
def wait_for_user_data(self, timeout: int = 10000) -> None:
|
||||
"""等待用户数据加载"""
|
||||
self.wait_for_selector(self.LOCATORS["user_name"], timeout=timeout)
|
||||
Reference in New Issue
Block a user