Files
37duAutomation/webhost/backend/plugins/demo.py
T
puddy 53913f0c7d refactor(workflows): 统一替换 yingdao 目录引用为 workflows
1.  将所有文档、代码中对 `yingdao/` 目录的引用替换为 `workflows/`,统一影刀版代码的命名空间
2.  调整 workflows/share 模块内的路径引用与文档注释,确保一致性
3.  同步更新测试代码与配置文件中的旧目录引用
2026-09-08 16:16:35 +08:00

39 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
"""示例场景插件:证明「后端 run + 前端通用表单 + 实时日志/进度」的插件化链路可用。
后续真实场景(如考勤月报封存检查)按同样方式接入即可。
"""
import time
from webhost.backend.plugins.base import PLUGINS, RunContext, ScenePlugin
class DemoPlugin(ScenePlugin):
id = "demo"
name = "示例检查"
version = "1.0.0"
description = "跑一个带进度与日志的假任务,用于验证插件链路。"
fields = [
{"key": "steps", "label": "步数", "type": "int", "default": 3},
{"key": "mode", "label": "模式", "type": "select",
"options": ["正常", "中途报错"], "default": "正常"},
]
def run(self, fields: dict, ctx: RunContext) -> dict:
steps = max(1, min(50, int(fields.get("steps", 3))))
mode = fields.get("mode", "正常")
ctx.log(f"开始示例检查:{steps} 步,模式={mode}")
for i in range(1, steps + 1):
time.sleep(0.6)
ctx.progress(int(i / steps * 90))
ctx.log(f"第 {i}/{steps} 步完成")
if mode == "中途报错":
raise RuntimeError("按模式设置的报错,用于演示失败处理")
ctx.progress(100)
ctx.log("示例检查完成")
return {
"summary": f"共执行 {steps} 步,全部正常",
"rows": [[i, f"结果 {i}"] for i in range(1, steps + 1)],
}
PLUGINS.append(DemoPlugin())