127 lines
4.1 KiB
Python
127 lines
4.1 KiB
Python
"""
|
|
组件配置文件
|
|
包含组件发现、注册和分类的相关配置
|
|
"""
|
|
from typing import Dict, List, Any
|
|
from data.models.component import ComponentCategoryEnum
|
|
|
|
class ComponentDiscovery:
|
|
"""组件自动发现配置"""
|
|
DEFAULT_PACKAGE = "components" # 默认组件包名
|
|
AUTO_REGISTER = True # 是否在启动时自动注册所有组件
|
|
|
|
class ComponentCategory:
|
|
"""组件类别配置"""
|
|
# 组件类别定义
|
|
HTTP_REQUEST = "HTTP请求"
|
|
SCRIPT = "脚本"
|
|
FLOW = "流程"
|
|
ROBOT = "机器人调度"
|
|
SITE = "库位"
|
|
DEVICE = "设备"
|
|
SUBTASK = "子任务"
|
|
TASK = "任务"
|
|
BASE = "基础"
|
|
|
|
# 组件类别映射配置
|
|
# 用于将组件类型映射到对应的类别,便于前端展示
|
|
@classmethod
|
|
def get_mapping(cls) -> Dict[str, str]:
|
|
"""获取组件类型到类别的映射"""
|
|
return {
|
|
# HTTP请求组件
|
|
"http": cls.HTTP_REQUEST,
|
|
|
|
# 脚本组件
|
|
"script": cls.SCRIPT,
|
|
|
|
# 流程控制组件
|
|
"if": cls.FLOW,
|
|
"if_else": cls.FLOW,
|
|
"if_else_if": cls.FLOW,
|
|
"for_each": cls.FLOW,
|
|
"while": cls.FLOW,
|
|
"break": cls.FLOW,
|
|
"return": cls.FLOW,
|
|
"delay": cls.FLOW,
|
|
|
|
# 机器人调度组件
|
|
"robot": cls.ROBOT,
|
|
|
|
# 库位组件
|
|
"site": cls.SITE,
|
|
|
|
# 设备组件
|
|
"modbus": cls.DEVICE,
|
|
|
|
# 子任务组件
|
|
"subtask": cls.SUBTASK,
|
|
}
|
|
|
|
# 组件分类优先级
|
|
# 控制前端组件面板中各分类的显示顺序
|
|
@classmethod
|
|
def get_priority(cls) -> List[str]:
|
|
"""获取组件类别优先级列表"""
|
|
return [
|
|
cls.SUBTASK,
|
|
cls.SCRIPT,
|
|
cls.HTTP_REQUEST,
|
|
cls.TASK,
|
|
cls.FLOW,
|
|
cls.BASE,
|
|
cls.SITE,
|
|
cls.ROBOT,
|
|
cls.DEVICE
|
|
]
|
|
|
|
class ComponentCategoryConfig:
|
|
"""组件分类配置"""
|
|
|
|
@classmethod
|
|
def get_category_name(cls, category_enum):
|
|
"""获取分类名称"""
|
|
names = {
|
|
ComponentCategoryEnum.SUBTASK: "子任务",
|
|
ComponentCategoryEnum.SCRIPT: "脚本",
|
|
ComponentCategoryEnum.HTTP: "HTTP请求",
|
|
ComponentCategoryEnum.TASK: "任务",
|
|
ComponentCategoryEnum.FLOW: "流程",
|
|
ComponentCategoryEnum.BASIC: "基础",
|
|
ComponentCategoryEnum.STORAGE: "库位",
|
|
ComponentCategoryEnum.ROBOT: "机器人调度",
|
|
ComponentCategoryEnum.DEVICE: "设备"
|
|
}
|
|
return names.get(category_enum, category_enum.value)
|
|
|
|
@classmethod
|
|
def get_category_description(cls, category_enum):
|
|
"""获取分类描述"""
|
|
descriptions = {
|
|
ComponentCategoryEnum.SUBTASK: "可重用的子任务组件",
|
|
ComponentCategoryEnum.SCRIPT: "执行脚本代码的组件",
|
|
ComponentCategoryEnum.HTTP: "发送HTTP请求的组件",
|
|
ComponentCategoryEnum.TASK: "任务管理相关组件",
|
|
ComponentCategoryEnum.FLOW: "流程控制相关组件",
|
|
ComponentCategoryEnum.BASIC: "基础功能组件",
|
|
ComponentCategoryEnum.STORAGE: "库位管理相关组件",
|
|
ComponentCategoryEnum.ROBOT: "机器人调度相关组件",
|
|
ComponentCategoryEnum.DEVICE: "设备控制相关组件"
|
|
}
|
|
return descriptions.get(category_enum, f"{category_enum.value}类组件")
|
|
|
|
@classmethod
|
|
def get_category_order(cls, category_enum):
|
|
"""获取分类排序"""
|
|
orders = {
|
|
ComponentCategoryEnum.BASIC: 1,
|
|
ComponentCategoryEnum.FLOW: 2,
|
|
ComponentCategoryEnum.TASK: 3,
|
|
ComponentCategoryEnum.SUBTASK: 4,
|
|
ComponentCategoryEnum.SCRIPT: 5,
|
|
ComponentCategoryEnum.HTTP: 6,
|
|
ComponentCategoryEnum.ROBOT: 7,
|
|
ComponentCategoryEnum.STORAGE: 8,
|
|
ComponentCategoryEnum.DEVICE: 9
|
|
}
|
|
return orders.get(category_enum, 99) |