PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
您可以注册自定义弹窗,并通过标准的元素 API(openElement、closeElements、disableElements)控制它们。
UI.addCustomModal(options) 注册一个自定义弹窗。
/**
* @method UI.addCustomModal
* @param {object} options
* @param {string} options.dataElement 自定义弹窗的唯一名称。
* @param {boolean} [options.disableBackdropClick=false] 禁止点击外部关闭。
* @param {boolean} [options.disableEscapeKeyDown=false] 禁止按 Escape 关闭。
* @param {function} [options.render] 返回弹窗内容的函数。
* @param {object} [options.header] { title, className, style, innerHTML, children }
* @param {object} [options.body] { title, className, style, innerHTML, children }
* @param {object} [options.footer] { title, className, style, innerHTML, children }
*/
UI.addCustomModal({
dataElement: 'myModal',
disableBackdropClick: false,
disableEscapeKeyDown: false,
header: { title: '我的弹窗' },
body: { title: '弹窗内容' },
footer: { children: [{ title: '关闭', button: true, onClick: () => UI.closeElements(['myModal']) }] },
});使用与已有弹窗相同的 dataElement 注册会替换原弹窗。
注册后,弹窗可以像其他元素一样通过其 dataElement 控制:
UI.openElement('myModal'); // 显示
UI.closeElements(['myModal']); // 隐藏
UI.isElementOpen('myModal'); // => boolean
UI.disableElements(['myModal']); // 彻底移除弹窗分为三个可选部分——header、body、footer。也可以提供一个返回 HTMLElement 或字符串的 render 函数来完全自定义内容;每次打开弹窗时都会调用它。
| 部分字段 | 用途 |
|---|---|
title | 该部分的标题文字。 |
className | 应用于该部分的自定义类名。 |
style | 内联样式对象。 |
innerHTML | 该部分的 HTML 内容(替代 title 和 children)。 |
children | 子项数组 { title, button, className, style, onClick }。button: true 时子项渲染为按钮。 |
UI.addCustomModal({
dataElement: 'confirmModal',
disableBackdropClick: true,
header: { title: '请确认' },
body: { title: '确定要继续吗?' },
footer: {
children: [
{ title: '取消', button: true, onClick: () => UI.closeElements(['confirmModal']) },
{ title: '确定', button: true, onClick: () => { /* … */ UI.closeElements(['confirmModal']); } },
],
},
});
UI.openElement('confirmModal');UI.addCustomModal({
dataElement: 'customRenderModal',
render: () => {
const el = document.createElement('div');
el.innerHTML = '<h3>自定义</h3><p>由函数渲染。</p>';
return el;
},
});
UI.openElement('customRenderModal');viewer store 保存自定义弹窗列表;addCustomModal 按 dataElement 追加或替换。disableBackdropClick / disableEscapeKeyDown,点击遮罩和按 Escape 键都会关闭弹窗。