modified: app/.env

modified:   app/ali_oss.py
	modified:   app/app.py
	new file:   app/blueprints/__pycache__/communication.cpython-39.pyc
	modified:   app/blueprints/communication.py
	modified:   app/brand_spider/__pycache__/main.cpython-39.pyc
	modified:   app/config.py
	modified:   app/main.py
	modified:   app/static/bg.jpg
	modified:   app/tool/__pycache__/devices.cpython-39.pyc
	modified:   app/web_source/brand.html
	modified:   app/web_source/templates_backup/brand.html
This commit is contained in:
铭坤
2026-03-30 19:44:04 +08:00
parent cb3b9e9cfe
commit d6625762cf
12 changed files with 1734 additions and 1946 deletions

View File

@@ -1,13 +1,14 @@
base_url=http://159.75.121.33:15124 base_url=http://8.136.19.173:15124
workflow_id=7608812635877900322 workflow_id=7608812635877900322
mysql_host=159.75.121.33 mysql_host=8.136.19.173
mysql_user=AIimage mysql_user=aiimage
proxy_url=https://api.jikip.com/ip-get?num=1&minute=1&format=json&area=all&protocol=1&mode=2&key=r4m8dov52giup2o proxy_url=https://api.jikip.com/ip-get?num=1&minute=1&format=json&area=all&protocol=1&mode=2&key=t24g6gi44ubufd8
proxy_mode=2 proxy_mode=2
client_name=NanriAI client_name=ShuFuAI
# java_api_base=http://8.136.19.173:18080
java_api_base=http://127.0.0.1:18080
java_api_base=http://8.136.19.173:18080

View File

@@ -14,7 +14,6 @@ def upload_file(file_content: bytes, key: str):
cfg.credentials_provider = credentials_provider cfg.credentials_provider = credentials_provider
cfg.region = region cfg.region = region
cfg.endpoint = endpoint cfg.endpoint = endpoint
cfg.retry_max_attempts = 3
client = oss.Client(cfg) client = oss.Client(cfg)
result = client.put_object( result = client.put_object(

View File

@@ -15,13 +15,24 @@ from blueprints.main import main_bp
from blueprints.admin import admin_bp from blueprints.admin import admin_bp
from blueprints.image import image_bp from blueprints.image import image_bp
from blueprints.brand import brand_bp from blueprints.brand import brand_bp
from blueprints.communication import communication_bp
def create_app(): def create_app():
app = Flask(__name__, template_folder=BASE_DIR, static_folder=BASE_DIR) app = Flask(__name__, template_folder=BASE_DIR, static_folder=BASE_DIR)
CORS(app) frontend_origin = os.environ.get('FRONTEND_ORIGIN', '*')
app.secret_key = os.environ.get('SECRET_KEY', secrets.token_hex(32)) cors_origins = frontend_origin if frontend_origin != '*' else '*'
CORS(
app,
supports_credentials=True,
resources={r"/api/*": {"origins": cors_origins}, r"/login": {"origins": cors_origins}},
)
# 生产环境必须通过环境变量注入固定 SECRET_KEY否则服务重启会使旧会话失效。
app.secret_key = os.environ.get('SECRET_KEY', 'dev-secret-key-change-me')
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7) app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7)
app.config['SESSION_COOKIE_HTTPONLY'] = True
app.config['SESSION_COOKIE_SAMESITE'] = os.environ.get('SESSION_COOKIE_SAMESITE', 'Lax')
app.config['SESSION_COOKIE_SECURE'] = os.environ.get('SESSION_COOKIE_SECURE', '0') == '1'
# 注册蓝图(不设 url_prefix保持原有 URL 路径不变,前端无需改动) # 注册蓝图(不设 url_prefix保持原有 URL 路径不变,前端无需改动)
app.register_blueprint(auth_bp) app.register_blueprint(auth_bp)
@@ -29,6 +40,7 @@ def create_app():
app.register_blueprint(admin_bp) app.register_blueprint(admin_bp)
app.register_blueprint(image_bp) app.register_blueprint(image_bp)
app.register_blueprint(brand_bp) app.register_blueprint(brand_bp)
app.register_blueprint(communication_bp)
return app return app

View File

@@ -1,18 +1,67 @@
from queue import Empty import threading
import time
from queue import Empty, Full
from flask import Blueprint, jsonify from flask import Blueprint, jsonify, request
from config import JSON_TASK_QUEUE from config import JSON_TASK_QUEUE
communication_bp = Blueprint('communication', __name__) communication_bp = Blueprint('communication', __name__)
_del_brand_cache = {}
_del_brand_cache_lock = threading.Lock()
_latest_del_brand_item = None
_latest_del_brand_ts = 0.0
def _resolve_request_id():
rid = request.args.get('id')
if rid is not None and str(rid).strip() != '':
return str(rid)
if request.method == 'POST':
body = request.get_json(silent=True) or {}
rid = body.get('id')
if rid is not None and str(rid).strip() != '':
return str(rid)
return None
@communication_bp.route('/api/amazon/del_brand', methods=['GET', 'POST']) @communication_bp.route('/api/amazon/del_brand', methods=['GET', 'POST'])
def del_brand(): def del_brand():
"""返回队列中的一个元素;队列为空时返回空提示""" """返回队列中的一个元素;同一 id 重复请求返回已缓存的同一元素2分钟内不同 id 也返回最近元素"""
global _latest_del_brand_item, _latest_del_brand_ts
request_id = _resolve_request_id()
if not request_id:
return jsonify({'success': False, 'message': '缺少参数 id', 'data': None}), 400
with _del_brand_cache_lock:
if request_id in _del_brand_cache:
item = _del_brand_cache[request_id]
print("【删除品牌】缓存命中", request_id, item)
return jsonify({'success': True, 'data': item})
if _latest_del_brand_item is not None and (time.time() - _latest_del_brand_ts) <= 120:
_del_brand_cache[request_id] = _latest_del_brand_item
print("【删除品牌】2分钟窗口命中", request_id, _latest_del_brand_item)
return jsonify({'success': True, 'data': _latest_del_brand_item})
try: try:
item = JSON_TASK_QUEUE.get_nowait() item = JSON_TASK_QUEUE.get_nowait()
return jsonify({'success': True, 'data': item})
except Empty: except Empty:
print("队列为空")
return jsonify({'success': False, 'message': '队列为空', 'data': None}) return jsonify({'success': False, 'message': '队列为空', 'data': None})
with _del_brand_cache_lock:
if request_id in _del_brand_cache:
try:
JSON_TASK_QUEUE.put_nowait(item)
except Full:
print("【删除品牌】队列已满,无法归还重复拉取的任务")
item = _del_brand_cache[request_id]
print("【删除品牌】并发归并", request_id, item)
return jsonify({'success': True, 'data': item})
_del_brand_cache[request_id] = item
_latest_del_brand_item = item
_latest_del_brand_ts = time.time()
print("【删除品牌】返回任务数据", item)
return jsonify({'success': True, 'data': item})

