diff --git a/app/amazon/__pycache__/approve.cpython-39.pyc b/app/amazon/__pycache__/approve.cpython-39.pyc index 6251979..42e8fe4 100644 Binary files a/app/amazon/__pycache__/approve.cpython-39.pyc and b/app/amazon/__pycache__/approve.cpython-39.pyc differ diff --git a/app/amazon/__pycache__/del_brand.cpython-39.pyc b/app/amazon/__pycache__/del_brand.cpython-39.pyc index 0e5aacf..213f2a3 100644 Binary files a/app/amazon/__pycache__/del_brand.cpython-39.pyc and b/app/amazon/__pycache__/del_brand.cpython-39.pyc differ diff --git a/app/amazon/__pycache__/match_action.cpython-39.pyc b/app/amazon/__pycache__/match_action.cpython-39.pyc index 5b64d1b..33ee517 100644 Binary files a/app/amazon/__pycache__/match_action.cpython-39.pyc and b/app/amazon/__pycache__/match_action.cpython-39.pyc differ diff --git a/app/amazon/__pycache__/price_match.cpython-39.pyc b/app/amazon/__pycache__/price_match.cpython-39.pyc index b9ca6b6..e5afa4b 100644 Binary files a/app/amazon/__pycache__/price_match.cpython-39.pyc and b/app/amazon/__pycache__/price_match.cpython-39.pyc differ diff --git a/app/amazon/approve.py b/app/amazon/approve.py index 5d86c4b..a16c8db 100644 --- a/app/amazon/approve.py +++ b/app/amazon/approve.py @@ -922,7 +922,90 @@ class ApproveTask: if task_id in runing_task: runing_task[task_id]["status"] = "failed" runing_task[task_id]["error"] = str(e) - + + def open_shop(self,max_retries,company_name,shop_name,iskill=False): + error_info = "" + driver = None + for retry in range(max_retries): + try: + self.log(f"尝试打开店铺 {shop_name} (第 {retry + 1}/{max_retries} 次)") + + if iskill: + self.log("重试前先杀掉浏览器进程...") + kill_process("v6") + kill_process("v5") + time.sleep(2) + + # 组装用户信息并创建驱动 + user_info = { + **self.user_info, + "company": company_name + } + driver = AmzoneApprove(user_info) + browser = driver.open_shop(shop_name) + + if browser and browser != "店铺不存在": + self.log(f"成功打开店铺 {shop_name}") + else: + self.log(f"打开店铺失败: {browser}", "WARNING") + driver = None + continue + + # 判断是否需要登录 + need_login = driver.need_login() + print("【是否需要登录】:", need_login) + if need_login: + self.log(f"店铺 {shop_name} 需要登录,正在登录...") + # 获取店铺凭证 + response = get_shop_info(shop_name) + print("【获取店铺凭证返回】:", response.text) + shop_data = response.json() + if not shop_data: + mes = f"获取店铺凭证失败,响应数据: {shop_data.get('message', '未知错误')}" + self.log(mes, "ERROR") + show_notification(mes, "ERROR") + continue + + password = shop_data["data"]["password"] + + login_success = driver.login(password) + if login_success: + self.log(f"店铺 {shop_name} 登录成功,正在重新打开店铺...") + browser = driver.open_shop(shop_name) + if browser and browser != "店铺不存在": + self.log(f"成功打开店铺 {shop_name} 登录后") + break + else: + self.log(f"登录后打开店铺失败: {browser}", "WARNING") + driver = None + else: + self.log(f"店铺 {shop_name} 登录失败", "WARNING") + driver = None + else: + break + + except Exception as e: + import traceback + self.log(f"打开店铺异常: {traceback.format_exc()}", "INFO") + driver = None + error_info = str(e) + time.sleep(10) + + # 如果还有重试机会,等待后继续 + if retry < max_retries - 1: + time.sleep(3) + + # 检查是否成功打开 + if not driver or not browser or browser == "店铺不存在": + error_msg = f"店铺 {shop_name} 打开失败,已重试 {max_retries} 次,跳过该店铺,{error_info}" + self.log(error_msg, "ERROR") + # 从执行列表中移除 + if shop_name in runing_shop: + del runing_shop[shop_name] + return driver + return driver + + def process_shop(self, shop_item: dict, country_codes: list, task_id: int, risk_listing_filter: str): """处理单个店铺 @@ -951,120 +1034,46 @@ class ApproveTask: # 店铺打开重试最多3次 driver = None max_retries = 3 - - error_info = "" - for retry in range(max_retries): + iskill = False + + # 处理每个国家 + for country_code in country_codes: + # 检查是否收到暂停请求 + if task_id in runing_task and runing_task[task_id].get("stop_requested", False): + self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "WARNING") + break + + # 打开店铺 + driver = self.open_shop(max_retries=max_retries, company_name=company_name, + shop_name=shop_name, iskill=iskill) + if driver is None: + self.log(f"任务 {task_id} 启动店铺失败,结束任务", "ERROR") + for country_code in country_codes: + self.post_result(task_id, shop_name, country_code, "", "", is_done=True) + return + try: - self.log(f"尝试打开店铺 {shop_name} (第 {retry + 1}/{max_retries} 次)") - - # 如果不是第一次尝试,先杀进程 - # if retry > 0: - # self.log("重试前先杀掉浏览器进程...") - # kill_process("v6") - # kill_process("v5") - # time.sleep(2) - - # 组装用户信息并创建驱动 - user_info = { - **self.user_info, - "company": company_name - } - driver = AmzoneApprove(user_info) - browser = driver.open_shop(shop_name) - - if browser and browser != "店铺不存在": - self.log(f"成功打开店铺 {shop_name}") - # break - else: - self.log(f"打开店铺失败: {browser}", "WARNING") - driver = None - continue - - # 判断是否需要登录 - need_login = driver.need_login() - print("【是否需要登录】:",need_login) - if need_login: - self.log(f"店铺 {shop_name} 需要登录,正在登录...") - # 获取店铺凭证 - response = get_shop_info(shop_name) - print("【获取店铺凭证返回】:",response.text) - shop_data = response.json() - if not shop_data: - mes = f"获取店铺凭证失败,响应数据: {shop_data.get('message', '未知错误')}" - self.log(mes, "ERROR") - show_notification(mes, "ERROR") - continue - - password = shop_data["data"]["password"] - - login_success = driver.login(password) - if login_success: - self.log(f"店铺 {shop_name} 登录成功,正在重新打开店铺...") - browser = driver.open_shop(shop_name) - if browser and browser != "店铺不存在": - self.log(f"成功打开店铺 {shop_name} 登录后") - break - else: - self.log(f"登录后打开店铺失败: {browser}", "WARNING") - driver = None - else: - self.log(f"店铺 {shop_name} 登录失败", "WARNING") - driver = None - else: - break + self.process_country(driver, country_code, task_id, shop_name,risk_listing_filter) except Exception as e: import traceback - self.log(f"打开店铺异常: {traceback.format_exc()}", "INFO") - driver = None - error_info = str(e) - time.sleep(10) - - # 如果还有重试机会,等待后继续 - if retry < max_retries - 1: - time.sleep(3) - - # 检查是否成功打开 - if not driver or not browser or browser == "店铺不存在": - error_msg = f"店铺 {shop_name} 打开失败,已重试 {max_retries} 次,跳过该店铺,{error_info}" - self.log(error_msg, "ERROR") - # 从执行列表中移除 - if shop_name in runing_shop: - del runing_shop[shop_name] - return - + self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR") + self.log(traceback.format_exc(), "ERROR") + if "与页面的连接已断开" in e: + iskill = True + + # 更新已处理国家数 + if task_id in runing_task: + runing_task[task_id]["processed_countries"] += 1 + # 最后回传,标记完成 try: - # 处理每个国家 - for country_code in country_codes: - # 检查是否收到暂停请求 - if task_id in runing_task and runing_task[task_id].get("stop_requested", False): - self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "WARNING") - break - - try: - self.process_country(driver, country_code, task_id, shop_name,risk_listing_filter) - except Exception as e: - import traceback - self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR") - self.log(traceback.format_exc(), "ERROR") - # 最后回传,标记完成 - try: - self.post_result(task_id, shop_name, country_code, "", "", is_done=True) - except Exception as e: - self.log(f"回传结果失败: {str(e)}", "ERROR") - finally: - # 关闭店铺 - try: - if driver: - self.log(f"关闭店铺 {shop_name}") - driver.close_store() - time.sleep(2) - except Exception as e: - self.log(f"关闭店铺失败: {str(e)}", "WARNING") - - # 从正在执行中的店铺列表中移除 - if shop_name in runing_shop: - del runing_shop[shop_name] - self.log(f"店铺 {shop_name} 已从执行列表中移除") + self.post_result(task_id, shop_name, country_code, "", "", is_done=True) + except Exception as e: + self.log(f"回传结果失败: {str(e)}", "ERROR") + + # 从正在执行中的店铺列表中移除 + if shop_name in runing_shop: + del runing_shop[shop_name] + self.log(f"店铺 {shop_name} 已从执行列表中移除") def process_country(self, driver: AmzoneApprove, country_code: str, task_id: int, shop_name: str, risk_listing_filter: str): """处理单个国家的审批任务 @@ -1176,42 +1185,33 @@ class ApproveTask: self.log(f"国家 {country_name} 有 {len(sku_ls)} 个需要审批的商品,开始处理...") # 处理所有需要审批的商品(通过yield获取结果) - try: - for asin, status in driver.run_page_action(): - # 检查是否收到暂停请求 - if task_id in runing_task and runing_task[task_id].get("stop_requested", False): - self.log(f"检测到任务 {task_id} 的暂停请求,停止处理ASIN", "WARNING") - break - - self.log(f"ASIN {asin} 处理结果: {status}") - - # 更新任务状态 - if task_id in runing_task: - runing_task[task_id]["current_asin"] = asin - runing_task[task_id]["processed_asins"] += 1 - - if status == "处理完成": - runing_task[task_id]["success_count"] += 1 - elif status in ["请求批准", "添加缺失的商品详情"]: - # 请求批准的商品也算作成功(因为不需要处理) - runing_task[task_id]["success_count"] += 1 - else: - runing_task[task_id]["failed_count"] += 1 - - # 回传结果到API - try: - self.post_result(task_id, shop_name, country_code, asin, status) - except Exception as e: - self.log(f"回传结果失败: {str(e)}", "ERROR") - - except Exception as e: - import traceback - self.log(f"处理审批商品异常: {str(e)}", "ERROR") - self.log(traceback.format_exc(), "ERROR") - - # 更新已处理国家数 - if task_id in runing_task: - runing_task[task_id]["processed_countries"] += 1 + for asin, status in driver.run_page_action(): + # 检查是否收到暂停请求 + if task_id in runing_task and runing_task[task_id].get("stop_requested", False): + self.log(f"检测到任务 {task_id} 的暂停请求,停止处理ASIN", "WARNING") + break + + self.log(f"ASIN {asin} 处理结果: {status}") + + # 更新任务状态 + if task_id in runing_task: + runing_task[task_id]["current_asin"] = asin + runing_task[task_id]["processed_asins"] += 1 + + if status == "处理完成": + runing_task[task_id]["success_count"] += 1 + elif status in ["请求批准", "添加缺失的商品详情"]: + # 请求批准的商品也算作成功(因为不需要处理) + runing_task[task_id]["success_count"] += 1 + else: + runing_task[task_id]["failed_count"] += 1 + + # 回传结果到API + try: + self.post_result(task_id, shop_name, country_code, asin, status) + except Exception as e: + self.log(f"回传结果失败: {str(e)}", "ERROR") + self.log(f"国家 {country_name} 处理完成") diff --git a/app/amazon/del_brand.py b/app/amazon/del_brand.py index fd0a311..af7c8ee 100644 --- a/app/amazon/del_brand.py +++ b/app/amazon/del_brand.py @@ -169,7 +169,7 @@ class ZiniaoDriver: "cookieTypeLoad": 0, "cookieTypeSave": cookieTypeSave, "runMode": "1", - "isLoadUserPlugin": False, + "isLoadUserPlugin": True, "pluginIdType": 1, "privacyMode": isprivacy } diff --git a/app/amazon/match_action.py b/app/amazon/match_action.py index 0eb6319..2a4d3e0 100644 --- a/app/amazon/match_action.py +++ b/app/amazon/match_action.py @@ -308,7 +308,89 @@ class MatchTak: if task_id in runing_task: runing_task[task_id]["status"] = "failed" runing_task[task_id]["error"] = str(e) - + + def open_shop(self,max_retries,company_name,shop_name,iskill=False): + error_info = "" + driver = None + for retry in range(max_retries): + try: + self.log(f"尝试打开店铺 {shop_name} (第 {retry + 1}/{max_retries} 次)") + + if iskill: + self.log("重试前先杀掉浏览器进程...") + kill_process("v6") + kill_process("v5") + time.sleep(2) + + # 组装用户信息并创建驱动 + user_info = { + **self.user_info, + "company": company_name + } + driver = AmzoneMatchAction(user_info) + browser = driver.open_shop(shop_name) + + if browser and browser != "店铺不存在": + self.log(f"成功打开店铺 {shop_name}") + else: + self.log(f"打开店铺失败: {browser}", "WARNING") + driver = None + continue + + # 判断是否需要登录 + need_login = driver.need_login() + print("【是否需要登录】:", need_login) + if need_login: + self.log(f"店铺 {shop_name} 需要登录,正在登录...") + # 获取店铺凭证 + response = get_shop_info(shop_name) + print("【获取店铺凭证返回】:", response.text) + shop_data = response.json() + if not shop_data: + mes = f"获取店铺凭证失败,响应数据: {shop_data.get('message', '未知错误')}" + self.log(mes, "ERROR") + show_notification(mes, "ERROR") + continue + + password = shop_data["data"]["password"] + + login_success = driver.login(password) + if login_success: + self.log(f"店铺 {shop_name} 登录成功,正在重新打开店铺...") + browser = driver.open_shop(shop_name) + if browser and browser != "店铺不存在": + self.log(f"成功打开店铺 {shop_name} 登录后") + break + else: + self.log(f"登录后打开店铺失败: {browser}", "WARNING") + driver = None + else: + self.log(f"店铺 {shop_name} 登录失败", "WARNING") + driver = None + else: + break + + except Exception as e: + import traceback + self.log(f"打开店铺异常: {traceback.format_exc()}", "INFO") + driver = None + error_info = str(e) + time.sleep(10) + + # 如果还有重试机会,等待后继续 + if retry < max_retries - 1: + time.sleep(3) + + # 检查是否成功打开 + if not driver or not browser or browser == "店铺不存在": + error_msg = f"店铺 {shop_name} 打开失败,已重试 {max_retries} 次,跳过该店铺,{error_info}" + self.log(error_msg, "ERROR") + # 从执行列表中移除 + if shop_name in runing_shop: + del runing_shop[shop_name] + return driver + return driver + # def process_shop(self, shop_item: dict, country_codes: list, task_id: int, risk_listing_filter: str): def process_shop(self, shop_item: dict, country_codes: list, task_id: int, risk_listing_filter: str, user_id=None, stage_index=None, final_stage: bool = True,limit:str=None): @@ -339,124 +421,52 @@ class MatchTak: # 店铺打开重试最多3次 driver = None max_retries = 3 - - error_info = "" - for retry in range(max_retries): + iskill = False + + # 处理每个国家 + for country_code in country_codes: + # 检查是否收到暂停请求 + if task_id in runing_task and runing_task[task_id].get("stop_requested", False): + self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "WARNING") + break + + # 打开店铺 + driver = self.open_shop(max_retries=max_retries, company_name=company_name, + shop_name=shop_name, iskill=iskill) + if driver is None: + self.log(f"任务 {task_id} 启动店铺失败,结束任务", "ERROR") + for country_code in country_codes: + self.post_result(task_id, shop_name, country_code, "", "", is_done=True) + return + try: - self.log(f"尝试打开店铺 {shop_name} (第 {retry + 1}/{max_retries} 次)") - - # 如果不是第一次尝试,先杀进程 - # if retry > 0: - # self.log("重试前先杀掉浏览器进程...") - # kill_process("v6") - # kill_process("v5") - # time.sleep(2) - - # 组装用户信息并创建驱动 - user_info = { - **self.user_info, - "company": company_name - } - driver = AmzoneMatchAction(user_info) - browser = driver.open_shop(shop_name) - - if browser and browser != "店铺不存在": - self.log(f"成功打开店铺 {shop_name}") - else: - self.log(f"打开店铺失败: {browser}", "WARNING") - driver = None - continue - - # 判断是否需要登录 - need_login = driver.need_login() - print("【是否需要登录】:",need_login) - if need_login: - self.log(f"店铺 {shop_name} 需要登录,正在登录...") - # 获取店铺凭证 - response = get_shop_info(shop_name) - print("【获取店铺凭证返回】:",response.text) - shop_data = response.json() - if not shop_data: - mes = f"获取店铺凭证失败,响应数据: {shop_data.get('message', '未知错误')}" - self.log(mes, "ERROR") - show_notification(mes, "ERROR") - continue - - password = shop_data["data"]["password"] - - login_success = driver.login(password) - if login_success: - self.log(f"店铺 {shop_name} 登录成功,正在重新打开店铺...") - browser = driver.open_shop(shop_name) - if browser and browser != "店铺不存在": - self.log(f"成功打开店铺 {shop_name} 登录后") - break - else: - self.log(f"登录后打开店铺失败: {browser}", "WARNING") - driver = None - else: - self.log(f"店铺 {shop_name} 登录失败", "WARNING") - driver = None - else: - break - + self.process_country(driver, country_code, task_id, shop_name,risk_listing_filter,limit) except Exception as e: import traceback - self.log(f"打开店铺异常: {traceback.format_exc()}", "INFO") - driver = None - error_info = str(e) - time.sleep(10) - - # 如果还有重试机会,等待后继续 - if retry < max_retries - 1: - time.sleep(3) - - # 检查是否成功打开 - if not driver or not browser or browser == "店铺不存在": - error_msg = f"店铺 {shop_name} 打开失败,已重试 {max_retries} 次,跳过该店铺,{error_info}" - self.log(error_msg, "ERROR") - # 从执行列表中移除 - if shop_name in runing_shop: - del runing_shop[shop_name] - return - + self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR") + self.log(traceback.format_exc(), "ERROR") + if "与页面的连接已断开" in e: + iskill = True + + # 更新已处理国家数 + if task_id in runing_task: + runing_task[task_id]["processed_countries"] += 1 + + # 最后回传,标记完成 try: - # 处理每个国家 - for country_code in country_codes: - # 检查是否收到暂停请求 - if task_id in runing_task and runing_task[task_id].get("stop_requested", False): - self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "WARNING") - break - - try: - self.process_country(driver, country_code, task_id, shop_name,risk_listing_filter,limit) - except Exception as e: - import traceback - self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR") - self.log(traceback.format_exc(), "ERROR") - # 最后回传,标记完成 - try: - # self.post_result(task_id, shop_name, country_code, "", "", is_done=True) - if final_stage: - self.post_result(task_id, shop_name, country_code, "", "", is_done=True) - else: - self.post_stage_finished(task_id, user_id, stage_index) - except Exception as e: - self.log(f"回传结果失败: {str(e)}", "ERROR") - finally: - # 关闭店铺 - try: - if driver: - self.log(f"关闭店铺 {shop_name}") - driver.close_store() - time.sleep(2) - except Exception as e: - self.log(f"关闭店铺失败: {str(e)}", "WARNING") - - # 从正在执行中的店铺列表中移除 - if shop_name in runing_shop: - del runing_shop[shop_name] - self.log(f"店铺 {shop_name} 已从执行列表中移除") + # self.post_result(task_id, shop_name, country_code, "", "", is_done=True) + if final_stage: + self.post_result(task_id, shop_name, country_code, "", "", is_done=True) + else: + self.post_stage_finished(task_id, user_id, stage_index) + except Exception as e: + self.log(f"回传结果失败: {str(e)}", "ERROR") + + + # 从正在执行中的店铺列表中移除 + if shop_name in runing_shop: + del runing_shop[shop_name] + self.log(f"店铺 {shop_name} 已从执行列表中移除") def process_country(self, driver: AmzoneMatchAction, country_code: str, task_id: int, shop_name: str, risk_listing_filter: str,limit:str=None): """处理单个国家的审批任务 @@ -487,7 +497,16 @@ class MatchTak: for retry in range(max_retries): try: self.log(f"尝试切换到国家 {country_name} (第 {retry + 1}/{max_retries} 次)") - + if retry > 1: + # 刷新不行就重新打开店铺 + self.log("重试前重新打开店铺...") + try: + driver.close_store() + time.sleep(3) + driver.open_shop(shop_name) + except Exception as e: + self.log(f"关闭重新打开店铺: {str(e)}", "WARNING") + # 如果不是第一次尝试,先刷新页面 if retry > 0: self.log("重试前刷新页面...") @@ -559,36 +578,28 @@ class MatchTak: self.log(f"国家 {country_name} 搜索出 {len(sku_ls)} 商品,开始处理...") # 处理所有需要审批的商品(通过yield获取结果) - try: - for asin, status in driver.run_page_action(): - # 检查是否收到暂停请求 - if task_id in runing_task and runing_task[task_id].get("stop_requested", False): - self.log(f"检测到任务 {task_id} 的暂停请求,停止处理ASIN", "WARNING") - break - - self.log(f"ASIN {asin} 处理结果: {status}") - - # 更新任务状态 - if task_id in runing_task: - runing_task[task_id]["current_asin"] = asin - runing_task[task_id]["processed_asins"] += 1 + for asin, status in driver.run_page_action(): + # 检查是否收到暂停请求 + if task_id in runing_task and runing_task[task_id].get("stop_requested", False): + self.log(f"检测到任务 {task_id} 的暂停请求,停止处理ASIN", "WARNING") + break + + self.log(f"ASIN {asin} 处理结果: {status}") + + # 更新任务状态 + if task_id in runing_task: + runing_task[task_id]["current_asin"] = asin + runing_task[task_id]["processed_asins"] += 1 + + runing_task[task_id]["failed_count"] += 1 + + # 回传结果到API + try: + self.post_result(task_id, shop_name, country_code, asin, status) + except Exception as e: + self.log(f"回传结果失败: {str(e)}", "ERROR") - runing_task[task_id]["failed_count"] += 1 - - # 回传结果到API - try: - self.post_result(task_id, shop_name, country_code, asin, status) - except Exception as e: - self.log(f"回传结果失败: {str(e)}", "ERROR") - - except Exception as e: - import traceback - self.log(f"处理审批商品异常: {str(e)}", "ERROR") - self.log(traceback.format_exc(), "ERROR") - - # 更新已处理国家数 - if task_id in runing_task: - runing_task[task_id]["processed_countries"] += 1 + self.log(f"国家 {country_name} 处理完成") diff --git a/app/amazon/price_match.py b/app/amazon/price_match.py index 08e393f..73ee741 100644 --- a/app/amazon/price_match.py +++ b/app/amazon/price_match.py @@ -114,6 +114,30 @@ def calculate_standard_competitor_pricing(my_current_price, target_competitor_pr class ChromeAmzone: mark_name = "亚马逊详情采集" + country_info = { + "英国": { + "url": "https://www.amazon.co.uk/dp/B0CJ8SNXXV", + "zip_code": "SW1A 1AA", + "mark": "SW1A 1" + }, + "德国": { + "url": "https://www.amazon.de/dp/B0CC8CW9G2?th=1", + "zip_code": "10115" + }, + "法国": { + "url": "https://www.amazon.fr/dp/B0FRG1MJ8H?th=1", + "zip_code": "75001" + }, + "西班牙": { + "url": "https://www.amazon.es/dp/B08ZXVNYNN", + "zip_code": "28001" + }, + "意大利": { + "url": "https://www.amazon.it/dp/B0D1P17T2Q", + "zip_code": "20121" + } + } + def __init__(self,tab): self.tab = tab @@ -136,8 +160,92 @@ class ChromeAmzone: if len(accept_btn) > 0: accept_btn[0].click() + def _set_zip_code(self, zip_code, mark=None): + """ + 设置邮编 - def run(self): + Args: + zip_code: 目标邮编 + """ + try: + # 检查当前邮编 + zip_display = self.tab.ele('xpath://div[@id="glow-ingress-block"]', timeout=10) + + if zip_display: + current_text = zip_display.text + # print(f"当前地址信息: {current_text}") + # 先检查标识 + if mark is not None and mark in current_text: + print(f"邮编检测到标识: {mark},无需修改") + return True + # 检查是否已经包含目标邮编 + if zip_code in current_text: + print(f"邮编已经设置为: {zip_code},无需修改") + return True + + # 需要设置邮编 + print(f"正在设置邮编为: {zip_code}") + + # 点击地址选择按钮 + location_link = self.tab.ele('xpath://a[@id="nav-global-location-popover-link"]', timeout=10) + if not location_link: + print("找不到地址设置按钮") + return False + + location_link.click() + time.sleep(1) + + # 等待邮编输入框出现 + zip_input = self.tab.ele('xpath://input[@id="GLUXZipUpdateInput"]', timeout=10) + if not zip_input: + print("找不到邮编输入框") + return False + + # 输入邮编 + zip_input.input(zip_code, clear=True) + time.sleep(0.5) + + # 点击提交按钮 + submit_btn = self.tab.ele('xpath://input[@aria-labelledby="GLUXZipUpdate-announce"]', timeout=10) + if not submit_btn: + print("找不到提交按钮") + return False + + submit_btn.click() + + continue_btn = self.tab.eles('xpath://div[@class="a-popover-footer"]//input[@id="GLUXConfirmClose"]', + timeout=10) + if len(continue_btn) > 0: + continue_btn[0].click() + + # 等待提交按钮消失(表示请求已发送) + print("等待邮编更新...") + time.sleep(2) + + # 等待页面加载完成 + self.tab.wait.doc_loaded(timeout=30, raise_err=False) + time.sleep(2) + + # 验证邮编是否设置成功 + zip_display_after = self.tab.ele('xpath://div[@id="glow-ingress-block"]', timeout=10) + if zip_display_after: + updated_text = zip_display_after.text + # print(f"更新后的地址信息: {updated_text}") + + if zip_code in updated_text: + print(f"邮编设置成功: {zip_code}") + return True + else: + # print(f"邮编设置可能失败,当前显示: {updated_text}") + return False + + return True + + except Exception as e: + print(f"设置邮编时出错: {traceback.format_exc()}") + return False + + def run(self,country): """ 运行亚马逊详情采集任务 @@ -149,6 +257,20 @@ class ChromeAmzone: dict: 包含采集到的数据 """ try: + if country not in self.country_info: + error_msg = f"不支持的国家: {country},支持的国家有: {list(self.country_info.keys())}" + print(error_msg) + show_notification(error_msg, "error") + return None + # 获取国家配置 + country_config = self.country_info[country] + zip_code = country_config["zip_code"] + mark = country_config.get("mark") + + self._set_zip_code(zip_code,mark) + + self.tab.wait.doc_loaded(timeout=5,raise_err=False) + self.tab.wait.doc_loaded(timeout=30, raise_err=False) @@ -379,7 +501,15 @@ class AmzonePriceMatch(AmamzonBase): print("当前操作的tab_id",self.tab.tab_id) self.browser.close_tabs(close_tab) - def run_page_action(self,current_shop_name:str,appoint_asin:str=None,skip_asin:list=[]): + def run_page_action(self,current_shop_name:str,mode:str, + appoint_asin:str=None,skip_asin:list=[],miniprice_info:dict={}): + """ + + miniprice_info : + { + "B0DSJGJBWV" : "19.81" # asin : 最低价 + } + """ print(f"【{self.mark_name}】,开始执行") num = 0 retry_num = 0 @@ -453,6 +583,24 @@ class AmzonePriceMatch(AmamzonBase): if len(current_price_ele) > 0: current_price = current_price_ele[0].attr("value") print("获取到当前价格为 ->",current_price) + # 如果紫鸟里当前价格低于最低价则删除,否则跳过 + if mode == "status" and miniprice_info.get(asin): + backend_price = float(miniprice_info.get(asin)) + if float(current_price) < backend_price: + yield (asin, { + "statu": "删除(当前价格低于最低价)", + "deleteSkipAsin": True, + "removeAsin": asin, + }) + continue + else: + yield (asin, { + "statu": "跳过(当前价格不低于最低价)", + "deleteSkipAsin": True, + "removeAsin": asin, + }) + continue + else: print(f"{self.mark_name} 没有获取到当前价格") yield (asin, { @@ -476,10 +624,16 @@ class AmzonePriceMatch(AmamzonBase): time.sleep(1) pass chrome = ChromeAmzone(tab=new_tab) - front_end_data = chrome.run() + front_end_data = chrome.run(country=current_country) chrome.close() print(self.mark_name,"亚马逊前台抓取到数据",front_end_data) - # + if front_end_data is None or len(front_end_data.get("top_sellers")) == 0: + yield (asin, { + "statu": "失败(第一名获取失败,请检查卖家精灵是否启用)", + "currentPrice": current_price, + }) + continue + cart_seller = front_end_data.get("cart_seller") if cart_seller == current_shop_name and len(front_end_data.get("top_sellers"))< 2: yield (asin, { @@ -769,6 +923,8 @@ class PriceTask: shopMallName = shop_item.get("shopMallName","") skip_asins_by_country = shop_item.get("skip_asins_by_country",{}) asin_rows_by_country = shop_item.get("asin_rows_by_country",{}) + skip_asin_details_by_country = shop_item.get("skip_asin_details_by_country",{}) + mode = shop_item.get("mode") if not company_name: self.log(f"店铺 {shop_name} 的公司名称为空,跳过", "WARNING") @@ -785,56 +941,61 @@ class PriceTask: # 店铺打开重试最多3次 driver = None max_retries = 3 + iskill = False + # 处理每个国家 + for country_code in country_codes: + # 打开店铺 + driver = self.open_shop(max_retries=max_retries, company_name=company_name, + shop_name=shop_name,iskill=iskill) + if driver is None: + self.log(f"任务 {task_id} 启动店铺失败,结束任务", "ERROR") + for country_code in country_codes: + self.post_result(task_id, shop_name, country_code, "", {}, shopMallName, is_done=True) + return - # 打开店铺 - driver = self.open_shop(max_retries=max_retries,company_name=company_name,shop_name=shop_name) - if driver is None: - self.log(f"任务 {task_id} 启动店铺失败,结束任务", "ERROR") - for country_code in country_codes: - self.post_result(task_id, shop_name, country_code, "", {}, shopMallName, is_done=True) - return - try: - # 处理每个国家 - for country_code in country_codes: - # 检查是否收到暂停请求 - if task_id in runing_task and runing_task[task_id].get("stop_requested", False): - self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "WARNING") - break - skip_asin = skip_asins_by_country.get(country_code,[]) #需要跳过的asin - appoint_asin = asin_rows_by_country.get(country_code,[]) - try: - self.process_country(driver, country_code, task_id, shop_name, risk_listing_filter, - shopMallName=shopMallName,skip_asin=skip_asin, limit=limit,appoint_asin=appoint_asin) - except Exception as e: - import traceback - self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR") - self.log(traceback.format_exc(), "ERROR") - # 最后回传,标记完成 + # 检查是否收到暂停请求 + if task_id in runing_task and runing_task[task_id].get("stop_requested", False): + self.log(f"检测到任务 {task_id} 的暂停请求,停止处理国家", "WARNING") + break + skip_asin = skip_asins_by_country.get(country_code,[]) #需要跳过的asin + appoint_asin = asin_rows_by_country.get(country_code,[]) + miniprice_info = {i.get('asin'):i.get('minimumPrice') for i in skip_asin_details_by_country.get(country_code,[])} try: - # self.post_result(task_id, shop_name, country_code, "", "", is_done=True) - if final_stage: - self.post_result(task_id, shop_name, country_code, "", {},shopMallName,is_done=True) - else: - self.post_stage_finished(task_id, user_id, stage_index) + self.process_country(driver, country_code, task_id, shop_name, risk_listing_filter, + shopMallName=shopMallName,skip_asin=skip_asin, limit=limit, + appoint_asin=appoint_asin,mode=mode,miniprice_info=miniprice_info) except Exception as e: - self.log(f"回传结果失败: {str(e)}", "ERROR") - finally: + import traceback + self.log(f"处理国家 {country_code} 失败: {str(e)}", "ERROR") + self.log(traceback.format_exc(), "ERROR") + if "与页面的连接已断开" in e: + iskill = True + # 更新已处理国家数 + if task_id in runing_task: + runing_task[task_id]["processed_countries"] += 1 + # 关闭店铺 - try: - if driver: - self.log(f"关闭店铺 {shop_name}") - driver.close_store() - time.sleep(2) - except Exception as e: - self.log(f"关闭店铺失败: {str(e)}", "WARNING") + driver.close_store() + + # 最后回传,标记完成 + try: + # self.post_result(task_id, shop_name, country_code, "", "", is_done=True) + if final_stage: + self.post_result(task_id, shop_name, country_code, "", {},shopMallName,is_done=True) + else: + self.post_stage_finished(task_id, user_id, stage_index) + except Exception as e: + self.log(f"回传结果失败: {str(e)}", "ERROR") - # 从正在执行中的店铺列表中移除 - if shop_name in runing_shop: - del runing_shop[shop_name] - self.log(f"店铺 {shop_name} 已从执行列表中移除") + # 从正在执行中的店铺列表中移除 + if shop_name in runing_shop: + del runing_shop[shop_name] + self.log(f"店铺 {shop_name} 已从执行列表中移除") def process_country(self, driver: AmzonePriceMatch, country_code: str, task_id: int, shop_name: str, - risk_listing_filter: str,shopMallName:str,skip_asin:list,appoint_asin:list,limit: str = None): + risk_listing_filter: str,shopMallName:str,skip_asin:list,appoint_asin:list,mode:str, + miniprice_info:dict={}, + limit: str = None): """处理单个国家的审批任务 Args: @@ -864,7 +1025,7 @@ class PriceTask: self.log(f"尝试切换到国家 {country_name} (第 {retry + 1}/{max_retries} 次)") if retry > 1: # 刷新不行就重新打开店铺 - self.log("重试前刷新页面...") + self.log("重试前重新打开店铺...") try: driver.close_store() time.sleep(3) @@ -946,49 +1107,41 @@ class PriceTask: self.log(f"国家 {country_name} 搜索出 {len(sku_ls)} 商品,开始处理...") # 处理所有需要审批的商品(通过yield获取结果) - try: - # 指定 asin - max_range = max(1,len(appoint_asin)) - for i in range(max_range): - if len(appoint_asin) > i: - _shopMallName = appoint_asin[i]["shopMallName"] - ap_asin = appoint_asin[i]["shopMallName"] - else: - _shopMallName = shopMallName - ap_asin = None - for asin, status in driver.run_page_action( - current_shop_name=_shopMallName, - appoint_asin=ap_asin,skip_asin=skip_asin - ): - # 检查是否收到暂停请求 - if task_id in runing_task and runing_task[task_id].get("stop_requested", False): - self.log(f"检测到任务 {task_id} 的暂停请求,停止处理ASIN", "WARNING") - break + # 指定 asin + max_range = max(1,len(appoint_asin)) + for i in range(max_range): + if len(appoint_asin) > i: + _shopMallName = appoint_asin[i]["shopMallName"] + ap_asin = appoint_asin[i]["shopMallName"] + else: + _shopMallName = shopMallName + ap_asin = None - self.log(f"ASIN {asin} 处理结果: {status}") + for asin, status in driver.run_page_action( + current_shop_name=_shopMallName, + appoint_asin=ap_asin,skip_asin=skip_asin,mode=mode, + miniprice_info=miniprice_info + ): + # 检查是否收到暂停请求 + if task_id in runing_task and runing_task[task_id].get("stop_requested", False): + self.log(f"检测到任务 {task_id} 的暂停请求,停止处理ASIN", "WARNING") + break - # 更新任务状态 - if task_id in runing_task: - runing_task[task_id]["current_asin"] = asin - runing_task[task_id]["processed_asins"] += 1 + self.log(f"ASIN {asin} 处理结果: {status}") - runing_task[task_id]["failed_count"] += 1 + # 更新任务状态 + if task_id in runing_task: + runing_task[task_id]["current_asin"] = asin + runing_task[task_id]["processed_asins"] += 1 - # 回传结果到API - try: - self.post_result(task_id, shop_name, country_code, asin, status,shopMallName) - except Exception as e: - self.log(f"回传结果失败: {str(e)}", "ERROR") + runing_task[task_id]["failed_count"] += 1 - except Exception as e: - import traceback - self.log(f"处理审批商品异常: {str(e)}", "ERROR") - self.log(traceback.format_exc(), "ERROR") - - # 更新已处理国家数 - if task_id in runing_task: - runing_task[task_id]["processed_countries"] += 1 + # 回传结果到API + try: + self.post_result(task_id, shop_name, country_code, asin, status,shopMallName) + except Exception as e: + self.log(f"回传结果失败: {str(e)}", "ERROR") self.log(f"国家 {country_name} 处理完成") @@ -1073,6 +1226,8 @@ class PriceTask: "secondPlace": status.get("secondPlace") if status.get("secondPlace") else "", "cartShopName": status.get("cartShopName") if status.get("cartShopName") else "", "priceChangeStatus": "UPDATED", + "deleteSkipAsin": status.get("deleteSkipAsin",False), + "removeAsin": status.get("removeAsin") if status.get("removeAsin") else "", # "modifyCount": "2", "status": status.get("statu") } diff --git a/app/assets/convert.js b/app/assets/convert.js index 9363954..5222ea0 100644 --- a/app/assets/convert.js +++ b/app/assets/convert.js @@ -1 +1 @@ -import{d as A,o as H,a as n,c as o,b as z,B as K,e as s,F as w,r as F,t as r,f as _,n as E,w as M,s as j,u as q,g as u,h as T,x as J,i as k,E as i,y as L,z as O,A as G,_ as Q,p as W,q as X}from"./pywebview-DuyK2jB1.js";import{e as Y}from"./brand-CKgrwtni.js";const Z={class:"page-shell module-page"},ee={class:"main-content"},se={class:"left-panel"},te={class:"upload-zone"},ae={class:"selected-files clean-placeholder"},le={key:0,class:"more-line"},ne={key:1},oe={class:"option-group"},ie=["value"],re={class:"template-item-content"},ce={class:"label"},ue={key:0,class:"template-tag"},de={key:1,class:"template-tag muted"},ve={key:2,class:"template-tag custom"},pe={class:"desc"},_e={key:0,class:"empty-option"},fe={class:"option-group"},me={class:"radio-item active"},he={class:"desc"},ye={class:"run-row"},ge=["disabled"],be={class:"loading-msg"},we={class:"right-panel"},ke={class:"task-list-wrap"},Ce={class:"clean-result-summary"},xe={class:"summary-card"},Fe={class:"summary-card"},Pe={class:"summary-card"},Ee={class:"result-list-wrap"},Te={key:0,class:"empty-tasks"},Ie={key:1,class:"task-list clean-result-list"},Be={class:"left"},Ne=["title"],$e={key:0,class:"files"},De={key:1,class:"files"},Re={class:"task-right"},Se=["onClick"],Ue=["onClick"],Ve=A({__name:"BrandConvertTab",setup(He){const v=u([]),g=u(""),f=u([]),m=u(!1),b=u([]),h=u({total:0,successCount:0,failedCount:0,items:[]}),d=u([]),c=u(""),C=T(()=>v.value.slice(0,8)),I=T(()=>d.value.find(a=>a.id===c.value)||null);async function P(a){const e=k();if(!e?.upload_file_to_java)throw new Error("当前桌面端未提供文件上传桥接能力");const t=[];for(const l of a){const p=typeof l=="string"?l:l.absolutePath,V=typeof l=="string"?void 0:l.relativePath,y=await e.upload_file_to_java(p,V);if(!y?.success||!y.data)throw new Error(y?.error||y?.message||`上传失败:${p}`);t.push(y.data)}return t}async function B(a){const e=await J();d.value=e||[];const t=d.value.find(p=>p.id===c.value);if(t){c.value=t.id;return}const l=d.value.find(p=>p.isDefault);if(l){c.value=l.id;return}c.value=d.value[0]?.id||""}async function N(a,e){v.value=a,g.value="",f.value=await P(a),i.success(e)}async function $(){const a=k();if(!a?.select_brand_xlsx_files){i.warning("当前环境不支持文件选择,请在本机客户端中打开");return}try{const e=await a.select_brand_xlsx_files();if(!e?.length)return;await N(e,`已选择 ${e.length} 个待转换文件`)}catch(e){i.error(e instanceof Error?e.message:"选择失败")}}async function D(){const a=k();if(!a?.select_brand_folder){i.warning("当前环境不支持文件夹选择,请在本机客户端中打开");return}try{const e=await a.select_brand_folder();if(!e)return;g.value=e.split(/[/\\]/).filter(Boolean).pop()||"";const t=await Y(e);if(t.success&&t.items?.length){v.value=t.items.map(l=>l.relativePath),f.value=await P(t.items),i.success(`已选择文件夹内 ${t.items.length} 个 xlsx 文件`);return}i.warning(t.error||"该文件夹下没有 xlsx 文件")}catch(e){i.error(e instanceof Error?e.message:"选择失败")}}async function R(){if(!f.value.length){i.warning("请先选择待转换 Excel 文件或文件夹");return}if(!c.value){i.warning("请先选择模板");return}try{m.value=!0;const a=await L({files:f.value.map(e=>({fileKey:e.fileKey,originalFilename:e.originalFilename,relativePath:e.relativePath})),templateId:c.value,archiveName:f.value.some(e=>!!e.relativePath)&&g.value?g.value:void 0});h.value=a,b.value=a.items||[],await x(),i.success("格式转换完成")}catch(a){i.error(a instanceof Error?a.message:"格式转换失败")}finally{m.value=!1}}async function x(){try{const a=await O();b.value=a.items||[],h.value={total:a.items?.length||0,successCount:a.items?.filter(e=>e.success).length||0,failedCount:a.items?.filter(e=>!e.success).length||0,items:a.items||[]}}catch{}}async function S(a){try{await G(a),await x(),i.success("已删除")}catch(e){i.error(e instanceof Error?e.message:"删除失败")}}async function U(a){const e=k();if(!a.downloadUrl){i.warning("当前结果没有下载地址");return}const t=a.outputFilename||`${new Date().toISOString().slice(0,10).replace(/-/g,"")}.txt`;if(e?.save_file_from_url_new){const l=await e.save_file_from_url_new(a.downloadUrl,t);l.success?i.success(`已保存:${l.path||t}`):l.error&&l.error!=="用户取消"&&i.error(l.error);return}}return H(()=>{B().catch(()=>{}),x().catch(()=>{})}),(a,e)=>(n(),o("div",Z,[z(K,{active:"convert"}),s("div",ee,[s("aside",se,[e[5]||(e[5]=s("div",{class:"section-title"},"选择文件",-1)),s("div",te,[e[1]||(e[1]=s("div",{class:"hint"},"选择需要转换的 Excel 文件或文件夹,将按所选模板生成 txt 文件。",-1)),s("div",{class:"btns"},[s("button",{type:"button",class:"opt-btn",onClick:$},"选择 Excel 文件"),s("button",{type:"button",class:"opt-btn",onClick:D},"选择文件夹")]),s("div",ae,[v.value.length?(n(),o(w,{key:0},[(n(!0),o(w,null,F(C.value,t=>(n(),o("span",{key:t},r(t),1))),128)),v.value.length>C.value.length?(n(),o("span",le," 还有 "+r(v.value.length-C.value.length)+" 个文件未展开显示 ",1)):_("",!0)],64)):(n(),o("span",ne,"暂未选择待转换文件"))])]),e[6]||(e[6]=s("div",{class:"section-title"},"模板选择",-1)),s("div",oe,[(n(!0),o(w,null,F(d.value,t=>(n(),o("label",{key:t.id,class:E(["radio-item",{active:c.value===t.id}])},[M(s("input",{"onUpdate:modelValue":e[0]||(e[0]=l=>c.value=l),type:"radio",value:t.id,name:"convert-template"},null,8,ie),[[j,c.value]]),s("div",re,[s("div",null,[s("span",ce,[q(r(t.templateName)+" ",1),t.isDefault?(n(),o("span",ue,"默认")):t.builtIn?(n(),o("span",de,"内置")):(n(),o("span",ve,"自定义"))]),s("div",pe,"输出文件:"+r(t.outputFilename),1)])])],2))),128)),d.value.length?_("",!0):(n(),o("div",_e,"暂无可用模板"))]),e[7]||(e[7]=s("div",{class:"section-title"},"转换说明",-1)),s("div",fe,[s("label",me,[e[3]||(e[3]=s("input",{type:"checkbox",checked:"",disabled:""},null,-1)),s("div",null,[e[2]||(e[2]=s("span",{class:"label"},"按当前模板输出",-1)),s("div",he,"当前模板:"+r(I.value?.templateName||"未加载模板"),1)])]),e[4]||(e[4]=s("label",{class:"radio-item active"},[s("input",{type:"checkbox",checked:"",disabled:""}),s("div",null,[s("span",{class:"label"},"SKU 使用雪花ID-序号"),s("div",{class:"desc"},"例如 1773816146796-1")])],-1))]),s("div",ye,[s("button",{type:"button",class:"btn-run",disabled:m.value,onClick:R},r(m.value?"转换中...":"开始转换"),9,ge),s("span",be,r(m.value?"正在生成并上传结果,请稍候…":"选择文件后即可执行格式转换,结果会显示在右侧供下载"),1)])]),s("section",we,[e[12]||(e[12]=s("div",{class:"panel-header"},"转换结果",-1)),s("div",ke,[s("div",Ce,[s("div",xe,[e[8]||(e[8]=s("span",{class:"summary-label"},"已处理文件",-1)),s("strong",null,r(h.value.total),1)]),s("div",Fe,[e[9]||(e[9]=s("span",{class:"summary-label"},"成功结果",-1)),s("strong",null,r(h.value.successCount),1)]),s("div",Pe,[e[10]||(e[10]=s("span",{class:"summary-label"},"失败文件",-1)),s("strong",null,r(h.value.failedCount),1)])]),s("div",Ee,[e[11]||(e[11]=s("div",{class:"result-list-header"},[s("span",null,"生成的结果压缩包列表")],-1)),b.value.length===0?(n(),o("div",Te," 暂无转换结果,完成格式转换后会在这里展示结果压缩包 ")):(n(),o("ul",Ie,[(n(!0),o(w,null,F(b.value,t=>(n(),o("li",{key:`${t.resultId||t.outputFilename||t.sourceFilename}`,class:"task-item"},[s("div",Be,[s("span",{class:"id",title:t.sourceFilename},r(t.sourceFilename||"-"),9,Ne),t.outputFilename?(n(),o("div",$e,"压缩包文件:"+r(t.outputFilename),1)):_("",!0),t.error?(n(),o("div",De,"错误信息:"+r(t.error),1)):_("",!0)]),s("div",Re,[s("span",{class:E(["status",t.success?"success":"failed"])},r(t.success?"已完成":"失败"),3),t.success&&t.downloadUrl?(n(),o("button",{key:0,type:"button",class:"download",onClick:l=>U(t)}," 下载压缩包 ",8,Se)):_("",!0),t.resultId?(n(),o("button",{key:1,type:"button",class:"btn-delete",onClick:l=>S(t.resultId)}," 删除 ",8,Ue)):_("",!0)])]))),128))]))])])])])]))}}),Ae=Q(Ve,[["__scopeId","data-v-7c280b44"]]);W(Ae).use(X).mount("#app"); +import{d as A,o as H,a as n,c as o,b as z,B as K,e as s,F as w,r as F,t as r,f as _,n as E,w as M,s as j,u as q,g as u,h as T,x as J,i as k,E as i,y as L,z as O,A as G,_ as Q,p as W,q as X}from"./pywebview-9YBa--7x.js";import{e as Y}from"./brand-CRmRvyGD.js";const Z={class:"page-shell module-page"},ee={class:"main-content"},se={class:"left-panel"},te={class:"upload-zone"},ae={class:"selected-files clean-placeholder"},le={key:0,class:"more-line"},ne={key:1},oe={class:"option-group"},ie=["value"],re={class:"template-item-content"},ce={class:"label"},ue={key:0,class:"template-tag"},de={key:1,class:"template-tag muted"},ve={key:2,class:"template-tag custom"},pe={class:"desc"},_e={key:0,class:"empty-option"},fe={class:"option-group"},me={class:"radio-item active"},he={class:"desc"},ye={class:"run-row"},ge=["disabled"],be={class:"loading-msg"},we={class:"right-panel"},ke={class:"task-list-wrap"},Ce={class:"clean-result-summary"},xe={class:"summary-card"},Fe={class:"summary-card"},Pe={class:"summary-card"},Ee={class:"result-list-wrap"},Te={key:0,class:"empty-tasks"},Ie={key:1,class:"task-list clean-result-list"},Be={class:"left"},Ne=["title"],$e={key:0,class:"files"},De={key:1,class:"files"},Re={class:"task-right"},Se=["onClick"],Ue=["onClick"],Ve=A({__name:"BrandConvertTab",setup(He){const v=u([]),g=u(""),f=u([]),m=u(!1),b=u([]),h=u({total:0,successCount:0,failedCount:0,items:[]}),d=u([]),c=u(""),C=T(()=>v.value.slice(0,8)),I=T(()=>d.value.find(a=>a.id===c.value)||null);async function P(a){const e=k();if(!e?.upload_file_to_java)throw new Error("当前桌面端未提供文件上传桥接能力");const t=[];for(const l of a){const p=typeof l=="string"?l:l.absolutePath,V=typeof l=="string"?void 0:l.relativePath,y=await e.upload_file_to_java(p,V);if(!y?.success||!y.data)throw new Error(y?.error||y?.message||`上传失败:${p}`);t.push(y.data)}return t}async function B(a){const e=await J();d.value=e||[];const t=d.value.find(p=>p.id===c.value);if(t){c.value=t.id;return}const l=d.value.find(p=>p.isDefault);if(l){c.value=l.id;return}c.value=d.value[0]?.id||""}async function N(a,e){v.value=a,g.value="",f.value=await P(a),i.success(e)}async function $(){const a=k();if(!a?.select_brand_xlsx_files){i.warning("当前环境不支持文件选择,请在本机客户端中打开");return}try{const e=await a.select_brand_xlsx_files();if(!e?.length)return;await N(e,`已选择 ${e.length} 个待转换文件`)}catch(e){i.error(e instanceof Error?e.message:"选择失败")}}async function D(){const a=k();if(!a?.select_brand_folder){i.warning("当前环境不支持文件夹选择,请在本机客户端中打开");return}try{const e=await a.select_brand_folder();if(!e)return;g.value=e.split(/[/\\]/).filter(Boolean).pop()||"";const t=await Y(e);if(t.success&&t.items?.length){v.value=t.items.map(l=>l.relativePath),f.value=await P(t.items),i.success(`已选择文件夹内 ${t.items.length} 个 xlsx 文件`);return}i.warning(t.error||"该文件夹下没有 xlsx 文件")}catch(e){i.error(e instanceof Error?e.message:"选择失败")}}async function R(){if(!f.value.length){i.warning("请先选择待转换 Excel 文件或文件夹");return}if(!c.value){i.warning("请先选择模板");return}try{m.value=!0;const a=await L({files:f.value.map(e=>({fileKey:e.fileKey,originalFilename:e.originalFilename,relativePath:e.relativePath})),templateId:c.value,archiveName:f.value.some(e=>!!e.relativePath)&&g.value?g.value:void 0});h.value=a,b.value=a.items||[],await x(),i.success("格式转换完成")}catch(a){i.error(a instanceof Error?a.message:"格式转换失败")}finally{m.value=!1}}async function x(){try{const a=await O();b.value=a.items||[],h.value={total:a.items?.length||0,successCount:a.items?.filter(e=>e.success).length||0,failedCount:a.items?.filter(e=>!e.success).length||0,items:a.items||[]}}catch{}}async function S(a){try{await G(a),await x(),i.success("已删除")}catch(e){i.error(e instanceof Error?e.message:"删除失败")}}async function U(a){const e=k();if(!a.downloadUrl){i.warning("当前结果没有下载地址");return}const t=a.outputFilename||`${new Date().toISOString().slice(0,10).replace(/-/g,"")}.txt`;if(e?.save_file_from_url_new){const l=await e.save_file_from_url_new(a.downloadUrl,t);l.success?i.success(`已保存:${l.path||t}`):l.error&&l.error!=="用户取消"&&i.error(l.error);return}}return H(()=>{B().catch(()=>{}),x().catch(()=>{})}),(a,e)=>(n(),o("div",Z,[z(K,{active:"convert"}),s("div",ee,[s("aside",se,[e[5]||(e[5]=s("div",{class:"section-title"},"选择文件",-1)),s("div",te,[e[1]||(e[1]=s("div",{class:"hint"},"选择需要转换的 Excel 文件或文件夹,将按所选模板生成 txt 文件。",-1)),s("div",{class:"btns"},[s("button",{type:"button",class:"opt-btn",onClick:$},"选择 Excel 文件"),s("button",{type:"button",class:"opt-btn",onClick:D},"选择文件夹")]),s("div",ae,[v.value.length?(n(),o(w,{key:0},[(n(!0),o(w,null,F(C.value,t=>(n(),o("span",{key:t},r(t),1))),128)),v.value.length>C.value.length?(n(),o("span",le," 还有 "+r(v.value.length-C.value.length)+" 个文件未展开显示 ",1)):_("",!0)],64)):(n(),o("span",ne,"暂未选择待转换文件"))])]),e[6]||(e[6]=s("div",{class:"section-title"},"模板选择",-1)),s("div",oe,[(n(!0),o(w,null,F(d.value,t=>(n(),o("label",{key:t.id,class:E(["radio-item",{active:c.value===t.id}])},[M(s("input",{"onUpdate:modelValue":e[0]||(e[0]=l=>c.value=l),type:"radio",value:t.id,name:"convert-template"},null,8,ie),[[j,c.value]]),s("div",re,[s("div",null,[s("span",ce,[q(r(t.templateName)+" ",1),t.isDefault?(n(),o("span",ue,"默认")):t.builtIn?(n(),o("span",de,"内置")):(n(),o("span",ve,"自定义"))]),s("div",pe,"输出文件:"+r(t.outputFilename),1)])])],2))),128)),d.value.length?_("",!0):(n(),o("div",_e,"暂无可用模板"))]),e[7]||(e[7]=s("div",{class:"section-title"},"转换说明",-1)),s("div",fe,[s("label",me,[e[3]||(e[3]=s("input",{type:"checkbox",checked:"",disabled:""},null,-1)),s("div",null,[e[2]||(e[2]=s("span",{class:"label"},"按当前模板输出",-1)),s("div",he,"当前模板:"+r(I.value?.templateName||"未加载模板"),1)])]),e[4]||(e[4]=s("label",{class:"radio-item active"},[s("input",{type:"checkbox",checked:"",disabled:""}),s("div",null,[s("span",{class:"label"},"SKU 使用雪花ID-序号"),s("div",{class:"desc"},"例如 1773816146796-1")])],-1))]),s("div",ye,[s("button",{type:"button",class:"btn-run",disabled:m.value,onClick:R},r(m.value?"转换中...":"开始转换"),9,ge),s("span",be,r(m.value?"正在生成并上传结果,请稍候…":"选择文件后即可执行格式转换,结果会显示在右侧供下载"),1)])]),s("section",we,[e[12]||(e[12]=s("div",{class:"panel-header"},"转换结果",-1)),s("div",ke,[s("div",Ce,[s("div",xe,[e[8]||(e[8]=s("span",{class:"summary-label"},"已处理文件",-1)),s("strong",null,r(h.value.total),1)]),s("div",Fe,[e[9]||(e[9]=s("span",{class:"summary-label"},"成功结果",-1)),s("strong",null,r(h.value.successCount),1)]),s("div",Pe,[e[10]||(e[10]=s("span",{class:"summary-label"},"失败文件",-1)),s("strong",null,r(h.value.failedCount),1)])]),s("div",Ee,[e[11]||(e[11]=s("div",{class:"result-list-header"},[s("span",null,"生成的结果压缩包列表")],-1)),b.value.length===0?(n(),o("div",Te," 暂无转换结果,完成格式转换后会在这里展示结果压缩包 ")):(n(),o("ul",Ie,[(n(!0),o(w,null,F(b.value,t=>(n(),o("li",{key:`${t.resultId||t.outputFilename||t.sourceFilename}`,class:"task-item"},[s("div",Be,[s("span",{class:"id",title:t.sourceFilename},r(t.sourceFilename||"-"),9,Ne),t.outputFilename?(n(),o("div",$e,"压缩包文件:"+r(t.outputFilename),1)):_("",!0),t.error?(n(),o("div",De,"错误信息:"+r(t.error),1)):_("",!0)]),s("div",Re,[s("span",{class:E(["status",t.success?"success":"failed"])},r(t.success?"已完成":"失败"),3),t.success&&t.downloadUrl?(n(),o("button",{key:0,type:"button",class:"download",onClick:l=>U(t)}," 下载压缩包 ",8,Se)):_("",!0),t.resultId?(n(),o("button",{key:1,type:"button",class:"btn-delete",onClick:l=>S(t.resultId)}," 删除 ",8,Ue)):_("",!0)])]))),128))]))])])])])]))}}),Ae=Q(Ve,[["__scopeId","data-v-7c280b44"]]);W(Ae).use(X).mount("#app"); diff --git a/app/assets/dedupe.js b/app/assets/dedupe.js index fd8a71d..8819953 100644 --- a/app/assets/dedupe.js +++ b/app/assets/dedupe.js @@ -1 +1 @@ -import{d as z,o as W,a as n,c as o,b as q,B as J,e as s,F as C,r as F,t as i,f as b,n as I,w as P,v as B,g as u,h as L,i as x,E as r,j as O,k as G,l as Q,m as X,_ as Y,p as Z,q as ee}from"./pywebview-DuyK2jB1.js";import{e as se}from"./brand-CKgrwtni.js";const te={class:"page-shell module-page"},le={class:"main-content"},ae={class:"left-panel"},ne={class:"upload-zone"},oe={class:"selected-files clean-placeholder"},re={key:0,class:"more-line"},ie={key:1},ue={class:"option-group column-option-group"},ce={class:"column-toolbar"},de={class:"column-count"},ve={key:0,class:"column-grid"},pe=["value"],fe={key:1,class:"empty-column-state"},_e={class:"option-group"},me={class:"run-row"},he=["disabled"],ge={class:"loading-msg"},ye={class:"right-panel"},be={class:"task-list-wrap"},we={class:"clean-result-summary"},ke={class:"summary-card"},Ce={class:"summary-card"},Ie={class:"summary-card"},xe={class:"result-list-wrap"},Ee={key:0,class:"empty-tasks"},De={key:1,class:"task-list clean-result-list"},Fe={class:"left"},Pe=["title"],Be={key:0,class:"files"},Se={key:1,class:"files"},Ue={class:"task-right"},Ne=["onClick"],$e=["onClick"],Ae=z({__name:"BrandDedupeTab",setup(Ke){const p=u([]),c=u([]),f=u([]),w=u(""),d=u([]),S=u(!1),_=u(!0),m=u(!0),h=u(!1),k=u([]),g=u({total:0,successCount:0,failedCount:0,items:[]}),E=L(()=>f.value.slice(0,8));function $(){c.value=[...p.value]}function A(){c.value=[]}async function U(l){const e=x();if(!e?.upload_file_to_java)throw new Error("当前桌面端未提供文件上传桥接能力");const t=[];for(const a of l){const v=typeof a=="string"?a:a.absolutePath,j=typeof a=="string"?void 0:a.relativePath,y=await e.upload_file_to_java(v,j);if(!y?.success||!y.data)throw new Error(y?.error||y?.message||`上传失败:${v}`);t.push(y.data)}return t}async function N(l){const e=await X(l);if(!e.headers?.length){r.error("读取 Excel 表头失败"),p.value=[],c.value=[];return}const t=["id","ASIN","国家","价格","卖家名称"],a=[...t.filter(v=>e.headers?.includes(v)),...(e.headers||[]).filter(v=>!t.includes(v))];p.value=a,c.value=t.filter(v=>a.includes(v))}async function H(l,e){f.value=l,w.value="",d.value=await U(l),d.value.length>0&&await N(d.value[0].fileKey),r.success(e)}async function K(){const l=x();if(!l?.select_brand_xlsx_files){r.warning("当前环境不支持文件选择,请在本机客户端中打开");return}try{const e=await l.select_brand_xlsx_files();if(!e?.length)return;await H(e,`已选择 ${e.length} 个待清洗文件`)}catch(e){r.error(e instanceof Error?e.message:"选择失败")}}async function R(){const l=x();if(!l?.select_brand_folder){r.warning("当前环境不支持文件夹选择,请在本机客户端中打开");return}try{const e=await l.select_brand_folder();if(!e)return;w.value=e.split(/[/\\]/).filter(Boolean).pop()||"";const t=await se(e);if(t.success&&t.items?.length){f.value=t.items.map(a=>a.relativePath),d.value=await U(t.items),d.value.length>0&&await N(d.value[0].fileKey),r.success(`已选择文件夹内 ${t.items.length} 个 xlsx 文件`);return}r.warning(t.error||"该文件夹下没有 xlsx 文件")}catch(e){r.error(e instanceof Error?e.message:"选择失败")}}async function V(){if(!d.value.length){r.warning("请先选择待清洗 Excel 文件或文件夹");return}if(!c.value.length){r.warning("请至少选择一列保留列");return}if(!S.value&&!_.value&&!m.value){r.warning("请至少选择一种 ID 保留规则");return}try{h.value=!0;const l=await O({files:d.value.map(e=>({fileKey:e.fileKey,originalFilename:e.originalFilename,relativePath:e.relativePath})),selectedColumns:c.value,keepIntegerIds:S.value,keepUnderscoreIds:_.value,keepIntegerMainIdsWhenNoSubIds:m.value,archiveName:d.value.some(e=>!!e.relativePath)&&w.value?w.value:void 0});g.value=l,k.value=l.items||[],await D(),r.success("数据去重完成")}catch(l){r.error(l instanceof Error?l.message:"去重失败")}finally{h.value=!1}}async function D(){try{const l=await G();k.value=l.items||[],g.value={total:l.items?.length||0,successCount:l.items?.filter(e=>e.success).length||0,failedCount:l.items?.filter(e=>!e.success).length||0,items:l.items||[]}}catch{}}async function M(l){try{await Q(l),await D(),r.success("已删除")}catch(e){r.error(e instanceof Error?e.message:"删除失败")}}async function T(l){const e=x();if(!l.downloadUrl){r.warning("当前结果没有下载地址");return}const t=l.outputFilename||`${new Date().toISOString().slice(0,10).replace(/-/g,"")}_cleaned.xlsx`;if(e?.save_file_from_url_new){const a=await e.save_file_from_url_new(l.downloadUrl,t);a.success?r.success(`已保存:${a.path||t}`):a.error&&a.error!=="用户取消"&&r.error(a.error);return}}return W(()=>{D().catch(()=>{})}),(l,e)=>(n(),o("div",te,[q(J,{active:"dedupe"}),s("div",le,[s("aside",ae,[e[7]||(e[7]=s("div",{class:"section-title"},"选择文件",-1)),s("div",ne,[e[3]||(e[3]=s("div",{class:"hint"},"选择需要清洗的 Excel 文件或文件夹,后续将按所选规则输出处理结果。",-1)),s("div",{class:"btns"},[s("button",{type:"button",class:"opt-btn",onClick:K},"选择 Excel 文件"),s("button",{type:"button",class:"opt-btn",onClick:R},"选择文件夹")]),s("div",oe,[f.value.length?(n(),o(C,{key:0},[(n(!0),o(C,null,F(E.value,t=>(n(),o("span",{key:t},i(t),1))),128)),f.value.length>E.value.length?(n(),o("span",re," 还有 "+i(f.value.length-E.value.length)+" 个文件未展开显示 ",1)):b("",!0)],64)):(n(),o("span",ie,"暂未选择待清洗文件"))])]),e[8]||(e[8]=s("div",{class:"section-title"},"保留列设置",-1)),s("div",ue,[s("div",ce,[s("span",de,"已选择 "+i(c.value.length)+" / "+i(p.value.length)+" 列",1),s("div",{class:"column-actions"},[s("button",{type:"button",class:"opt-btn small",onClick:$},"全选"),s("button",{type:"button",class:"opt-btn small",onClick:A},"清空")])]),p.value.length?(n(),o("div",ve,[(n(!0),o(C,null,F(p.value,t=>(n(),o("label",{key:t,class:I(["column-item",{active:c.value.includes(t)}])},[P(s("input",{"onUpdate:modelValue":e[0]||(e[0]=a=>c.value=a),type:"checkbox",value:t},null,8,pe),[[B,c.value]]),s("span",null,i(t),1)],2))),128))])):(n(),o("div",fe,"请选择 Excel 文件后读取表头并填充可保留列")),e[4]||(e[4]=s("div",{class:"desc"},"读取首个 Excel 文件的第一行作为表头,用于动态选择需要保留的列。",-1))]),e[9]||(e[9]=s("div",{class:"section-title"},"ID 保留规则",-1)),s("div",_e,[s("label",{class:I(["radio-item",{active:_.value}])},[P(s("input",{"onUpdate:modelValue":e[1]||(e[1]=t=>_.value=t),type:"checkbox"},null,512),[[B,_.value]]),e[5]||(e[5]=s("div",null,[s("span",{class:"label"},"保留子链接"),s("div",{class:"desc"},"例如 1_1、2_3 这种带下划线的子项 ID")],-1))],2),s("label",{class:I(["radio-item",{active:m.value}])},[P(s("input",{"onUpdate:modelValue":e[2]||(e[2]=t=>m.value=t),type:"checkbox"},null,512),[[B,m.value]]),e[6]||(e[6]=s("div",null,[s("span",{class:"label"},"仅剩主链接无子链接"),s("div",{class:"desc"},"当某个主链接只有 13 这类主 ID、没有 13_1 这类对应子 ID 时,自动保留该主 ID")],-1))],2)]),s("div",me,[s("button",{type:"button",class:"btn-run",disabled:h.value,onClick:V},i(h.value?"清洗中...":"开始清洗"),9,he),s("span",ge,i(h.value?"正在处理文件并上传结果,请稍候…":"选择文件、列和 ID 规则后即可执行清洗,结果会显示在右侧供下载"),1)])]),s("section",ye,[e[14]||(e[14]=s("div",{class:"panel-header"},"去重结果",-1)),s("div",be,[s("div",we,[s("div",ke,[e[10]||(e[10]=s("span",{class:"summary-label"},"已处理文件",-1)),s("strong",null,i(g.value.total),1)]),s("div",Ce,[e[11]||(e[11]=s("span",{class:"summary-label"},"成功结果",-1)),s("strong",null,i(g.value.successCount),1)]),s("div",Ie,[e[12]||(e[12]=s("span",{class:"summary-label"},"失败文件",-1)),s("strong",null,i(g.value.failedCount),1)])]),s("div",xe,[e[13]||(e[13]=s("div",{class:"result-list-header"},[s("span",null,"处理后的 Excel 列表")],-1)),k.value.length===0?(n(),o("div",Ee," 暂无去重结果,完成数据去重后会在这里展示输出文件 ")):(n(),o("ul",De,[(n(!0),o(C,null,F(k.value,t=>(n(),o("li",{key:`${t.resultId||t.outputFilename||t.sourceFilename}`,class:"task-item"},[s("div",Fe,[s("span",{class:"id",title:t.sourceFilename},i(t.sourceFilename||"-"),9,Pe),t.outputFilename?(n(),o("div",Be,"输出文件:"+i(t.outputFilename),1)):b("",!0),t.error?(n(),o("div",Se,"错误信息:"+i(t.error),1)):b("",!0)]),s("div",Ue,[s("span",{class:I(["status",t.success?"success":"failed"])},i(t.success?"已完成":"失败"),3),t.success&&t.downloadUrl?(n(),o("button",{key:0,type:"button",class:"download",onClick:a=>T(t)}," 下载文件 ",8,Ne)):b("",!0),t.resultId?(n(),o("button",{key:1,type:"button",class:"btn-delete",onClick:a=>M(t.resultId)}," 删除 ",8,$e)):b("",!0)])]))),128))]))])])])])]))}}),He=Y(Ae,[["__scopeId","data-v-bdaefe1c"]]);Z(He).use(ee).mount("#app"); +import{d as z,o as W,a as n,c as o,b as q,B as J,e as s,F as C,r as F,t as i,f as b,n as I,w as P,v as B,g as u,h as L,i as x,E as r,j as O,k as G,l as Q,m as X,_ as Y,p as Z,q as ee}from"./pywebview-9YBa--7x.js";import{e as se}from"./brand-CRmRvyGD.js";const te={class:"page-shell module-page"},le={class:"main-content"},ae={class:"left-panel"},ne={class:"upload-zone"},oe={class:"selected-files clean-placeholder"},re={key:0,class:"more-line"},ie={key:1},ue={class:"option-group column-option-group"},ce={class:"column-toolbar"},de={class:"column-count"},ve={key:0,class:"column-grid"},pe=["value"],fe={key:1,class:"empty-column-state"},_e={class:"option-group"},me={class:"run-row"},he=["disabled"],ge={class:"loading-msg"},ye={class:"right-panel"},be={class:"task-list-wrap"},we={class:"clean-result-summary"},ke={class:"summary-card"},Ce={class:"summary-card"},Ie={class:"summary-card"},xe={class:"result-list-wrap"},Ee={key:0,class:"empty-tasks"},De={key:1,class:"task-list clean-result-list"},Fe={class:"left"},Pe=["title"],Be={key:0,class:"files"},Se={key:1,class:"files"},Ue={class:"task-right"},Ne=["onClick"],$e=["onClick"],Ae=z({__name:"BrandDedupeTab",setup(Ke){const p=u([]),c=u([]),f=u([]),w=u(""),d=u([]),S=u(!1),_=u(!0),m=u(!0),h=u(!1),k=u([]),g=u({total:0,successCount:0,failedCount:0,items:[]}),E=L(()=>f.value.slice(0,8));function $(){c.value=[...p.value]}function A(){c.value=[]}async function U(l){const e=x();if(!e?.upload_file_to_java)throw new Error("当前桌面端未提供文件上传桥接能力");const t=[];for(const a of l){const v=typeof a=="string"?a:a.absolutePath,j=typeof a=="string"?void 0:a.relativePath,y=await e.upload_file_to_java(v,j);if(!y?.success||!y.data)throw new Error(y?.error||y?.message||`上传失败:${v}`);t.push(y.data)}return t}async function N(l){const e=await X(l);if(!e.headers?.length){r.error("读取 Excel 表头失败"),p.value=[],c.value=[];return}const t=["id","ASIN","国家","价格","卖家名称"],a=[...t.filter(v=>e.headers?.includes(v)),...(e.headers||[]).filter(v=>!t.includes(v))];p.value=a,c.value=t.filter(v=>a.includes(v))}async function H(l,e){f.value=l,w.value="",d.value=await U(l),d.value.length>0&&await N(d.value[0].fileKey),r.success(e)}async function K(){const l=x();if(!l?.select_brand_xlsx_files){r.warning("当前环境不支持文件选择,请在本机客户端中打开");return}try{const e=await l.select_brand_xlsx_files();if(!e?.length)return;await H(e,`已选择 ${e.length} 个待清洗文件`)}catch(e){r.error(e instanceof Error?e.message:"选择失败")}}async function R(){const l=x();if(!l?.select_brand_folder){r.warning("当前环境不支持文件夹选择,请在本机客户端中打开");return}try{const e=await l.select_brand_folder();if(!e)return;w.value=e.split(/[/\\]/).filter(Boolean).pop()||"";const t=await se(e);if(t.success&&t.items?.length){f.value=t.items.map(a=>a.relativePath),d.value=await U(t.items),d.value.length>0&&await N(d.value[0].fileKey),r.success(`已选择文件夹内 ${t.items.length} 个 xlsx 文件`);return}r.warning(t.error||"该文件夹下没有 xlsx 文件")}catch(e){r.error(e instanceof Error?e.message:"选择失败")}}async function V(){if(!d.value.length){r.warning("请先选择待清洗 Excel 文件或文件夹");return}if(!c.value.length){r.warning("请至少选择一列保留列");return}if(!S.value&&!_.value&&!m.value){r.warning("请至少选择一种 ID 保留规则");return}try{h.value=!0;const l=await O({files:d.value.map(e=>({fileKey:e.fileKey,originalFilename:e.originalFilename,relativePath:e.relativePath})),selectedColumns:c.value,keepIntegerIds:S.value,keepUnderscoreIds:_.value,keepIntegerMainIdsWhenNoSubIds:m.value,archiveName:d.value.some(e=>!!e.relativePath)&&w.value?w.value:void 0});g.value=l,k.value=l.items||[],await D(),r.success("数据去重完成")}catch(l){r.error(l instanceof Error?l.message:"去重失败")}finally{h.value=!1}}async function D(){try{const l=await G();k.value=l.items||[],g.value={total:l.items?.length||0,successCount:l.items?.filter(e=>e.success).length||0,failedCount:l.items?.filter(e=>!e.success).length||0,items:l.items||[]}}catch{}}async function M(l){try{await Q(l),await D(),r.success("已删除")}catch(e){r.error(e instanceof Error?e.message:"删除失败")}}async function T(l){const e=x();if(!l.downloadUrl){r.warning("当前结果没有下载地址");return}const t=l.outputFilename||`${new Date().toISOString().slice(0,10).replace(/-/g,"")}_cleaned.xlsx`;if(e?.save_file_from_url_new){const a=await e.save_file_from_url_new(l.downloadUrl,t);a.success?r.success(`已保存:${a.path||t}`):a.error&&a.error!=="用户取消"&&r.error(a.error);return}}return W(()=>{D().catch(()=>{})}),(l,e)=>(n(),o("div",te,[q(J,{active:"dedupe"}),s("div",le,[s("aside",ae,[e[7]||(e[7]=s("div",{class:"section-title"},"选择文件",-1)),s("div",ne,[e[3]||(e[3]=s("div",{class:"hint"},"选择需要清洗的 Excel 文件或文件夹,后续将按所选规则输出处理结果。",-1)),s("div",{class:"btns"},[s("button",{type:"button",class:"opt-btn",onClick:K},"选择 Excel 文件"),s("button",{type:"button",class:"opt-btn",onClick:R},"选择文件夹")]),s("div",oe,[f.value.length?(n(),o(C,{key:0},[(n(!0),o(C,null,F(E.value,t=>(n(),o("span",{key:t},i(t),1))),128)),f.value.length>E.value.length?(n(),o("span",re," 还有 "+i(f.value.length-E.value.length)+" 个文件未展开显示 ",1)):b("",!0)],64)):(n(),o("span",ie,"暂未选择待清洗文件"))])]),e[8]||(e[8]=s("div",{class:"section-title"},"保留列设置",-1)),s("div",ue,[s("div",ce,[s("span",de,"已选择 "+i(c.value.length)+" / "+i(p.value.length)+" 列",1),s("div",{class:"column-actions"},[s("button",{type:"button",class:"opt-btn small",onClick:$},"全选"),s("button",{type:"button",class:"opt-btn small",onClick:A},"清空")])]),p.value.length?(n(),o("div",ve,[(n(!0),o(C,null,F(p.value,t=>(n(),o("label",{key:t,class:I(["column-item",{active:c.value.includes(t)}])},[P(s("input",{"onUpdate:modelValue":e[0]||(e[0]=a=>c.value=a),type:"checkbox",value:t},null,8,pe),[[B,c.value]]),s("span",null,i(t),1)],2))),128))])):(n(),o("div",fe,"请选择 Excel 文件后读取表头并填充可保留列")),e[4]||(e[4]=s("div",{class:"desc"},"读取首个 Excel 文件的第一行作为表头,用于动态选择需要保留的列。",-1))]),e[9]||(e[9]=s("div",{class:"section-title"},"ID 保留规则",-1)),s("div",_e,[s("label",{class:I(["radio-item",{active:_.value}])},[P(s("input",{"onUpdate:modelValue":e[1]||(e[1]=t=>_.value=t),type:"checkbox"},null,512),[[B,_.value]]),e[5]||(e[5]=s("div",null,[s("span",{class:"label"},"保留子链接"),s("div",{class:"desc"},"例如 1_1、2_3 这种带下划线的子项 ID")],-1))],2),s("label",{class:I(["radio-item",{active:m.value}])},[P(s("input",{"onUpdate:modelValue":e[2]||(e[2]=t=>m.value=t),type:"checkbox"},null,512),[[B,m.value]]),e[6]||(e[6]=s("div",null,[s("span",{class:"label"},"仅剩主链接无子链接"),s("div",{class:"desc"},"当某个主链接只有 13 这类主 ID、没有 13_1 这类对应子 ID 时,自动保留该主 ID")],-1))],2)]),s("div",me,[s("button",{type:"button",class:"btn-run",disabled:h.value,onClick:V},i(h.value?"清洗中...":"开始清洗"),9,he),s("span",ge,i(h.value?"正在处理文件并上传结果,请稍候…":"选择文件、列和 ID 规则后即可执行清洗,结果会显示在右侧供下载"),1)])]),s("section",ye,[e[14]||(e[14]=s("div",{class:"panel-header"},"去重结果",-1)),s("div",be,[s("div",we,[s("div",ke,[e[10]||(e[10]=s("span",{class:"summary-label"},"已处理文件",-1)),s("strong",null,i(g.value.total),1)]),s("div",Ce,[e[11]||(e[11]=s("span",{class:"summary-label"},"成功结果",-1)),s("strong",null,i(g.value.successCount),1)]),s("div",Ie,[e[12]||(e[12]=s("span",{class:"summary-label"},"失败文件",-1)),s("strong",null,i(g.value.failedCount),1)])]),s("div",xe,[e[13]||(e[13]=s("div",{class:"result-list-header"},[s("span",null,"处理后的 Excel 列表")],-1)),k.value.length===0?(n(),o("div",Ee," 暂无去重结果,完成数据去重后会在这里展示输出文件 ")):(n(),o("ul",De,[(n(!0),o(C,null,F(k.value,t=>(n(),o("li",{key:`${t.resultId||t.outputFilename||t.sourceFilename}`,class:"task-item"},[s("div",Fe,[s("span",{class:"id",title:t.sourceFilename},i(t.sourceFilename||"-"),9,Pe),t.outputFilename?(n(),o("div",Be,"输出文件:"+i(t.outputFilename),1)):b("",!0),t.error?(n(),o("div",Se,"错误信息:"+i(t.error),1)):b("",!0)]),s("div",Ue,[s("span",{class:I(["status",t.success?"success":"failed"])},i(t.success?"已完成":"失败"),3),t.success&&t.downloadUrl?(n(),o("button",{key:0,type:"button",class:"download",onClick:a=>T(t)}," 下载文件 ",8,Ne)):b("",!0),t.resultId?(n(),o("button",{key:1,type:"button",class:"btn-delete",onClick:a=>M(t.resultId)}," 删除 ",8,$e)):b("",!0)])]))),128))]))])])])])]))}}),He=Y(Ae,[["__scopeId","data-v-bdaefe1c"]]);Z(He).use(ee).mount("#app"); diff --git a/app/assets/delete-brand.js b/app/assets/delete-brand.js index ffe6881..95d635d 100644 --- a/app/assets/delete-brand.js +++ b/app/assets/delete-brand.js @@ -1 +1 @@ -import{d as Ye,o as Ze,I as es,a as d,c as f,b as ss,B as ts,e as l,F as H,r as fe,t as v,f as h,J as ns,K as De,n as Me,g as y,h as J,L as as,i as G,E as p,M as ls,N as rs,O as os,P as us,Q as is,_ as cs,p as ds,q as fs}from"./pywebview-DuyK2jB1.js";import{e as vs}from"./brand-CKgrwtni.js";const hs={class:"page-shell module-page"},ps={class:"main-content"},_s={class:"left-panel"},ys={class:"upload-zone"},gs={class:"selected-files clean-placeholder split-selected-files"},ms={key:0,class:"more-line"},ks={key:1},ws={class:"run-row"},Is=["disabled"],bs=["disabled"],Ss={class:"loading-msg"},Ts={key:0,class:"queue-debug-card"},Cs={key:0,class:"queue-debug-line"},Es={key:1,class:"queue-debug-payload"},Fs={class:"right-panel"},Ps={class:"task-list-wrap"},Rs={class:"clean-result-summary"},xs={class:"summary-card"},Ns={class:"summary-card"},$s={class:"summary-card"},As={class:"result-list-wrap"},Ds={key:0,class:"empty-tasks"},Ms={key:0,class:"result-subsection"},Bs={class:"task-list clean-result-list"},qs={class:"left split-result-main"},Ls=["title"],Us={class:"files"},Os={class:"files"},Ks={key:0,class:"files"},Hs={key:1,class:"files"},Js={key:2,class:"files"},Gs={key:3,class:"time"},js={key:4,class:"delete-brand-progress-block"},zs={class:"delete-brand-progress-header"},Vs={class:"delete-brand-progress-bar"},Qs={class:"files delete-brand-progress"},Xs={key:5,class:"files split-entry-list delete-brand-preview"},Ws={key:6,class:"files"},Ys={class:"task-right split-result-actions"},Zs=["onClick"],et=["onClick"],st={key:1,class:"result-subsection"},tt={class:"task-list clean-result-list"},nt={class:"left split-result-main"},at=["title"],lt={class:"files"},rt={class:"files"},ot={key:0,class:"files"},ut={key:1,class:"files"},it={key:2,class:"time"},ct={key:3,class:"delete-brand-progress-block"},dt={class:"delete-brand-progress-header"},ft={class:"delete-brand-progress-bar"},vt={class:"files delete-brand-progress"},ht={key:4,class:"files split-entry-list delete-brand-preview"},pt={key:5,class:"files"},_t={class:"task-right split-result-actions"},yt=["onClick"],gt=["onClick"],mt=Ye({__name:"BrandDeleteBrandTab",setup(wt){function $(){return`delete-brand:current-tasks:${typeof window<"u"&&window.localStorage.getItem("uid")||"0"}`}const A=y([]),j=y([]),B=y(!1),ve=y([]),i=y([]),q=y([]),z=y({total:0,successCount:0,failedCount:0,items:[]}),b=y(""),S=y(""),g=y({}),T=y(null),ee=y(!1),V=y(!1),E=y(!1),D=y(""),Q=y(!1),L=y(null),se=y(!1),te=J(()=>A.value.slice(0,10)),F=J(()=>{const e=[];return i.value.forEach(s=>{e.push(...s.items)}),e});function Be(){try{const e=typeof window<"u"?window.localStorage.getItem($()):null;if(e){if(i.value=JSON.parse(e),i.value.length>0){const s=i.value[i.value.length-1];b.value=s.queuePushResult||"",S.value=s.queuePayloadText||""}}else i.value=[]}catch{i.value=[]}}function ne(e,s,t,n){if(!s?.length)return;const a=i.value.findIndex(c=>c.taskId===e),o=a>=0?i.value[a]:null,r=s.map(c=>{const _=o?.items.find(We=>M(We,c)),k=Array.isArray(c.countries)?c.countries:void 0,m=Array.isArray(_?.countries)?_?.countries:void 0,w=k&&k.length>0?k:m&&m.length>0?m:k??m,I=Array.isArray(c.previewRows)?c.previewRows:void 0,C=Array.isArray(_?.previewRows)?_?.previewRows:void 0,de=I&&I.length>0?I:C&&C.length>0?C:I??C;return{...c,countries:w,previewRows:de,_pushed:_?._pushed??c._pushed??!1,_completed:_?._completed??c._completed??!1}}),u={taskId:e,items:r,createdAt:o?.createdAt||Date.now(),queuePushResult:t??o?.queuePushResult,queuePayloadText:n??o?.queuePayloadText};a>=0?i.value[a]=u:i.value.push(u),typeof window<"u"&&window.localStorage.setItem($(),JSON.stringify(i.value))}function he(e){const s=i.value.length;i.value=i.value.filter(t=>t.taskId!==e),i.value.length!==s&&typeof window<"u"&&window.localStorage.setItem($(),JSON.stringify(i.value))}function pe(e){return e==="SUCCESS"||e==="FAILED"||e==="COMPLETED"}function qe(e){if(!e?.length)return!1;const s=new Set;if(e.forEach(n=>{n.taskId&&pe(n.taskStatus)&&s.add(n.taskId)}),!s.size)return!1;const t=i.value.length;return i.value=i.value.filter(n=>!s.has(n.taskId)),i.value.length!==t?(ae(),!0):!1}const X=J(()=>q.value.filter(e=>!F.value.some(s=>M(s,e)))),Le=J(()=>F.value.length>0||X.value.length>0),Ue=J(()=>F.value.filter(e=>xe(e)&&P(e)==="未入队"));function ae(){typeof window<"u"&&(i.value.length===0?window.localStorage.removeItem($()):window.localStorage.setItem($(),JSON.stringify(i.value)))}function R(e){return e?(i.value.find(t=>t.taskId===e)?.items.length||0)>1:!1}function le(e){return e&&i.value.find(s=>s.taskId===e)||null}function M(e,s){return!e||!s?!1:e.resultId!=null&&s.resultId!=null?e.resultId===s.resultId:e.fileKey&&s.fileKey?e.fileKey===s.fileKey:e.sourceFilename===s.sourceFilename}function x(e,s){const t=le(e);return t&&t.items.find(n=>M(n,s))||null}function _e(e){if(!e)return!1;const s=le(e);if(!s)return!1;let t=!1;const n=g.value[e]?.line_progress?.info,a=R(e);if(n?.file_name&&n.current_line!=null&&n.total_lines!=null&&n.total_lines>0&&n.current_line>=n.total_lines){const o=s.items.find(r=>r.sourceFilename===n.file_name);o&&!o._completed&&(o._completed=!0,t=!0)}if(!a){const o=g.value[e]?.task?.status;if((o==="SUCCESS"||o==="FAILED")&&s.items.length===1){const r=s.items[0];r&&!r._completed&&(r._completed=!0,t=!0)}}return t&&ae(),t}function ye(e){return e&&g.value[e]?.task?.status||""}function W(e){if(e.error)return e.error;if(e.matchStatus&&e.matchStatus!=="MATCHED")return e.matchMessage||"";const s=e.taskId;return s&&g.value[s]?.task?.errorMessage||""}function ge(e){const s=e.taskId;if(!s)return!1;const t=g.value[s]?.line_progress,n=ye(s),a=R(s),o=P(e);if(a){const r=x(s,e),u=K(e)===D.value,c=!!(t?.has_progress&&t?.info?.file_name===e.sourceFilename);return u||c||r?._pushed||(n==="RUNNING"||n==="PENDING"||!n)&&r?._completed?!0:{success:!1,retryable:!0}}return o==="本文件解析完毕"||o==="已被全局判定为终态"?!1:t?.has_progress||t?.info?!0:o==="已入队"||o==="处理中"}function me(e){return e.map(s=>s.matchStatus==="MATCHED"?{...s,_pushed:!1,_completed:!1}:{...s,matched:!1,openStoreUrl:void 0,error:s.error||void 0,_pushed:!1,_completed:!1})}function ke(e){return e.matchStatus==="MATCHED"?`已匹配 ${e.shopId||""}`.trim():e.matchMessage?e.matchMessage:e.matchStatus==="CONFLICT"?"存在多个同名店铺,请人工确认":e.matchStatus==="PENDING"||e.matchStatus==="INDEX_STALE"?"店铺索引暂未就绪":e.matchStatus?e.matchStatus:e.matched?`已匹配 ${e.shopId||""}`.trim():"待匹配"}function Oe(){ve.value=[...F.value,...X.value]}function N(){Oe(),Ke(ve.value)}function Ke(e){z.value={total:e.length,successCount:e.filter(s=>s.success).length,failedCount:e.filter(s=>!s.success).length,items:e}}function re(e){const s=e.taskId;return s&&(g.value[s]?.fileProgress||[]).find(a=>a.fileKey&&e.fileKey?a.fileKey===e.fileKey:a.sourceFilename&&e.sourceFilename?a.sourceFilename===e.sourceFilename:!1)||null}function we(e){const s=e.taskId;if(!s)return"";const t=g.value[s],n=t?.line_progress?.info,a=re(e);if(R(s)){const u=x(s,e),c=t?.task?.status,_=!!(n?.file_name&&n.file_name===e.sourceFilename);let k=u?._completed?"COMPLETED":(u?._pushed,"PENDING"),m=0,w=Math.max(0,e.totalRows??a?.totalRows??0);c==="SUCCESS"||c==="FAILED"&&u?._completed?(k="COMPLETED",m=w):_?(k="RUNNING",m=Math.max(0,Math.min(w||Number.MAX_SAFE_INTEGER,n?.current_line??0)),!w&&n?.total_lines&&n.total_lines>0&&(w=n.total_lines)):u?._completed?(k="COMPLETED",m=w):u?._pushed&&(k="PENDING",m=0);const I=[];if(I.push(`文件状态:${k}`),I.push(`文件进度:${m}/${w}`),n?.finished_files!=null){const C=n.file_total&&n.file_total>0?`/${n.file_total}`:"";I.push(`已完成文件:${n.finished_files}${C}`)}return n?.phase&&I.push(`阶段:${n.phase}`),I.join("|")}if(a){const u=[],c=a.processedRows??0,_=a.totalRows??0;if(a.status&&u.push(`文件状态:${a.status}`),u.push(`文件进度:${c}/${_}`),n?.finished_files!=null){const k=n.file_total&&n.file_total>0?`/${n.file_total}`:"";u.push(`已完成文件:${n.finished_files}${k}`)}return n?.phase&&u.push(`阶段:${n.phase}`),u.join("|")}if(!t?.line_progress?.has_progress||!n){const u=t?.task?.status;return u?`任务状态:${u}`:""}const r=[];if(n.phase&&r.push(`阶段:${n.phase}`),n.file_index&&n.file_total&&r.push(`文件:${n.file_index}/${n.file_total}`),n.file_name&&r.push(`当前文件:${n.file_name}`),n.current_line!=null&&n.total_lines!=null&&r.push(`${R(s)?"当前文件进度":"进度"}:${n.current_line}/${n.total_lines}`),n.current_country&&r.push(`国家:${n.current_country}`),n.current_asin&&r.push(`ASIN:${n.current_asin}`),n.finished_files!=null){const u=n.file_total&&n.file_total>0?`/${n.file_total}`:"";r.push(`已完成文件:${n.finished_files}${u}`)}return r.join("|")}function Y(e){const s=e.taskId;if(!s)return 0;const t=g.value[s]?.line_progress?.info;if(R(s)){const r=x(s,e);if(g.value[s]?.task?.status==="SUCCESS"||r?._completed)return 100;const c=Math.max(0,e.totalRows??re(e)?.totalRows??0);if(!!(t?.file_name&&t.file_name===e.sourceFilename)){if(t?.current_line!=null&&t?.total_lines&&t.total_lines>0)return Math.max(0,Math.min(100,Math.round(t.current_line/t.total_lines*100)));if(t?.current_line!=null&&c>0)return Math.max(0,Math.min(100,Math.round(t.current_line/c*100)))}return 0}const a=re(e);return a?Math.max(0,Math.min(100,a.percent??0)):t?t.current_line!=null&&t.total_lines&&t.total_lines>0?Math.max(0,Math.min(100,Math.round(t.current_line/t.total_lines*100))):t.finished_files!=null&&t.file_total&&t.file_total>0?Math.max(0,Math.min(100,Math.round(t.finished_files/t.file_total*100))):g.value[s]?.task?.status==="SUCCESS"?100:0:0}function Ie(e){const s=g.value[e]?.task?.status;return pe(s)}function U(){const e=new Set;return i.value.forEach(s=>{s.items.some(t=>t._pushed)&&e.add(s.taskId)}),Array.from(e)}function P(e){const s=e.taskId;if(!s||!le(s))return"";const n=x(s,e),a=ye(s),o=g.value[s]?.line_progress,r=R(s);if(!r&&(a==="SUCCESS"||a==="FAILED"||e.taskStatus==="SUCCESS"||e.taskStatus==="FAILED"))return"已被全局判定为终态";if(n?._completed)return"本文件解析完毕";if(a==="RUNNING"&&o?.has_progress&&o?.info?.file_name===e.sourceFilename)return"处理中";if(r&&!n?._pushed&&!n?._completed)return"未入队";if(r&&a==="SUCCESS")return"本文件解析完毕";if(!r){const u=g.value[s];if(u?.items&&u.items.find(_=>M(_,e))&&a==="SUCCESS")return"本文件解析完毕"}return n?._pushed?"已入队":"未入队"}function be(e){if(e.downloadUrl)return!0;const s=e.taskId;return s?g.value[s]?.task?.status==="SUCCESS":{success:!1,retryable:!1}}function He(e){const s=e?.task?.id;if(!s)return!1;const t=i.value.find(r=>r.taskId===s);if(!t)return{success:!1,retryable:!1};const n=e?.items||[];let a=!1;const o=t.items.map(r=>{const u=n.find(de=>M(de,r));if(!u)return r;const c=Array.isArray(u.countries)?u.countries:void 0,_=Array.isArray(r.countries)?r.countries:void 0,k=c&&c.length>0?c:_&&_.length>0?_:c??_,m=Array.isArray(u.previewRows)?u.previewRows:void 0,w=Array.isArray(r.previewRows)?r.previewRows:void 0,I=m&&m.length>0?m:w&&w.length>0?w:m??w,C={...r,...u,countries:k,previewRows:I,_pushed:r._pushed,_completed:r._completed};return JSON.stringify(C)!==JSON.stringify(r)&&(a=!0),C});for(const r of n)o.some(u=>M(u,r))||(o.push({...r,_pushed:!1,_completed:!1}),a=!0);return JSON.stringify(o)!==JSON.stringify(t.items)&&(t.items=o,a=!0),a&&ae(),a}async function oe(e){const s=e||U();if(s.length)try{const t=await as(s);se.value&&E.value&&(b.value="后端已恢复,继续执行当前任务并自动衔接后续任务..."),se.value=!1;let n=!1;for(const a of t.items||[]){const o=a?.task?.id;typeof o=="number"&&o>0&&(g.value[o]=a,He(a)&&(n=!0),_e(o)&&(n=!0))}n&&N()}catch(t){const n=(t instanceof Error?t.message:String(t||"")).toLowerCase();["无法连接到后端服务","bad gateway","gateway timeout","network error","timeout","502","503","504"].some(o=>n.includes(o.toLowerCase()))&&E.value&&(se.value=!0,b.value="当前任务运行中,正在等待后端服务恢复...")}}function Je(){return is()}function ue(e=!1){if(T.value){if(!e)return;clearTimeout(T.value),T.value=null}const s=async()=>{if(T.value=null,ee.value){ue();return}const t=U();if(!t.length)return;ee.value=!0;let n=!1,a=!1;try{await oe(t),await Ae();for(const o of t)Ie(o)&&(he(o),n=!0,a=!0)}finally{ee.value=!1}a?await O():n&&N(),U().length>0&&ue()};e?s():T.value=window.setTimeout(s,Je())}function ie(e=!1){T.value&&!e||ue(e)}function Z(e){const s=e.taskId?g.value[e.taskId]?.task?.status:null;return s==="SUCCESS"?{className:"success",text:"已完成"}:s==="FAILED"?{className:"failed",text:"失败"}:s==="RUNNING"?{className:"running",text:"执行中"}:e.taskStatus==="SUCCESS"?{className:"success",text:"已完成"}:e.taskStatus==="FAILED"?{className:"failed",text:"失败"}:e.taskStatus==="RUNNING"?{className:"running",text:"执行中"}:e.success?{className:"success",text:"已完成"}:{className:"failed",text:"失败"}}function Se(){T.value&&(window.clearTimeout(T.value),T.value=null),ce()}async function Te(e){const s=G();if(!s?.upload_file_to_java)throw new Error("当前桌面端未提供文件上传桥接能力");const t=[];for(const n of e){const a=typeof n=="string"?n:n.absolutePath,o=typeof n=="string"?void 0:n.relativePath,r=await s.upload_file_to_java(a,o);if(!r?.success||!r.data)throw new Error(r?.error||r?.message||`上传失败:${a}`);t.push(r.data)}return t}async function Ge(){const e=G();if(!e?.select_brand_xlsx_files){p.warning("当前环境不支持文件选择,请在本机客户端中打开");return}try{const s=await e.select_brand_xlsx_files();if(!s?.length)return;A.value=s,j.value=await Te(s),p.success(`已选择 ${s.length} 个删除品牌文件`)}catch(s){p.error(s instanceof Error?s.message:"选择失败")}}async function je(){const e=G();if(!e?.select_brand_folder){p.warning("当前环境不支持文件夹选择,请在本机客户端中打开");return}try{const s=await e.select_brand_folder();if(!s)return;const t=await vs(s);if(!t.success||!t.items?.length){p.warning(t.error||"该文件夹下没有 xlsx 文件");return}A.value=t.items.map(n=>n.relativePath||n.absolutePath),j.value=await Te(t.items),p.success(`已选择文件夹内 ${t.items.length} 个 xlsx 文件`)}catch(s){p.error(s instanceof Error?s.message:"选择失败")}}async function ze(){if(!j.value.length){p.warning("请先选择待处理文件");return}try{B.value=!0;const e=await ls({files:j.value.map(a=>({fileKey:a.fileKey,originalFilename:a.originalFilename,relativePath:a.relativePath}))}),s=me(e.items||[]),t=s.some(a=>a.matchStatus==="MATCHED"),n=s.some(a=>a.matchStatus&&a.matchStatus!=="MATCHED");b.value=t?"解析完成,可在左侧点击“推送到 Python 队列”开始串行处理":"解析完成,当前没有可推送的已匹配文件",S.value="",s.length&&s[0].taskId&&ne(s[0].taskId,s,b.value,S.value),N(),n?p.warning("部分文件尚未命中可用店铺索引,已保留状态信息,请等待后台刷新后重试。"):t?p.success("删除品牌解析完成,请在左侧推送到 Python 队列"):p.warning("当前没有可推送的已匹配文件,请先等待店铺索引刷新。"),await O()}catch(e){p.error(e instanceof Error?e.message:"执行失败")}finally{B.value=!1}}async function Ce(e){const s=e.taskId;if(!s){p.warning("未找到任务ID");return}const t=G(),n=rs(s),a=e.outputFilename||e.sourceFilename||`delete-brand_${s}.xlsx`;if(t?.save_file_from_url_new){const o=await t.save_file_from_url_new(n,a);o.success?p.success(`已保存:${o.path||a}`):o.error&&o.error!=="用户取消"&&p.error(o.error);return}}async function O(){try{const e=await os();q.value=me(e.items||[]),qe(q.value),N(),await oe(),ie(!0)}catch(e){const s=(e instanceof Error?e.message:String(e||"")).toLowerCase();["无法连接到后端服务","bad gateway","gateway timeout","network error","timeout","502","503","504"].some(n=>s.includes(n.toLowerCase()))||console.error("loadHistory error:",e)}}function Ee(e){i.value.forEach(t=>{t.items=t.items.filter(n=>n.resultId!==e)});const s=i.value.length;i.value=i.value.filter(t=>t.items.length>0),i.value.length!==s&&typeof window<"u"&&window.localStorage.setItem($(),JSON.stringify(i.value)),q.value=q.value.filter(t=>t.resultId!==e),N(),U().length===0&&Se()}async function Fe(e){try{await us(e),Ee(e),await O(),p.success("已删除")}catch(s){const t=s instanceof Error?s.message:"删除失败";if(typeof t=="string"&&t.includes("记录不存在")){Ee(e),p.success("已删除");return}p.error(t)}}function Pe(e){const s=e.slice(0,5).map(n=>`${n.country}:${n.asin}${n.status?`(${n.status})`:""}`);return e.length-s.length>0?`${s.join("、")} 等 ${e.length} 条`:s.join("、")}function It(e,s){}function ce(){L.value&&(window.clearTimeout(L.value),L.value=null)}function Ve(e=3e3){ce(),L.value=window.setTimeout(()=>{L.value=null,Ae().catch(()=>{})},e)}function Qe(e){return e.includes("当前店铺正在执行中")}function Re(){for(const e of i.value)for(const s of e.items){const t=P(s);if(t==="已入队"||t==="处理中")return!0}return!1}function K(e){return e.resultId!=null?`result:${e.resultId}`:`task:${e.taskId||0}:${e.sourceFilename||""}`}function xe(e){return!!(e.taskId&&(e.matchStatus==="MATCHED"||e.matched))}function Ne(){return F.value.find(e=>!xe(e)||K(e)===D.value||x(e.taskId,e)?._completed?!1:P(e)==="未入队")}async function $e(e,s){if(s?.auto&&Re())return e.taskId,e.sourceFilename,{success:!1,retryable:!0};const t=G(),n=e.taskId;if(!n)return{success:!1,retryable:!1};const a=i.value.find(c=>c.taskId===n);if(!a)return{success:!1,retryable:!1};if(!t?.enqueue_json)return p.error("当前环境未启用 pywebview enqueue_json(浏览器环境不会推送)"),{success:!1,retryable:!1};const o={type:"delete-brand-run",ts:Date.now(),data:{taskId:n,items:[e]}};S.value=JSON.stringify(o,null,2);const r=await t.enqueue_json(o);let u="";if(r?.success){u=`已推送文件 ${e.sourceFilename},当前队列长度:${r.queue_size??"-"}`;const c=x(n,e);return c&&(c._pushed=!0,c._completed=!1),D.value=K(e),ne(n,a.items,u,S.value),ie(!0),b.value=u,{success:!0,retryable:!1}}else{const c=r?.error||"未知错误";if(u=`推送到 Python 队列失败:${c}`,b.value=u,ne(n,a.items,u,S.value),s?.auto&&Qe(c))return{success:!1,retryable:!0}}return b.value=u,{success:!1,retryable:!1}}async function Xe(){const e=Ne();if(!e){p.warning("当前没有可推送的已匹配文件");return}V.value=!0,E.value=!0,ce();const s=await $e(e);if(V.value=!1,!s.success){E.value=!1,D.value="";return}p.success("已开始按顺序推送到 Python 队列")}async function Ae(){if(!E.value||Q.value){E.value,Q.value;return}if(Re())return;const e=D.value;if(e){const t=F.value.find(n=>K(n)===e);if(t){const n=t.taskId,a=R(n);a&&(_e(n),P(t),void 0);const o=P(t);if(o==="已入队"||o==="处理中"){t.sourceFilename;return}if(a){const r=x(n,t);if(r&&!r._completed){t.sourceFilename,r._pushed,r._completed;return}}}}const s=Ne();if(!s){D.value="",E.value=!1;return}Q.value=!0;try{s.taskId,s.sourceFilename,K(s);const t=await $e(s,{auto:!0});if(!t.success){if(t.retryable){s.taskId,s.sourceFilename,Ve();return}s.taskId,s.sourceFilename,E.value=!1}}finally{Q.value=!1}}return Ze(()=>{Be();const e=U();e.length>0?oe(e).then(async()=>{let s=!1,t=!1;for(const n of e)Ie(n)&&(he(n),s=!0,t=!0);t?await O():s&&N(),ie(!0)}):N(),O().catch(()=>{})}),es(()=>{Se()}),(e,s)=>(d(),f("div",hs,[ss(ts,{active:"delete-brand"}),l("div",ps,[l("aside",_s,[s[2]||(s[2]=l("div",{class:"section-title"},"选择文件",-1)),l("div",ys,[s[0]||(s[0]=l("div",{class:"hint"},"上传删除品牌 Excel;无论是直接上传文件还是上传文件夹批量导入,都会按每个 Excel 文件名作为店铺名。",-1)),l("div",{class:"btns"},[l("button",{type:"button",class:"opt-btn",onClick:Ge},"选择 Excel 文件"),l("button",{type:"button",class:"opt-btn",onClick:je},"选择文件夹")]),l("div",gs,[A.value.length?(d(),f(H,{key:0},[(d(!0),f(H,null,fe(te.value,t=>(d(),f("span",{key:t},v(t),1))),128)),A.value.length>te.value.length?(d(),f("span",ms," 还有 "+v(A.value.length-te.value.length)+" 个文件未展开显示 ",1)):h("",!0)],64)):(d(),f("span",ks,"暂未选择删除品牌文件"))])]),s[3]||(s[3]=ns('