mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-06-06 15:40:15 +00:00
15 lines
11 KiB
JavaScript
15 lines
11 KiB
JavaScript
import{ax as s,z as e,A as a,b5 as t}from"./chunks/framework.V2ssSR2R.js";const g=JSON.parse('{"title":"Page","description":"","frontmatter":{},"headers":[],"relativePath":"runtime-api/core/page.md","filePath":"runtime-api/core/page.md"}'),n={name:"runtime-api/core/page.md"};function l(d,i,p,h,o,r){return a(),e("div",null,[...i[0]||(i[0]=[t(`<h1 id="page" tabindex="-1">Page <a class="header-anchor" href="#page" aria-label="Permalink to “Page”"></a></h1><p><code>Page</code> 是 <code>@tmagic/core</code> 的页面类,继承自 <code>Node</code>,用于管理页面及其子节点。</p><h2 id="构造函数" tabindex="-1">构造函数 <a class="header-anchor" href="#构造函数" aria-label="Permalink to “构造函数”"></a></h2><div class="language-typescript"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Page</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(options: PageOptions)</span></span></code></pre></div><h3 id="pageoptions" tabindex="-1">PageOptions <a class="header-anchor" href="#pageoptions" aria-label="Permalink to “PageOptions”"></a></h3><p>继承自 NodeOptions,参见 <a href="./node.html">Node</a> 构造函数。</p><h2 id="属性" tabindex="-1">属性 <a class="header-anchor" href="#属性" aria-label="Permalink to “属性”"></a></h2><table tabindex="0"><thead><tr><th>属性</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>nodes</code></td><td><code>Map<Id, Node></code></td><td>页面内所有节点的映射表</td></tr></tbody></table><p>继承自 Node 的属性请参见 <a href="./node.html#属性">Node 属性</a>。</p><h2 id="实例方法" tabindex="-1">实例方法 <a class="header-anchor" href="#实例方法" aria-label="Permalink to “实例方法”"></a></h2><h3 id="initnode" tabindex="-1">initNode <a class="header-anchor" href="#initnode" aria-label="Permalink to “initNode”"></a></h3><ul><li><p><strong>参数:</strong></p><ul><li><code>{MComponent | MContainer} config</code> 节点配置</li><li><code>{Node} parent</code> 父节点</li></ul></li><li><p><strong>返回:</strong></p><ul><li><code>{void}</code></li></ul></li><li><p><strong>详情:</strong></p><p>初始化节点,根据配置创建节点实例并通过 <code>setNode</code> 添加到页面:</p><ul><li>当节点类型属于 <code>app.iteratorContainerType</code> 时,会创建 <code>IteratorContainer</code> 并直接返回,<strong>不会</strong>继续递归 <code>config.items</code>(迭代容器内的子节点由 <code>IteratorContainer</code> 自身在每次迭代时按需初始化)。</li><li>当属于 <code>app.pageFragmentContainerType</code> 且配置了 <code>pageFragmentId</code> 时,会在 <code>app.pageFragments</code> 中创建对应的页面片段实例。</li><li>其他类型会创建普通节点后递归初始化 <code>config.items</code> 子节点。</li></ul></li><li><p><strong>示例:</strong></p></li></ul><div class="language-typescript"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">page.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">initNode</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> id: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'button_1'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> type: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'button'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> style: { width: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> page,</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span></code></pre></div><h3 id="getnode" tabindex="-1">getNode <a class="header-anchor" href="#getnode" aria-label="Permalink to “getNode”"></a></h3><ul><li><p><strong>参数:</strong></p><ul><li><code>{Id} id</code> 节点 ID</li><li><code>{GetNodeOptions} options</code> 获取选项(可选)</li></ul></li><li><p><strong>返回:</strong></p><ul><li><code>{Node | undefined}</code></li></ul></li><li><p><strong>详情:</strong></p><p>获取页面中指定 ID 的节点。支持从迭代器容器和页面片段中获取节点。</p></li><li><p><strong>GetNodeOptions:</strong></p></li></ul><table tabindex="0"><thead><tr><th>参数</th><th>类型</th><th>说明</th></tr></thead><tbody><tr><td><code>iteratorContainerId</code></td><td><code>Id[]</code></td><td>迭代器容器 ID 数组</td></tr><tr><td><code>iteratorIndex</code></td><td><code>number[]</code></td><td>迭代器索引数组</td></tr><tr><td><code>pageFragmentContainerId</code></td><td><code>Id</code></td><td>页面片段容器 ID</td></tr><tr><td><code>strict</code></td><td><code>boolean</code></td><td>是否严格模式</td></tr></tbody></table><ul><li><strong>示例:</strong></li></ul><div class="language-typescript"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> node</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> page.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getNode</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'button_1'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 从迭代器中获取</span></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> iteratorNode</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> page.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getNode</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'item_1'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, {</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> iteratorContainerId: [</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'iterator_1'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> iteratorIndex: [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><h3 id="setnode" tabindex="-1">setNode <a class="header-anchor" href="#setnode" aria-label="Permalink to “setNode”"></a></h3><ul><li><p><strong>参数:</strong></p><ul><li><code>{Id} id</code> 节点 ID</li><li><code>{Node} node</code> 节点实例</li></ul></li><li><p><strong>返回:</strong></p><ul><li><code>{void}</code></li></ul></li><li><p><strong>详情:</strong></p><p>设置页面中的节点。</p></li></ul><h3 id="deletenode" tabindex="-1">deleteNode <a class="header-anchor" href="#deletenode" aria-label="Permalink to “deleteNode”"></a></h3><ul><li><p><strong>参数:</strong></p><ul><li><code>{Id} id</code> 节点 ID</li></ul></li><li><p><strong>返回:</strong></p><ul><li><code>{void}</code></li></ul></li><li><p><strong>详情:</strong></p><p>删除页面中指定 ID 的节点。</p></li><li><p><strong>示例:</strong></p></li></ul><div class="language-typescript"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">page.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">deleteNode</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'button_1'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span></code></pre></div><h3 id="destroy" tabindex="-1">destroy <a class="header-anchor" href="#destroy" aria-label="Permalink to “destroy”"></a></h3><ul><li><p><strong>返回:</strong></p><ul><li><code>{void}</code></li></ul></li><li><p><strong>详情:</strong></p><p>销毁页面及其所有子节点。</p></li><li><p><strong>示例:</strong></p></li></ul><div class="language-typescript"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">page.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">destroy</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span></code></pre></div>`,26)])])}const c=s(n,[["render",l]]);export{g as __pageData,c as default};
|