Commit a326b311 authored by 邱阿朋's avatar 邱阿朋

refactor(gui): 重构店铺管理工具GUI,提升界面与流程体验

- 重构VCManagerGUI类,拆分功能,简化代码结构
- 使用ttkbootstrap实现现代化深色主题和美观样式
- 增加暂停/继续按钮,支持任务暂停控制
- 优化日志显示,添加日志级别颜色和时间戳
- 实现日志队列异步处理,提升界面响应
- 完善进度条显示,自动根据日志数据更新
- 统一处理器创建逻辑,简化不同功能调用
- 细化输入验证和用户交互提示,提升使用体验
- 优化浏览器初始化与资源清理流程,保证稳定性
- 删除无用的console日志模块,减少冗余代码
- AutoInterface接口中新增运行状态控制方法,支持暂停机制
- 各业务类新增调用父类初始化和暂停检查,实现统一控制暂停状态
parent ff5e2359
# coding: utf-8
import logging
from app.logger.logger import Logger
class ColoredFormatter(logging.Formatter):
def format(self, record):
# 为不同的日志级别定义一些颜色
colors = {
'DEBUG': '\033[94m', # blue
'INFO': '\033[92m', # green
'WARNING': '\033[93m', # yellow
'ERROR': '\033[91m', # red
'CRITICAL': '\033[95m' # magenta
}
# 从记录中获取原始消息
message = super().format(record)
# 如果日志级别定义了颜色,则添加颜色代码
if record.levelname in colors:
color_code = colors[record.levelname]
message = f"{color_code}{message}\033[0m"
return message
class ConsoleLog(Logger):
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(ConsoleLog, cls).__new__(cls)
cls._instance._initialize()
return cls._instance
def _initialize(self):
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.DEBUG)
# 使用彩色格式化程序创建控制台处理程序
console_handler = logging.StreamHandler()
console_handler.setFormatter(ColoredFormatter('%(asctime)s %(message)s'))
# 将控制台处理程序添加到记录器
self.logger.addHandler(console_handler)
def info(self, arg):
self.logger.info(arg)
def debug(self, arg):
self.logger.debug(arg)
def warning(self, arg):
self.logger.warning(arg)
def error(self, arg):
self.logger.error(arg)
\ No newline at end of file
......@@ -32,5 +32,4 @@ class GuiLog(Logger):
self.__message("ERROR", arg)
def __message(self, t, message):
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
self._log_queue.put(f"[{t}] [{timestamp}] {message}")
self._log_queue.put(f"[{t}] {message}")
......@@ -16,6 +16,7 @@ from app.vc.interface import AutoInterface
class AdvertCost(AutoInterface):
def __init__(self, logger: Logger, page: Page, country: str):
super().__init__() # 调用父类初始化
self.logger = logger
self.page = page
self.country = country
......@@ -177,8 +178,8 @@ class AdvertCost(AutoInterface):
store_ids = country_store_ids[self.country]
for store_id in store_ids:
while not self.running:
time.sleep(1)
# 检查暂停状态
self.check_pause()
name = store_id
self.logger.debug(f"开始处理店铺:{name}")
......
# coding: utf-8
from abc import ABC, abstractmethod
import time
# 定义一个接口
class AutoInterface(ABC):
def __init__(self):
self._running = True # 运行状态标志
def set_running(self, status: bool):
"""设置运行状态"""
self._running = status
def is_running(self) -> bool:
"""获取运行状态"""
return self._running
def check_pause(self):
"""检查暂停状态,如果暂停则等待"""
while not self._running:
time.sleep(0.5)
@abstractmethod
def run(self, file_name: str):
pass
@abstractmethod
def push_data_queue(self):
pass
\ No newline at end of file
pass
......@@ -20,6 +20,7 @@ from app.vc.interface import AutoInterface
class Payment(AutoInterface):
def __init__(self, logger: Logger, page: Page, country: str, payee_code: str, shop_code: str):
super().__init__() # 调用父类初始化
self.logger = logger
self.page = page
self.country = country
......@@ -313,9 +314,13 @@ class Payment(AutoInterface):
all_price_pay_data = []
i = 0
for _, data in list_data.iterrows():
# 检查暂停状态
self.check_pause()
i += 1
invoice_number = data.get("Invoice Number")
invoice_amount = data.get("Invoice Amount")
self.logger.info({"index": i, "invoice_number": invoice_number})
# 获取当前订单的Payee和优惠比例
vendor_payment_terms = self.__get_po_code(i, invoice_number)
......
......@@ -11,6 +11,7 @@ from app.vc.interface import AutoInterface
class PaymentPush(AutoInterface):
def __init__(self, logger: Logger, country: str, shop_code: str):
super().__init__() # 调用父类初始化
self.logger = logger
self.country = country
self.shop_code = shop_code
......@@ -55,8 +56,12 @@ class PaymentPush(AutoInterface):
i = 0
for _, data in invoices.iterrows():
# 检查暂停状态
self.check_pause()
i += 1
payment_number = data.get("Payment Number")
self.logger.info({"index": i, "payment_number": payment_number})
payment_date = payments_map.get(payment_number, {}).get('Payment Date', '')
platform_payable_amount = data.get('Invoice Amount', '')
if self.country == 'FR' or self.country == 'UK':
......
......@@ -16,6 +16,7 @@ from datetime import datetime, timedelta
class ProductSales(AutoInterface):
def __init__(self, logger: Logger, page: Page, country: str):
super().__init__() # 调用父类初始化
self.logger = logger
self.page = page
self.country = country
......@@ -50,8 +51,9 @@ class ProductSales(AutoInterface):
self.page.ele("#raw_xlsx_btn").click()
self.logger.debug("点击导出等待下载任务提交...")
while True:
while not self.running:
time.sleep(1)
# 检查暂停状态
self.check_pause()
try:
self.page.wait(3)
......
......@@ -15,6 +15,7 @@ from app.vc.interface import AutoInterface
class ReturnGoods(AutoInterface):
def __init__(self, logger: Logger, page: Page, country: str, shop_code: str):
super().__init__() # 调用父类初始化
self.logger = logger
self.page = page
self.country = country
......@@ -63,6 +64,9 @@ class ReturnGoods(AutoInterface):
new_list_data = []
i = 0
for _, data in list_data.iterrows():
# 检查暂停状态
self.check_pause()
i += 1
return_id = data.get('Return ID')
self.logger.info({"index": i, "return_id": return_id})
......
......@@ -17,6 +17,7 @@ from app.vc.interface import AutoInterface
class Spa(AutoInterface):
def __init__(self, logger: Logger, page: Page, country: str, shop_code: str):
super().__init__() # 调用父类初始化
self.logger = logger
self.page = page
self.country = country
......@@ -407,6 +408,9 @@ class Spa(AutoInterface):
large_sheet_data = {} # 保存大数据(需要分 Sheet)
# 遍历合作列表
for index, coop in coop_list.iterrows():
# 检查暂停状态
self.check_pause()
index += 1
invoice_id = coop.get("Invoice ID") # 获取发票 ID
self.logger.info({"index": index, "invoice_id": invoice_id})
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment