Form code generation method and device, computer equipment and storage medium
By receiving interface parameter information from the user terminal, filtering the control with the highest matching degree and using the template engine to generate form code, the problems of low efficiency and poor accuracy in traditional code generation methods are solved, and the effect of automatic matching of parameters and improving development efficiency is achieved. .
Patent Information
- Application Number
- CN202411063199.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-12-10
AI Technical Summary
Traditional code generation methods have problems such as low efficiency and poor accuracy in front-end separation and distribution. Especially during the parameter transfer of form components, developers need to manually review the component library documents, which makes the operation time-consuming and error-prone. .
By receiving interface parameter information sent by the user terminal, calling the built control code base, filtering the control with the highest matching degree, and using the template engine to generate target form code, reducing the cumbersome process of manually filling in codes and improving development efficiency and accuracy.
Automatic matching of parameters is realized, the process of manually filling in code is reduced, development efficiency and code accuracy are improved, and the problems of low efficiency and poor accuracy in traditional methods are solved.
Smart Images

Figure CN119105734A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of development assistance technology, and in particular to a form code generation method, device, computer equipment and storage medium. Background Art
[0002] In the existing industry, there are some code generation tools, most of which are implemented through visual drag and drop components. In the development of front-end and back-end separation, these tools do not provide effective solutions to the problem of parameter transfer between the front-end and back-end. Among many components, form components often involve the most complex parameter transfer in the connection between the front-end and back-end.
[0003] In the traditional code generation method, developers need to manually consult the component library documentation to obtain the required control code from numerous form controls and manually bind parameters.
[0004] However, the applicant found that the traditional code generation method is time-consuming and limits the development efficiency. In addition, for complex forms, the process of manually filling in parameters is often mechanically repetitive and may be wrong. It can be seen that the traditional code generation method has the problems of low efficiency and poor accuracy. Summary of the invention
[0005] The purpose of the embodiments of the present application is to propose a form code generation method, apparatus, computer equipment and storage medium to solve the problems of low efficiency and poor accuracy of traditional code generation methods.
[0006] In order to solve the above technical problems, the embodiment of the present application provides a form code generation method, which adopts the following technical solution:
[0007] Receiving interface parameter information sent by a user terminal, wherein the interface parameter information at least includes data type information;
[0008] Calling a constructed control code library, and obtaining a set of to-be-selected controls that matches the data type information in the constructed control code library;
[0009] According to the parameter characteristics of the interface parameter information, the control with the highest matching degree is selected from the set of candidate controls to obtain a target control;
[0010] The target control and the data type information corresponding to the target control are processed by code generation according to the template engine to obtain the target form code.
[0011] Furthermore, before the step of calling the constructed control code library and obtaining the target control matching the data type information in the constructed control code library, the following steps are also included:
[0012] Establish the initial control code library;
[0013] Create a hash table instance according to the control type of the control to be stored, and store the control type as a key in the hash table instance;
[0014] The control code snippet corresponding to the control type is stored as a value in a hash table in a key-value pair manner to obtain a key-value pair of the control type and the control code snippet.
[0015] Furthermore, the control type of the target control is input, select and / or textarea, and the step of performing code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code specifically includes the following steps:
[0016] If the control type of the target control is input, fill in the name and id attributes of the input tag according to the name and ID of the target control to obtain the target form code;
[0017] If the control type of the target control is select, fill the name and id attributes of the select tag according to the name and ID of the target control, and generate the corresponding option subtag according to the value of the control to obtain the target form code;
[0018] If the control type of the target control is textarea, the name and id attributes of the textarea tag are filled according to the name and ID of the target control, and the value of the target control is set to the initial content of the textarea to obtain the target form code.
[0019] Furthermore, after the step of performing code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code, the following steps are also included:
[0020] Obtain the names and identification information of all target controls in the target form code;
[0021] Check whether there is a subordinate and dependent relationship between the target controls, and obtain a dependency relationship graph between the target controls;
[0022] According to the dependency graph, event listeners are bound to related controls to determine the controls and events that need to execute linkage logic.
[0023] Furthermore, after the step of performing code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code, the following steps are also included:
[0024] Adaptively typeset the target form code according to the responsive layout
[0025] In order to solve the above technical problems, the embodiment of the present application also provides a form code generation device, which adopts the following technical solution:
[0026] A parameter acquisition module, used to receive interface parameter information sent by a user terminal, wherein the interface parameter information at least includes data type information;
[0027] A module for obtaining a control to be selected, used for obtaining a module for calling a constructed control code library, and obtaining a set of controls to be selected that match the data type information in the constructed control code library;
[0028] A target control acquisition module, used for selecting the control with the highest matching degree in the candidate control set according to the parameter characteristics of the interface parameter information, and obtaining the target control;
[0029] The code generation module is used to perform code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code.
[0030] Furthermore, the device also includes:
[0031] Code library creation module, used to create the initial control code library;
[0032] A hash table creation module, used to create a hash table instance according to the control type of the control to be stored, and store the control type as a key in the hash table instance;
[0033] The key-value pair acquisition module is used to store the control code snippet corresponding to the control type as a value in a hash table according to the key-value pair method, and obtain the key-value pair of the control type and the control code snippet.
[0034] Furthermore, the control type of the target control is input, select and / or textarea, and the target control acquisition module includes:
[0035] The first target control acquisition submodule is used to fill the name and id attributes of the input tag according to the name and ID of the target control to obtain the target form code if the control type of the target control is input;
[0036] The second target control acquisition submodule is used to fill the name and id attributes of the select tag according to the name and ID of the target control if the control type of the target control is select, and generate the corresponding option subtag according to the value of the control to obtain the target form code;
[0037] The third target control acquisition submodule is used to fill the name and id attributes of the textarea tag according to the name and ID of the target control if the control type of the target control is textarea, and set the value of the target control to the initial content of the textarea to obtain the target form code.
[0038] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0039] The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the form code generation method as described above when executing the computer-readable instructions.
[0040] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0041] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the form code generation method described above are implemented.
[0042] The present application provides a form code generation method, including: receiving interface parameter information sent by a user terminal, wherein the interface parameter information includes at least data type information; calling a constructed control code library, and obtaining a set of selected controls that match the data type information in the constructed control code library; screening the control with the highest matching degree in the set of selected controls according to the parameter characteristics of the interface parameter information to obtain a target control; performing code generation processing on the target control and the data type information corresponding to the target control according to a template engine to obtain a target form code. Compared with the prior art, the present application stores various types of form control codes in a component library into a model, and does not need to consult component library documents to obtain; according to a parameter list input by a user, a form control is selected to associate with a parameter to achieve automatic parameter matching; by automatically generating code, the tedious process of manually filling in code is reduced, and development efficiency and code accuracy are improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0045] Figure 2 This is a flowchart of the implementation of the form code generation method provided in Example 1 of the present application;
[0046] Figure 3 It is a structural diagram of a form code generating device provided in Embodiment 2 of the present application;
[0047] Figure 4 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0049] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0050] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0051] like Figure 1As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0052] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0053] The terminal devices 101, 102, and 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0054] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .
[0055] It should be noted that the form code generation method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the form code generation device is generally arranged in the server / terminal device.
[0056] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0057] Embodiment 1
[0058] Continue to refer Figure 2 , shows a flow chart of an embodiment of a form code generation method according to the present application. The form code generation method comprises: step S201, step S202, step S203 and step S204.
[0059] In step S201, interface parameter information sent by a user terminal is received, wherein the interface parameter information at least includes data type information.
[0060] In the embodiments of the present application, the user terminal refers to a terminal device used to execute the image processing method for preventing document abuse provided by the present application. The user terminal can be a mobile terminal such as a mobile phone, a smart phone, a laptop computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a navigation device, etc., as well as a fixed terminal such as a digital TV, a desktop computer, etc. It should be understood that the examples of user terminals here are only for the convenience of understanding and are not used to limit the present application.
[0061] In the embodiment of the present application, the parameter information submitted by the user can be obtained through the interface to obtain a parameter data list.
[0062] In step S202, the constructed control code library is called, and a set of to-be-selected controls matching the data type information is obtained from the constructed control code library.
[0063] In an embodiment of the present application, the present application pre-builds a control code library, and the control code library stores different kinds of control types and control code snippets corresponding to different control types.
[0064] In step S203, the control with the highest matching degree is screened in the set of selectable controls according to the parameter characteristics of the interface parameter information to obtain a target control.
[0065] In an embodiment of the present application, if the parameter list is not empty, each interface parameter is traversed to obtain the parameter's data type, length limit, value range, and parameter characteristics of other related attributes.
[0066] In the embodiment of the present application, the implementation method of filtering the control with the highest matching degree may be:
[0067] (1) If the parameter data type is a string type, then further determine whether there is a length limit. If there is a length limit, determine whether the text box is used. Otherwise, determine whether the value is an enumeration value. If so, a drop-down box or radio button group is preferred. If neither is satisfied, use a text field:
[0068] (2) If the data type of the parameter is a numeric type, then determine the control type based on the value range. If the value range is a continuous value, it is preferred to use a slider; if the value range is a discrete value, a numeric input box is preferred; if the value involves a scoring type, use a scoring control;
[0069] (3) If the parameter data type is Boolean, select the control based on the specific business needs. If a single selection is required, a switch or radio button is preferred; if multiple selections are required, a check box is preferred;
[0070] (4) If the data type of the parameter is a date and time type, determine the specific needs. If you need to select a date, use a date picker; if you need to select a time, use a time picker; if you need to select both a date and a time, use a date and time picker;
[0071] (5) If the parameter has a value range limit, then determine the relevant properties of the control based on the range. If it is an enumeration value, obtain these enumeration values and set them to the options of the drop-down box or radio button group; if it is a numerical range, set the minimum and maximum values of the slider or numeric input box;
[0072] (6) Based on the mandatory attribute of the parameter, determine whether the control needs to be set as a mandatory item; if it is required, mark it as required in the control properties;
[0073] (7) Get the default value of the parameter and set it as the initial value of the control; if there is no default value, use the default initial value of the control;
[0074] (8) Based on the parameter description and validation rules, determine the label name of the control and the explanatory text next to its label, and set validation rules in the control properties to ensure data validity.
[0075] In the embodiment of the present application, through the previous steps, a complete mapping relationship between parameters and controls is finally generated. It should be understood that the example of the implementation method of screening the controls with the highest matching degree here is only for the convenience of understanding and is not used to limit the present application.
[0076] In step S204, the target control and the data type information corresponding to the target control are processed by code generation according to the template engine to obtain the target form code.
[0077] In the embodiment of the present application, according to the placeholder hint information (placeholder) of the form control, the placeholder hint is filled into the corresponding HTML attribute to obtain the final complete HTML code fragment.
[0078] In an embodiment of the present application, a form code generation method is provided, including: receiving interface parameter information sent by a user terminal, wherein the interface parameter information includes at least data type information; calling a constructed control code library, and obtaining a set of selected controls that match the data type information in the constructed control code library; screening the control with the highest matching degree in the set of selected controls according to the parameter characteristics of the interface parameter information to obtain a target control; performing code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain a target form code. Compared with the prior art, the present application stores various types of form control codes in the component library into a model, and does not need to consult the component library document to obtain; according to the parameter list input by the user, the form control is selected to associate with the parameter to achieve automatic parameter matching; by automatically generating code, the tedious process of manually filling in the code is reduced, and the development efficiency and code accuracy are improved.
[0079] In some optional implementations of the embodiments of the present application, before step S202, the following steps are also included:
[0080] Establish the initial control code library;
[0081] Create a hash table instance according to the control type of the control to be stored, and store the control type as a key in the hash table instance;
[0082] The control code snippet corresponding to the control type is stored as a value in the hash table in a key-value pair manner, thereby obtaining a key-value pair of the control type and the control code snippet.
[0083] In the embodiment of the present application, a hash table instance is created according to the control type, and the control type is stored as a key in the table; the corresponding control code snippet is stored as a value in the hash table in a key-value pair manner to obtain a key-value pair of the control type and the code snippet, specifically:
[0084] (1) If the control type already exists in the hash table, update the corresponding control code snippet. If the control type does not exist in the hash table, insert the new control type and its code snippet into the hash table to obtain the latest hash table status;
[0085] (2) After obtaining the control code snippet, generate a control label according to the control's function, style, interaction mode and other features, and append the label information to the control record to obtain a control record with the label information;
[0086] (3) Classify and store the control code snippets according to the control labels. If the labels are the same, the control code snippets are stored in the same category; if the labels are different, a new category is created to store the control code snippets, and a classified control code library is obtained;
[0087] (4) Obtain the current version information of the control code snippet. If the version information does not exist, initialize the version number to 0; if the version information exists, increment the version number as needed to obtain the latest version number information;
[0088] (5) Obtain the control author information. If the author information does not exist, record the author of the current control code snippet; if the author information exists and the author is different, update the control author information to obtain the latest author information;
[0089] (6) Obtain the creation time of the control code snippet. If the creation time is empty, record the current time as the creation time; if the creation time is not empty, do not update it, save the original creation time, and obtain the creation time information;
[0090] (7) Obtain the update time of the control code snippet. Each time the control code snippet is updated, the time of the update operation is recorded to obtain the most recent update time.
[0091] In an embodiment of the present application, a control record object containing all the information, such as the control type, code snippet, label, version, author, creation time, update time, etc., is constructed according to the control type, code snippet, label, version, author, creation time, update time, etc. obtained in the above steps, and is stored in a control code library to form a complete control record.
[0092] In some optional implementations of the embodiments of the present application, the control type of the target control is input, select and / or textarea, and step S204 specifically includes the following steps:
[0093] If the control type of the target control is input, fill in the name and id attributes of the input tag according to the name and ID of the target control to obtain the target form code;
[0094] If the control type of the target control is select, fill the name and id attributes of the select tag according to the name and ID of the target control, and generate the corresponding option subtag according to the value of the control to obtain the target form code;
[0095] If the control type of the target control is textarea, fill in the name and id attributes of the textarea tag according to the name and ID of the target control, and set the value of the target control to the initial content of the textarea to obtain the target form code.
[0096] In some optional implementation methods of the embodiments of the present application, the present application can also determine whether the class or style attribute is included according to the style of the form control. If it is included, the attribute value is filled into the part of the HTML code in the target form code obtained previously to form an updated HTML code; if there is an event handling function, the event handling function is bound to the corresponding event attribute according to the event type of the form control (onchange, onclick, etc.), and the HTML code continues to be updated.
[0097] In some optional implementation methods of the embodiments of the present application, the present application can also associate the data model with the control according to the data binding information of the form control, synchronize the attribute value of the data model with the attribute value of the control through template syntax or data binding technology, and further update the HTML code; if there are validation rules for the form control, then according to the validation rules (such as required, pattern, etc.), fill the rule attributes into the previous HTML code and update the HTML code.
[0098] In some optional implementations of the embodiments of the present application, after step S204, the following steps are further included:
[0099] Get the name and identification information of all target controls in the target form code;
[0100] Check whether there are subordinate and dependent relationships between target controls, and obtain a dependency graph between target controls;
[0101] Bind event listeners to related controls according to the dependency graph to determine the controls and events that need to execute linkage logic.
[0102] In the embodiment of the present application, the names and IDs of all controls are obtained, and it is checked whether there is a subordinate and dependent relationship between the controls, and it is determined whether the state of the control depends on other controls, and a dependency graph between the controls is obtained;
[0103] If there is a dependency, bind an event listener to the related controls, respond to changes in the controls through the listener, and determine the controls and events that need to execute linkage logic; in the event processing function, dynamically update the options and status of the associated controls according to the control value triggered by the event to ensure data synchronization and display update of the associated controls, and obtain the updated control status and options.
[0104] Furthermore, DOM can be operated through JavaScript to check the status and process data of the control that triggers the event, determine whether the properties and options of the associated control need to be modified, and obtain a list of controls that need to be modified and their properties and option values; dynamically update the DOM node properties of the associated control according to the list of controls and their properties and option values that need to be modified, set the options and status of the associated control, ensure the accuracy of data transmission and display, and obtain an updated DOM structure; use a data synchronization mechanism to synchronize the data of the associated control to the global state or data storage in real time, ensure the consistency of global data in the event processing function, and obtain a globally synchronized data state.
[0105] In the embodiment of the present application, by checking the global data status and updating the display and status of all associated controls, the overall data consistency of the form and the smoothness of user interaction are ensured, and the final consistent form control status and data are obtained.
[0106] In some optional implementation methods of the embodiments of the present application, the types and properties of all controls can be obtained by parsing the HTML structure of the form, and the purpose of each control and the type of data required to be filled in can be analyzed to obtain a mapping relationship between the control type and purpose; according to the purpose and data type of the control, the name and ID of the control can be reasonably named to ensure that the name and ID are semantic, and a semantic control name and ID list can be obtained.
[0107] In some optional implementations of the embodiments of the present application, after step S204, the following steps are further included:
[0108] Adaptively typeset the target form code based on the responsive layout.
[0109] In the embodiment of the present application, adaptive layout can dynamically calculate the size and position of controls according to the device screen size and orientation, and use the grid system or elastic box model to achieve the display effect of the form on different devices. At the same time, the validation rules are integrated with the layout to ensure the correct display of validation prompts on different devices. Specifically:
[0110] Media query: Set media query according to the device screen size and orientation, determine the current screen size and orientation and get the corresponding CSS style; get the current size and orientation of the device through window.innerWidth and window.innerHeight, and determine the CSS style to use based on the size range;
[0111] Percentage width: Based on the results of the media query, the width of the control is defined in percentage;
[0112] Determine whether the CSS style of the current device is the desktop version or the mobile version, get the corresponding percentage width setting, and set the appropriate width for the control;
[0113] Maximum / minimum width: According to the percentage width setting of the control, the actual width of the control is calculated, and the max-width and min-width attributes in CSS are used to limit the upper and lower limits of the control width to ensure that the control width is not too wide or too narrow;
[0114] Flexible box layout: Use display:flex to arrange form controls horizontally or vertically according to the current screen size and orientation;
[0115] Determine the arrangement of form controls by judging the device size and orientation to determine whether form controls are arranged horizontally or vertically;
[0116] Grid system: divides the form into columns of equal width based on screen size and orientation;
[0117] The width of each column and the number of columns that a control spans are determined through media query results, and the control size is automatically adjusted to ensure the display effect of the control on different devices.
[0118] Relative positioning: Use position:relative and top / right / bottom / left to adjust the control position according to the layout of the grid system;
[0119] By obtaining the position of each control in the grid system, the offset of relative positioning is determined and the control position is adjusted;
[0120] Automatic line break: According to the width and content of the control, the label text is automatically wrapped according to the width of the control by setting white-space:normal;
[0121] Determine the length of the control content and set the white-space property to ensure that the label content automatically wraps under different control widths;
[0122] Scale fonts: Set font sizes using rem or em units based on device screen size and orientation;
[0123] Determine the appropriate rem or em value based on the results of media queries and adjust the font size to ensure readability on different devices;
[0124] Integration of validation rules and layout: After calculating the position and size of all controls, integrate validation rules and monitor the validation status of controls through JavaScript to ensure that validation prompts are displayed correctly on different devices;
[0125] In the embodiment of the present application, the position and style of the verification prompt are dynamically adjusted by judging the verification status of the control to ensure the visibility of the prompt information.
[0126] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0127] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0128] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0129] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0130] Embodiment 2
[0131] Further references Figure 3 , as a response to the above Figure 2 The present application provides an embodiment of a form code generation device, and the device embodiment is similar to Figure 2Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0132] like Figure 3 As shown, the form code generating device 200 of the embodiment of the present application includes:
[0133] The parameter acquisition module 210 is used to receive the interface parameter information sent by the user terminal, wherein the interface parameter information at least includes data type information;
[0134] The module 220 for obtaining the control to be selected is used for obtaining a module for calling the constructed control code library to obtain a set of control to be selected that matches the data type information in the constructed control code library;
[0135] The target control acquisition module 230 is used to select the control with the highest matching degree from the set of candidate controls according to the parameter characteristics of the interface parameter information to obtain the target control;
[0136] The code generation module 240 is used to perform code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code.
[0137] In an embodiment of the present application, a form code generation device 200 is provided, including: a parameter acquisition module 210, for receiving interface parameter information sent by a user terminal, wherein the interface parameter information at least includes data type information; a candidate control acquisition module 220, for acquiring a module, for calling a constructed control code library, and acquiring a candidate control set matching the data type information in the constructed control code library; a target control acquisition module 230, for screening the control with the highest matching degree in the candidate control set according to the parameter characteristics of the interface parameter information, and obtaining a target control; a code generation module 240, for performing code generation processing on the target control and the data type information corresponding to the target control according to the template engine, and obtaining a target form code. Compared with the prior art, the present application stores various types of form control codes in the component library into a model, and does not need to consult the component library document to obtain; according to the parameter list input by the user, the form control is selected and associated with the parameter to realize automatic matching of the parameters; by automatically generating the code, the tedious process of manually filling in the code is reduced, and the development efficiency and code accuracy are improved.
[0138] In some optional implementations of the embodiments of the present application, the form code generating device 200 further includes:
[0139] Code library creation module, used to create the initial control code library;
[0140] A hash table creation module, used to create a hash table instance according to the control type of the control to be stored, and store the control type as a key in the hash table instance;
[0141] The key-value pair acquisition module is used to store the control code snippet corresponding to the control type as a value in the hash table according to the key-value pair method, and obtain the key-value pair of the control type and the control code snippet.
[0142] In some optional implementations of the embodiments of the present application, the control type of the target control is input, select and / or textarea, and the target control acquisition module includes:
[0143] The first target control acquisition submodule is used to fill the name and id attributes of the input tag according to the name and ID of the target control to obtain the target form code if the control type of the target control is input;
[0144] The second target control acquisition submodule is used to fill the name and id attributes of the select tag according to the name and ID of the target control if the control type of the target control is select, and generate the corresponding option subtag according to the value of the control to obtain the target form code;
[0145] The third target control acquisition submodule is used to fill the name and id attributes of the textarea tag according to the name and ID of the target control if the control type of the target control is textarea, and set the value of the target control to the initial content of the textarea to obtain the target form code.
[0146] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of a computer device according to an embodiment of the present application.
[0147] The computer device 300 includes a memory 310, a processor 320, and a network interface 330 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 300 having components 310-330, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital processors (DSPs), embedded devices, etc.
[0148] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0149] The memory 310 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 310 can be an internal storage unit of the computer device 300, such as a hard disk or memory of the computer device 300. In other embodiments, the memory 310 can also be an external storage device of the computer device 300, such as a plug-in hard disk equipped on the computer device 300, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. Of course, the memory 310 can also include both the internal storage unit of the computer device 300 and its external storage device. In the embodiment of the present application, the memory 310 is generally used to store the operating system and various application software installed on the computer device 300, such as computer-readable instructions of the form code generation method, etc. In addition, the memory 310 can also be used to temporarily store various data that have been output or are to be output.
[0150] The processor 320 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 320 is generally used to control the overall operation of the computer device 300. In the embodiment of the present application, the processor 320 is used to run the computer-readable instructions stored in the memory 310 or process data, such as running the computer-readable instructions of the form code generation method.
[0151] The network interface 330 may include a wireless network interface or a wired network interface. The network interface 330 is generally used to establish a communication connection between the computer device 300 and other electronic devices.
[0152] The computer device provided by the present application stores various types of form control codes in the component library into the model, without the need to consult the component library document to obtain them; according to the parameter list input by the user, the form control is selected to associate with the parameter to achieve automatic parameter matching; by automatically generating code, the tedious process of manually filling in the code is reduced, thereby improving development efficiency and code accuracy.
[0153] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the form code generation method as described above.
[0154] The computer-readable storage medium provided by the present application stores various types of form control codes in the component library into the model without the need to consult the component library document to obtain them; according to the parameter list input by the user, the form control is selected to associate with the parameter to achieve automatic parameter matching; by automatically generating code, the tedious process of manually filling in the code is reduced, thereby improving development efficiency and code accuracy.
[0155] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0156] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A form code generation method, characterized in that: The steps include: Receiving interface parameter information sent by a user terminal, wherein the interface parameter information at least includes data type information; Calling a constructed control code library, and obtaining a set of to-be-selected controls that matches the data type information in the constructed control code library; According to the parameter characteristics of the interface parameter information, the control with the highest matching degree is selected from the set of candidate controls to obtain a target control; The target control and the data type information corresponding to the target control are processed by code generation according to the template engine to obtain the target form code.
2. The form code generation method according to claim 1, characterized in that: Before the step of calling the constructed control code library and obtaining the target control matching the data type information in the constructed control code library, the following steps are also included: Establish the initial control code library; Create a hash table instance according to the control type of the control to be stored, and store the control type as a key in the hash table instance; The control code snippet corresponding to the control type is stored as a value in a hash table in a key-value pair manner to obtain a key-value pair of the control type and the control code snippet.
3. The form code generation method according to claim 1, characterized in that: The control type of the target control is input, select and / or textarea, and the step of performing code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code specifically includes the following steps: If the control type of the target control is input, fill in the name and id attributes of the input tag according to the name and ID of the target control to obtain the target form code; If the control type of the target control is select, fill the name and id attributes of the select tag according to the name and ID of the target control, and generate the corresponding option subtag according to the value of the control to obtain the target form code; If the control type of the target control is textarea, the name and id attributes of the textarea tag are filled according to the name and ID of the target control, and the value of the target control is set to the initial content of the textarea to obtain the target form code.
4. The form code generation method according to claim 1, characterized in that: After the step of performing code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code, the following steps are also included: Obtain the names and identification information of all target controls in the target form code; Check whether there is a subordinate and dependent relationship between the target controls, and obtain a dependency relationship graph between the target controls; According to the dependency graph, event listeners are bound to related controls to determine the controls and events that need to execute linkage logic.
5. The form code generation method according to claim 1, characterized in that: After the step of performing code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code, the following steps are also included: The target form code is adaptively typeset according to a responsive layout.
6. A form code generating device, characterized in that: include: A parameter acquisition module, used to receive interface parameter information sent by a user terminal, wherein the interface parameter information at least includes data type information; A module for obtaining a control to be selected, used for obtaining a module for calling a constructed control code library, and obtaining a set of controls to be selected that match the data type information in the constructed control code library; A target control acquisition module, used for selecting the control with the highest matching degree in the candidate control set according to the parameter characteristics of the interface parameter information, and obtaining the target control; The code generation module is used to perform code generation processing on the target control and the data type information corresponding to the target control according to the template engine to obtain the target form code.
7. The form code generating device according to claim 6, characterized in that: The device also includes: Code library creation module, used to create the initial control code library; A hash table creation module, used to create a hash table instance according to the control type of the control to be stored, and store the control type as a key in the hash table instance; The key-value pair acquisition module is used to store the control code snippet corresponding to the control type as a value in a hash table according to the key-value pair method, and obtain the key-value pair of the control type and the control code snippet.
8. The form code generating device according to claim 6, characterized in that: The control type of the target control is input, select and / or textarea, and the target control acquisition module includes: The first target control acquisition submodule is used to fill the name and id attributes of the input tag according to the name and ID of the target control to obtain the target form code if the control type of the target control is input; The second target control acquisition submodule is used to fill the name and id attributes of the select tag according to the name and ID of the target control if the control type of the target control is select, and generate the corresponding option subtag according to the value of the control to obtain the target form code; The third target control acquisition submodule is used to fill the name and id attributes of the textarea tag according to the name and ID of the target control if the control type of the target control is textarea, and set the value of the target control to the initial content of the textarea to obtain the target form code.
9. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the form code generation method according to any one of claims 1 to 5 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the form code generation method according to any one of claims 1 to 5 are implemented.
