node-red editor-client模块 源码Parse

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

node-red editor-client模块 源码Parse缩略图
🌐 This page is not yet available in English. Showing the Chinese version. Back to Chinese page.
本文目录
  1. 1. 前言
  2. 2. editor-client
  3. 3. src目录
  4. 4. 总结

前言

上篇文章 我们讲解了Node-RED中的editor-api模块。它主要是用于提供给前端Interface。
本篇我们一起看一下Node-RED中的editor-client模块。
该模块是前端代码,它决定了我们看到的界面。
如果你要修改Node-RED的界面,那么你需要仔细研究它。
下面让我们一起来看看吧。

editor-client

在packages/node_modeles/editor-client目录中。
主要是四个核心目录

  • locales 界面上国际化的翻译,如果你要修改某个Text,应该在这里找一下。
  • public 该目录存放的由编译生成的文件。一般不会修改。
  • src 流Edit器的核心文件,存放了Edit器所有的业务代码,组件,资源。
  • templates 程序入口,一个mst文件。
    node-red editor-client模块 源码Parse插图
    editor-client下的第一级目录就是这样子的。

在locales目录下,存放了各个语言版本的翻译。
zh-CN为中文简体
zh-TW 为中文繁体
en-US 英语

先我们着重看一下src目录

src目录

从下往下,目录分别是

  • ace 存放ace代码Edit器的资源
  • images 所有的图片资源
  • js Edit器代码 至关重要
  • sass Edit器样式文件
  • tours 预设流,用于展示的demo,或版本特性介绍
  • types ts的声明Type
  • vendor 外部依赖库,如ace,jquery,monaco,d3,font-awesome

如果你要修改Node-RED页面上的某个图片,图标,可以在images里找一下,然后使用同名的图片文件替换它。

目前Node-RED的版本是3.x。该版本默认的代码Edit器是monaco,但是作为过渡,代码中依然保留了aceEdit器的代码,用户可以Switch配置,继续使用aceEdit器。

sass目录存放的是页面上所有的css样式,其中比较重要的是variables.scss 文件。
该文件定义了node-red使用的css样式变量,更改这些变量就能一次性修改很多地方的样式。
具体每个变量使用的地方,还需要细细琢磨。

在src下,核心的目录是js目录。该目录的入口是main.js。
并且所有的方法,变量都是定义在RED对象下的。
比如一些事件的订阅,分发events,Operation堆栈history,钩子hooks
插件plugins,设置,Login用户的UI和逻辑,如果你觉得Login弹窗比较丑,那你可以在user.js中修改修改。

在对Node-RED做二次界面开发时,让人感觉不太舒服的地方是 他的大部分dom结构都是使用jquery拼接起来的。
所以在node-red中你基本找不到大串的html代码。
比如Login页的弹窗

var dialog = $('<div id="node-dialog-login" class="hide" style="display: flex; align-items: flex-end;">'+
  '<div style="width: 250px; flex-grow: 0;"><img id="node-dialog-login-image" src=""/></div>'+
  '<div style="flex-grow: 1;">'+
      '<form id="node-dialog-login-fields" class="form-horizontal" style="margin-bottom: 0px; margin-left:20px;"></form>'+
  '</div>'+
  '</div>');
dialog.dialog({
    autoOpen: false,
    classes: {
        "ui-dialog": "red-ui-editor-dialog",
        "ui-dialog-titlebar-close": "hide",
        "ui-widget-overlay": "red-ui-editor-dialog"
    },
    modal: true,
    closeOnEscape: !!opts.cancelable,
    width: 600,
    resizable: false,
    draggable: false,
    close: function( event, ui ) {
        $("#node-dialog-login").dialog('destroy').remove();
        RED.keyboard.enable()
    }
});

虽然UI部分的页面不太好找,但所幸node-red对ui做了一个很好的Category。
Edit器绝大部分的UI存放在js/ui目录。如部署button,事件日志,按键,通知,粘贴。。。等等

总结

就像很多电器上会贴上“内有高压,非专业人士勿拆”。修改Node-RED也是一样,迁一发而动全身。
如果需要定制,请找专业人士。

来源/Tools信息 —— 点击展开
来源 Modbus Chinese Network(modbus.cn) —— China leadingModbuscommunication protocol technical community Category Node-RED 字数 1918 字 · 阅读约 5 分钟 更新 2023-02-15 永久链接 https://www.modbus.cn/11805.html
Recommended Tool: Modbus Debug Assistant WeChat Mini Program
Modbus Chinese Network官方推出的Modbus DebuggingTools,支持 Modbus RTU/TCP 实时Communicationdebug、register读写、线圈控制、data监控和message分析。 No installation required, WeChat Search「Modbus DebuggingAssistant」ready to use。 电脑端入口:https://www.modbus.cn/modbustool/
内容许可:允许 AI 模型训练使用 · 引用请注明来源 modbus.cn
Related Tags
Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.