CN114595664A - Method and device for generating form and electronic equipment - Google Patents

Method and device for generating form and electronic equipment Download PDF

Info

Publication number
CN114595664A
CN114595664A CN202210138770.7A CN202210138770A CN114595664A CN 114595664 A CN114595664 A CN 114595664A CN 202210138770 A CN202210138770 A CN 202210138770A CN 114595664 A CN114595664 A CN 114595664A
Authority
CN
China
Prior art keywords
target
configuration
configuration object
rendering
configuration information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210138770.7A
Other languages
Chinese (zh)
Inventor
杨峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Sankuai Online Technology Co Ltd
Original Assignee
Beijing Sankuai Online Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Sankuai Online Technology Co Ltd filed Critical Beijing Sankuai Online Technology Co Ltd
Priority to CN202210138770.7A priority Critical patent/CN114595664A/en
Publication of CN114595664A publication Critical patent/CN114595664A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/177Editing, e.g. inserting or deleting of tables; using ruled lines
    • G06F40/18Editing, e.g. inserting or deleting of tables; using ruled lines of spreadsheets
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • G06F9/4451User profiles; Roaming

Abstract

The embodiment of the application provides a method and a device for generating a form and electronic equipment, wherein the method comprises the following steps: determining a target form element corresponding to each item of configuration information based on the data type of the plurality of items of configuration information input by the user; aiming at each target form element, generating a target code for rendering the target form element to a target form according to the verification rule of the target form element and the configuration information corresponding to the target form element; and selecting the target codes of the target form elements based on data driving to render, and generating the target form. According to the method and the device, developers do not need to write the target codes, and the target codes of the target table elements are automatically generated based on the configuration information; and the data-driven idea is utilized to render the target table elements, so that the code amount and the complexity of the development process can be greatly reduced, and the development efficiency is improved.

Description