View File

@@ -18,9 +18,9 @@ proxy_url = os.getenv("proxy_url")
proxy_mode = int(os.getenv("proxy_mode",1)) proxy_mode = int(os.getenv("proxy_mode",1))
client_name=os.getenv("client_name") + ".exe" client_name=os.getenv("client_name") + ".exe"
# JAVA_API_BASE = os.getenv("java_api_base", "http://8.136.19.173:18080")
JAVA_API_BASE = os.getenv("java_api_base", "http://127.0.0.1:18080") JAVA_API_BASE = os.getenv("java_api_base", "http://127.0.0.1:18080")
cache_path = "./user_data" cache_path = "./user_data"
region = "cn-hangzhou" region = "cn-hangzhou"
@@ -39,8 +39,8 @@ os.environ['OSS_ACCESS_KEY_SECRET'] = accessKeySecret
os.environ['SECRET_KEY'] = "ddffc7c1d02121d9554d7b080b2511b6" os.environ['SECRET_KEY'] = "ddffc7c1d02121d9554d7b080b2511b6"
debug = True debug = False
version = "1.0.13" version = "1.0.22"
APP_UPDATE_URL = f"{_base_url}/api/version/latest" # 检测更新接口地址,返回 { "file_url": "...", "version": "x.x.x" } APP_UPDATE_URL = f"{_base_url}/api/version/latest" # 检测更新接口地址,返回 { "file_url": "...", "version": "x.x.x" }
os.environ['APP_VERSION'] = version os.environ['APP_VERSION'] = version
os.environ['APP_UPDATE_URL'] = APP_UPDATE_URL os.environ['APP_UPDATE_URL'] = APP_UPDATE_URL

View File

