feat: add ERP credential configuration for User mode in settings

Allow User type users to configure ERP username and password through
the settings interface. The credentials are stored as shared config
in .env file, and the URL remains admin-configured.

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-27 15:21:46 +08:00
parent 4a17c8fd11
commit 2d485be0ac

View File

@@ -65,15 +65,16 @@ class SettingsTab(ttk.Frame):
self._create_validation_group(scrollable_frame)
self._create_ui_group(scrollable_frame)
else:
# User 用户:显示路径配置和执行设置
# User 用户:显示 ERP 凭据、路径配置和执行设置
self._create_user_erp_group(scrollable_frame)
self._create_paths_group(scrollable_frame)
self._create_user_execution_group(scrollable_frame)
# 按钮区域 - 根据用户类型显示不同按钮
button_frame = ttk.Frame(scrollable_frame)
if is_user_only:
# User 用户显示测试按钮和保存设置按钮row=4 因为有执行设置组)
button_frame.grid(row=4, column=0, columnspan=2, pady=20, sticky="ew")
# User 用户显示测试按钮和保存设置按钮row=3 因为有 ERP 凭据组、路径设置组、执行设置组)
button_frame.grid(row=3, column=0, columnspan=2, pady=20, sticky="ew")
else:
# 管理员显示所有按钮
button_frame.grid(row=7, column=0, columnspan=2, pady=20, sticky="ew")
@@ -138,6 +139,41 @@ class SettingsTab(ttk.Frame):
group.columnconfigure(1, weight=1)
def _create_user_erp_group(self, parent):
"""创建 User 用户的 ERP 凭据配置组"""
group = ttk.LabelFrame(parent, text="ERP 登录凭据", padding=10)
group.grid(row=0, column=0, columnspan=2, pady=10, padx=10, sticky="ew")
# 用户名
ttk.Label(group, text="ERP 用户名:").grid(row=0, column=0, sticky="w", pady=5)
self.user_erp_username_var = tk.StringVar()
ttk.Entry(group, textvariable=self.user_erp_username_var, width=40).grid(
row=0, column=1, pady=5, sticky="ew"
)
# 密码(带显示/隐藏切换)
ttk.Label(group, text="ERP 密码:").grid(row=1, column=0, sticky="w", pady=5)
self.user_erp_password_var = tk.StringVar()
password_entry = ttk.Entry(group, textvariable=self.user_erp_password_var, width=40, show="*")
password_entry.grid(row=1, column=1, pady=5, sticky="ew")
# 显示/隐藏密码按钮
self.password_visible = tk.BooleanVar(value=False)
ttk.Checkbutton(
group, text="显示密码", variable=self.password_visible,
command=lambda: password_entry.configure(show="" if self.password_visible.get() else "*")
).grid(row=2, column=1, sticky="w", pady=2)
# 提示文字
hint_label = ttk.Label(
group,
text="提示:此凭据为共享配置,修改后所有用户将使用新的 ERP 账号。",
foreground="gray",
)
hint_label.grid(row=3, column=0, columnspan=2, sticky="w", pady=(5, 0))
group.columnconfigure(1, weight=1)
def _create_database_group(self, parent):
"""创建数据库配置组"""
group = ttk.LabelFrame(parent, text="数据库配置", padding=10)
@@ -252,7 +288,8 @@ class SettingsTab(ttk.Frame):
group = ttk.LabelFrame(parent, text="路径设置", padding=10)
if is_user_only:
group.grid(row=2, column=1, pady=10, padx=10, sticky="nsew")
# User 用户ERP 凭据在 row=0路径设置在 row=1
group.grid(row=1, column=0, columnspan=2, pady=10, padx=10, sticky="ew")
else:
group.grid(row=2, column=1, pady=10, padx=10, sticky="nsew")
@@ -286,7 +323,8 @@ class SettingsTab(ttk.Frame):
def _create_user_execution_group(self, parent):
"""创建 User 用户的执行设置组"""
group = ttk.LabelFrame(parent, text="执行设置", padding=10)
group.grid(row=3, column=0, columnspan=2, pady=10, padx=10, sticky="ew")
# User 用户ERP 凭据在 row=0路径设置在 row=1执行设置在 row=2
group.grid(row=2, column=0, columnspan=2, pady=10, padx=10, sticky="ew")
# dryrun 模式设置
self.user_dryrun_var = tk.BooleanVar(value=False)
@@ -466,7 +504,10 @@ class SettingsTab(ttk.Frame):
)
if is_user_only:
# User 用户模式 - 只需要加载路径设置到界面
# User 用户模式 - 只需要加载 ERP 凭据、路径设置到界面
# ERP 凭据
self.user_erp_username_var.set(self.config.get("erp.username", ""))
self.user_erp_password_var.set(self.config.get("erp.password", ""))
# 路径设置
self.data_dir_selector.set(self.config.get("paths.data_dir", ""))
self.default_output_var.set(self.config.get("paths.default_output", ""))
@@ -559,7 +600,11 @@ class SettingsTab(ttk.Frame):
)
if is_user_only:
# User 用户模式 - 只保存路径设置和执行设置
# User 用户模式 - 只保存 ERP 凭据、路径设置和执行设置
# ERP 凭据
self.config.set("erp.username", self.user_erp_username_var.get())
self.config.set("erp.password", self.user_erp_password_var.get())
# 路径设置
self.config.set("paths.data_dir", self.data_dir_selector.get())
self.config.set("paths.default_output", self.default_output_var.get())
self.config.set(