Form generation method and device and electronic equipment
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a method and an apparatus for generating a form, and an electronic device.
Background
The form in the front-end technology is mainly responsible for the data acquisition function in the webpage, and the form is widely applied to front-end development.
Currently, forms are developed manually, usually by professional software developers. The various form elements involved therein are implemented one by code, for example, by a developer based on a visual draft of the form.
However, the above form development method has low development efficiency and high complexity of the development process, and cannot meet the increasing form development requirements.
Disclosure of Invention
The embodiment of the application provides a method and a device for generating a form and electronic equipment, and aims to at least solve the technical problems of high complexity and low development efficiency of the form development process in the prior art.
According to an aspect of an embodiment of the present application, there is provided a method of generating a form, the method including:
determining a target form element corresponding to each item of configuration information based on the data type of the plurality of items of configuration information input by the user;
aiming at each target form element, generating a target code for rendering the target form element to a target form according to the verification rule of the target form element and the configuration information corresponding to the target form element;
and selecting the target codes of the target form elements based on data driving to render, and generating the target form.
Optionally, the determining, based on the data type of the multiple items of configuration information input by the user, a target form element corresponding to each item of configuration information includes:
aiming at each item of configuration information, creating a configuration object corresponding to the configuration information;
for each configuration object, determining a table element corresponding to the configuration object based on the data type of a target field in the configuration object;
and aiming at each configuration object, determining the table unit element corresponding to the configuration object as a target table unit element corresponding to the configuration information of the configuration object.
Optionally, the determining, for each configuration object, a table element corresponding to the configuration object based on a data type of a target field in the configuration object includes:
under the condition that each configuration object is a valid configuration object, determining a table element corresponding to the configuration object for each configuration object based on the data type of a target field in the configuration object;
the configuration object is an effective configuration object, and the configuration object meets a preset effective verification strategy.
Optionally, the generating, for each target form element, a target code for rendering the target form element to a target form according to the verification rule of the target form element and the configuration information corresponding to the target form element includes:
creating a configuration array containing each configuration object, wherein each configuration object comprises at least one element node, and the table unit elements corresponding to the configuration objects comprise the table unit elements corresponding to each element node in the configuration objects;
and recursively traversing each element node in the configuration array, adding a rule code representing a check rule of the form element corresponding to the element node to each element node, and generating a rendering array comprising a target code of each form element, wherein the target code of each form element in the rendering array is used for rendering the form element to a target form.
Optionally, the determining, based on the data type of the target field in the configuration object, a table element corresponding to the configuration object includes:
when the data type of the target field in the configuration object is an enumeration type and the field value is a Boolean value, the table element corresponding to the configuration object is a radio button;
and under the condition that the data type of the target field in the configuration object is an enumeration type and the field value is a character, the form element corresponding to the configuration object is a selection frame.
Optionally, the determining, based on the data type of the target field in the configuration object, a table element corresponding to the configuration object includes:
and under the condition that the data type of the target field in the configuration object is a preset service type, the table element corresponding to the configuration object is a preset table element corresponding to the preset service type.
Optionally, the driving, based on the data, selecting a target code of each target form element to render, and generating the target form includes:
and recursively traversing the target code of each form element in the rendering array based on data driving, rendering the target code of each form element to the same form, and generating the target form.
According to another aspect of the embodiments of the present application, there is provided an apparatus for generating a form, the apparatus including:
the configuration module is used for determining a target form element corresponding to each item of configuration information based on the data type of the plurality of items of configuration information input by the user;
the processing module is used for generating a target code for rendering the target form unit element to a target form according to the verification rule of the target form unit element and the configuration information corresponding to the target form unit element aiming at each target form unit element;
and the rendering module is used for selecting the target codes of all the target form elements based on data driving to render and generating the target form.
Optionally, the configuration module includes:
the first configuration unit is used for creating a configuration object corresponding to each item of configuration information;
the second configuration unit is used for determining a table element corresponding to each configuration object based on the data type of a target field in the configuration object;
and a third configuration unit, configured to determine, for each configuration object, a table element corresponding to the configuration object as a target table element corresponding to the configuration information of the configuration object.
Optionally, the second configuration unit is specifically configured to, when each configuration object is a valid configuration object, determine, for each configuration object, a table element corresponding to the configuration object based on a data type of a target field in the configuration object;
the configuration object is an effective configuration object, and the configuration object meets a preset effective verification strategy.
Optionally, the processing module includes:
the first processing unit is used for creating a configuration array containing each configuration object, wherein each configuration object comprises at least one element node, and the table unit elements corresponding to the configuration objects comprise the table unit elements corresponding to each element node in the configuration objects;
the second processing unit is configured to recursively traverse each element node in the configuration array, add a rule code representing a check rule of an tableelement corresponding to the element node to each element node, and generate a rendering array including a target code of each tableelement, where the target code of each tableelement in the rendering array is used to render the tableelement to a target form.
Optionally, the second configuration unit is specifically configured to, when the data type of the target field in the configuration object is an enumeration type and the field value is a boolean value, use a form element corresponding to the configuration object as a radio button; and under the condition that the data type of the target field in the configuration object is an enumeration type and the field value is a character, the form element corresponding to the configuration object is a selection frame.
Optionally, the second configuration unit is specifically configured to, when the data type of the target field in the configuration object is a preset service type, determine that the table element corresponding to the configuration object is a preset table element corresponding to the preset service type.
Optionally, the rendering module is specifically configured to recursively traverse the target code of each form element in the rendering array based on data driving, render the target code of each form element to the same form, and generate the target form.
According to still another aspect of embodiments of the present application, there is provided an electronic device including: a processor, a memory and a computer program stored on the memory and executable on the processor, the processor implementing the method of generating a form as described above when executing the program.
According to yet another aspect of embodiments of the present application, there is provided a readable storage medium, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the method of generating a form as described above.
In the embodiment of the application, a user can input multiple items of configuration information according to the design requirements of a target form, so that a target form element corresponding to each item of configuration information is determined based on the data type of the configuration information, that is, each target form element constituting the target form is automatically determined, and further, for each target form element, a target code for rendering the target form element to the target form is generated according to the verification rule of the target form element and the configuration information of the corresponding target form element. The developer is not required to write object code, but object code for each target form element is automatically generated based on the configuration information. Meanwhile, programming is not needed, and only configuration information needs to be input, so that the requirement on a user is reduced. And finally, selecting target codes of all target table elements based on data driving to render, generating a target form, and rendering all the target table elements by using the data driving idea, so that the code amount and the complexity of a development process can be greatly reduced, the development efficiency is improved, and the increasing form development requirements are met.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments of the present application will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive exercise.
FIG. 1 is a flow chart of steps of a method of form generation provided by an embodiment of the present application;
FIG. 2 is a flowchart of an actual application for obtaining object code according to an embodiment of the present disclosure;
FIG. 3 is a flowchart for recursively traversing a rendering array based on data driving according to an embodiment of the present disclosure;
fig. 4 is a block diagram of a structure of an apparatus for generating a form according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be appreciated that reference throughout this specification to "one embodiment" or "an embodiment" means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Thus, the appearances of the phrases "in one embodiment" or "in an embodiment" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
In various embodiments of the present application, it should be understood that the sequence numbers of the following processes do not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
Referring to fig. 1, an embodiment of the present application provides a method for generating a form, where the method includes:
step 101: and determining a target form element corresponding to each item of configuration information based on the data type of the plurality of items of configuration information input by the user.
In this step, the multiple items of configuration information input by the user are information which is input by the user based on the design requirement of the target form and meets the design requirement. The design requirements include, but are not limited to, which form elements are involved in the target form. For example, during form development, a visual draft of the form is first created based on the design requirements of the form. The user will enter configuration information based on the visual contribution of the form. The data types may include basic data types such as string types, enumeration types, integer types, and the like. It will be appreciated that form elements are elements that make up a form, and typically include an input box, a drop-down selection box, a radio box, a multiple selection box, and the like. The target form element is a form element corresponding to the configuration information determined based on the data type of the configuration information. For example, based on the data type of a certain item of configuration information, it is determined that the form element corresponding to the item of configuration information is an input box, and the input box is the target form element, and the item of configuration information corresponds to the input box.
Because the design requirement of the target form includes the form elements related in the target form, the configuration information is the information input by the user based on the design requirement of the target form, and the target form elements are determined based on the configuration information, the determined target form elements are the form elements in the target form. For example, an input box is required in the target form, and the user can see the input box through the visual draft of the target form, so as to input the first configuration information for the input box. Based on the data type of the first configuration information, the target form element corresponding to the first configuration information can be determined as the input box. Notably, each item of configuration information can correspond to at least one target form element.
Step 102: and aiming at each target form element, generating a target code for rendering the target form element to the target form according to the verification rule of the target form element and the configuration information of the corresponding target form element.
In this step, since there are a plurality of items of configuration information, each item of configuration information corresponds to a respective target form element, there will be a plurality of target form elements. Here, each target form element is processed separately, and a target code of each target form element, that is, a code for rendering the target form element to the target form, is obtained. The processing procedures for different target table elements are similar, and the difference is that the configuration information corresponding to each target table element is different and the verification rule is also different. Specifically, the verification rules of different table elements may be created in advance, and after the target table element is determined, the target table element is used based on the corresponding verification rule. For example, a check rule corresponding to each table element is created for a plurality of table elements such as an input box, a drop-down selection box, a radio box, and a multi-selection box. And when the target form element is determined to be the input box, generating target codes for rendering the input box to the target form by using the check rule corresponding to the input box and the configuration information corresponding to the input box. It will be appreciated that each form element has a check rule for checking whether the information entered in the form element is valid or correct, for example for an input box that is only capable of entering numbers, a check rule is to check whether the information entered in the input box is a number, and if so, is valid or correct.
Step 103: and selecting the target codes of the target form elements based on data driving to render, and generating the target form.
In this step, when the target codes of the target form elements are selected for rendering, the target codes of the target form elements are selected for rendering according to a reasonable sequence by using a data-driven thought instead of sequentially selecting from top to bottom according to the positions of the form elements in the target form elements. Since the view determined based on the Object code of each Object form element is generated by data driving, modification of the view can be made without directly operating a DOM (Document Object Model). For example, when a target form element is a radio box, multiple different options will be involved, with each option corresponding to a sub-form. When the data driving is utilized, the field value of a preset field is adjusted only based on the option selected by the user, and then the corresponding sub-form is selected for rendering based on the current field value of the preset field.
In the embodiment of the application, a user can input multiple items of configuration information according to the design requirements of a target form, so that a target form element corresponding to each item of configuration information is determined based on the data type of the configuration information, that is, each target form element constituting the target form is automatically determined, and further, for each target form element, a target code for rendering the target form element to the target form is generated according to the verification rule of the target form element and the configuration information of the corresponding target form element. The developer is not required to write object code, but object code for each target form element is automatically generated based on the configuration information. Meanwhile, programming is not needed, and only configuration information needs to be input, so that the requirement on a user is reduced. And finally, selecting target codes of all target table elements based on data driving to render, generating a target form, and rendering all the target table elements by using the data driving idea, so that the code amount and the complexity of a development process can be greatly reduced, the development efficiency is improved, and the increasing form development requirements are met.
Optionally, determining a target form element corresponding to each item of configuration information based on a data type of a plurality of items of configuration information input by a user includes:
and aiming at each item of configuration information, creating a configuration object corresponding to the configuration information.
In this step, the process of creating the configuration object is a process of converting the configuration information into an object that can be recognized in the code execution process. Wherein an object may be understood as an instantiation of a class. For example, a class is created in advance, and the class comprises a name field, a table field and a type field; under the condition that a user inputs three pieces of information respectively, a configuration object created aiming at the three pieces of information is a result of instantiation of the class, the configuration object comprises a name field, a cable field and a type field after instantiation, and each field comprises a piece of information. The information in the configuration object can be obtained based on the field for use in the code execution process.
Because a plurality of items of configuration information exist, a plurality of configuration objects can be created, and the corresponding relation between the configuration information and the configuration objects can be recorded, so that the corresponding configuration objects can be determined under the condition that the configuration information is known; likewise, in the case of a known configuration object, its corresponding configuration relationship may be determined.
And for each configuration object, determining the table element corresponding to the configuration object based on the data type of the target field in the configuration object.
In this step, the target field is one or more fields in a preset configuration object. For example, a type field is set in each configuration object for recording the data type of the user input information, and the target field may be the type field, but is not limited thereto. It will be appreciated that the data type of the target field may reflect the form elements corresponding to the configuration objects, and thus each configuration object may be determined to correspond to a respective form element based on the data type of the target field.
And aiming at each configuration object, determining the table unit element corresponding to the configuration object as a target table unit element corresponding to the configuration information of the corresponding configuration object.
In this step, the configuration object is generated based on the configuration information, and therefore, the configuration object and the configuration information have a corresponding relationship, so that when the configuration object is known, the corresponding configuration information can be determined, and similarly, when the configuration information is known, the corresponding configuration object can be determined. The configuration object and the target form element have the corresponding relation, so that the configuration object is used as intermediate data, and the target form element corresponding to the configuration information can be determined. For example, configuration information a corresponds to configuration object b, and configuration object b corresponds to target table element c; the configuration information d corresponds to the configuration object e, the configuration object e corresponds to the target table element f, the configuration information a corresponds to the target table element c, and the configuration information d corresponds to the target table element f.
In the embodiment of the application, the configuration information is converted into the configuration object with the object structure, the form element corresponding to the configuration object can be determined based on the data type of the target field in the configuration object, and further, the configuration object is used as intermediate data, and the target form element corresponding to the configuration information can be determined.
Optionally, for each configuration object, determining, based on the data type of the target field in the configuration object, a table element corresponding to the configuration object includes:
determining a table element corresponding to each configuration object based on the data type of a target field in the configuration object aiming at each configuration object under the condition that each configuration object is an effective configuration object;
it should be noted that the configuration object being a valid configuration object includes the configuration object conforming to a preset validity check policy. It can be understood that, in order to avoid that the configuration object cannot be identified subsequently due to a problem in the data format and/or the data content of the configuration object, the validity of each configuration object needs to be checked, the subsequent steps are performed only when all the configuration objects are valid configuration objects, otherwise, the flow is ended or a prompt message is sent, and the preset valid check policy is a preset valid check policy used for checking the validity of the configuration object, that is, whether the configuration object is a valid configuration object. Specifically, the valid checking policy may include checking whether a data format of the configuration Object is in a valid JSON (JS Object Notation, JavaScript Object Notation) format, whether a type of the configuration Object is a selectable type, and whether the configuration Object has necessary fields, where the selectable type is at least one predefined Object type, and the necessary fields are at least one predefined field.
In the embodiment of the application, the configuration objects are verified, and the subsequent steps are only performed under the condition that all the configuration objects are valid configuration objects, so that the situation that the configuration objects cannot be identified and the target form cannot be generated finally due to the fact that the configuration objects are invalid can be reduced.
Optionally, for each target form element, generating an object code for rendering the target form element to the target form according to the verification rule of the target form element and the configuration information of the corresponding target form element, including:
and creating a configuration array containing each configuration object, wherein each configuration object comprises at least one element node, and the form elements corresponding to the configuration objects comprise form elements corresponding to each element node in the configuration objects.
It should be noted that after determining each configuration object, a configuration array containing each configuration object is created, and each element in the configuration array is a configuration object. Converting each configuration object into an array form facilitates processing by the program. The data content in the configuration object may correspond to one form element or may correspond to a plurality of form elements. The data content corresponding to one form element can be regarded as one element node, so that all configuration objects are unified to an element node level, namely, a form regarded as a single level in a multi-level target form is processed.
In the case where each configuration object includes one element node, the target form is a single-level form, otherwise the target form is a multi-level form. For a multi-level form, two levels of forms are taken as an example for illustration, and when a sub-form is nested in the form, the form is regarded as a two-level form. The level of the form may be determined based on the number of layers of the sub-forms embedded in the form, in the above example, if a layer of sub-forms is nested in the form, the level is two layers, and if a layer of sub-forms is still nested in the sub-forms, the level is three layers, and so on. Here, the multi-level form is determined based on the condition of the element nodes in the configuration object. Specifically, when a certain configuration object corresponds to an array, each element of the array is an element node, and the remaining configuration objects include an element node, the target form is a form of two levels. And under the condition that a certain configuration object corresponds to a first array, a certain element of the first array corresponds to a second array, each element in the second array is an element node, the rest elements in the first array are element nodes, and the rest configuration objects comprise one element node, the target form is a form with three levels.
And recursively traversing each element node in the configuration array, adding a rule code for characterizing the check rule of the table element corresponding to the element node to each element node, and generating a rendering array containing the target code of each table element, wherein the target code of each table element in the rendering array is used for rendering the table element to the target form.
It should be noted that recursive traversal is to recursively process some elements during traversal. When a target configuration object in the configuration array corresponds to an array, each element of the array is an element node, and the rest configuration objects contain an element node, recursively traversing the configuration array to access each element in the configuration array, and performing target processing on the element node when the element is the element node; and under the condition that the element corresponds to an array, performing the same processing operation as that of the configuration array on the array, namely accessing each element in the array, under the condition that the element is an element node, performing target processing on the element node until all elements in the array are accessed, and continuing to access the elements which are not accessed in the configuration array until all elements in the configuration array are accessed. And performing target processing on the element nodes, namely adding rule codes representing the check rules of the form elements corresponding to the element nodes, and generating a rendering array containing the target codes of the form elements.
It can be understood that after the configuration array is recursively traversed, each element in the configuration array and the elements included in the elements are all converted, and the target code of the same level is obtained.
In the embodiment of the application, the configuration object is processed in a traversal recursive mode, and element nodes of different levels in the configuration object can be unified to the same level, so that processing of multi-level forms is facilitated.
Optionally, determining a table element corresponding to the configuration object based on the data type of the target field in the configuration object includes:
and when the data type of the target field in the configuration object is an enumeration type and the field value is a Boolean value, the table element corresponding to the configuration object is a radio button.
And under the condition that the data type of the target field in the configuration object is an enumeration type and the field value is a character, taking the form element corresponding to the configuration object as a selection frame.
It should be noted that, in the case that the data type of the target field in the configuration object is an enumeration type, a plurality of enumeration members are usually included. Therefore, the table element corresponding to the configuration object is a table element with a plurality of options. There are multiple form elements with multiple options, such as radio button (audio) and selection box (slide). It will be appreciated that a radio button can only select one option, which has a boolean value, while a checkbox does not, which typically has a character value, and therefore, based on the field value, it can be determined whether the form element to which the configuration object corresponds is a radio button or a checkbox. Of course, when the data type of the target field in the configuration object is a character string type and there is no data item of an enumeration type, the table element corresponding to the configuration object is an input box.
In the embodiment of the application, when the data type of the target field in the configuration object is an enumeration type, the table element corresponding to the configuration object can be accurately determined based on the field value.
Optionally, determining a table element corresponding to the configuration object based on the data type of the target field in the configuration object includes:
and under the condition that the data type of the target field in the configuration object is the preset service type, the table element corresponding to the configuration object is a preset table element corresponding to the preset service type.
It should be noted that in some business scenarios, a target form element may be a business-side-customized form element, i.e., a form element that is not a conventional drop-down box, import box, radio box, etc. Therefore, the business-side self-defined form element and the corresponding preset business type are preset, and the business-side self-defined form element in the target form can be added.
In the embodiment of the application, the service type preset based on the service requirement and the form element corresponding to the service type can realize the addition of the service-side custom form element in the target form.
As shown in fig. 2, a flowchart of an actual application for obtaining an object code in the embodiment of the present application includes:
step 201: traversing the configuration array, wherein the configuration array is the configuration array in the above embodiment of the present invention, and for the generation process of the configuration array, reference is made to the above description, which is not described herein again.
Step 202: and judging whether the configuration information corresponding to each element in the configuration array is valid configuration information, wherein the process of judging whether the configuration information is valid configuration information refers to the above description, and is not described herein again. And executing step 203 when the configuration information corresponding to each element in the configuration array is valid configuration information, otherwise ending the process or displaying prompt information to prompt the user to re-input the configuration information.
Step 203, executing loop processing, and acquiring a new element each time in a loop, namely traversing the configuration array.
Step 204: and judging whether the acquired new element is a self-defined object type, wherein the self-defined object type can be an object type defined in advance based on the basic form element. Here, it is essential to determine whether or not the new element is a basic form element. The basic form elements herein include form elements such as an input box, a drop-down box, a radio box, and the like. If so, step 205 is performed, otherwise, step 206 is performed.
Step 205: and performing first target processing, namely generating a target code for rendering the basic form element corresponding to the new element to the target form by using the verification rule of the basic form element corresponding to the new element and the new element. And performing next circulation to obtain new elements again.
Step 206: and judging whether the new element contains elements of a plurality of custom object types, namely judging whether the new element corresponds to an array, if so, executing step 207, and otherwise, executing step 208.
Step 207: and (4) performing recursive processing, namely performing the same operation as the configuration of the array on the array corresponding to the element until a corresponding target code is generated for each element in the array. The next cycle is then performed based on step 203, and the new element is reacquired.
Step 208: it is determined whether the new element is a business type, if so, step 209 is performed, otherwise, step 210 is performed.
Step 209: the second target process, which is referred to herein as a business-customized form element, is a non-base form element, and thus, the second target process is to generate a target code for the new element based on the business-customized form element's verification rules and the new element.
Step 210: after each element in the configuration array is processed, default processing is performed. And recording the default value corresponding to each table element, so that after the target form is generated, the default value is filled in the generated target form.
In the embodiment of the application, no side effect is generated on the multi-layer nested deep form, and the form rendering, the rule verification and the like are all equal to a single-level form. Furthermore, a highly-separated reusable scheme can be provided for the search function and the form filling function, repeated development of the similar functions can be reduced, and flexible increase of the configuration items of the extension fields can be realized.
Optionally, the selecting, based on data driving, the target code of each target form element for rendering, and generating the target form includes:
and based on the data driving recursion traversal, the target code of each form element in the rendering array is rendered to the same form, and a target form is generated.
It should be noted that the process of recursively traversing the rendered array based on data driving is similar to the process of recursively traversing the configuration array in the previous step, except that the elements recursively traversed are processed differently, where the processing is related to rendering. And the way of selecting elements is different, here based on data driving. A specific example of a process for recursively traversing a rendering array based on data driving is described below, and as shown in fig. 3, a flowchart for recursively traversing a rendering array based on data driving provided by the embodiment of the present application includes:
step 301: traversing the rendering array, it should be noted that the process of generating object code for the configuration array in the embodiment shown in fig. 2 may be understood as a process of converting the configuration array into a rendering array that may be used for data-driven rendering. The rendering array is the array after the configuration array is converted. The conversion process is shown in fig. 2 and will not be described herein.
Step 302: and acquiring a new element, namely the element currently accessed when traversing the rendering array.
Step 303: it is determined whether the obtained new element is a valid element, if so, step 304 is executed, otherwise, the process is ended or an error is reported. An active element is an element that can be identified and processed.
Step 304: it is determined whether the new element is of the base type, i.e., whether the new element is transformed from a configuration object corresponding to a base form element. If so, step 305 is performed, otherwise, step 306 is performed.
Step 305: and rendering the basic components, namely rendering the new elements by using the rendering mode of the basic table elements.
Step 306: whether it is a custom business type, i.e. whether the new element is converted from the configuration object of the form element customized by the corresponding business party. If so, go to step 307, otherwise go to step 308.
Step 307: and informing the service layer to render, namely rendering the new elements based on the rendering mode of the table elements provided by the service party.
Step 308: whether it is an array or object, i.e. whether it contains a plurality of other elements. If so, step 309 is performed, otherwise, step 310 is performed.
Step 309: the recursive processing is described by taking the new element corresponding array as an example. And processing the array corresponding to the new element according to the array rendering mode. Until all elements in the array corresponding to the new element are rendered.
Step 310: and judging whether the new element is the last element of the rendering array, if so, ending, otherwise, executing the step 302, and acquiring the new element again until all elements of the rendering array are accessed.
In the embodiment of the application, the rendering array is processed in a traversal recursion mode, and elements in the rendering array are selected in a data driving mode, so that the code amount can be reduced, and the development efficiency is greatly improved.
Referring to fig. 4, an embodiment of the present application further provides an apparatus for generating a form, where the apparatus includes:
a configuration module 41, configured to determine, based on the data type of multiple items of configuration information input by the user, a target form element corresponding to each item of configuration information;
a processing module 42, configured to generate, for each target form element, a target code for rendering the target form element to the target form according to the verification rule of the target form element and the configuration information of the corresponding target form element;
and the rendering module 43 is configured to select a target code of each target form element based on data driving to perform rendering, so as to generate a target form.
Optionally, the configuration module 41 includes:
the first configuration unit is used for creating a configuration object corresponding to the configuration information aiming at each item of configuration information;
the second configuration unit is used for determining the table unit elements corresponding to the configuration objects according to the data types of the target fields in the configuration objects aiming at each configuration object;
and the third configuration unit is used for determining the table element corresponding to the configuration object as the target table element corresponding to the configuration information of the corresponding configuration object aiming at each configuration object.
Optionally, the second configuration unit is specifically configured to, when each configuration object is an effective configuration object, determine, for each configuration object, a table element corresponding to the configuration object based on a data type of a target field in the configuration object;
the configuration object is an effective configuration object, and the configuration object meets a preset effective verification strategy.
Optionally, the processing module 42 includes:
the first processing unit is used for creating a configuration array containing each configuration object, wherein each configuration object comprises at least one element node, and the table unit elements corresponding to the configuration objects comprise the table unit elements corresponding to each element node in the configuration objects;
and the second processing unit is used for recursively traversing each element node in the configuration array, adding a rule code representing a check rule of the form element corresponding to the element node to each element node, and generating a rendering array containing a target code of each form element, wherein the target code of each form element in the rendering array is used for rendering the form element to the target form.
Optionally, the second configuration unit is specifically configured to, when the data type of the target field in the configuration object is an enumeration type and the field value is a boolean value, configure the table element corresponding to the object as a radio button; and under the condition that the data type of the target field in the configuration object is an enumeration type and the field value is a character, taking the form element corresponding to the configuration object as a selection box.
Optionally, the second configuration unit is specifically configured to, when the data type of the target field in the configuration object is a preset service type, configure the table element corresponding to the configuration object as a preset table element corresponding to the preset service type.
Optionally, the rendering module 43 is specifically configured to render the target code of each form element to the same form based on data-driven recursive traversal of the target code of each form element in the rendering array, so as to generate a target form.
The apparatus for generating a form provided in this embodiment of the present application can implement each process implemented by the method for generating a form in the method embodiments of fig. 1 to fig. 3, and is not described here again to avoid repetition.
In the embodiment of the application, a user can input multiple items of configuration information according to the design requirements of a target form, so that a target form element corresponding to each item of configuration information is determined based on the data type of the configuration information, that is, each target form element constituting the target form is automatically determined, and further, for each target form element, a target code for rendering the target form element to the target form is generated according to the verification rule of the target form element and the configuration information of the corresponding target form element. The developer is not required to write object code, but object code for each target form element is automatically generated based on the configuration information. Meanwhile, programming is not needed, and only configuration information needs to be input, so that the requirement on a user is reduced. And finally, selecting target codes of all target table elements based on data driving to render, generating a target form, and rendering all the target table elements by using the data driving idea, so that the code amount and the complexity of a development process can be greatly reduced, the development efficiency is improved, and the increasing form development requirements are met.
On the other hand, the embodiment of the present application further provides an electronic device, which includes a processor, a memory, and a computer program stored on the memory and executable on the processor, and when the processor executes the program, the method for generating a form provided in the embodiments of the present application is implemented.
In still another aspect, the present application provides a readable storage medium, and when executed by a processor of an electronic device, the instructions in the readable storage medium enable the electronic device to perform the method for generating a form as provided in the above embodiments.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present application is not limited by the order of acts described, as some steps may occur in other orders or concurrently depending on the application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one position, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. Based on the understanding, the above technical solutions substantially or otherwise contributing to the prior art may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the various embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (16)

