稳定性:stable 的范围是当前 iframe 消息代理方法与其异步语义。非 iframe mount 返回实际 Vue Builder 实例,源码没有把其全部方法定义为独立稳定公共接口,因此不要承诺未验证的方法。
调用方式与方法签名
iframe 代理读取/校验方法:
| 方法 | 参数 | 返回值 |
|---|---|---|
getFormItemsInfo |
无 | Promise |
getFormData |
无 | Promise |
getFormItemData |
无 | Promise |
updateScopeData |
data, noLoading = false |
Promise |
findCellByField |
fieldId |
Promise |
validate |
无 | Promise |
iframe 代理 setter:
| 方法 | 参数 | 同步返回值 |
|---|---|---|
setFormItemDisabled |
identifier, state |
无 |
setFormItemDisabledByField |
field, state |
无 |
setFormItemData |
field, value |
无 |
setFormData |
formData |
无 |
setTableZoom |
scale, origin |
无 |
setCellStyleByPosition |
row, col, options |
无 |
setFormItemRequiredByField |
field, state, message |
无 |
setFormRules |
rules |
无 |
setRowsVisible |
rows |
无 |
setRowsHidden |
rows |
无 |
参数与默认值
只有 updateScopeData 的 noLoading 在代理中有明确默认值 false。其他参数的数据结构由报表控件和子页实现解释;字段名应来自设计器配置,不要写死生产字段值。
返回值与异常
读取方法通过 postMessage 等待同名响应;响应 status === "rejected" 时 Promise reject。当前实现没有内建超时,集成方可在业务层添加合理超时和错误提示。setter 只发送消息,不能通过返回值判断子页是否已应用。
最小示例
const container = document.querySelector("#report-host");
if (!container) throw new Error("Missing #report-host");
const instance = await api.mount(
{
iframe: true,
reportOptions: {
url: "/bee-report/index.html",
reportCode: "sales-summary",
reportVersion: "1.0.0",
},
},
container,
Vue,
);
const data = await instance.getFormData();
instance.setFormItemData("region", "east");
const valid = await instance.validate();
iframe 模式差异
本页表格是 iframe 代理的源码事实。虽然这些方法使用 postMessage,挂载流程仍直接访问 contentWindow.document 和 contentWindow.$$BEEREPORT_PARAMS,所以当前要求同源;跨域需先改造完整挂载协议。非 iframe 实例可能具有同名 Builder 方法,但其可用性、参数和返回值必须按当前部署代码验证,不从本页推导。
相关 API
常见错误
不要给 setter 加 await 并误以为它确认了子页状态;不要把非 iframe Builder 的内部方法自动视为稳定 API。
