跳到内容
Lenso
简体中文
Esc
navigateopen⌘Jpreview
本页内容

管理界面

通过 Runtime Console公开模块数据、操作、查询和自定义操作员视图。

管理界面是模块变得可操作的方式。他们描述了数据, Runtime Console无需导入即可显示的操作和只读值 模块内部结构。

三种界面模式

模式 使用时
Schema 该模块公开普通列表/详细业务记录
DeclarativeCustom 该模块需要使用受信任的控制台组件提供更丰富的主机渲染页面
EmbeddedCustom 该模块拥有一个单独的 UI 运行时,并且必须被沙箱化

Schema 开始。仅当操作员工作流需要时才转向声明式 不仅仅是表格和详细视图。仅当模块真正拥有时才使用嵌入 无法表达为数据的 UI。

Schema 界面

Schema 界面是无聊但有用的路径。该模块声明实体和 领域;主机通过模块的管理数据源读取记录。

use lenso::{AdminSchema, EntitySchema, FieldSchema, FieldType, ModuleManifest};

pub fn manifest() -> ModuleManifest {
    ModuleManifest::builder("support")
        .capabilities(vec!["support.tickets.read".to_owned()])
        .admin(AdminSchema {
            entities: vec![EntitySchema {
                name: "tickets".to_owned(),
                label: "Tickets".to_owned(),
                read_capability: "support.tickets.read".to_owned(),
                fields: vec![
                    FieldSchema {
                        name: "title".to_owned(),
                        label: "Title".to_owned(),
                        field_type: FieldType::String,
                        nullable: false,
                    },
                    FieldSchema {
                        name: "status".to_owned(),
                        label: "Status".to_owned(),
                        field_type: FieldType::String,
                        nullable: false,
                    },
                ],
            }],
        })
        .build()
}

Runtime Console通过主机拥有的 /admin/data/* 端点读取记录。 模块内部保留强类型;通用管理数据跨越 作为 JSON 记录的边界。

声明式自定义界面

声明性自定义界面让模块可以构建更丰富的操作页面,而无需 运输前端代码。Manifest提供结构化数据;运行时 控制台拥有渲染、样式、可访问性和行为。

use lenso::{
    AdminAction, AdminActionDangerLevel, AdminActionInputField,
    AdminActionInputSchema, AdminDeclarativeComponent, AdminDeclarativePage,
    AdminDeclarativeSection, AdminDeclarativeSurface, AdminSchema, EntitySchema,
    FieldSchema, FieldType, ModuleManifest,
};

fn fallback_schema() -> AdminSchema {
    AdminSchema {
        entities: vec![EntitySchema {
            name: "tickets".to_owned(),
            label: "Tickets".to_owned(),
            read_capability: "support.tickets.read".to_owned(),
            fields: vec![FieldSchema {
                name: "title".to_owned(),
                label: "Title".to_owned(),
                field_type: FieldType::String,
                nullable: false,
            }],
        }],
    }
}

pub fn manifest() -> ModuleManifest {
    ModuleManifest::builder("support")
        .capabilities(vec![
            "support.tickets.read".to_owned(),
            "support.tickets.assign".to_owned(),
            "support.metrics.read".to_owned(),
        ])
        .declarative_admin(AdminDeclarativeSurface {
            pages: vec![AdminDeclarativePage {
                name: "overview".to_owned(),
                label: "Overview".to_owned(),
                sections: vec![
                    AdminDeclarativeSection {
                        name: "ticket-count".to_owned(),
                        label: "Ticket Count".to_owned(),
                        component: AdminDeclarativeComponent::QueryValue {
                            query: "ticket_metrics".to_owned(),
                            capability: "support.metrics.read".to_owned(),
                            value_path: "open_count".to_owned(),
                        },
                    },
                    AdminDeclarativeSection {
                        name: "tickets".to_owned(),
                        label: "Tickets".to_owned(),
                        component: AdminDeclarativeComponent::EntityTable {
                            entity: "tickets".to_owned(),
                        },
                    },
                ],
            }],
            actions: vec![AdminAction {
                name: "assign_ticket".to_owned(),
                label: "Assign Ticket".to_owned(),
                capability: "support.tickets.assign".to_owned(),
                input_schema: Some(AdminActionInputSchema {
                    fields: vec![AdminActionInputField {
                        name: "assignee".to_owned(),
                        label: "Assignee".to_owned(),
                        field_type: FieldType::String,
                        required: true,
                        description: Some("User id to assign".to_owned()),
                    }],
                }),
                confirmation: None,
                danger_level: AdminActionDangerLevel::Low,
            }],
            fallback_schema: Some(fallback_schema()),
        })
        .build()
}

fallback_schema 让控制台呈现可信实体表/详细信息并读取 通过相同的管理数据路径进行记录。它不会将模块变成 普通Schema 界面,未在 /admin/data/schema 中列出。

操作和查询

声明性页面可以显示只读查询值并调用声明的操作。 主机验证Manifest、检查功能声明、验证 动作输入,然后调用模块行为接口。

声明 主机端点形态
AdminDeclarativeComponent::QueryValue /admin/data/{module}/queries/{query}
AdminAction /admin/data/{module}/actions/{action}
fallback_schema实体 /admin/data/{module}/{entity}

成功和失败的管理操作调用都会投射到运行时中 Story和技术操作,因此操作员的工作留下了证据。

嵌入式定制界面

嵌入式自定义界面是模块拥有的 UI 的逃生口。他们开始 作为具有明确来源且没有主机桥的沙盒 iframe。

use lenso::{
    AdminEmbeddedEntry, AdminEmbeddedRuntime, AdminEmbeddedSurface,
    AdminPermission, AdminSandboxPolicy, ModuleManifest,
};

pub fn manifest() -> ModuleManifest {
    ModuleManifest::builder("crm")
        .embedded_admin(AdminEmbeddedSurface {
            runtime: AdminEmbeddedRuntime::Iframe,
            entry: AdminEmbeddedEntry::Url {
                url: "https://crm.example.test/admin".to_owned(),
                allowed_origins: vec!["https://crm.example.test".to_owned()],
            },
            sandbox: AdminSandboxPolicy {
                allow_scripts: true,
                allow_forms: false,
                allow_popups: false,
                allow_same_origin: false,
            },
            permissions: vec![AdminPermission::ReadEntity {
                entity: "contacts".to_owned(),
            }],
            fallback_schema: None,
        })
        .build()
}

不要使用嵌入式界面来走私主机令牌、任意 JavaScript 桥接器,或私有控制台导入到模块中。主机/模块通信 需要一个版本化的协议。

模块本地配置

模块本地配置属于静态主机配置,不可编辑的运行时配置 数据库行:

LENSO_MODULE_AUTH_PASSWORD__JWT_ISSUER=acme
LENSO_MODULE_SUPPORT__DEFAULT_ASSIGNEE=usr_1

模块加载切换是单独的并且仅重新启动:

LENSO_MODULE_SUPPORT_ENABLED=false

使用运行时配置来获取操作员可编辑的平台值。使用模块本地环境 配置模块代码在启动时所需的值。

最后更新于 2026年8月1日

这个页面有帮助吗?