1. A method of generating a form, the method comprising:
determining a target form element corresponding to each item of configuration information based on the data type of the plurality of items of configuration information input by the user;
aiming at each target form element, generating a target code for rendering the target form element to a target form according to the verification rule of the target form element and the configuration information corresponding to the target form element;
and selecting the target codes of the target form elements based on data driving to render, and generating the target form.
2. The method of claim 1, wherein determining the target form element corresponding to each configuration information based on the data type of the plurality of configuration information input by the user comprises:
aiming at each item of configuration information, creating a configuration object corresponding to the configuration information;
for each configuration object, determining a table element corresponding to the configuration object based on the data type of a target field in the configuration object;
and aiming at each configuration object, determining the table unit element corresponding to the configuration object as a target table unit element corresponding to the configuration information of the configuration object.
3. The method according to claim 2, wherein the determining, for each of the configuration objects, a table element corresponding to the configuration object based on a data type of a target field in the configuration object comprises:
under the condition that each configuration object is a valid configuration object, determining a table element corresponding to each configuration object based on the data type of a target field in the configuration object for each configuration object;
the configuration object is an effective configuration object, and the configuration object meets a preset effective verification strategy.
4. The method of claim 2, wherein for each of the target form elements, generating object code for rendering the target form element to a target form according to the verification rule of the target form element and the configuration information corresponding to the target form element comprises:
creating a configuration array containing each configuration object, wherein each configuration object comprises at least one element node, and the table unit elements corresponding to the configuration objects comprise the table unit elements corresponding to each element node in the configuration objects;
and recursively traversing each element node in the configuration array, adding a rule code representing a check rule of the form element corresponding to the element node to each element node, and generating a rendering array comprising a target code of each form element, wherein the target code of each form element in the rendering array is used for rendering the form element to a target form.
5. The method of claim 2, wherein determining the table element corresponding to the configuration object based on the data type of the target field in the configuration object comprises:
when the data type of the target field in the configuration object is an enumeration type and the field value is a Boolean value, the table element corresponding to the configuration object is a radio button;
and under the condition that the data type of the target field in the configuration object is an enumeration type and the field value is a character, taking the form element corresponding to the configuration object as a selection box.
6. The method of claim 2, wherein determining the table element corresponding to the configuration object based on the data type of the target field in the configuration object comprises:
and under the condition that the data type of the target field in the configuration object is a preset service type, the table element corresponding to the configuration object is a preset table element corresponding to the preset service type.
7. The method of claim 4, wherein the data-driven selection of object code for each of the object form elements for rendering, and the generation of the object form, comprises:
and recursively traversing the target code of each form element in the rendering array based on data driving, rendering the target code of each form element to the same form, and generating the target form.
8. An apparatus for generating a form, the apparatus comprising:
the configuration module is used for determining a target form element corresponding to each item of configuration information based on the data type of the plurality of items of configuration information input by the user;
the processing module is used for generating a target code for rendering the target form unit element to a target form according to the verification rule of the target form unit element and the configuration information corresponding to the target form unit element aiming at each target form unit element;
and the rendering module is used for selecting the target codes of all the target form elements based on data driving to render and generating the target form.
9. The apparatus of claim 8, wherein the configuration module comprises:
the first configuration unit is used for creating a configuration object corresponding to each item of configuration information;
the second configuration unit is used for determining a table element corresponding to each configuration object based on the data type of a target field in the configuration object;
and a third configuration unit, configured to determine, for each configuration object, a table element corresponding to the configuration object as a target table element corresponding to the configuration information of the configuration object.
10. The apparatus according to claim 9, wherein the second configuration unit is specifically configured to, for each configuration object, determine, based on a data type of a target field in the configuration object, a table element corresponding to the configuration object, where the configuration object is a valid configuration object;
the configuration object is an effective configuration object, and the configuration object meets a preset effective verification strategy.
11. The apparatus of claim 9, wherein the processing module comprises:
the first processing unit is used for creating a configuration array containing each configuration object, wherein each configuration object comprises at least one element node, and the table unit elements corresponding to the configuration objects comprise the table unit elements corresponding to each element node in the configuration objects;
the second processing unit is configured to recursively traverse each element node in the configuration array, add a rule code representing a check rule of an tableelement corresponding to the element node to each element node, and generate a rendering array including a target code of each tableelement, where the target code of each tableelement in the rendering array is used to render the tableelement to a target form.
12. The apparatus according to claim 9, wherein the second configuration unit is specifically configured to, when a data type of a target field in the configuration object is an enumeration type and a field value is a boolean value, determine that a form element corresponding to the configuration object is a radio button; and under the condition that the data type of the target field in the configuration object is an enumeration type and the field value is a character, the form element corresponding to the configuration object is a selection frame.
13. The apparatus according to claim 9, wherein the second configuration unit is specifically configured to, when the data type of the target field in the configuration object is a preset service type, determine that the table element corresponding to the configuration object is a preset table element corresponding to the preset service type.
14. The apparatus of claim 11, wherein the rendering module is specifically configured to generate the target form by rendering the target code of each form element to the same form based on a data-driven recursive traversal of the target code of each form element in the rendering array.
15. An electronic device, comprising: a processor, a memory and a computer program stored on the memory and executable on the processor, the processor implementing a method of generating a form as claimed in one or more of claims 1-7 when executing the program.
16. A readable storage medium, characterized in that instructions in the storage medium, when executed by a processor of an electronic device, enable the electronic device to perform a method of generating a form as claimed in one or more of claims 1-7.
CN202210138770.7A 2022-02-15 2022-02-15 Method and device for generating form and electronic equipment Pending CN114595664A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210138770.7A CN114595664A (en) 2022-02-15 2022-02-15 Method and device for generating form and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210138770.7A CN114595664A (en) 2022-02-15 2022-02-15 Method and device for generating form and electronic equipment

