浮动窗口的管理操作
<div data-v-77845de8="" id="doc-title-box" class="doc-title-box" style="height: auto; width: auto; border-bottom: 1px solid rgba(0, 0, 0, 0.05); padding-bottom: 25px; padding-top: 25px; margin: 10px auto; text-align: center; color: rgb(52, 58, 64); font-family: "Microsoft Yahei", 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; font-size: 13px;"><span data-v-77845de8="" id="doc-title" class="v3-font-size-lg font-bold " style="font-size: 24px; font-weight: 700;">关闭close与释放内存</span><span data-v-77845de8="" class="float-right" style="float: right;"><span data-v-77845de8="" id="full-page" class="el-icon-full-screen" style="speak: none; font-variant-numeric: normal; font-variant-east-asian: normal; line-height: 1; vertical-align: baseline; display: inline-block; -webkit-font-smoothing: antialiased; float: right; font-size: 18px; margin-right: 20px; cursor: pointer; color: rgb(204, 204, 204); font-family: element-icons !important;"></span></span></div><div data-v-77845de8="" id="doc-body" style="width: calc(100% - 10px); margin-left: 10px; color: rgb(52, 58, 64); font-family: "Microsoft Yahei", 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; font-size: 13px;"><div data-v-77845de8="" id="page_md_content" class="page_content_main" style="margin-right: auto; margin-left: auto; height: 15910.6px; overflow: hidden; padding: 10px 10px 90px; color: rgb(51, 51, 51);"><div data-v-77845de8="" id="editor-md" class="main-editor markdown-body editormd-html-preview" style="text-size-adjust: 100%; overflow: auto hidden; font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; line-height: 1.75; width: 820px;"><p style="margin-bottom: 1.5em; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">第一个:定义一个关闭当前窗口的函数</code><br style="box-sizing: border-box;"><img src="http://doc.aiwork24.com:91/server/index.php?s=/api/attachment/visitFile&sign=87a4095a2fac4fa40265888b27457cd4" alt="" style="box-sizing: border-box; border: 0px; max-width: 100%;"></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 定义一个关闭当前窗口的函数</span><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">close</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 本示例创建一个带有一个按钮的窗口,点击按钮关闭当前窗口</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 初始化一个新的活动(窗口)</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ac = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> activity();
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 加载布局代码,使用 LinearLayout 替换 vertical</span>
ac.loadXML(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">`
<LinearLayout>
<Button id="button1" text="第一个按钮"/>
</LinearLayout>
`</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取按钮的实例</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> btn = ac.findViewById(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"button1"</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 确保按钮对象不为null后再设置点击事件</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (btn) {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 设置按钮的点击事件监听器</span>
btn.setOnClickListener(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 在新线程中执行 JavaScript 代码</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> thread().runJsCode(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">fun</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用 console.log() 打印信息</span>
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'线程执行代码防止占用UI线程'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 关闭窗口</span>
ac.close();
}, <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"-线程名"</span>);
});
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"按钮未找到,无法设置点击事件。"</span>);
}
}
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例调用</span>
close(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 调用关闭窗口的函数,显示带按钮的窗口</span>
</code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">函数定义</span>:<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">function close()</code> 定义了一个名为 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">close</code> 的函数,用于创建一个新窗口并设置按钮的点击事件。</li><li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">窗口初始化</span>:<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var ac = new activity();</code> 创建一个新的活动实例,代表一个新的窗口。</li><li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">布局加载</span>:使用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ac.loadXML(...)</code> 方法加载 XML 格式的布局,使用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">LinearLayout</code> 容器包含了一个按钮 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">Button</code>。</li><li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">按钮获取</span>:<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var btn = ac.findViewById("button1");</code> 通过按钮的 ID 获取其实例。</li><li style="box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">点击事件设置</span>:<ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;">通过判断 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">btn</code> 是否为空,确保按钮存在。</li><li style="list-style: disc; box-sizing: border-box;">使用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">btn.setOnClickListener(...)</code> 设置点击事件,当按钮被点击时,会执行其中的代码。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">线程执行</span>:使用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">new thread().runJsCode(...)</code> 启动新线程来执行代码。</p></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">窗口关闭</span>:<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ac.close();</code> 关闭当前窗口。</p></li></ol><p style="margin-bottom: 1.5em; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">第二个:定义一个关闭应用的函数</code><br style="box-sizing: border-box;"><img src="http://doc.aiwork24.com:91/server/index.php?s=/api/attachment/visitFile&sign=e58138b52278b3486bfc02be46a9a9ed" alt="" style="box-sizing: border-box; border: 0px; max-width: 100%;"></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs less" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 定义一个关闭应用的函数</span>
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">function</span> <span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">closeApp</span>(arg0) {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 这个函数的作用是关闭指定名称的应用</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 参数:</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// String arg0: 需要关闭的应用包名 (package name)</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 检查传入的包名是否为空</span>
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">if</span> (arg0 != <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">""</span>) {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 这里可以加入关闭应用的逻辑,比如通过 API 关闭应用</span>
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">console</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.log</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"正在关闭应用: "</span> + arg0);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 关闭应用的相关逻辑代码</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例:调用系统 API 来关闭应用(例如 Android 上的相关逻辑)</span>
} <span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">else</span> {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 如果包名为空,输出提示信息</span>
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">console</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.log</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"未提供包名,无法关闭应用。"</span>);
}
}
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例调用</span>
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">app</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.closeApp</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"com.liubowang.drawingboard"</span>); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 调用关闭应用的函数,关闭包名为 "com.liubowang.drawingboard" 的应用</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 若不提供包名的情况</span>
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">app</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.closeApp</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">""</span>); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 这将输出未提供包名的提示</span>
</code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">函数定义</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">function closeApp(arg0)</code>:定义了一个名为 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">closeApp</code> 的函数,接受一个参数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">arg0</code>,该参数是需要关闭的应用的包名,通常以字符串形式提供。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">参数说明</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">String arg0</code>: 作为输入,这个参数代表要关闭的应用的包名,例子如 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">"com.liubowang.drawingboard"</code>。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">包名检查</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">if (arg0 != "")</code>: 该条件判断语句用来检查传入的参数 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">arg0</code> 是否为空。如果包名不为空,表示有有效的应用需要关闭。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">输出关闭信息</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">console.log("正在关闭应用: " + arg0);</code>: 将关闭应用的信息打印到控制台,有助于调试和确认操作。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">关闭应用的逻辑</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;">这个部分可以包含实际的代码逻辑,用于关闭应用。具体实现将依赖于不同平台的 API。例如,在 Android 中,可以使用某些系统调用来结束进程。</li><li style="list-style: disc; box-sizing: border-box;">示例中提到的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">android.os.Process.killProcess(android.os.Process.myPid());</code> 是一种关闭应用进程的方式,具体需要根据实际业务场景来决定是否使用。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">处理空包名</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;">如果 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">arg0</code> 为空,函数将执行 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">console.log("未提供包名,无法关闭应用。");</code>,反馈给用户未提供有效的包名,从而避免执行无效或错误的操作。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">示例调用</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">app.closeApp("com.liubowang.drawingboard");</code> 是实际调用函数的方式,尝试关闭指定的应用。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">app.closeApp("");</code> 是一个示例,表明如果不传入包名,将提示用户未提供包名的错误。</li></ul></li></ol><p style="margin-bottom: 1.5em; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">第三个:关闭floatUI所有窗口</code><br style="box-sizing: border-box;"><img src="http://doc.aiwork24.com:91/server/index.php?s=/api/attachment/visitFile&sign=35be2882c709846e2cfa7678fc516c49" alt="" style="box-sizing: border-box; border: 0px; max-width: 100%;"></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 定义一个简单的 FloatWindow 构造函数来模拟浮动窗口</span>
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">FloatWindow</span>(<span class="hljs-params" style="box-sizing: border-box;">name</span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.name = name;
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.name + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">" 窗口已打开"</span>);
}
FloatWindow.prototype.close = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.name + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">" 窗口已关闭"</span>);
};
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 定义一个 floatUI 构造函数来管理浮动窗口</span>
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">floatUI</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.windows = [];
}
floatUI.prototype.addWindow = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;">name</span>) </span>{
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">window</span> = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> FloatWindow(name);
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.windows.push(<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">window</span>);
};
floatUI.prototype.closeAll = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.windows.forEach(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"><span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">window</span></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">window</span>.close();
});
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.windows = []; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 清空窗口数组</span>
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"所有窗口已关闭"</span>);
};
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 创建一个 floatUI 实例并添加一些浮动窗口</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ui = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> floatUI();
ui.addWindow(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"窗口1"</span>);
ui.addWindow(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"窗口2"</span>);
ui.addWindow(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"窗口3"</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 关闭所有浮动窗口</span>
ui.closeAll();
</code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">定义 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">FloatWindow</code> 构造函数</span></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">FloatWindow</span>(<span class="hljs-params" style="box-sizing: border-box;">name</span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.name = name;
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.name + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">" 窗口已打开"</span>);
}
</code></pre></li></ol><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs markdown" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-bullet" style="box-sizing: border-box; color: rgb(97, 174, 238);">*</span> 当你使用 <span class="hljs-code" style="box-sizing: border-box;">`new FloatWindow(name)`</span> 创建一个新实例时,会在控制台输出窗口已打开的信息。
</code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">定义 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">FloatWindow</code> 的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">close</code> 方法</span></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;">FloatWindow.prototype.close = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.name + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">" 窗口已关闭"</span>);
};
</code></pre></li></ol><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs markdown" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-bullet" style="box-sizing: border-box; color: rgb(97, 174, 238);">*</span> 当你调用 <span class="hljs-code" style="box-sizing: border-box;">`window.close()`</span> 方法时,会在控制台输出窗口已关闭的信息。
</code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">定义 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">floatUI</code> 构造函数</span></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">floatUI</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.windows = [];
}
</code></pre></li></ol><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs markdown" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-bullet" style="box-sizing: border-box; color: rgb(97, 174, 238);">*</span> 当你使用 <span class="hljs-code" style="box-sizing: border-box;">`new floatUI()`</span> 创建一个新实例时,会初始化一个空数组 <span class="hljs-code" style="box-sizing: border-box;">`windows`</span> 用于存储浮动窗口对象。
</code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">定义 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">floatUI</code> 的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">addWindow</code> 方法</span></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;">floatUI.prototype.addWindow = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;">name</span>) </span>{
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">window</span> = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> FloatWindow(name);
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.windows.push(<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">window</span>);
};
</code></pre></li></ol><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs markdown" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-bullet" style="box-sizing: border-box; color: rgb(97, 174, 238);">*</span> 当你调用 <span class="hljs-code" style="box-sizing: border-box;">`ui.addWindow(name)`</span> 方法时,会创建一个新的 <span class="hljs-code" style="box-sizing: border-box;">`FloatWindow`</span> 对象,并将其添加到 <span class="hljs-code" style="box-sizing: border-box;">`ui.windows`</span> 数组中。同时,<span class="hljs-code" style="box-sizing: border-box;">`FloatWindow`</span> 的构造函数会在控制台输出窗口已打开的信息。
</code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">定义 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">floatUI</code> 的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">closeAll</code> 方法</span></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;">floatUI.prototype.closeAll = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.windows.forEach(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"><span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">window</span></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">window</span>.close();
});
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.windows = []; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 清空窗口数组</span>
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"所有窗口已关闭"</span>);
};
</code></pre></li></ol><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs markdown" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-bullet" style="box-sizing: border-box; color: rgb(97, 174, 238);">*</span> 当你调用 <span class="hljs-code" style="box-sizing: border-box;">`ui.closeAll()`</span> 方法时,会遍历 <span class="hljs-code" style="box-sizing: border-box;">`ui.windows`</span> 数组中的每个 <span class="hljs-code" style="box-sizing: border-box;">`FloatWindow`</span> 对象,并调用其 <span class="hljs-code" style="box-sizing: border-box;">`close`</span> 方法来关闭窗口。每个窗口关闭时,<span class="hljs-code" style="box-sizing: border-box;">`FloatWindow`</span> 的 <span class="hljs-code" style="box-sizing: border-box;">`close`</span> 方法会在控制台输出窗口已关闭的信息。最后,清空 <span class="hljs-code" style="box-sizing: border-box;">`ui.windows`</span> 数组,并在控制台输出所有窗口已关闭的信息。
</code></pre><h3 id="h3-u6267u884Cu8FC7u7A0B" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; font-size: 1.25em !important;"><a name="执行过程" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>执行过程</h3><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">创建 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">floatUI</code> 实例</span></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ui = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> floatUI();
</code></pre></li></ol><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs markdown" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-bullet" style="box-sizing: border-box; color: rgb(97, 174, 238);">*</span> 控制台输出:无(因为 <span class="hljs-code" style="box-sizing: border-box;">`floatUI`</span> 构造函数中没有输出信息)
</code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">添加浮动窗口</span></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs less" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">ui</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.addWindow</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"窗口1"</span>);
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">ui</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.addWindow</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"窗口2"</span>);
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">ui</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.addWindow</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"窗口3"</span>);
</code></pre></li></ol><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs markdown" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-bullet" style="box-sizing: border-box; color: rgb(97, 174, 238);">*</span> 控制台输出:
<span class="hljs-code" style="box-sizing: border-box;"> 窗口1 窗口已打开
窗口2 窗口已打开
窗口3 窗口已打开
</span></code></pre><ol style="margin-bottom: 1.5em; padding-left: 2em; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">关闭所有浮动窗口</span></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs less" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">ui</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.closeAll</span>();
</code></pre></li></ol><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs markdown" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-bullet" style="box-sizing: border-box; color: rgb(97, 174, 238);">*</span> 控制台输出:
<span class="hljs-code" style="box-sizing: border-box;"> 窗口1 窗口已关闭
窗口2 窗口已关闭
窗口3 窗口已关闭
所有窗口已关闭
</span></code></pre><h3 id="h3-u603Bu7ED3" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; font-size: 1.25em !important;"><a name="总结" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>总结</h3><p style="margin-bottom: 1.5em; box-sizing: border-box;">在执行 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ui.addWindow("窗口1")</code>、<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ui.addWindow("窗口2")</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ui.addWindow("窗口3")</code> 时,控制台会输出每个窗口已打开的信息。然后在执行 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ui.closeAll()</code> 时,控制台会输出每个窗口已关闭的信息,最后输出所有窗口已关闭的信息。如果你没有看到打开窗体的输出,可能是控制台没有显示这些信息,或者你在执行代码时没有注意到这些输出。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">第四个:HUI交互模块关闭</code></p><p style="margin-bottom: 1.5em; box-sizing: border-box;"><img src="http://doc.aiwork24.com:91/server/index.php?s=/api/attachment/visitFile&sign=fa9834aed8682dfe5f73255777c17ddf" alt="" style="box-sizing: border-box; border: 0px; max-width: 100%;"></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs kotlin" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 定义 HUI 模块</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> HUI = {
name: <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"HUI交互模块"</span>,
isOpen: <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">false</span>, <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 模块是否开启</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打开模块</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">open</span>: function() {
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">this</span>.isOpen = <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">true</span>;
console.log(<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">this</span>.name + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">" 已打开"</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 这里应该是调用显示窗口的逻辑</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 比如可能是使用某个框架的显示窗口方法</span>
},
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 关闭模块</span>
close: function() {
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">this</span>.isOpen) {
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">this</span>.isOpen = <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">false</span>;
console.log(<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">this</span>.name + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">" 已关闭"</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 这里应该是调用隐藏窗口的逻辑</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 比如可能是使用某个框架的隐藏窗口方法</span>
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
console.log(<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">this</span>.name + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">" 已处于关闭状态"</span>);
}
}
};
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例:打开 HUI 模块</span>
HUI.<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">open</span>(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打开窗口</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例:关闭 HUI 模块</span>
HUI.close(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 关闭窗口</span>
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">这段代码的主要目的是创建一个简单的管理模块,以便控制其打开和关闭状态。open 和 close 方法分别用于管理模块显示的逻辑。虽然代码中的显示和隐藏逻辑需要根据实际使用的框架或设备予以实现,但基本的逻辑结构已经完成。这使得代码在组织方式上清晰,并提供了一个位于将来可能添加界面功能的基础。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">第四个: JsWebView 模块浏览器关闭</code></p><p style="margin-bottom: 1.5em; box-sizing: border-box;"><img src="http://doc.aiwork24.com:91/server/index.php?s=/api/attachment/visitFile&sign=a090d30d5589c2ad7b9930207c48dfbc" alt="" style="box-sizing: border-box; border: 0px; max-width: 100%;"></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 定义 JsWebView 类</span>
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">JsWebView</span>(<span class="hljs-params" style="box-sizing: border-box;">url</span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.url = url;
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.isOpen = <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">false</span>;
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打开 WebView</span>
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.open = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.isOpen = <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">true</span>;
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"WebView 打开,加载 URL: "</span> + <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.url);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 这里可以添加实际打开 WebView 的代码</span>
};
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 关闭 WebView</span>
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.close = <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.isOpen) {
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.isOpen = <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">false</span>;
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"WebView 已关闭"</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 这里可以添加实际关闭 WebView 的代码</span>
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"WebView 已处于关闭状态"</span>);
}
};
}
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 创建 JsWebView 实例</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> myWebView = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> JsWebView(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"https://example.com"</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打开 WebView</span>
myWebView.open();
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 关闭 WebView</span>
myWebView.close();
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">定义 JsWebView 类</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">function JsWebView(url):构造函数接受一个 URL,用于加载内容。<br style="box-sizing: border-box;">this.url:存储传入的 URL。<br style="box-sizing: border-box;">this.isOpen:跟踪 WebView 的打开状态,初始值为 false。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">打开 WebView</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">this.open = function():一个方法用于打开 WebView。<br style="box-sizing: border-box;">将 isOpen 设置为 true,并输出 WebView 打开和加载的 URL 信息。<br style="box-sizing: border-box;">可在此处插入实际打开 WebView 的代码。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">关闭 WebView</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">this.close = function():一个方法用于关闭 WebView。<br style="box-sizing: border-box;">检查 isOpen 状态,如果 WebView 打开,则设置为 false 并输出已关闭的信息;如果已关闭,则输出已处于关闭状态的信息。<br style="box-sizing: border-box;">可在此处插入实际关闭 WebView 的代码。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">创建实例并调用</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">var myWebView = new JsWebView(“<a href="https://example.xn--com%22%29:-bv1qu94j/" style="color: rgb(65, 131, 196); text-decoration-line: none; transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;">https://example.com"):创建</a> JsWebView 的实例,并传入一个 URL。<br style="box-sizing: border-box;">调用 open() 方法打开 WebView,并调用 close() 方法关闭 WebView。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">该示例展示了如何创建一个简单的 JsWebView 类,能够打开和关闭 WebView。您可以将其作为基础,根据具体需求扩展或者集成到其他 JAVA/JavaScript 代码中去。在实际应用中,”打开” 和 “关闭” 的逻辑会根据使用的平台进行实际实施。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">第五个: 关闭日志窗口</code><br style="box-sizing: border-box;"><img src="http://doc.aiwork24.com:91/server/index.php?s=/api/attachment/visitFile&sign=1da01c588733be0140033c39a09848eb" alt="" style="box-sizing: border-box; border: 0px; max-width: 100%;"></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 假设 logWindow 对象已经存在,并包含有 close 方法</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> logWindow = {
<span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">isOpen</span>: <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">false</span>,
<span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">open</span>: <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.isOpen = <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">true</span>;
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"日志窗口已打开"</span>);
},
<span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">close</span>: <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.isOpen) {
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">this</span>.isOpen = <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">false</span>;
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"日志窗口已关闭"</span>);
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">console</span>.log(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"日志窗口已处于关闭状态"</span>);
}
}
};
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用示例</span>
logWindow.open(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打开日志窗口</span>
logWindow.close();<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 关闭日志窗口</span>
logWindow.close();<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 尝试再次关闭</span>
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">第六个:释放 YOLO</code><br style="box-sizing: border-box;"><img src="http://doc.aiwork24.com:91/server/index.php?s=/api/attachment/visitFile&sign=aabc1d13ed2788edabd89b6105cf4c79" alt="" style="box-sizing: border-box; border: 0px; max-width: 100%;"></p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><span class="btn-pre-copy" style="box-sizing: border-box; display: block; user-select: none; position: absolute; top: 10px; right: 12px; font-size: 11px; line-height: 1; cursor: pointer; color: rgb(153, 153, 153); transition: color 0.1s ease 0s;">复制</span><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// OCR 部分</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">let</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">let</span> ocrres = img.paddleOCR(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">640</span>, [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>]);
printl(ocrres); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打印 OCR 结果</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 查找含有 "qq" 的文字目标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> qqrect = ocrres.findIncludeText(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"qq"</span>);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (qqrect) {
qqrect.hidClick(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 点击找到的目标</span>
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"没有找到包含 'qq' 的文本"</span>); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 提示未找到</span>
}
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// YOLO 部分</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 初始化 yolov5</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> yolo = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> yoloV5();
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 加载插件文件夹里的识别库</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> labelPath = project.getResourcesPath() + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'close.txt'</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> paramPath = project.getResourcesPath() + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'close.param'</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> binPath = project.getResourcesPath() + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'close.bin'</span>;
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 加载模型</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> model = yolo.loadModel(labelPath, paramPath, binPath, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">4</span>, <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">false</span>);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (model != <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">null</span>) {
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'模型加载失败'</span>);
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 再次截图</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> res = yolo.detectPercent(img, [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>], <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.4</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.45</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">640</span>);
printl(res); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打印检测结果</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (res != <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">null</span> && res.length > <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>) {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 无障碍点击</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// res.click(); // 如果有检测结果,可以点击第一个</span>
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"没有检测到目标"</span>); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 提示未检测到</span>
}
}
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 释放 YOLO</span>
yolo.Close();
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">OCR(光学字符识别)和 YOLO(You Only Look Once,对象检测算法)来处理图像,查找文本和目标。以下是代码的逐步解释:</p><h3 id="h3-1-ocr-" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; font-size: 1.25em !important;"><a name="1. OCR 部分" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>1. OCR 部分</h3><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">let</span> img = screen.screenShotFull(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 截取整个屏幕</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">let</span> ocrres = img.paddleOCR(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">640</span>, [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>]); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用 PaddleOCR 进行文字识别</span>
printl(ocrres); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打印 OCR 结果</span>
</code></pre><ul style="margin-bottom: 1.5em; margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">screen.screenShotFull()</code></span>:截取当前屏幕的完整图像并赋值给变量 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">img</code>。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">img.paddleOCR(640, )</code></span>:通过 PaddleOCR 对截取的图片进行文字识别。<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">640</code> 是识别图像的尺寸,<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);"></code> 是识别区域的参数。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">printl(ocrres)</code></span>:将识别结果打印到控制台,以便查看识别的文本。</p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;">// 查找含有 “qq” 的文字目标<br style="box-sizing: border-box;">var qqrect = ocrres.findIncludeText(“qq”);<br style="box-sizing: border-box;">if (qqrect) {</p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs less" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">qqrect</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.hidClick</span>(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 点击找到的目标</span>
</code></pre><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;">} else {</p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs less" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">printl</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"没有找到包含 'qq' 的文本"</span>); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 提示未找到</span>
</code></pre><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;">}</p></li></ul><ul style="margin-bottom: 1.5em; margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ocrres.findIncludeText("qq")</code></span>:在 OCR 结果中查找包含字符 “qq” 的文本,返回相应的文本框区域。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">if (qqrect)</code></span>:检查找到的目标框 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">qqrect</code> 是否存在。<ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;">如果存在,则调用 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">hidClick()</code> 方法模拟点击该文本目标。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;">如果不存在,则输出”没有找到包含 ‘qq’ 的文本”的提示信息。</li></ul></li></ul><h3 id="h3-2-yolo-" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; font-size: 1.25em !important;"><a name="2. YOLO 部分" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>2. YOLO 部分</h3><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 初始化 yolov5</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> yolo = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> yoloV5(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 创建 YOLO 实例</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 加载插件文件夹里的识别库</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> labelPath = project.getResourcesPath() + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'close.txt'</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> paramPath = project.getResourcesPath() + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'close.param'</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> binPath = project.getResourcesPath() + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'close.bin'</span>;
</code></pre><ul style="margin-bottom: 1.5em; margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">new yoloV5()</code></span>:创建一个新的 YOLO 实例,用于对象检测。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">加载识别库</span>:通过 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">getResourcesPath()</code> 方法获取模型文件的路径,并将标签、参数和二进制文件路径分配给 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">labelPath</code>、<code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">paramPath</code> 和 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; margin-right: 4px; margin-left: 5px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">binPath</code> 变量。</p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;">// 加载模型<br style="box-sizing: border-box;">var model = yolo.loadModel(labelPath, paramPath, binPath, 4, false);</p><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;">if (model != null) {</p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs less" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">printl</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'模型加载失败'</span>); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 如果 model 不为 null,表示加载失败</span>
</code></pre><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;">} else {</p><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 再次截图</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> res = yolo.detectPercent(img, [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>], <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.4</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.45</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">640</span>); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 进行对象检测</span>
printl(res); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打印检测结果</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (res != <span class="hljs-literal" style="box-sizing: border-box; color: rgb(86, 182, 194);">null</span> && res.length > <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>) {
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 无障碍点击</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// res.click(); // 如果有检测结果,可以点击第一个</span>
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"没有检测到目标"</span>); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 提示未检测到</span>
}
</code></pre><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;">}</p></li></ul><ul style="margin-bottom: 1.5em; margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">yolo.loadModel(...)</code></span>:加载 YOLO 模型,使用之前准备的标签、参数和二进制文件。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">if (model != null)</code></span>:检查模型加载是否成功。如果返回的 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">model</code> 不为 <code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">null</code>,则输出”模型加载失败”。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">screen.screenShotFull()</code></span>:再次截取屏幕进行对象检测。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">yolo.detectPercent(...)</code></span>:在指定区域内进行对象检测,返回检测结果。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">printl(res)</code></span>:打印检测结果。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">if (res != null && res.length > 0)</code></span>:检查检测结果数组是否有内容。<ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;">如果存在检测结果,注释部分提到可以点击第一个目标。</li><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;">如果没有检测到目标,输出”没有检测到目标”的提示信息。</li></ul></li></ul><h3 id="h3-3-" style="margin-top: 1em; margin-bottom: 1.5em; box-sizing: border-box; position: relative; line-height: 1.75; font-size: 1.25em !important;"><a name="3. 释放资源" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>3. 释放资源</h3><pre style="overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs less" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 释放 YOLO</span>
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">yolo</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.Close</span>(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 释放 YOLO 模型的资源</span>
</code></pre><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style-position: initial; list-style-image: initial; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">yolo.Close()</code></span>:释放 YOLO 模型占用的资源,以清理内存和其他使用。</li><li></li></ul></div></div></div><p></p>
页:
[1]