diff --git a/config/loader.py b/config/loader.py index 2e7068f..9e259be 100644 --- a/config/loader.py +++ b/config/loader.py @@ -111,7 +111,7 @@ class ConfigLoader: "ERP_IGNORE_HTTPS_ERRORS": config.erp.ignore_https_errors, "ERP_AUTO_CLOSE_BROWSER": config.erp.auto_close_browser, # 数据库配置 - "DB_TYPE": config.database.db_type.value, + "DB_TYPE": config.database.db_type.value if isinstance(config.database.db_type, DatabaseType) else config.database.db_type, "DB_SERVER": config.database.server, "DB_NAME": config.database.database, "DB_USERNAME": config.database.username, diff --git a/config/schema.py b/config/schema.py index 306667f..b66a9d2 100644 --- a/config/schema.py +++ b/config/schema.py @@ -312,7 +312,7 @@ class AppConfig: "auto_close_browser": self.erp.auto_close_browser, }, "database": { - "db_type": self.database.db_type.value, + "db_type": self.database.db_type if isinstance(self.database.db_type, str) else self.database.db_type.value, "server": self.database.server, "database": self.database.database, "username": self.database.username, diff --git a/gui/config_manager.py b/gui/config_manager.py index b525b5b..0a41d28 100644 --- a/gui/config_manager.py +++ b/gui/config_manager.py @@ -94,8 +94,20 @@ class ConfigManager: for k in keys[:-1]: obj = getattr(obj, k) + # 获取目标字段信息用于类型转换 + target_field = keys[-1] + field_type = type(getattr(obj, target_field)) + + # 如果是字符串且目标字段是枚举类型,进行转换 + if isinstance(value, str) and hasattr(field_type, "__members__"): # 它是一个 Enum + try: + value = field_type(value) + except ValueError: + # 无效的枚举值,保持当前值不变 + value = getattr(obj, target_field) + # 设置最终值 - setattr(obj, keys[-1], value) + setattr(obj, target_field, value) def reset_to_defaults(self) -> None: """重置为默认配置"""