@@ -237,6 +237,9 @@ class WindowAPI:
def enqueue_json(self, data): def enqueue_json(self, data):
"""保存任务到队列""" """保存任务到队列"""
try: try:
print("==============================")
print(datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S"),"调用传入",data)
print("==================================")
payload = data payload = data
if isinstance(data, str): if isinstance(data, str):
payload = json.loads(data) payload = json.loads(data)
@@ -349,7 +352,7 @@ def main():
window.expose(api.close, api.minimize, api.maximize, api.toggle_maximize, generate_images, api.save_image, api.save_image_to_folder, api.select_folder, api.select_brand_xlsx_files, api.select_brand_folder, window.expose(api.close, api.minimize, api.maximize, api.toggle_maximize, generate_images, api.save_image, api.save_image_to_folder, api.select_folder, api.select_brand_xlsx_files, api.select_brand_folder,
api.save_file_from_url, api.save_template_xlsx,api.save_template_zip,api.upload_file_to_java,api.enqueue_json) api.save_file_from_url, api.save_template_xlsx,api.save_template_zip,api.upload_file_to_java,api.enqueue_json)
webview.start( webview.start(
debug=True, debug=False,
storage_path=cache_path, storage_path=cache_path,
private_mode=False private_mode=False
) )

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 3.9 MiB

View File

@@ -1,17 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-CN"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>亚马逊 - 南日AI</title> <title>亚马逊 - 南日AI</title>
<style> <style>
* { * { margin: 0; padding: 0; box-sizing: border-box; }
margin: 0;
padding: 0;
box-sizing: border-box;
}
body { body {
font-family: "Microsoft YaHei", "Noto Serif SC", "SimSun", "Songti SC", "Times New Roman", serif; font-family: "Microsoft YaHei", "Noto Serif SC", "SimSun", "Songti SC", "Times New Roman", serif;
background: rgba(13, 13, 13, 1); background: rgba(13, 13, 13, 1);
@@ -20,7 +14,6 @@
height: 100vh; height: 100vh;
font-weight: bold; font-weight: bold;
} }
.top-bar { .top-bar {
height: 56px; height: 56px;
display: flex; display: flex;
@@ -29,19 +22,12 @@
padding: 0 16px; padding: 0 16px;
border-bottom: 1px solid #2a2a2a; border-bottom: 1px solid #2a2a2a;
} }
.logo-area { .logo-area {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 10px;
} }
.top-bar .app-name { font-size: 18px; font-weight: 600; color: #fff; }
.top-bar .app-name {
font-size: 18px;
font-weight: 600;
color: #fff;
}
.btn-home { .btn-home {
font-size: 13px; font-size: 13px;
color: #999; color: #999;
@@ -50,11 +36,7 @@
border-radius: 6px; border-radius: 6px;
transition: all 0.2s; transition: all 0.2s;
} }
.btn-home:hover { color: #fff; background: #2a2a2a; }
.btn-home:hover {
color: #fff;
background: #2a2a2a;
}
/* 顶部栏目导航(容器化,便于后续增加栏目) */ /* 顶部栏目导航(容器化,便于后续增加栏目) */
.nav-tabs { .nav-tabs {
@@ -62,7 +44,6 @@
align-items: center; align-items: center;
gap: 0; gap: 0;
} }
.nav-tab-group { .nav-tab-group {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -70,7 +51,6 @@
background: rgba(77, 72, 72, 0.99); background: rgba(77, 72, 72, 0.99);
border-radius: 10px; border-radius: 10px;
} }
.nav-tab-sep { .nav-tab-sep {
width: 1px; width: 1px;
height: 20px; height: 20px;
@@ -79,7 +59,6 @@
flex-shrink: 0; flex-shrink: 0;
opacity: 0.9; opacity: 0.9;
} }
.nav-tab { .nav-tab {
padding: 8px 14px; padding: 8px 14px;
font-size: 13px; font-size: 13px;
@@ -90,17 +69,14 @@
cursor: pointer; cursor: pointer;
transition: all 0.2s; transition: all 0.2s;
} }
.nav-tab:hover { .nav-tab:hover {
color: #fff; color: #fff;
background: #2a2a2a; background: #2a2a2a;
} }
.nav-tab.active { .nav-tab.active {
color: #3498db; color: #3498db;
background: rgba(52, 152, 219, 0.2); background: rgba(52, 152, 219, 0.2);
} }
.top-right { .top-right {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -111,7 +87,6 @@
display: flex; display: flex;
height: calc(100vh - 56px); height: calc(100vh - 56px);
} }
/* 栏目内容容器:每个栏目一个 .tab-panel通过 data-panel 与导航对应 */ /* 栏目内容容器:每个栏目一个 .tab-panel通过 data-panel 与导航对应 */
.tab-panel { .tab-panel {
display: none; display: none;
@@ -119,11 +94,9 @@
min-width: 0; min-width: 0;
min-height: 0; min-height: 0;
} }
.tab-panel.active { .tab-panel.active {
display: flex; display: flex;
} }
.left-panel { .left-panel {
width: 380px; width: 380px;
background: #1e1e1e; background: #1e1e1e;
@@ -131,7 +104,6 @@
overflow-y: auto; overflow-y: auto;
border-right: 1px solid #2a2a2a; border-right: 1px solid #2a2a2a;
} }
.right-panel { .right-panel {
flex: 1; flex: 1;
display: flex; display: flex;
@@ -139,13 +111,11 @@
min-width: 0; min-width: 0;
background: #1a1a1a; background: #1a1a1a;
} }
.section-title { .section-title {
font-size: 13px; font-size: 13px;
color: #bbb; color: #bbb;
margin-bottom: 10px; margin-bottom: 10px;
} }
.upload-zone { .upload-zone {
border: 1px dashed #3a3a3a; border: 1px dashed #3a3a3a;
border-radius: 10px; border-radius: 10px;
@@ -155,25 +125,9 @@
margin-bottom: 20px; margin-bottom: 20px;
transition: all 0.2s; transition: all 0.2s;
} }
.upload-zone:hover { border-color: #3498db; background: #2a2a2a; }
.upload-zone:hover { .upload-zone .hint { color: #888; font-size: 13px; margin-bottom: 12px; }
border-color: #3498db; .upload-zone .btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
background: #2a2a2a;
}
.upload-zone .hint {
color: #888;
font-size: 13px;
margin-bottom: 12px;
}
.upload-zone .btns {
display: flex;
gap: 10px;
justify-content: center;
flex-wrap: wrap;
}
.opt-btn { .opt-btn {
padding: 8px 16px; padding: 8px 16px;
font-size: 13px; font-size: 13px;
@@ -184,14 +138,7 @@
cursor: pointer; cursor: pointer;
transition: all 0.2s; transition: all 0.2s;
} }
.opt-btn:hover { color: #fff; background: #333; border-color: #3498db; color: #3498db; }
.opt-btn:hover {
color: #fff;
background: #333;
border-color: #3498db;
color: #3498db;
}
.selected-files { .selected-files {
margin-top: 12px; margin-top: 12px;
font-size: 12px; font-size: 12px;
@@ -199,17 +146,8 @@
max-height: 72px; max-height: 72px;
overflow-y: auto; overflow-y: auto;
} }
.selected-files span { display: block; margin: 4px 0; word-break: break-all; }
.selected-files span { .option-group { margin-bottom: 20px; }
display: block;
margin: 4px 0;
word-break: break-all;
}
.option-group {
margin-bottom: 20px;
}
.radio-item { .radio-item {
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;
@@ -221,35 +159,16 @@
border: 1px solid #2a2a2a; border: 1px solid #2a2a2a;
margin-bottom: 8px; margin-bottom: 8px;
} }
.radio-item:hover { background: #2a2a2a; }
.radio-item:hover { .radio-item input { margin-top: 3px; }
background: #2a2a2a; .radio-item .label { font-weight: 500; color: #e0e0e0; font-size: 13px; }
} .radio-item .desc { font-size: 12px; color: #888; margin-top: 2px; font-weight: normal; }
.radio-item input {
margin-top: 3px;
}
.radio-item .label {
font-weight: 500;
color: #e0e0e0;
font-size: 13px;
}
.radio-item .desc {
font-size: 12px;
color: #888;
margin-top: 2px;
font-weight: normal;
}
.run-row { .run-row {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 12px; gap: 12px;
margin-top: 16px; margin-top: 16px;
} }
.btn-run { .btn-run {
padding: 10px 22px; padding: 10px 22px;
background: #3498db; background: #3498db;
@@ -260,21 +179,9 @@
cursor: pointer; cursor: pointer;
transition: all 0.2s; transition: all 0.2s;
} }
.btn-run:hover { background: #2980b9; }
.btn-run:hover { .btn-run:disabled { background: #555; cursor: not-allowed; color: #999; }
background: #2980b9; .loading-msg { color: #3498db; font-size: 13px; }
}
.btn-run:disabled {
background: #555;
cursor: not-allowed;
color: #999;
}
.loading-msg {
color: #3498db;
font-size: 13px;
}
.template-download-row { .template-download-row {
margin-top: 16px; margin-top: 16px;
@@ -288,22 +195,16 @@
transition: all 0.25s ease; transition: all 0.25s ease;
cursor: pointer; cursor: pointer;
} }
.template-download-row:hover { .template-download-row:hover {
border-color: #2e7d32; border-color: #2e7d32;
background: linear-gradient(135deg, #2a2a2a 0%, #243324 100%); background: linear-gradient(135deg, #2a2a2a 0%, #243324 100%);
box-shadow: 0 4px 12px rgba(46, 125, 50, 0.15); box-shadow: 0 4px 12px rgba(46, 125, 50, 0.15);
} }
.template-download-row:hover .template-download-text .title { color: #2ecc71; }
.template-download-row:hover .template-download-text .title {
color: #2ecc71;
}
.template-download-row:hover .template-download-icon { .template-download-row:hover .template-download-icon {
transform: scale(1.05); transform: scale(1.05);
box-shadow: 0 6px 16px rgba(46, 125, 50, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.15); box-shadow: 0 6px 16px rgba(46, 125, 50, 0.45), inset 0 1px 0 rgba(255,255,255,0.15);
} }
.template-download-icon { .template-download-icon {
width: 48px; width: 48px;
height: 48px; height: 48px;
@@ -313,28 +214,15 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
box-shadow: 0 4px 12px rgba(46, 125, 50, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.1); box-shadow: 0 4px 12px rgba(46, 125, 50, 0.35), inset 0 1px 0 rgba(255,255,255,0.1);
transition: transform 0.2s, box-shadow 0.2s; transition: transform 0.2s, box-shadow 0.2s;
} }
.template-download-icon svg { .template-download-icon svg {
width: 28px; width: 28px;
height: 28px; height: 28px;
} }
.template-download-text .title { font-size: 14px; color: #e0e0e0; font-weight: 600; display: block; }
.template-download-text .title { .template-download-text .hint { font-size: 12px; color: #888; margin-top: 2px; font-weight: normal; }
font-size: 14px;
color: #e0e0e0;
font-weight: 600;
display: block;
}
.template-download-text .hint {
font-size: 12px;
color: #888;
margin-top: 2px;
font-weight: normal;
}
.panel-header { .panel-header {
padding: 16px 20px; padding: 16px 20px;
@@ -347,11 +235,9 @@
justify-content: space-between; justify-content: space-between;
gap: 12px; gap: 12px;
} }
.panel-header-title { .panel-header-title {
flex: 1; flex: 1;
} }
.btn-refresh-tasks { .btn-refresh-tasks {
padding: 6px 14px; padding: 6px 14px;
font-size: 12px; font-size: 12px;
@@ -363,23 +249,17 @@
transition: all 0.2s; transition: all 0.2s;
white-space: nowrap; white-space: nowrap;
} }
.btn-refresh-tasks:hover { .btn-refresh-tasks:hover {
background: #333; background: #333;
border-color: #3498db; border-color: #3498db;
color: #3498db; color: #3498db;
} }
.task-list-wrap { .task-list-wrap {
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
padding: 16px; padding: 16px;
} }
.task-list { list-style: none; }
.task-list {
list-style: none;
}
.task-item { .task-item {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -390,155 +270,38 @@
margin-bottom: 10px; margin-bottom: 10px;
background: #1e1e1e; background: #1e1e1e;
} }
.task-item .left { flex: 1; min-width: 0; }
.task-item .left { .task-item .id { font-weight: 600; color: #e0e0e0; font-size: 13px; }
flex: 1; .task-item .files { font-size: 12px; color: #888; margin-top: 4px; }
min-width: 0; .task-item .time { font-size: 12px; color: #666; margin-top: 2px; }
}
.task-item .id {
font-weight: 600;
color: #e0e0e0;
font-size: 13px;
}
.task-item .files {
font-size: 12px;
color: #888;
margin-top: 4px;
}
.task-item .time {
font-size: 12px;
color: #666;
margin-top: 2px;
}
.task-item .status { .task-item .status {
padding: 4px 10px; padding: 4px 10px;
border-radius: 6px; border-radius: 6px;
font-size: 12px; font-size: 12px;
margin-right: 12px; margin-right: 12px;
} }
.task-item .status.pending { background: rgba(255,193,7,0.2); color: #d4a500; }
.task-item .status.pending { .task-item .status.running { background: rgba(52,152,219,0.2); color: #3498db; }
background: rgba(255, 193, 7, 0.2); .task-item .status.success { background: rgba(46,204,113,0.2); color: #2ecc71; }
color: #d4a500; .task-item .status.failed { background: rgba(231,76,60,0.2); color: #e74c3c; }
} .task-item .status.cancelled { background: rgba(149,165,166,0.2); color: #95a5a6; }
.task-item .progress-wrap { margin-top: 8px; margin-right: 8px; flex-shrink: 0; width: 120px; }
.task-item .status.running { .task-item .progress-bar-bg { height: 6px; background: #2a2a2a; border-radius: 3px; overflow: hidden; }
background: rgba(52, 152, 219, 0.2); .task-item .progress-bar-fill { height: 100%; background: #3498db; border-radius: 3px; transition: width 0.2s; }
color: #3498db; .task-item .btn-cancel, .task-item .btn-delete {
} padding: 6px 12px; font-size: 12px; border-radius: 6px; cursor: pointer; border: none; margin-left: 6px;
.task-item .status.success {
background: rgba(46, 204, 113, 0.2);
color: #2ecc71;
}
.task-item .status.failed {
background: rgba(231, 76, 60, 0.2);
color: #e74c3c;
}
.task-item .status.cancelled {
background: rgba(149, 165, 166, 0.2);
color: #95a5a6;
}
.task-item .progress-wrap {
margin-top: 8px;
margin-right: 8px;
flex-shrink: 0;
width: 120px;
}
.task-item .progress-bar-bg {
height: 6px;
background: #2a2a2a;
border-radius: 3px;
overflow: hidden;
}
.task-item .progress-bar-fill {
height: 100%;
background: #3498db;
border-radius: 3px;
transition: width 0.2s;
}
.task-item .btn-cancel,
.task-item .btn-delete {
padding: 6px 12px;
font-size: 12px;
border-radius: 6px;
cursor: pointer;
border: none;
margin-left: 6px;
transition: all 0.2s; transition: all 0.2s;
} }
.task-item .btn-cancel { background: #e67e22; color: #fff; }
.task-item .btn-cancel { .task-item .btn-cancel:hover { background: #d35400; }
background: #e67e22; .task-item .btn-delete { background: #444; color: #ccc; }
color: #fff; .task-item .btn-delete:hover { background: #e74c3c; color: #fff; }
} .task-item .task-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.run-row .progress-wrap { margin-top: 10px; width: 100%; max-width: 280px; }
.task-item .btn-cancel:hover { .run-row .progress-bar-bg { height: 8px; background: #2a2a2a; border-radius: 4px; overflow: hidden; }
background: #d35400; .run-row .progress-bar-fill { height: 100%; background: #3498db; border-radius: 4px; transition: width 0.2s; }
} .run-row .btn-cancel-run { margin-left: 12px; padding: 8px 16px; background: #e67e22; color: #fff; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; }
.run-row .btn-cancel-run:hover { background: #d35400; }
.task-item .btn-delete {
background: #444;
color: #ccc;
}
.task-item .btn-delete:hover {
background: #e74c3c;
color: #fff;
}
.task-item .task-right {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.run-row .progress-wrap {
margin-top: 10px;
width: 100%;
max-width: 280px;
}
.run-row .progress-bar-bg {
height: 8px;
background: #2a2a2a;
border-radius: 4px;
overflow: hidden;
}
.run-row .progress-bar-fill {
height: 100%;
background: #3498db;
border-radius: 4px;
transition: width 0.2s;
}
.run-row .btn-cancel-run {
margin-left: 12px;
padding: 8px 16px;
background: #e67e22;
color: #fff;
border: none;
border-radius: 6px;
font-size: 13px;
cursor: pointer;
}
.run-row .btn-cancel-run:hover {
background: #d35400;
}
.task-item .download { .task-item .download {
padding: 6px 14px; padding: 6px 14px;
background: #3498db; background: #3498db;
@@ -551,29 +314,15 @@
white-space: nowrap; white-space: nowrap;
transition: all 0.2s; transition: all 0.2s;
} }
.task-item .download:hover { background: #2980b9; color: #fff; }
.task-item .download:hover { .task-item .download.hide { display: none; }
background: #2980b9; .empty-tasks { text-align: center; color: #666; padding: 32px; font-size: 13px; }
color: #fff;
}
.task-item .download.hide {
display: none;
}
.empty-tasks {
text-align: center;
color: #666;
padding: 32px;
font-size: 13px;
}
.toast { .toast {
position: fixed; position: fixed;
bottom: 32px; bottom: 32px;
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
background: rgba(0, 0, 0, 0.85); background: rgba(0,0,0,0.85);
color: #fff; color: #fff;
padding: 12px 24px; padding: 12px 24px;
border-radius: 8px; border-radius: 8px;
@@ -583,13 +332,9 @@
transition: opacity 0.3s; transition: opacity 0.3s;
border: 1px solid #333; border: 1px solid #333;
} }
.toast.show { opacity: 1; }
.toast.show {
opacity: 1;
}
</style> </style>
</head> </head>
<body> <body>
<header class="top-bar"> <header class="top-bar">
<div class="logo-area"> <div class="logo-area">
@@ -599,12 +344,7 @@
<nav class="nav-tabs"> <nav class="nav-tabs">
<span class="nav-tab-group"> <span class="nav-tab-group">
<button type="button" class="nav-tab active" data-panel="brandCheck">品牌检测</button> <button type="button" class="nav-tab active" data-panel="brandCheck">品牌检测</button>
<button type="button" class="nav-tab" <!-- 后续增加栏目时在此添加,例如:<button type="button" class="nav-tab" data-panel="other">其他栏目</button> -->
onclick="window.location='/new_web_source/dedupe.html'">总数据去重</button>
<button type="button" class="nav-tab"
onclick="window.location='/new_web_source/convert.html'">格式转换</button>
<button type="button" class="nav-tab"
onclick="window.location='/new_web_source/split.html'">表格拆分</button>
</span> </span>
<!-- 多组栏目时可用分隔符:<span class="nav-tab-sep" aria-hidden="true"></span> --> <!-- 多组栏目时可用分隔符:<span class="nav-tab-sep" aria-hidden="true"></span> -->
</nav> </nav>
@@ -664,33 +404,23 @@
<button type="button" class="btn-run" id="btnRun">立即运行</button> <button type="button" class="btn-run" id="btnRun">立即运行</button>
<span class="loading-msg" id="loadingMsg" style="display:none;">生成中,请稍候…</span> <span class="loading-msg" id="loadingMsg" style="display:none;">生成中,请稍候…</span>
<div class="progress-wrap" id="runProgressWrap" style="display:none;"> <div class="progress-wrap" id="runProgressWrap" style="display:none;">
<div class="progress-bar-bg"> <div class="progress-bar-bg"><div class="progress-bar-fill" id="runProgressFill" style="width:0%;"></div></div>
<div class="progress-bar-fill" id="runProgressFill" style="width:0%;"></div>
</div>
<span class="hint" style="font-size:12px;color:#888;" id="runProgressText">0 / 0</span> <span class="hint" style="font-size:12px;color:#888;" id="runProgressText">0 / 0</span>
</div> </div>
<!-- 当前文件行级进度(不经数据库中转,只读内存接口) --> <!-- 当前文件行级进度(不经数据库中转,只读内存接口) -->
<div class="progress-wrap" id="runLineProgressWrap" style="display:none;"> <div class="progress-wrap" id="runLineProgressWrap" style="display:none;">
<div class="progress-bar-bg"> <div class="progress-bar-bg"><div class="progress-bar-fill" id="runLineProgressFill" style="width:0%;"></div></div>
<div class="progress-bar-fill" id="runLineProgressFill" style="width:0%;"></div>
</div>
<span class="hint" style="font-size:12px;color:#888;" id="runLineProgressText">0 / 0</span> <span class="hint" style="font-size:12px;color:#888;" id="runLineProgressText">0 / 0</span>
</div> </div>
<button type="button" class="btn-cancel-run" id="btnCancelRun" <button type="button" class="btn-cancel-run" id="btnCancelRun" style="display:none;">取消生成</button>
style="display:none;">取消生成</button>
</div> </div>
</div> </div>
<div class="template-download-row" id="templateDownloadRow" role="button" tabindex="0" <div class="template-download-row" id="templateDownloadRow" role="button" tabindex="0" title="下载品牌文档格式模板(选择保存位置)">
title="下载品牌文档格式模板(选择保存位置)">
<span class="template-download-icon" aria-hidden="true"> <span class="template-download-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z" <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" <path d="M14 2v6h6" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
stroke-linejoin="round" /> <path d="M8 13h8M8 17h5" stroke="rgba(255,255,255,0.85)" stroke-width="1.5" stroke-linecap="round"/>
<path d="M14 2v6h6" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round"
stroke-linejoin="round" />
<path d="M8 13h8M8 17h5" stroke="rgba(255,255,255,0.85)" stroke-width="1.5"
stroke-linecap="round" />
</svg> </svg>
</span> </span>
<span class="template-download-text"> <span class="template-download-text">
@@ -698,17 +428,12 @@
<span class="hint">品牌文档格式_模板.xlsx · 点击选择保存位置</span> <span class="hint">品牌文档格式_模板.xlsx · 点击选择保存位置</span>
</span> </span>
</div> </div>
<div class="template-download-row" id="templateDownloadRow2" role="button" tabindex="0" <div class="template-download-row" id="templateDownloadRow2" role="button" tabindex="0" title="下载模板2以文件夹方式上传">
title="下载模板2以文件夹方式上传">
<span class="template-download-icon" aria-hidden="true"> <span class="template-download-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z" <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" <path d="M14 2v6h6" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
stroke-linejoin="round" /> <path d="M3 7v10h4v-4h2v4h8v-4h2v4h2V7H3z" stroke="rgba(255,255,255,0.85)" stroke-width="1.5" stroke-linecap="round"/>
<path d="M14 2v6h6" stroke="rgba(255,255,255,0.9)" stroke-width="1.8" stroke-linecap="round"
stroke-linejoin="round" />
<path d="M3 7v10h4v-4h2v4h8v-4h2v4h2V7H3z" stroke="rgba(255,255,255,0.85)"
stroke-width="1.5" stroke-linecap="round" />
</svg> </svg>
</span> </span>
<span class="template-download-text"> <span class="template-download-text">
@@ -734,18 +459,18 @@
<div class="toast" id="toast"></div> <div class="toast" id="toast"></div>
<script> <script>
(function () { (function() {
var selectedPaths = []; var selectedPaths = [];
var cachedTasks = []; var cachedTasks = [];
var api = window.pywebview && window.pywebview.api; var api = window.pywebview && window.pywebview.api;
// 顶部栏目切换:点击 nav-tab 时显示对应 data-panel 的 tab-panel // 顶部栏目切换:点击 nav-tab 时显示对应 data-panel 的 tab-panel
document.querySelectorAll('.nav-tab').forEach(function (tab) { document.querySelectorAll('.nav-tab').forEach(function(tab) {
tab.addEventListener('click', function () { tab.addEventListener('click', function() {
var panelId = this.getAttribute('data-panel'); var panelId = this.getAttribute('data-panel');
if (!panelId) return; if (!panelId) return;
document.querySelectorAll('.nav-tab').forEach(function (t) { t.classList.remove('active'); }); document.querySelectorAll('.nav-tab').forEach(function(t) { t.classList.remove('active'); });
document.querySelectorAll('.tab-panel').forEach(function (p) { document.querySelectorAll('.tab-panel').forEach(function(p) {
p.classList.toggle('active', p.getAttribute('data-panel') === panelId); p.classList.toggle('active', p.getAttribute('data-panel') === panelId);
}); });
this.classList.add('active'); this.classList.add('active');
@@ -756,7 +481,7 @@
var el = document.getElementById('toast'); var el = document.getElementById('toast');
el.textContent = msg; el.textContent = msg;
el.classList.add('show'); el.classList.add('show');
setTimeout(function () { el.classList.remove('show'); }, 2500); setTimeout(function() { el.classList.remove('show'); }, 2500);
} }
function renderSelected() { function renderSelected() {
@@ -766,14 +491,14 @@
return; return;
} }
el.innerHTML = '已选 <b>' + selectedPaths.length + '</b> 个文件:<br>' + el.innerHTML = '已选 <b>' + selectedPaths.length + '</b> 个文件:<br>' +
selectedPaths.slice(0, 20).map(function (p) { selectedPaths.slice(0, 20).map(function(p) {
var name = p.split(/[/\\]/).pop(); var name = p.split(/[/\\]/).pop();
return '<span title="' + p + '">' + name + '</span>'; return '<span title="' + p + '">' + name + '</span>';
}).join('') + }).join('') +
(selectedPaths.length > 20 ? '<span>… 等 ' + selectedPaths.length + ' 个</span>' : ''); (selectedPaths.length > 20 ? '<span>… 等 ' + selectedPaths.length + ' 个</span>' : '');
} }
document.getElementById('btnSelectFiles').onclick = async function (e) { document.getElementById('btnSelectFiles').onclick = async function(e) {
e.stopPropagation(); e.stopPropagation();
if (!api || !api.select_brand_xlsx_files) { if (!api || !api.select_brand_xlsx_files) {
showToast('当前环境不支持文件选择,请在本机客户端中打开'); showToast('当前环境不支持文件选择,请在本机客户端中打开');
@@ -791,7 +516,7 @@
} }
}; };
document.getElementById('templateDownloadRow').onclick = async function (e) { document.getElementById('templateDownloadRow').onclick = async function(e) {
e.preventDefault(); e.preventDefault();
if (api && api.save_template_xlsx) { if (api && api.save_template_xlsx) {
try { try {
@@ -808,11 +533,11 @@
} }
window.location.href = '/static/品牌文档格式_模板.xlsx'; window.location.href = '/static/品牌文档格式_模板.xlsx';
}; };
document.getElementById('templateDownloadRow').onkeydown = function (e) { document.getElementById('templateDownloadRow').onkeydown = function(e) {
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this.click(); } if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this.click(); }
}; };
document.getElementById('templateDownloadRow2').onclick = async function (e) { document.getElementById('templateDownloadRow2').onclick = async function(e) {
e.preventDefault(); e.preventDefault();
if (api && api.save_template_zip) { if (api && api.save_template_zip) {
try { try {
@@ -829,11 +554,11 @@
} }
window.location.href = '/static/模板2-以文件夹方式上传.zip'; window.location.href = '/static/模板2-以文件夹方式上传.zip';
}; };
document.getElementById('templateDownloadRow2').onkeydown = function (e) { document.getElementById('templateDownloadRow2').onkeydown = function(e) {
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this.click(); } if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this.click(); }
}; };
document.getElementById('btnSelectFolder').onclick = async function (e) { document.getElementById('btnSelectFolder').onclick =async function(e) {
e.stopPropagation(); e.stopPropagation();
if (!api || !api.select_brand_folder) { if (!api || !api.select_brand_folder) {
showToast('当前环境不支持文件夹选择,请在本机客户端中打开'); showToast('当前环境不支持文件夹选择,请在本机客户端中打开');
@@ -848,8 +573,8 @@
credentials: 'same-origin', credentials: 'same-origin',
body: JSON.stringify({ folder: folder }) body: JSON.stringify({ folder: folder })
}) })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res) { .then(function(res) {
if (res.success && res.paths && res.paths.length) { if (res.success && res.paths && res.paths.length) {
selectedPaths = res.paths; selectedPaths = res.paths;
renderSelected(); renderSelected();
@@ -858,7 +583,7 @@
showToast(res.error || '该文件夹下没有 xlsx 文件'); showToast(res.error || '该文件夹下没有 xlsx 文件');
} }
}) })
.catch(function () { showToast('请求失败'); }); .catch(function() { showToast('请求失败'); });
} catch (err) { } catch (err) {
showToast('选择失败:' + (err.message || err)); showToast('选择失败:' + (err.message || err));
} }
@@ -916,10 +641,10 @@
var runProgressWrap = document.getElementById('runProgressWrap'); var runProgressWrap = document.getElementById('runProgressWrap');
runProgressWrap.style.display = 'block'; runProgressWrap.style.display = 'block';
btnCancelRun.style.display = 'inline-block'; btnCancelRun.style.display = 'inline-block';
btnCancelRun.onclick = function () { btnCancelRun.onclick = function() {
fetch('/api/brand/tasks/' + taskId + '/cancel', { method: 'POST', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } }) fetch('/api/brand/tasks/' + taskId + '/cancel', { method: 'POST', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res) { .then(function(res) {
if (res.success) onRunTaskFinished('cancelled'); if (res.success) onRunTaskFinished('cancelled');
else showToast(res.error || '取消失败'); else showToast(res.error || '取消失败');
}); });
@@ -928,7 +653,7 @@
// 通过 SSE 订阅任务完成事件,完成后由后端主动推送,前端收到后立即隐藏进度条和取消按钮 // 通过 SSE 订阅任务完成事件,完成后由后端主动推送,前端收到后立即隐藏进度条和取消按钮
var eventsUrl = '/api/brand/tasks/' + taskId + '/events'; var eventsUrl = '/api/brand/tasks/' + taskId + '/events';
runTaskEventSource = new EventSource(eventsUrl); runTaskEventSource = new EventSource(eventsUrl);
runTaskEventSource.onmessage = function (e) { runTaskEventSource.onmessage = function(e) {
try { try {
var data = JSON.parse(e.data); var data = JSON.parse(e.data);
if (data && (data.status === 'success' || data.status === 'failed' || data.status === 'cancelled')) { if (data && (data.status === 'success' || data.status === 'failed' || data.status === 'cancelled')) {
@@ -937,9 +662,9 @@
// tick(); // tick();
onRunTaskFinished(data.status); onRunTaskFinished(data.status);
} }
} catch (err) { } } catch (err) {}
}; };
runTaskEventSource.onerror = function () { runTaskEventSource.onerror = function() {
runTaskEventSource.close(); runTaskEventSource.close();
runTaskEventSource = null; runTaskEventSource = null;
}; };
@@ -947,8 +672,8 @@
function tick() { function tick() {
if (!pollTaskId) return; if (!pollTaskId) return;
fetch('/api/brand/tasks/' + taskId, { credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } }) fetch('/api/brand/tasks/' + taskId, { credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res) { .then(function(res) {
if (!res.success || !res.task) return; if (!res.success || !res.task) return;
var t = res.task; var t = res.task;
var total = t.progress_total || 0; var total = t.progress_total || 0;
@@ -976,8 +701,8 @@
credentials: 'same-origin', credentials: 'same-origin',
headers: { 'X-Requested-With': 'XMLHttpRequest' } headers: { 'X-Requested-With': 'XMLHttpRequest' }
}) })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res2) { .then(function(res2) {
if (!res2.success || !res2.has_progress || !res2.info) { if (!res2.success || !res2.has_progress || !res2.info) {
runLineProgressWrap.style.display = 'none'; runLineProgressWrap.style.display = 'none';
return; return;
@@ -989,7 +714,7 @@
runLineProgressFill.style.width = totalLines ? (100 * curLine / totalLines) + '%' : '0%'; runLineProgressFill.style.width = totalLines ? (100 * curLine / totalLines) + '%' : '0%';
runLineProgressText.textContent = totalLines ? (curLine + ' / ' + totalLines) : '当前文件处理中…'; runLineProgressText.textContent = totalLines ? (curLine + ' / ' + totalLines) : '当前文件处理中…';
}) })
.catch(function () { }); .catch(function() {});
} else { } else {
runLineProgressWrap.style.display = 'none'; runLineProgressWrap.style.display = 'none';
} }
@@ -1005,7 +730,7 @@
pollTimer = setInterval(tick, 5000); pollTimer = setInterval(tick, 5000);
} }
document.getElementById('btnRun').onclick = function () { document.getElementById('btnRun').onclick = function() {
if (selectedPaths.length === 0) { if (selectedPaths.length === 0) {
showToast('请先选择 Excel 文件或文件夹'); showToast('请先选择 Excel 文件或文件夹');
return; return;
@@ -1024,8 +749,8 @@
credentials: 'same-origin', credentials: 'same-origin',
body: JSON.stringify({ paths: selectedPaths, strategy: strategy, task_type: 1 }) body: JSON.stringify({ paths: selectedPaths, strategy: strategy, task_type: 1 })
}) })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res) { .then(function(res) {
if (res.success && res.task_id) { if (res.success && res.task_id) {
loadingMsg.style.display = 'none'; loadingMsg.style.display = 'none';
pollRunTask(res.task_id); pollRunTask(res.task_id);
@@ -1034,7 +759,7 @@
showToast(res.error || '运行失败'); showToast(res.error || '运行失败');
} }
}) })
.catch(function () { .catch(function() {
stopPollAndResetRunUI(); stopPollAndResetRunUI();
showToast('请求失败或超时'); showToast('请求失败或超时');
}); });
@@ -1045,8 +770,8 @@
credentials: 'same-origin', credentials: 'same-origin',
body: JSON.stringify({ paths: selectedPaths, strategy: strategy, task_type: 2 }) body: JSON.stringify({ paths: selectedPaths, strategy: strategy, task_type: 2 })
}) })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res) { .then(function(res) {
if (res.success) { if (res.success) {
showToast('任务已添加,请在任务队列查看'); showToast('任务已添加,请在任务队列查看');
loadTasks(); loadTasks();
@@ -1054,14 +779,14 @@
showToast(res.error || '添加失败'); showToast(res.error || '添加失败');
} }
}) })
.catch(function () { showToast('请求失败'); }); .catch(function() { showToast('请求失败'); });
} }
}; };
function loadTasks() { function loadTasks() {
fetch('/api/brand/tasks', { credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } }) fetch('/api/brand/tasks', { credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res) { .then(function(res) {
var list = document.getElementById('taskList'); var list = document.getElementById('taskList');
var empty = document.getElementById('emptyTasks'); var empty = document.getElementById('emptyTasks');
if (!res.success || !res.items || res.items.length === 0) { if (!res.success || !res.items || res.items.length === 0) {
@@ -1071,7 +796,7 @@
} }
empty.style.display = 'none'; empty.style.display = 'none';
cachedTasks = res.items; cachedTasks = res.items;
list.innerHTML = res.items.map(function (t) { list.innerHTML = res.items.map(function(t) {
var statusClass = (t.status || 'pending').toLowerCase(); var statusClass = (t.status || 'pending').toLowerCase();
var statusText = { pending: '等待中', running: '执行中', success: '已完成', failed: '失败', cancelled: '已取消' }[t.status] || t.status; var statusText = { pending: '等待中', running: '执行中', success: '已完成', failed: '失败', cancelled: '已取消' }[t.status] || t.status;
var filesDesc = (t.file_paths && t.file_paths.length) ? t.file_paths.length + ' 个文件' : ''; var filesDesc = (t.file_paths && t.file_paths.length) ? t.file_paths.length + ' 个文件' : '';
@@ -1106,7 +831,7 @@
'</div></li>'; '</div></li>';
}).join(''); }).join('');
}) })
.catch(function () { }); .catch(function() {});
} }
// 手动刷新任务状态按钮 // 手动刷新任务状态按钮
@@ -1118,7 +843,7 @@
}; };
} }
document.getElementById('taskList').addEventListener('click', function (e) { document.getElementById('taskList').addEventListener('click', function(e) {
var target = e.target && e.target.closest && (e.target.closest('a.js-save-zip') || e.target.closest('button.js-cancel-task') || e.target.closest('button.js-delete-task')); var target = e.target && e.target.closest && (e.target.closest('a.js-save-zip') || e.target.closest('button.js-cancel-task') || e.target.closest('button.js-delete-task'));
if (!target) return; if (!target) return;
e.preventDefault(); e.preventDefault();
@@ -1127,8 +852,8 @@
var btn = target.classList.contains('js-cancel-task') ? target : target.closest('.js-cancel-task'); var btn = target.classList.contains('js-cancel-task') ? target : target.closest('.js-cancel-task');
if (!btn) return; if (!btn) return;
fetch('/api/brand/tasks/' + taskId + '/cancel', { method: 'POST', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } }) fetch('/api/brand/tasks/' + taskId + '/cancel', { method: 'POST', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res) { .then(function(res) {
if (res.success) { showToast('已取消'); loadTasks(); } else { showToast(res.error || '取消失败'); } if (res.success) { showToast('已取消'); loadTasks(); } else { showToast(res.error || '取消失败'); }
}); });
return; return;
@@ -1137,15 +862,15 @@
var btn = target.classList.contains('js-delete-task') ? target : target.closest('.js-delete-task'); var btn = target.classList.contains('js-delete-task') ? target : target.closest('.js-delete-task');
if (!btn) return; if (!btn) return;
fetch('/api/brand/tasks/' + taskId, { method: 'DELETE', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } }) fetch('/api/brand/tasks/' + taskId, { method: 'DELETE', credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } })
.then(function (r) { return r.json(); }) .then(function(r) { return r.json(); })
.then(function (res) { .then(function(res) {
if (res.success) { showToast('已删除'); loadTasks(); } else { showToast(res.error || '删除失败'); } if (res.success) { showToast('已删除'); loadTasks(); } else { showToast(res.error || '删除失败'); }
}); });
return; return;
} }
var a = target.closest('a.js-save-zip') || target; var a = target.closest('a.js-save-zip') || target;
if (!a || !a.classList || !a.classList.contains('js-save-zip')) return; if (!a || !a.classList || !a.classList.contains('js-save-zip')) return;
var task = cachedTasks.filter(function (t) { return String(t.id) === String(taskId); })[0]; var task = cachedTasks.filter(function(t) { return String(t.id) === String(taskId); })[0];
if (!task || !task.result_paths || !task.result_paths.zip_url) { if (!task || !task.result_paths || !task.result_paths.zip_url) {
showToast('无法获取下载地址'); showToast('无法获取下载地址');
return; return;
@@ -1154,7 +879,7 @@
var filename = 'brand_task_' + taskId + '.zip'; var filename = 'brand_task_' + taskId + '.zip';
if (api && api.save_file_from_url) { if (api && api.save_file_from_url) {
a.style.pointerEvents = 'none'; a.style.pointerEvents = 'none';
var done = function (ret) { var done = function(ret) {
if (ret && ret.success) { if (ret && ret.success) {
showToast('已保存:' + (ret.path || filename)); showToast('已保存:' + (ret.path || filename));
} else if (ret && ret.error && ret.error !== '用户取消') { } else if (ret && ret.error && ret.error !== '用户取消') {
@@ -1165,7 +890,7 @@
try { try {
var ret = api.save_file_from_url(zipUrl, filename); var ret = api.save_file_from_url(zipUrl, filename);
if (ret && typeof ret.then === 'function') { if (ret && typeof ret.then === 'function') {
ret.then(done).catch(function (err) { showToast('保存失败:' + (err && err.message || err)); a.style.pointerEvents = ''; }); ret.then(done).catch(function(err) { showToast('保存失败:' + (err && err.message || err)); a.style.pointerEvents = ''; });
} else { } else {
done(ret); done(ret);
} }
@@ -1182,13 +907,12 @@
// setInterval(loadTasks, 10000); // setInterval(loadTasks, 10000);
if (window.addEventListener) { if (window.addEventListener) {
window.addEventListener('pywebviewready', function () { window.addEventListener('pywebviewready', function() {
api = window.pywebview && window.pywebview.api; api = window.pywebview && window.pywebview.api;
}); });
} }
if (window.pywebview && window.pywebview.api) api = window.pywebview.api; if (window.pywebview && window.pywebview.api) api = window.pywebview.api;
})(); })();
</script> </script>
</body> </body>
</html> </html>