EMOS

@report-sdk/react-designer (1.0.0)

Published 2026-10-26 15:14:44 +08:00 by sunqh

Installation

@report-sdk:registry=http://chenfeng.tech:3000/api/packages/EMOS/npm/
npm install @report-sdk/react-designer@1.0.0
"@report-sdk/react-designer": "1.0.0"

About this package

Embeddable React report designer for CFReport SDK

@report-sdk/react-designer

import { ReportDesigner } from "@report-sdk/react-designer";
import "@report-sdk/react-designer/styles.css";

<ReportDesigner initialValue={report} onChange={(next) => saveDraft(next)} />;

The File workflow imports and exports CFReport JSON only. The designer does not support Stimulsoft .mrt files.

The Report tab edits persisted report metadata and rendering preferences. The Page tab persists column layout and watermarks; these settings are rendered consistently by the design canvas and @report-sdk/react-viewer preview.

value/onChange 为受控模式,initialValue 为非受控模式,两种模式不能混用。

宿主应用可通过 documentGateway 接管文件生命周期:

<ReportDesigner
  initialValue={report}
  workspaceStorageKey="my-app:report-designer-workspace"
  documentGateway={{
    open: () => fetch("/api/reports/current").then((res) => res.json()),
    save: (next) => fetch("/api/reports/current", {
      method: "PUT",
      headers: { "content-type": "application/json" },
      body: JSON.stringify(next),
    }),
  }}
/>

插件可以同时贡献组件、数据适配器、安全表达式函数、预览导出和 Ribbon 命令:

const workflowPlugin: DesignerPlugin = {
  id: "workflow",
  dataProviders: [ordersProvider],
  expressionFunctions: {
    money: (value) => `¥${Number(value).toFixed(2)}`,
  },
  exportActions: [archiveExportAction],
  ribbonCommands: [{
    id: "approve",
    tab: "home",
    label: "标记审批",
    run: ({ execute }) => execute({
      type: "update-document",
      patch: { name: "已审批报表" },
    }),
  }],
};

插件函数不会注册到 window 或执行动态 JavaScript;它们只在传入该插件的设计器及其布局流程中可用。

workspaceStorageKey 为可选项;提供后会恢复 Ribbon、导航面板、面板宽度、网格、标尺、吸附和缩放偏好。不提供时组件不会写入 localStorage。

recoveryStorageKey 用于自动保存并恢复通过 Schema 校验的报表草稿,recoveryDelayMs 控制防抖延迟;成功执行保存命令后草稿会清除。theme 支持 light、dark、highContrast,primaryColor="#1677ff" 以一个不透明十六进制主色自动生成各模式配色,覆盖内置预览及所属弹窗/浮层;themeVariables 继续提供优先级更高的精细覆盖。主题按实例隔离,不改变报表实际外观。插入菜单中的“报表向导”可生成标准、图表、标签、主从、交叉表和仪表盘报表。

当前 Alpha 支持命令历史、撤销重做、套索/多选、八向缩放、旋转、智能吸附、对齐、组合、层级、页面操作、剪贴板、快捷菜单和插件报表项。所有变更也可通过 DesignerHandle.execute(command) 执行。

Beta 1 组件层还包括注册式工具箱、Band、条件样式、格式刷、表格合并拆分、资源面板、可搜索报表树以及七类本地黄金模板;所有功能均不依赖登录、注册或云账号。

Insert 功能区按基础、内容、业务、数据和仪表盘类别显示注册组件,并与工具箱共用“选择工具后在画布单击/拖动放置”的交互。图片组件支持本地文件内嵌、HTTP(S) URL、报表图片资源、数据列和表达式来源,以及拉伸、保持比例、裁剪、对齐、图片旋转、边距和平滑缩放。表达式与数据列在 layoutReport 阶段解析,资源在设计器和查看器中都可直接预览。

JSON 数据源通过 HTTP/HTTPS 连接向导创建。默认使用浏览器 fetch;需要认证、处理 CORS 或经由后端网关时,可使用 createProxyJsonFetcher 连接宿主提供的同源代理:

import { createProxyJsonFetcher } from "@report-sdk/core";

<ReportDesigner
  initialValue={report}
  jsonFetcher={createProxyJsonFetcher("/api/json-proxy")}
/>

/api/json-proxy 必须由宿主服务端实现,并校验目标协议、主机、重定向、超时和响应大小。Playground 包含可运行的 Vite 开发代理示例;生产部署需在实际后端提供等价路由。

Dependencies

Dependencies

ID Version
@report-sdk/core ^1.0.0
@report-sdk/locales ^1.0.0
@report-sdk/react-viewer ^1.0.0
fflate ^0.8.2

Peer Dependencies

ID Version
react ^18.2.0 || ^19.0.0
react-dom ^18.2.0 || ^19.0.0
Details
npm
2026-10-26 15:14:44 +08:00
5
UNLICENSED
1.8 MiB
Assets (1)
Versions (20) View all
2.2.0 2026-11-23
2.1.14 2026-11-20
2.1.13 2026-11-17
2.1.12 2026-11-17
2.1.11 2026-11-16