diff --git a/main.py b/main.py index 3dba172..477dd2a 100644 --- a/main.py +++ b/main.py @@ -113,6 +113,7 @@ class App: self.running = False self.paused = False self.results = [] + self._text_rows = None # 文本导入的单号数据,与 Excel 互斥 # 固定值编辑框变量 self.fv_product = StringVar() @@ -176,6 +177,9 @@ class App: Button(row2, text="选择文件", command=self._pick_file, width=10).pack( side="right" ) + Button(row2, text="从文本导入", command=self._pick_text, width=12).pack( + side="right", padx=5 + ) # 延时设置 row3 = Frame(config_frame) @@ -644,6 +648,36 @@ class App: if path: self.excel_path.set(path) self.file_label.configure(text=path, fg="black") + self._text_rows = None # 清空文本导入数据 + + def _pick_text(self): + """弹出文本框粘贴单号,一行一个。""" + win = Toplevel(self.root) + win.title("从文本导入单号") + win.geometry("400x350") + win.transient(self.root) + win.grab_set() + + Label(win, text="粘贴单号(一行一个):", font=("", 10, "bold"), pady=8).pack() + + text = Text(win, width=50, height=15, font=("Consolas", 9)) + text.pack(fill="both", expand=True, padx=10, pady=5) + + def do_import(): + raw = text.get("1.0", "end-1c").strip() + if not raw: + messagebox.showwarning("提示", "请输入单号", parent=win) + return + lines = [l.strip() for l in raw.splitlines() if l.strip()] + self._text_rows = [{"单号": l} for l in lines] + self.excel_path.set("") # 清空 Excel + self.file_label.configure(text=f"文本导入: {len(lines)} 条单号", fg="black") + win.destroy() + + btn_f = Frame(win) + btn_f.pack(pady=8) + Button(btn_f, text="导入", command=do_import, bg="#4CAF50", fg="white", width=10).pack(side="left", padx=5) + Button(btn_f, text="取消", command=win.destroy, width=8).pack(side="left", padx=5) def _on_close(self): """关闭窗口;atexit 会强制清理 Node.js 子进程。""" @@ -698,18 +732,21 @@ class App: if self.running: return - if not self.excel_path.get(): - messagebox.showwarning("提示", "请先选择 Excel 文件") - return - - try: - rows, headers = read_input_excel(self.excel_path.get()) - except Exception as e: - messagebox.showerror("读取错误", f"读取 Excel 失败:\n{e}") - return + if self._text_rows: + rows = self._text_rows + headers = ["单号"] + else: + if not self.excel_path.get(): + messagebox.showwarning("提示", "请先选择 Excel 文件或从文本导入单号") + return + try: + rows, headers = read_input_excel(self.excel_path.get()) + except Exception as e: + messagebox.showerror("读取错误", f"读取 Excel 失败:\n{e}") + return if not rows: - messagebox.showwarning("提示", "Excel 中没有数据") + messagebox.showwarning("提示", "没有数据") return # 保存固定值到配置文件(必须在验证之前,确保用户选择的产品/客户已写入 config)