pcacc 5 mesi fa
parent
commit
907c4b9597
3 ha cambiato i file con 26 aggiunte e 15 eliminazioni
  1. 25 10
      app_dongri.py
  2. 0 5
      scriptBase/ocr.py
  3. 1 0
      templates/index_dongri.html

+ 25 - 10
app_dongri.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-import datetime
+from datetime import datetime 
 from flask import Flask, render_template
 from flask_socketio import SocketIO, emit
 from scriptBase.comon import *
@@ -15,9 +15,9 @@ from concurrent.futures import ThreadPoolExecutor
 executor = ThreadPoolExecutor(max_workers=1)
 
 app = Flask(__name__)
-socketio = SocketIO(app)
+socketio = SocketIO(app, cors_allowed_origins="*")
 event = threading.Event()
-g_status = ''
+g_status_list = []
 last_time = 0.0
 task_queue = deque()
 last_process = ''
@@ -60,18 +60,33 @@ def send_hint(msg):#数组信息
     emit('processing_hint', msg)
 
 def send_status(msg):#软件执行状态
-    global g_status
+    global g_status_list
     try:
-        if msg == '':
-            emit('processing_status', g_status)
-            return
+        if not msg == "":
+            # 添加新的状态消息和时间到列表
+            timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')  # 获取当前时间
+            status_entry = {'msg': msg, 'time': timestamp}  # 存储消息和时间
+            g_status_list.append(status_entry)
+
+            # 如果列表超过 5 条,移除最早的一条
+            if len(g_status_list) > 5:
+                g_status_list.pop(0)
         else:
-            g_status = msg
+            sendStr = ''
+            for item in g_status_list:
+                sendStr = sendStr + f"{item['time']}-{item['msg']}<br>" 
+
+            #print(sendStr)
+            emit('processing_status', sendStr)
+        
         
+
+        # 如果消息是 "结束",发送所有状态并清空列表
         if msg == "结束":
+            g_status_list = []  # 清空列表
             event.clear()
-        emit('processing_status', msg)
-    except:
+    except Exception as e:
+        print(f"Error in send_status: {e}")
         return
 
 

+ 0 - 5
scriptBase/ocr.py

@@ -1,12 +1,7 @@
 from paddleocr import PaddleOCR
 from PIL import Image, ImageGrab
-import paddle
-import paddleocr
 import numpy as np
 
-print(paddle.__version__)  # 打印 PaddlePaddle 版本
-print(paddleocr.__version__)  # 打印 PaddleOCR 版本
-
 # 定义截图和OCR识别函数
 def capture_and_ocr(region):
     # 读取屏幕截图

+ 1 - 0
templates/index_dongri.html

@@ -94,6 +94,7 @@
         socket.on('processing_status', (msg) => {
             var messageBox = document.getElementById('status_message');
             messageBox.innerHTML = msg;
+            console.log(msg);
         });
         socket.on('processing_title', (msg) => {
             var messageBox = document.getElementById('title_message');