如何在 node-red 中创建配置节点

问题描述 投票:0回答:0

我尝试创建像 this 这样的配置节点,但它只显示文本框没有配置,我希望 projectid 成为配置节点,我尝试使用配置节点跟踪许多节点,但它对我不起作用,如何解决?

graphql_query.js

module.exports = function(RED) {
    function netpie_graphql_query(nodeConfig) {
        RED.nodes.createNode(this,nodeConfig);
        var node = this;
        node.on('input', function(msg) {
            var gqlquery = nodeConfig.gqlquery;

            nodeConfig.projectid = RED.nodes.getNode(nodeConfig.projectid).projectid;

            const axios = require('axios');
            let data = JSON.stringify({
            query: gqlquery,
            variables: {}
            });

            let axiosConfig = {
            method: 'post',
            maxBodyLength: Infinity,
            url: 'http://gqlv2.aaaaa.io/',
            headers: { 
                'Authorization': 'bearer '+auth.token, 
                'Content-Type': 'application/json'
            },
            data : data
            };

            axios.request(axiosConfig)
            .then((response) => {
            data = (JSON.stringify(response.data));
            msg.payload = data;
            node.send(msg);
            })
            .catch((error) => {
            //console.log(error);
            this.error("Request failed with status code 400, please check your schema");
            });
        });
    }
    RED.nodes.registerType("netpie_graphql_query",netpie_graphql_query);
}

graphql_query.html

    RED.nodes.registerType('netpie_graphql_query',{
        category: 'graphql',
        color:'#00adff',
        defaults:{

            projectid:{value:"", type:"projectid"},

            name:{value:""},
            gqlquery:{value:""}

        },
        inputs:1,
        outputs:1,
        icon:"template.svg",
        label:function(){
            return this.name||"netpie graphql";
        },
        oneditprepare: function() {
            this.editor = RED.editor.createEditor({
            id: 'gqlquery-message-editor',
            mode: 'ace/mode/text',
            value: $("#node-input-gqlquery").val()
        });
        },
        oneditsave: function() {
            $("#node-input-gqlquery").val(this.editor.getValue());
            this.editor.destroy();
            delete this.editor;
        },
        oneditcancel: function() {
            this.editor.destroy();
            delete this.editor;
        }
            
    });
    </script>

    <script type="text/html" data-template-name="netpie_graphql_query">
        <div class="form-row">
            <label for="node-input-name"><i class="fa fa-tag"></i>Name</label>
            <input type = "text" id="node-input-name" placeholder="Name">
        </div>

        <div class="form-row">
            <label for="node-input-projectid"><i class="fa fa-tag"></i>Project ID</label>
            <input type = "text" id="node-input-projectid">
        </div>

        <div class="form-row">
            <label for="node-input-gqlquery"><i class="fa fa-cog"></i> <span>Query</span></label>
            <div style="height: 250px;" class="node-text-editor" id="gqlquery-message-editor"></div>
            <input type="hidden" id="node-input-gqlquery">
        </div>

    </script>

    <script type="text/html" data-help-name="netpie_graphql_query">
        <p>netpie graphql query</p>
    </script>

graphql_query_config.js

    function projectid(nodeConfig) {
        RED.nodes.createNode(this,nodeConfig);
        this.name = nodeConfig.name;
        this.projectid = nodeConfig.projectid;
    }
    RED.nodes.registerType("projectid",projectid);
}

graphql_query_config.html

    RED.nodes.registerType('projectid',{
        category: 'config',
        defaults: {
            name: {value:""},
            projectid: {value:""}
        },
        label: function() {
            return this.name || this.("projectid");
        }
    });
</script>

<script type="text/html" data-template-name="projectid">
    <div class="form-row">
        <label for="node-config-input-name"><i class="fa fa-bookmark"></i> Name</label>
        <input type="text" id="node-config-input-name">
    </div>
    <div class="form-row">
        <label for="node-config-input-projectid"><i class="fa fa-bookmark"></i> projectid</label>
        <input type="text" id="node-config-input-projectid">
    </div>
</script>

但 projectid 不是配置节点

javascript node-red
© www.soinside.com 2019 - 2024. All rights reserved.