本次提交完成了整体项目的目录梳理与代码迁移: 1. 将根级controlplane、webhost等目录的代码迁移至desktop/对应子目录,统一桌面端架构 2. 移动并整理了插件目录结构,将插件统一放入根级plugins/ 3. 调整了前端项目的路径与配置,统一前后端开发构建流程 4. 清理了废弃的旧版app/目录与冗余的构建中间文件 5. 更新了.gitignore与README.md,适配新的项目结构
39 lines
1.5 KiB
Python
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()) |