Mingcedar

所属产品: Mingcedar Studio DESIGNER

常用组合写法:按业务动作组合方法 | Mingcedar Studio

实际项目中很少只调用一个方法。通常需要将读取配置、读取 Tag、修改页面、写变量和跳转组合起来,形成完整业务动作。

首次发布 最近更新

<section id="script-combos" class="docs-block docs-block-intro docs-block-current"> <span class="section-kicker">组合</span> <h2>常用组合写法:按业务动作组合方法</h2> <p>实际项目中很少只调用一个方法。通常需要将读取配置、读取 Tag、修改页面、写变量和跳转组合起来,形成完整业务动作。</p> <div class="docs-detail-list"> <article id="script-combos-item-1" class="docs-detail-row"> <strong>页面打开后按配置刷新标题</strong> <p>这是典型页面脚本组合:先从当前页 Page Script 准备好的变量取值,再直接更新页面标题对象。相比将标题固定在 PPT 对象中,该方式更便于按页面上下文维护。</p> <pre class="docs-code-block"><code>window.hqVisuDesignerPageReady = function() {

var title = window.panelTitle || &quot;未命名页面&quot;;

hqVisuDesigner.setComponentText(&quot;PageTitle&quot;, title);

};</code></pre> </article><article id="script-combos-item-2" class="docs-detail-row"> <strong>质量异常时给对象描边并显示提示</strong> <p>这个组合适合设备状态提示。先用 ReadTagQualityGood 判断质量,再同时修改边框和提示图标显隐。</p> <pre class="docs-code-block"><code>var qualityGood = ReadTagQualityGood(&quot;PLC_LINE01.PUMP01.RUN&quot;);

hqVisuDesigner.setComponentBorder(&quot;PumpBody&quot;, qualityGood ? &quot;#0f172a&quot; : &quot;#f97316&quot;);

hqVisuDesigner.setComponentVisible(&quot;QualityBadge&quot;, !qualityGood);</code></pre> </article><article id="script-combos-item-3" class="docs-detail-row"> <strong>点击按钮后写值,并记录页面运行时状态</strong> <p>部分动作除了写 Tag,还需要页面同步记录本次操作已经触发。此时可以先写页面变量,再调用写值方法。</p> <pre class="docs-code-block"><code>hqVisuDesigner.writeVariable(&quot;lastAction&quot;, &quot;start&quot;);

WriteTagBoolean(&quot;PLC_LINE01.PUMP01.START&quot;, true);</code></pre> </article><article id="script-combos-item-4" class="docs-detail-row"> <strong>脚本里先拿模板输入值,再决定后续动作</strong> <p>template.getValue(...) 读取输入模板当前值,供脚本校验、写入或跳转。参数是带引号的实例名,如 template.getValue(&quot;Input Template&quot;)。</p> <pre class="docs-code-block"><code>var inputValue = template.getValue(&quot;Input Template&quot;);

if (inputValue !== &quot;&quot;) {

WriteTagString(&quot;PLC_LINE01.PUMP01.RECIPE&quot;, inputValue);

}</code></pre> </article> </div> <div class="docs-note-grid"> <figure id="script-combos-image-1" class="docs-note-card manual-doc-image-card"> <img src="/WEB_img/HQPPT/HyperlinkBehaviorEditorForm.png" alt="打开链接" loading="lazy" decoding="async"> <figcaption> <strong>页面跳转与外链</strong> <p>导航类脚本通常会和页面级方法一起组合使用。</p> </figcaption> </figure><figure id="script-combos-image-2" class="docs-note-card manual-doc-image-card"> <img src="/WEB_img/HQPPT/LanguageSettingsForm.png" alt="多语言文本" loading="lazy" decoding="async"> <figcaption> <strong>多语言切换</strong> <p>语言切换通常也会和页面刷新、脚本初始化配合使用。</p> </figcaption> </figure> </div> </section>