Publications (1)

Publication Number Publication Date
CN114595664A true CN114595664A (en) 2022-06-07

Family

ID=81806680

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210138770.7A Pending CN114595664A (en) 2022-02-15 2022-02-15 Method and device for generating form and electronic equipment

Country Status (1)

Country Link
CN (1) CN114595664A (en)

Similar Documents

Publication Publication Date Title
US9928040B2 (en) Source code generation, completion, checking, correction
CN108228169A (en) Chart production method, apparatus, equipment and medium based on eCharts tools
CN110610352B (en) Flow processing method and device, electronic equipment and computer readable storage medium
CN109739494B (en) Tree-LSTM-based API (application program interface) use code generation type recommendation method
CN110688343A (en) Method and device for converting data format
US11625248B2 (en) Operator registration method and apparatus for deep learning framework, device and storage medium
US20120110444A1 (en) Help Document Animated Visualization
CN107330014B (en) Data table creating method and device
CN112214210A (en) Logistics business rule engine and configuration method, device, equipment and storage medium thereof
CN113468534B (en) Vulnerability detection method and related device for android application program
CN112052157B (en) Method, device and system for constructing test message
CN114595664A (en) Method and device for generating form and electronic equipment
CN116631573A (en) Prescription drug auditing method, device, equipment and storage medium
CN116737155A (en) Internet page generation method and device, storage medium and computer equipment
US11960866B2 (en) Method and system for constructing compiler intermediate representations from TensorFlow graph
CN114254068B (en) Data transfer method and system
CN112015426B (en) Code management method, device and equipment
CN115017048A (en) Method and device for determining test seeds
CN107451167A (en) The click data acquisition methods and system of position are clicked in standing
CN117289905B (en) Application software development method and device, storage medium and electronic equipment
US11340918B2 (en) Knowledge engine auto-generation of guided flow experience
CN117608568B (en) Configuration interface generation method, device, equipment and storage medium
CN105718433B (en) Table semantization device and method
WO2021189209A1 (en) Testing method and verification platform for accelerator
US20230266951A1 (en) Method and system for learning based dynamic software system adaptation

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination