Disclosure of Invention
In view of the above, it is necessary to provide a code generation method, apparatus, computer device and storage medium capable of improving efficiency.
In a first aspect, a method for generating a code is provided, the method including:
determining candidate functional components according to a component selection instruction input by a user on a current interface;
displaying a code template list corresponding to the candidate functional component according to the candidate functional component; wherein the code template list comprises a plurality of code filling templates;
generating an object code according to an object code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system.
In one embodiment, the generating object code according to an object code filling template selected by a user based on the list of code templates includes:
according to the target code filling template, acquiring a template code corresponding to the target code filling template from a template code library;
and generating the object code according to the template code.
In one embodiment, after the obtaining the template code corresponding to the target code filling template from the template code library, the method further includes:
and displaying the template code corresponding to the target code filling template.
In one embodiment, the method further comprises:
and according to the corresponding relation between the different target code filling template identifications and different template codes, establishing the template code base.
In one embodiment, the object code fill template includes a code parameter fill field; the generating of the object code according to the object code filling template selected by the user based on the code template list comprises:
acquiring a code parameter input by a user in the code parameter filling bar;
and generating the object code according to the object code filling template and the code parameter.
In one embodiment, the method further comprises:
and acquiring an object code editing instruction input by a user, wherein the object code editing instruction is used for updating the object code.
In one embodiment, after generating object code according to an object code fill template selected by a user based on the list of code templates, the method further comprises:
and displaying the effect graph of the candidate functional component corresponding to the target code.
In a second aspect, there is provided a code generation apparatus, the apparatus comprising:
the determining module is used for determining candidate functional components according to a component selection instruction input on the current interface by a user;
the first display module is used for displaying a code template list corresponding to the candidate functional component according to the candidate functional component; wherein the code template list comprises a plurality of code filling templates;
the generating module is used for generating target codes according to target code filling templates selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system.
In a third aspect, a computer device is provided, comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
determining candidate functional components according to a component selection instruction input by a user on a current interface;
displaying a code template list corresponding to the candidate functional component according to the candidate functional component; wherein the code template list comprises a plurality of code filling templates;
generating an object code according to an object code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system.
In a fourth aspect, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of:
determining candidate functional components according to a component selection instruction input by a user on a current interface;
displaying a code template list corresponding to the candidate functional component according to the candidate functional component; wherein the code template list comprises a plurality of code filling templates;
generating an object code according to an object code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system.
According to the code generation method, the code generation device, the computer equipment and the storage medium, firstly, candidate functional components are determined according to component selection instructions input by a user on a current interface; then, according to the candidate functional component, a code template list corresponding to the candidate functional component is displayed; wherein the code template list comprises a plurality of code filling templates; finally, generating a target code according to a target code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system. According to the code generation method, when a developer writes codes, the developer can obtain the target codes of the corresponding functions only by selecting the code filling templates of the corresponding functions, and repeated writing work is not needed. Therefore, the code generation method provided by the application can greatly improve the efficiency of developing software products.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The code generation method provided by the application can be applied to the application environment shown in fig. 1. Wherein the terminal 101 communicates with the server 102 via a network. The terminal 101 may send the acquired component selection instruction triggered by the user on the current interface to the server 102, then the server 102 determines a candidate functional component according to the component selection instruction, sends a code template list corresponding to the candidate functional component to the terminal 101, and displays the code template list to the user through the terminal 101. Then, the terminal 101 may send the target code filling template selected by the user based on the code template list to the server 102, and then the server 102 may query the template code library for the target code corresponding to the target code filling template and send the target code to the terminal 101, so that the terminal 101 may present the target code to the user.
It should be noted that the implementation environment related to the present application may only include the terminal 101, and in the case that the implementation environment only includes the terminal 101, the terminal 101 may store a template code library, and after acquiring the component selection instruction input on the current interface by the user, the terminal 101 may determine the candidate functional component according to the component selection instruction. The terminal 101 may then present a code template list corresponding to the candidate functional component to the user, where the code template list includes a plurality of code-filling templates. Next, the terminal 101 may query the corresponding object code from the template code library according to the object code filling template selected by the user based on the code template list, and finally, the terminal 101 may present the object code to the user.
The terminal 101 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices, and the server 102 may be implemented by an independent server or a server cluster formed by a plurality of servers.
In an embodiment of the present application, as shown in fig. 2, there is provided a code generation method, where an execution subject of the method may be a computer device, including the following steps:
step 201, according to the component selection instruction input by the user on the current interface, determining candidate functional components.
Wherein a component may be understood as an element or an object. In front-end programming, a component may be an element in an interface, e.g., a table, a button, a dialog box, or a clickable link in a front-end interface, etc., may all be referred to as a component. Typically, the basic functions performed by the various components will be different.
In this step, when developing the software application, a developer may preliminarily determine a required component according to an actually required function to be implemented, and use the required component as a candidate functional component. For example, a developer may need to insert a button in the front-end interface, and then may preliminarily determine that the desired function is a button function, and then may input a component selection instruction regarding the button on the current interface of the computer device.
Alternatively, referring to fig. 3, the manner of inputting the component selection instruction by the developer may be directly inputting the corresponding component name in the search box (as indicated by a in fig. 3), or selecting the corresponding component name in the candidate component list (as indicated by C in fig. 3) provided by the computer device, and finally, the developer may confirm the component selection instruction by clicking a confirmation button (as indicated by B in fig. 3).
Step 202, according to the candidate functional component, a code template list corresponding to the candidate functional component is displayed.
In this step, the code template list includes a plurality of code-filling templates. After the user initially selects the candidate functional component, the computer device presents the code template list corresponding to the candidate functional component for the user to further select. Specifically, after the user selects the button assembly, the computer device may present the user with a code template list with more detailed functions corresponding to the button assembly, which is referred to as D in fig. 4, for example, the code template list of the button assembly may include code templates with different functions, such as a save data button code template, a confirm button code template, a return button code template, or a delete button code template.
Optionally, the code template list may show identifiers of different code templates, or may also show keywords of the code templates, as long as the different code templates can be distinguished, which is not limited in this embodiment.
Step 203, generating a target code according to a target code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system.
In this step, after the user selects the corresponding object code filling template from the code template list, the computer device displays the object code corresponding to the object code filling template to the user. In the code template list, a plurality of code filling templates are included, which already include the backbone logical structure of the code. Optionally, an editable part can be reserved in the target code filling template for a user to further edit the code filling template according to actual requirements; default parameter values may also be set for the editable portion without requiring the user to edit again.
In the embodiment of the application, the user can directly utilize the generated target code, and can further edit the generated target code, so that the target code further meets the requirements in actual use.
In practical applications, the object code may be used to implement business functions of the power information system. For example, the object code may be used to generate various page components in a grid status analysis page, a power demand prediction page, a power electricity balance page, an investment estimation and economic evaluation page, a planning project atlas management page, a planning project library management page, a substation location aided design page, and a line selection aided design page in a power information system.
In the code generation method, firstly, candidate functional components are determined according to a component selection instruction input by a user on a current interface; then, according to the candidate functional component, a code template list corresponding to the candidate functional component is displayed; wherein the code template list comprises a plurality of code filling templates; finally, generating a target code according to a target code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system. According to the code generation method, when a developer writes codes, the developer can obtain the target codes of the corresponding functions only by selecting the code filling templates of the corresponding functions, and repeated writing work is not needed. Therefore, the code generation method provided by the application can greatly improve the efficiency of developing software products.
In an embodiment of the present application, please refer to fig. 5, further providing a code generating method, which relates to a specific process of generating an object code according to an object code filling template, where an execution subject of the method may be a computer device, and the method includes:
step 301, according to the object code filling template, obtaining a template code corresponding to the object code filling template from a template code library.
In this step, optionally, after the user selects a corresponding target code filling template from the code template list, the computer device may query a template code corresponding to the target code filling template from a pre-stored template code library.
The template code base stores template codes of different functions. Generally, the logic of corresponding code of the same functional component is substantially the same. For example, for a data saving button, the logical structure of the code is generally that data to be saved is checked first, then a background method is called to implement persistence on the data, then a result is fed back to a user operation, and finally a front-end page is refreshed or closed. Therefore, different template codes can be established according to different functions.
Regarding the establishment of the template code base, optionally, the template code base may be established according to the correspondence between different target code filling template identifications and different template codes. The template codes can be classified according to different code functions, and then the backbone logic structure is written for the template codes with different functions. Optionally, when writing the backbone logic structure of the template code, the variables in the template code may be set to be editable, and a vacancy may also be reserved in the template code, so that a user may fill the content according to actual needs. Then, different object codes are set for different template codes to fill in the template identification. And finally, storing the corresponding relation between the different target code filling template identifications and the different template codes into a template code library. Optionally, the user can add a new characteristic template to the template code library in a template self-defining manner, so that more and more templates are continuously expanded into the template code library, and the effect of software asset precipitation is achieved.
Step 302, generating the object code according to the template code.
In the embodiment of the application, the template code base with clear function classification is pre-made, so that when a user selects the target code in the code selection list to fill the template, the template code required by the user can be selected more accurately and clearly.
In this embodiment of the present application, after obtaining the template code corresponding to the target code filling template from the template code library, the method further includes: and displaying the template code corresponding to the target code filling template. Specifically, referring to fig. 4, the computer device may present the template code corresponding to the object code filling template in the area indicated by E in fig. 4.
In the embodiment of the application, the target code filling template comprises a code parameter filling column; referring to fig. 6, step 203 may include:
step 401, acquiring a code parameter input by a user in the code parameter filling bar;
in this step, optionally, a code parameter padding field (indicated as H in fig. 4) may be set in advance for the user to input the code parameter. The user can fill in the parameter fill-in bar with some specific parameters needed for writing the object code.
Step 402, generating the object code according to the object code filling template and the code parameter.
In this step, after the user has filled the corresponding parameters, the target code filling template with the parameters filled is used as the final target code.
Based on the above embodiment, optionally, the user may edit the generated object code. Specifically, the computer device may obtain an object code editing instruction input by a user, where the object code editing instruction is used to update the object code.
Please refer to the reserved blank lines denoted by F and G in fig. 4. Optionally, some blank lines may be reserved in the object code generated by the computer device, so that the user may further edit the generated object code. For example, the user can perform various forms of editing instructions such as whole line insertion or deletion, multiple line insertion or deletion, and blank filling on the reserved blank line of the target code.
In the embodiment of the application, the parameter filling column and the reserved blank line are preset for the user, so that the user can change specific parameters and code details in the target code filling template according to actual requirements, and further, the finally generated target code can better meet the requirements in actual use.
In the embodiment of the application, after the target code is generated according to the target code filling template selected by the user based on the code template list, the effect graph of the candidate functional component corresponding to the target code can be displayed.
In the embodiment of the application, when the target code is displayed, the component effect graph of the front-end page corresponding to the target code can be displayed together. Optionally, based on the above description in the embodiments, the user may fill in the parameters of the object code or edit the generated object code. The method and the device for displaying the component effect diagram of the front-end page can also display the component effect diagram of the front-end page corresponding to the current code in real time when the user fills the parameters of the target code or edits the generated target code.
In the embodiment of the application, the effect diagram of the candidate functional component is displayed in real time, so that the purposes of online arrangement, online operation, real-time presentation of complete front-end service effect and synchronization of development and operation are achieved.
It should be understood that, although the steps in the flowcharts of fig. 2 to 6 are shown in sequence as indicated by the arrows, the steps are not necessarily performed in sequence as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 2-6 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performing the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
In an embodiment of the present application, as shown in fig. 7, there is provided a code generation apparatus 700 including: a determining module 701, a first displaying module 702 and a generating module 703, wherein:
a determining module 701, configured to determine a candidate functional component according to a component selection instruction input by a user on a current interface;
a first display module 702, configured to display, according to the candidate functional component, a code template list corresponding to the candidate functional component; wherein the code template list comprises a plurality of code filling templates;
a generating module 703, configured to generate a target code according to a target code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system.
In this embodiment of the application, the generating module 703 is specifically configured to, according to the target code filling template, obtain a template code corresponding to the target code filling template from a template code library; and generating the object code according to the template code.
In this embodiment of the present application, please refer to fig. 8, another code generating apparatus 800 is provided, where the code generating apparatus 800 includes, in addition to the modules included in the code generating apparatus 700, optionally, the code generating apparatus 800 further includes: a second presentation module 704, a code template library establishing module 705, an obtaining module 706 and a third presentation module 707, wherein:
the second displaying module 704 is configured to display the template code corresponding to the object code filling template after obtaining the template code corresponding to the object code filling template from the template code library.
In this embodiment of the present application, the module library establishing module 705 is configured to establish the template code library according to the correspondence between different object code filling template identifiers and different template codes.
In the embodiment of the application, the target code filling template comprises a code parameter filling column; the generating module 703 is specifically configured to obtain a code parameter input by the user in the code parameter filled column; and generating the object code according to the object code filling template and the code parameter.
In this embodiment of the application, the obtaining module 706 is configured to obtain an object code editing instruction input by a user, where the object code editing instruction is used to update the object code.
In this embodiment of the application, the third presenting module 707 is configured to, after generating an object code according to an object code filling template selected by a user based on the code template list, present an effect diagram of a candidate functional component corresponding to the object code.
For specific limitations of the code generation apparatus, reference may be made to the above limitations of the code generation method, which are not described herein again. The modules in the code generation apparatus can be implemented in whole or in part by software, hardware, and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In the embodiment of the present application, a computer device is provided, where the computer device may be a terminal, and its internal structure diagram may be as shown in fig. 9. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a code generation method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 9 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In an embodiment of the present application, there is provided a computer device including a memory and a processor, the memory storing a computer program, and the processor implementing the following steps when executing the computer program:
determining candidate functional components according to a component selection instruction input by a user on a current interface;
displaying a code template list corresponding to the candidate functional component according to the candidate functional component; wherein the code template list comprises a plurality of code filling templates;
generating an object code according to an object code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system.
The implementation principle and technical effect of the computer device provided in this embodiment are similar to those of the method embodiments described above, and are not described herein again.
In the embodiment of the present application, the processor, when executing the computer program, further implements the following steps:
according to the target code filling template, acquiring a template code corresponding to the target code filling template from a template code library; and generating the object code according to the template code.
In this embodiment of the present application, after the template code corresponding to the target code filling template is obtained from the template code library, the processor executes the computer program to further implement the following steps:
and displaying the template code corresponding to the target code filling template.
In the embodiment of the present application, the processor, when executing the computer program, further implements the following steps:
and according to the corresponding relation between the different target code filling template identifications and different template codes, establishing the template code base.
In the embodiment of the application, the target code filling template comprises a code parameter filling column; the processor, when executing the computer program, further performs the steps of:
acquiring a code parameter input by a user in the code parameter filling bar; and generating the object code according to the object code filling template and the code parameter.
In the embodiment of the present application, the processor, when executing the computer program, further implements the following steps:
and acquiring an object code editing instruction input by a user, wherein the object code editing instruction is used for updating the object code.
In an embodiment of the application, after generating object code according to an object code filling template selected by a user based on the list of code templates, the processor executes the computer program to further implement the following steps:
and displaying the effect graph of the candidate functional component corresponding to the target code.
In an embodiment of the application, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, realizes the steps of:
determining candidate functional components according to a component selection instruction input by a user on a current interface;
displaying a code template list corresponding to the candidate functional component according to the candidate functional component; wherein the code template list comprises a plurality of code filling templates;
generating an object code according to an object code filling template selected by a user based on the code template list; the object code is used for realizing the business function of the electric power information system.
The implementation principle and technical effect of the computer-readable storage medium provided by this embodiment are similar to those of the above-described method embodiment, and are not described herein again.
In an embodiment of the application, the computer program when executed by the processor further performs the steps of:
according to the target code filling template, acquiring a template code corresponding to the target code filling template from a template code library; and generating the object code according to the template code.
In the embodiment of the present application, after the template code corresponding to the target code filling template is obtained from the template code library, the computer program further implements the following steps when executed by the processor:
and displaying the template code corresponding to the target code filling template.
In an embodiment of the application, the computer program when executed by the processor further performs the steps of:
and according to the corresponding relation between the different target code filling template identifications and different template codes, establishing the template code base.
In the embodiment of the application, the target code filling template comprises a code parameter filling column; the computer program when executed by the processor further realizes the steps of:
acquiring a code parameter input by a user in the code parameter filling bar; and generating the object code according to the object code filling template and the code parameter.
In an embodiment of the application, the computer program when executed by the processor further performs the steps of:
and acquiring an object code editing instruction input by a user, wherein the object code editing instruction is used for updating the object code.
In an embodiment of the application, after generating the object code according to the object code filling template selected by the user based on the list of code templates, the computer program when executed by the processor further implements the steps of:
and displaying the effect graph of the candidate functional component corresponding to the target code.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.