暂提更新

This commit is contained in:
super
2026-03-22 11:35:45 +08:00
parent 497d65d41d
commit cfbd5d6e84
7 changed files with 86 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
"""
基于 pywebview 实现的跨平台 UI需先登录方可使用
"""
from config import cache_path,debug,version,java_api_base
from config import cache_path,debug,version,JAVA_API_BASE
import datetime
import json
import sys
@@ -26,7 +26,6 @@ with open("version.txt","w",encoding="utf-8") as file:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
APP_URL = "http://127.0.0.1:5123"
PORT = 5123
JAVA_API_BASE = java_api_base
def generate_images(params):
@@ -235,6 +234,27 @@ class WindowAPI:
except Exception as e:
return {'success': False, 'error': str(e)}
def upload_file_to_java(self, file_path):
"""按本地路径读取文件并上传到 Java 后端临时目录。"""
if not file_path or not str(file_path).strip():
return {'success': False, 'error': '文件路径为空'}
normalized_path = os.path.abspath(str(file_path).strip())
if not os.path.isfile(normalized_path):
return {'success': False, 'error': '文件不存在'}
try:
with open(normalized_path, 'rb') as file_obj:
response = requests.post(
f"{JAVA_API_BASE}/api/files/upload",
files={'file': (os.path.basename(normalized_path), file_obj)},
timeout=120,
)
response.raise_for_status()
payload = response.json()
if not isinstance(payload, dict):
return {'success': False, 'error': 'Java 返回格式错误'}
return payload
except Exception as e:
return {'success': False, 'error': str(e)}
def _select_folder_win32():
"""Windows: 用 ctypes 调用系统文件夹选择对话框,打包成 exe 后也能正常弹窗(不依赖 tkinter"""
@@ -346,7 +366,7 @@ def main():
time.sleep(2)
window = webview.create_window(
title="南日AI",
title="数富AI",
url=APP_URL,
width=1400,
height=900,
@@ -357,7 +377,8 @@ def main():
easy_drag=True
)
api = WindowAPI(window)
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.upload_file_to_java, api.save_file_from_url, api.save_template_xlsx,api.save_template_zip)
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)
webview.start(
debug=True,
storage_path=cache_path,