Page code generation method and device, electronic equipment and storage medium
By receiving and processing form information submitted by front-end devices, generating front-end project code that supports event interaction, and adjusting the code according to the UI diagram, solving the high cost and inefficiency problems caused by manual encoding, realizing automated generation and efficient development.
Patent Information
- Application Number
- CN202410925179.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-11-12
AI Technical Summary
During the page development process, manual coding leads to high labor costs, long time and low efficiency, affecting development efficiency.
By receiving form information on the characterization page development details submitted by the front-end device, project initialization is performed based on the front-end framework name, code storage path and project name, and front-end project code that supports event interaction functions is generated based on the code generation rules, prototype interaction diagrams and UI diagrams. And adjust the code according to the UI diagram to generate target front-end code that matches the UI diagram.
It realizes automated code generation, saves labor costs, improves page development efficiency, and allows front-end developers to modify the generated code to ensure development results.
Smart Images

Figure CN118939258A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a page code generation method, device, electronic device and storage medium. Background Art
[0002] Currently, when developing a page, the front-end technician obtains the requirement document (used to record the development time corresponding to the current requirement, the online time, various documents required for the current requirement, and a brief explanation of the current requirement, etc.) and the prototype document (used to record the specific interaction and implementation method of the current requirement), and then develops an adaptive, user-interactive front-end page based on the requirement document and the prototype document.
[0003] During the development process, various front-end frameworks and packaging tools are needed, and technical personnel use manual coding. This processing method consumes manpower, resulting in excessively high labor costs, and is time-consuming and inefficient, which in turn affects the efficiency of page development. Summary of the invention
[0004] In view of the above problems, embodiments of the present application provide a page code generation method, device, electronic device, and storage medium that overcome the above problems or at least partially solve the above problems.
[0005] In a first aspect, an embodiment of the present application provides a page code generation method, which is applied to a server, comprising:
[0006] Receive form information representing page development details submitted by a front-end device, wherein the form information includes a front-end framework name, a code storage path, a project name, a code generation rule, a prototype interaction diagram, and multiple user interface UI diagrams, wherein the prototype interaction diagram is used to indicate the interaction between UI pages corresponding to the multiple UI diagrams;
[0007] Initialize the front-end project according to the front-end framework name, the code storage path and the project name;
[0008] Generate a front-end project code that supports event interaction functions and can be compiled and built according to the code generation rules, the prototype interaction diagram, and the multiple UI diagrams;
[0009] The front-end project code is adjusted based on the multiple UI diagrams to generate target front-end codes matching the multiple UI diagrams, wherein the target front-end codes correspond to multiple UI pages to be developed.
[0010] In a second aspect, an embodiment of the present application provides a page code generation device, which is applied to a server, including:
[0011] A receiving module is used to receive form information representing page development details submitted by a front-end device, wherein the form information includes a front-end framework name, a code storage path, a project name, a code generation rule, a prototype interaction diagram, and multiple user interface UI diagrams, wherein the prototype interaction diagram is used to indicate the interaction between UI pages corresponding to the multiple UI diagrams;
[0012] A processing module, used for initializing the front-end project according to the front-end framework name, the code storage path and the project name;
[0013] A generation module, used to generate a front-end project code that supports event interaction functions and can be compiled and built according to the code generation rules, the prototype interaction diagram and the multiple UI diagrams;
[0014] An adjustment generation module is used to adjust the front-end project code based on the multiple UI diagrams to generate target front-end codes matching the multiple UI diagrams, wherein the target front-end codes correspond to multiple UI pages to be developed.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the page code generation method described in the first aspect above are implemented.
[0016] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the page code generation method described in the first aspect above are implemented.
[0017] The technical solution of the embodiment of the present application, after receiving the form information representing the page development details provided by the front-end device, initializes the front-end project based on the front-end framework name, code storage path and project name in the form information to generate a front-end project; after building the front-end project, based on the code generation rules, prototype interaction diagrams and multiple UI diagrams in the form information, generates a front-end project code that supports event interaction functions and can be compiled and built, adjusts the front-end project code according to the multiple UI diagrams, and generates a target front-end code that matches the corresponding UI page and UI diagram. Based on automated code generation, it can save labor costs and improve page development efficiency, and the generated target front-end code is a code that has not been compressed and built, allowing the code front-end developer to modify it to ensure the page development effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 A schematic diagram showing a page code generation method provided in an embodiment of the present application;
[0019] Figure 2 A schematic diagram showing a process of generating a target front-end code based on form information by a server provided in an embodiment of the present application;
[0020] Figure 3 A schematic diagram showing a process of cooperating between a front-end device and a server to generate a front-end page code according to an embodiment of the present application;
[0021] Figure 4 A schematic diagram showing a page code generating device provided in an embodiment of the present application;
[0022] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0023] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0024] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. The multiple in the embodiments of the present application can include two and more than two.
[0025] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the following processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0026] The present application embodiment provides a page code generation method, which is applied to a server, such as Figure 1 As shown, the method comprises the following steps:
[0027] Step 101, receiving form information representing page development details submitted by a front-end device, wherein the form information includes a front-end framework name, a code storage path, a project name, code generation rules, a prototype interaction diagram, and multiple user interface UI diagrams, and the prototype interaction diagram is used to indicate the interaction between UI pages corresponding to the multiple UI diagrams.
[0028] In an embodiment of the present application, a technician creates a front-end page to be displayed on a front-end device, such as using a react technology stack (a tool plug-in related to the react framework) to create a set of front-end pages. The created front-end page is a form, which needs to be filled in by the user. The user here is the form user, and can also be understood as the user who operates the front-end device and the user who needs to develop a page. After the user fills in the content for the form, the front-end device obtains the form information adapted to the user, and the form information is used to indicate the page development details corresponding to the page to be developed, and the page development details can be understood as the page development requirements. Among them, the form includes a note option, and the user can add note information to this option.
[0029] The server interacts with the front-end device and obtains the form information sent by the front-end device. The form information is provided by the user, including the front-end framework name, code storage path, project name, code generation rules, prototype interaction diagrams, and multiple UI (UserInterface) diagrams. Among them, the front-end framework name is used to indicate which front-end framework is used for project construction. The user can select a framework from multiple front-end frameworks supported by the form. The code storage path is used to indicate the storage location of the generated code. The project name is the name corresponding to the constructed project. Multiple UI diagrams are used to indicate multiple UI pages to be developed, and the prototype interaction diagram is used to indicate the interaction between multiple UI pages.
[0030] For the prototype interaction diagram, it corresponds to at least two UI pages, and is used to indicate the interaction between UI pages, such as indicating that one UI page jumps to another UI page based on the controls on the page. Through the interaction between UI pages indicated by the prototype interaction diagram, the codes corresponding to different pages can be associated during code generation, and then a UI page adapted to the interaction indicated by the prototype interaction diagram can be developed.
[0031] Step 102: Initialize the front-end project according to the front-end framework name, code storage path and project name.
[0032] After obtaining the form information, the server extracts the front-end framework name, code storage path and project name from the form information, and initializes the front-end project according to the extracted content to generate a front-end project for page development.
[0033] For example, based on the code storage path and project name, the react framework is used to generate a front-end project; or, based on the code storage path and project name, the vue framework is used to generate a front-end project.
[0034] Step 103: Generate a front-end project code that supports event interaction functions and can be compiled and built according to the code generation rules, the prototype interaction diagram, and the multiple UI diagrams.
[0035] After the front-end project is initialized on the server side, code generation rules, prototype interaction diagrams, and multiple UI diagrams are extracted from the form information, and code generation is performed based on the extracted information to generate front-end project code associated with the front-end project.
[0036] Since multiple UI diagrams are used to indicate multiple UI pages to be developed and prototype interaction diagrams are used to indicate the interaction between UI pages corresponding to the multiple UI diagrams, the front-end project code generated based on the code generation rules, prototype interaction diagrams and multiple UI diagrams supports event interaction functions, and the front-end project code generated in this embodiment is a semi-finished code that supports compilation and construction, so as to facilitate code modification.
[0037] Step 104: adjust the front-end project code based on the multiple UI diagrams to generate target front-end codes matching the multiple UI diagrams, where the target front-end codes correspond to the multiple UI pages to be developed.
[0038] After generating the front-end project code that supports event interaction functions and can be compiled and built, the front-end project code is adjusted based on multiple UI diagrams so that the multiple UI pages corresponding to the target front-end code generated after the adjustment match the multiple UI diagrams, thereby realizing the development of pages that meet user needs.
[0039] Among them, since the front-end project code is generated based on the prototype interaction diagram and multiple UI diagrams, when the front-end project code is adjusted based on multiple UI diagrams, the front-end project code is actually adjusted based on the page details of the UI diagram to obtain the target front-end code, so that the target front-end code is adapted to the UI diagram provided by the user, to ensure that the UI page adapted to the multiple UI diagrams can be presented based on the target front-end code.
[0040] The above implementation scheme of the present application, after receiving the form information representing the page development details provided by the front-end device, initializes the front-end project based on the front-end framework name, code storage path and project name in the form information to generate a front-end project; after building the front-end project, based on the code generation rules, prototype interaction diagrams and multiple UI diagrams in the form information, generates a front-end project code that supports event interaction functions and can be compiled and built, adjusts the front-end project code according to the multiple UI diagrams, and generates a target front-end code that matches the corresponding UI page and UI diagram. Based on automated code generation, it can save labor costs and improve page development efficiency, and the generated target front-end code is a code that has not been compressed and built, allowing the code front-end developer to modify it to ensure the page development effect.
[0041] The following is an introduction to the process of the server obtaining and verifying form information. When receiving form information representing page development details submitted by the front-end device, it includes: receiving the form information submitted by the front-end device after verifying the form information and the verification passes; wherein, the server performs a second verification on the form information after receiving the form information, and initializes the front-end project after the verification passes.
[0042] In this embodiment, the form developed by the technician is displayed in the form of a front-end page on the front-end device. After the user fills in the content of the form, the front-end device obtains the form information adapted to the user and verifies the form information. After the verification is passed, the form information is submitted to the server based on the interaction with the server. After the server obtains the form information submitted by the front-end device, it verifies the form information. If the secondary verification is successful, it is determined that the form information has passed the double-layer verification of the front-end device and the server. At this time, the server can initialize the front-end project based on the form information.
[0043] The front-end device verifies the form information. If the verification passes, the server verifies the form information again. The front-end project can be built and the code generated based on the verified form information, thereby ensuring the accuracy of the code generation.
[0044] The following is an introduction to the process of project initialization. When the front-end project is initialized according to the front-end framework name, code storage path and project name, it includes:
[0045] Determine the target framework according to the front-end framework name, and generate the target framework command corresponding to the target framework;
[0046] Generate a project folder corresponding to the target location based on the code storage path and project name. The target location is determined based on the code storage path.
[0047] Execute the target framework command to initialize the front-end project in the project folder.
[0048] Since front-end projects are generally generated using scaffolding, each framework has a different scaffolding and generates different commands. The server can determine the target framework based on the front-end framework name in the form information, and then determine the scaffolding corresponding to the framework. For example, the react framework is determined based on the front-end framework name in the form information, and then the create-react-app scaffolding is determined; or the vue framework is determined based on the front-end framework name in the form information, and then the corresponding scaffolding is determined.
[0049] When building a front-end project, the server also needs to extract the code storage path and project name from the form information, and generate a project folder corresponding to the project name at the target location corresponding to the code storage path. Among them, the server can generate a project folder by calling an AI (Artificial Intelligence) model, such as providing the following information to the AI model: Help me generate a folder in the "code storage path", the folder name is "project name", so as to use the AI model to generate a project folder at the target location. Among them, the AI model can be a Gemini model or a ChatGPT (Chat Generative Pre-trained Transformer) model, and the form supports one or more AI models, and the user specifies the model to be used in one or more AI models; in the case where the form supports one AI model, the AI model is specified by the technician, and the user can directly select the AI model.
[0050] After determining the scaffolding corresponding to the target framework and generating a project folder at the target location, generate a target framework command corresponding to the scaffolding, use the command to initialize the front-end project in the project folder, and generate the front-end project.
[0051] It should be noted that the code storage path is provided by the user, and the device corresponding to the code storage path is the device that needs to obtain the code, such as device A, which is different from the front-end device. By generating a project folder at the target location corresponding to the code storage path and generating a front-end project at this location based on the commands corresponding to the scaffolding, the generated code can be stored at this location, thereby ensuring that device A can obtain the code corresponding to the front-end project.
[0052] The above implementation scheme, when initializing the front-end project, determines the target framework based on the name of the front-end framework, and then determines the scaffolding used to generate the front-end project. Based on the code storage path and the project name, a project folder is generated at the target location. The command corresponding to the scaffolding is used to initialize the front-end project under the project folder, which can ensure that the front-end project is built in an appropriate location based on user needs.
[0053] After generating the front-end project, you need to generate the front-end project code for the front-end project. The following is an introduction to the code generation process. The code generation rules include multiple functional modules corresponding to the prototype interaction diagram and module introductions corresponding to the multiple functional modules. Each module corresponds to at least one interactive event. When generating the front-end project code that supports event interaction functions and can be compiled and built according to the code generation rules, the prototype interaction diagram, and multiple UI diagrams, it includes:
[0054] Generate the code to be tested that supports jumps between UI pages based on functional modules and can be compiled and built according to multiple functional modules, module introductions, prototype interaction diagrams and multiple UI diagrams;
[0055] Generate front-end project code based on the code to be tested;
[0056] The code to be detected is generated based on the target model and is located in the project folder corresponding to the initialization of the front-end project. The target model supports code generation, code recognition and processing, and the code generation rules include identification information corresponding to the target model.
[0057] In this embodiment, the code generation rules include multiple functional modules corresponding to the prototype interaction diagram and module introductions corresponding to the multiple functional modules. For the prototype interaction diagram, the user divides the prototype interaction diagram into multiple functional modules according to the function, each module is named according to the function, and the content corresponding to each module is an array. When filling in the form, the user fills in multiple functional modules and module introductions. The module introduction includes, for example, the following content: the interactive events contained in each functional module; the part of the module that displays pictures / videos is marked, and the corresponding code is displayed using blank placeholders.
[0058] When the server generates code based on the form information, it extracts content from the form information, obtains multiple functional modules, module introductions, prototype interaction diagrams, and multiple UI diagrams, and generates code to be tested based on the extracted content that supports jumping between UI pages based on functional modules and can be compiled and built. When the server generates the code to be tested, it calls the target model and generates code based on the target model. The target model is an AI model that supports code generation, code recognition, and processing, and the code generation rules include identification information corresponding to the target model, so that the target model can be called for code generation, and the above-mentioned AI model used to generate the project folder is also the target model.
[0059] As an example, the server calls the target model and provides the following information to the target model: Now you are an expert in HTML front-end development and are proficient in the react front-end framework. Please use the react front-end framework to create a set of front-end pages that are exactly the same as the prototype interaction diagram and multiple UI diagrams in the project folder named "Project Name" under "Code Storage Path". At the same time, combine the interaction copy annotations of the same parts of the prototype interaction diagram and multiple UI diagrams, and write the corresponding interaction events. The called target model generates code based on the above information.
[0060] Among them, the following issues need to be paid attention to during the code generation process:
[0061] 1. Write code based on multiple functional modules and module introductions. The component name is the corresponding component name in the form information (the name of the functional module). Correctly write the event type in each component. If there are pictures / videos, use divs with the same width and height to occupy the place.
[0062] 2. If there is content in the remarks, you should also pay attention to the remarks information submitted by the user during the encoding process.
[0063] 3. When encountering icons, use plug-ins (such as font-awesome plug-ins) to solve icon problems, automatically load font files, and render their corresponding fonts.
[0064] 4. Background color, font color, font size, font family, margins, padding, etc. should be consistent with the prototype interaction diagram and UI. Figure 1 To.
[0065] 5. Use text content that is consistent with the prototype interaction diagram and UI diagram.
[0066] 6. If you encounter a list, prototype interaction diagram, or UI diagram, write as many items as needed. Do not use comments to omit them.
[0067] 7. If you encounter a picture or video and no additional instructions are given, use a blank div with the same width and height as the picture and video to take up space.
[0068] After the server generates the code to be detected in the project folder using the target model, it generates the front-end project code based on the code to be detected. When the server generates the front-end project code based on the code to be detected, it includes:
[0069] Execute compile, build and package commands on the code to be tested to detect whether the code to be tested runs abnormally;
[0070] In response to the abnormal operation of the code to be detected, based on the error situation, the target model is used to modify the code to be detected, and the front-end project code is determined when the modified code can run normally;
[0071] In response to the code to be detected running normally, it is determined that the code to be detected is a front-end project code.
[0072] After the server generates the code to be tested by calling the target model, it executes the compilation, construction and packaging commands for the code to be tested to detect whether the code can run normally. If there is an error, the code to be tested is modified based on the error situation, and the test continues after the modification. If there is still an error, continue to modify until the code can run normally, and the code that can run normally is determined as the front-end project code.
[0073] When modifying the code to be checked based on the error situation, call the target model and use the code recognition and processing capabilities of the target model to repair the code. If the target model is a Gemini model, provide the Gemini model with the following information: Please repair the errors of the generated code in the project folder according to the error information prompted. The target model repairs the code to be checked based on the error situation. After the repair is completed, the server will check again whether the code can run normally. If the test result is that the code can run normally, it is determined that the current code is the front-end project code. If the test result is that the code runs abnormally, call the target model to continue to repair the code until the front-end project code that can run normally is obtained.
[0074] If the server executes the compile, build and package command for the first time and determines that the code to be tested can run normally, there is no need to call the target model for code repair, and the code to be tested can be directly determined as the front-end project code.
[0075] The above implementation scheme generates the code to be tested that supports jumping between pages and can be compiled and built based on the content extracted from the form information, and then tests the generated code. If the code runs abnormally, the target model is called to repair the code until the code can run normally. If the code runs normally, the current code is directly determined as the front-end project code to ensure that the code in the project folder can run normally.
[0076] In an optional embodiment of the present application, the process of generating the front-end project code further includes:
[0077] Detect whether the UI page to be developed is a mobile page based on code generation rules;
[0078] If the UI page to be developed is a mobile page, a target plug-in for making the front-end project code adaptive on the mobile terminal is inserted into the code to be detected.
[0079] In an embodiment of the present application, the code generation rule includes the page type of the UI page to be developed provided by the user, that is, when the user fills in the content in the form, fill in whether the page to be developed is a mobile terminal page or a PC (Personal Computer) page. Since there are many mobile terminal models and adaptation is required, additional processing is required for the mobile terminal page during code generation. That is, in the process of generating the front-end project code, a target plug-in for making the code adaptive on the mobile terminal is inserted into the code to be detected, such as inserting a flexible plug-in into the code to be detected. The flexible plug-in is used as a mobile terminal adaptation plug-in to ensure that the page corresponding to the code is displayed normally on the mobile terminal.
[0080] In the case where the UI page to be developed is a mobile page, inserting a mobile adaptation plug-in after generating the code to be detected can make the front-end project code determined based on the code to be detected adapt to the mobile terminal, thereby ensuring that the page corresponding to the front-end project code is displayed normally on the mobile terminal.
[0081] In an optional embodiment of the present application, the front-end project code includes JS code and Cascading Style Sheet CSS code. When the front-end project code is adjusted based on multiple UI diagrams to generate target front-end codes matching multiple UI diagrams, it includes:
[0082] Based on the target model, multiple UI pages corresponding to the front-end project code are compared with multiple UI diagrams to obtain comparison results; the target model is used to adjust the style of the CSS code based on the comparison results to generate a target front-end code that matches the multiple UI diagrams.
[0083] The front-end project code generated by the embodiment of the present application includes JS code and CSS (Cascading Style Sheets) code, among which CSS can perform pixel-level precise control on the layout of element positions in web pages, supports almost all font sizes and styles, and has the ability to edit web page objects and model styles.
[0084] After generating the front-end project code that can run normally, the CSS code is adjusted based on multiple UI images to adjust the page style of the front-end project code. Specifically, the server calls the target model to compare the multiple UI pages corresponding to the front-end project code with the multiple UI images provided by the user, obtains the comparison results, and the target model adjusts the CSS code for the differences based on the comparison results to adjust the page style of the front-end project code, and obtains the target front-end code that matches the multiple UI images, thereby ensuring that the UI page presented based on the target front-end code is almost completely consistent with the UI image provided by the user.
[0085] By using the target model to compare the UI page corresponding to the front-end project code with the UI diagram and adjusting the CSS code for the differences, it is possible to ensure that the target front-end code that fully adapts to user needs is generated based on the UI diagram, thereby ensuring that the UI page that fully adapts to the UI diagram is presented.
[0086] The following is an introduction to the process of generating target front-end code based on form information on the server side through a specific implementation process. Figure 2 As shown:
[0087] Step 201: The server extracts the front-end framework name, code storage path and project name from the form information and initializes the front-end project.
[0088] Step 202 , detecting whether the page to be developed is a mobile terminal page, if so, inserting a mobile terminal adaptation plug-in during the code generation process in step 203 .
[0089] Step 203: The server generates a code to be tested that supports jumps between UI pages and can be compiled and constructed based on the multiple functional modules, module introductions, prototype interaction diagrams, and multiple UI diagrams extracted from the form information.
[0090] Step 204 , execute compile, build and package commands on the code to be detected to detect whether the code to be detected runs abnormally. If it runs abnormally, execute step 205 ; otherwise, execute step 206 .
[0091] Step 205 : Based on the error situation, the target model is used to modify the code to be detected, and the front-end project code that can run normally is obtained, and then step 207 is executed.
[0092] Step 206 , determine that the code to be detected is a front-end project code, and then execute step 207 .
[0093] Step 207: Adjust the front-end project code based on the multiple UI diagrams to generate a target front-end code that matches the multiple UI diagrams.
[0094] In the above implementation process, the server uses the target model to automatically generate interactive front-end page codes that are compatible with the prototype interaction diagram and UI diagram based on the form information provided by the front-end device, thereby improving the efficiency of page development.
[0095] In an optional embodiment of the present application, after generating the target front-end code matching multiple UI images, the server sends a prompt message indicating successful code generation to the front-end device; wherein the front-end device displays an indicator indicating successful code generation based on the prompt message.
[0096] After generating the target front-end code, the server can directly send a prompt message to the front-end device, or send a prompt message to the front-end device based on the polling of the front-end device, and the prompt message is used to indicate that the front-end page code is successfully generated in the project folder. After the front-end device obtains the prompt message, it displays an indicator indicating that the code is successfully generated on the front-end page, such as displaying the words "Code is generated successfully", or displaying a check mark, so that the user determines that the front-end page code is successfully generated based on the indicator displayed on the front-end page.
[0097] The following is an introduction to the overall implementation process of the front-end device and the server to generate the front-end page code. Figure 3 As shown:
[0098] Step 301: The user fills in a form on the front-end page of the front-end device.
[0099] Step 302: The front-end device obtains the form information, verifies the form information, and submits the form information to the server after the verification is successful.
[0100] Step 303: The server verifies the form information. If the verification passes, step 304 is executed.
[0101] Step 304: The server extracts the front-end framework name, code storage path and project name from the form information and initializes the front-end project.
[0102] Step 305: The server selectively introduces a mobile-end adaptation plug-in according to whether the page to be developed is a mobile-end page, and inserts the mobile-end adaptation plug-in during the code generation process.
[0103] Step 306: The server extracts relevant information from the form information and generates a code to be tested that supports jumps between UI pages and can be compiled and constructed. For the mobile terminal page, a mobile terminal adaptation plug-in is inserted into the code to be tested.
[0104] Step 307 : If the code to be detected can run normally, the server determines that the code to be detected is a front-end project code, and then executes step 309 .
[0105] Step 308: If the code to be detected runs abnormally, the server modifies the code until the code can run normally, determines the front-end project code, and then executes step 309.
[0106] Step 309: The server adjusts the style of the front-end project code based on the multiple UI diagrams to generate a target front-end code.
[0107] Step 310: The server sends a prompt message indicating successful code generation to the front-end device.
[0108] Step 311: The front-end device displays an indication that the code is successfully generated based on the prompt information.
[0109] In the above implementation process, the user fills in the content in the form developed by the technician, and the front-end device submits the verified form information to the server. After the server successfully verifies the form information, it initializes the front-end project and generates code. When the code can run normally, it adjusts the style and generates the target front-end code corresponding to the required UI page that matches the UI diagram. The front-end page code that supports interactive functions can be automatically generated to improve page development efficiency.
[0110] The above is the overall implementation plan of the page code generation method provided in the embodiment of the present application. After receiving the form information representing the page development details provided by the front-end device, the server initializes the front-end project based on the front-end framework name, code storage path and project name in the form information to generate a front-end project; after building the front-end project, based on the code generation rules, prototype interaction diagrams and multiple UI diagrams in the form information, a front-end project code that supports event interaction functions and can be compiled and built is generated, the front-end project code is adjusted according to the multiple UI diagrams, and the corresponding UI page is generated. The target front-end code that is compatible with the UI diagram can be generated based on automated code generation, saving labor costs and improving page development efficiency, and the generated target front-end code is a code that has not been compressed and constructed, allowing the code front-end developer to modify it to ensure the page development effect.
[0111] Furthermore, by having the front-end device verify the form information, the server verifies the form information again if the verification passes, and can build the front-end project and generate code based on the verified form information, thereby ensuring the accuracy of code generation; for mobile pages, inserting the mobile adaptation plug-in after generating the code to be tested can ensure that the page corresponding to the front-end project code is displayed normally on the mobile terminal.
[0112] The present application embodiment provides a page code generation device, which is applied to a server, such as Figure 4 As shown, including:
[0113] The receiving module 401 is used to receive form information representing page development details submitted by the front-end device, wherein the form information includes the front-end framework name, code storage path, project name, code generation rules, prototype interaction diagram and multiple user interface UI diagrams, wherein the prototype interaction diagram is used to indicate the interaction between UI pages corresponding to the multiple UI diagrams;
[0114] Processing module 402, used to initialize the front-end project according to the front-end framework name, the code storage path and the project name;
[0115] A generation module 403 is used to generate a front-end project code that supports event interaction functions and can be compiled and constructed according to the code generation rules, the prototype interaction diagram and the multiple UI diagrams;
[0116] The adjustment generation module 404 is used to adjust the front-end project code based on the multiple UI diagrams to generate target front-end codes matching the multiple UI diagrams, wherein the target front-end codes correspond to multiple UI pages to be developed.
[0117] Optionally, the receiving module is further used for:
[0118] Receiving the form information submitted by the front-end device after verifying the form information and passing the verification;
[0119] Among them, the server performs a second verification on the form information after receiving the form information, and initializes the front-end project after the verification passes.
[0120] Optionally, the processing module includes:
[0121] A first generating submodule is used to determine a target framework according to the front-end framework name, and generate a target framework command corresponding to the target framework;
[0122] A second generation submodule is used to generate a project folder corresponding to a target location according to the code storage path and the project name, wherein the target location is determined based on the code storage path;
[0123] The processing submodule is used to execute the target framework command and initialize the front-end project in the project folder.
[0124] Optionally, the code generation rule includes a plurality of functional modules corresponding to the prototype interaction diagram and module introductions corresponding to the plurality of functional modules, and each module corresponds to at least one interaction event;
[0125] The generation module comprises:
[0126] A third generation submodule is used to generate a code to be tested that supports jumping between UI pages based on the function modules and can be compiled and constructed according to the multiple function modules, the module introductions, the prototype interaction diagram and the multiple UI diagrams;
[0127] A fourth generating submodule, used for generating the front-end project code based on the code to be detected;
[0128] The code to be detected is generated based on a target model and is located in a project folder corresponding to the initialization of a front-end project. The target model supports code generation, code recognition and processing, and the code generation rule includes identification information corresponding to the target model.
[0129] Optionally, the fourth generation submodule includes:
[0130] An execution detection unit is used to execute a compile, build and package command on the code to be detected to detect whether the code to be detected runs abnormally;
[0131] A modification determination unit, configured to modify the code to be detected using the target model in response to the abnormal operation of the code to be detected based on an error condition, and determine the front-end project code when the modified code can run normally;
[0132] The determination unit is used to determine that the code to be detected is the front-end project code in response to the code to be detected running normally.
[0133] Optionally, the device further comprises:
[0134] A detection module, used for detecting whether the UI page to be developed is a mobile terminal page based on the code generation rule during the process of the generation module generating the front-end project code;
[0135] The insertion module is used to insert a target plug-in for making the front-end project code adaptive on the mobile terminal into the code to be detected if the UI page to be developed is a mobile terminal page.
[0136] Optionally, the front-end project code includes JS code and Cascading Style Sheet CSS code, and the adjustment generation module includes:
[0137] A comparison and acquisition submodule, used for comparing the multiple UI pages corresponding to the front-end project code with the multiple UI images based on the target model to obtain a comparison result;
[0138] The adjustment generation submodule is used to use the target model to adjust the style of the CSS code based on the comparison result, and generate a target front-end code that matches the multiple UI images.
[0139] Optionally, the device further comprises:
[0140] A sending module, configured to send prompt information indicating successful code generation to the front-end device after the adjustment generation module generates a target front-end code matching the multiple UI images;
[0141] Wherein, the front-end device displays an indication mark indicating that the code is successfully generated based on the prompt information.
[0142] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0143] An embodiment of the present application also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, each process of the above-mentioned page code generation method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0144] For example, Figure 5 FIG. 1 shows a schematic diagram of the physical structure of an electronic device. Figure 5As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530, and the processor 510 is used to perform the following steps: receiving form information representing page development details submitted by the front-end device, the form information including the front-end framework name, the code storage path, the project name, the code generation rule, the prototype interaction diagram and multiple user interface UI diagrams, the prototype interaction diagram is used to indicate the interaction between the UI pages corresponding to the multiple UI diagrams; initializing the front-end project according to the front-end framework name, the code storage path and the project name; generating the front-end project code that supports the event interaction function and can be compiled and constructed according to the code generation rule, the prototype interaction diagram and the multiple UI diagrams; adjusting the front-end project code based on the multiple UI diagrams to generate the target front-end code matching the multiple UI diagrams, the target front-end code corresponding to the multiple UI pages to be developed. The processor 510 may also execute other schemes in the embodiments of the present application, which will not be further elaborated here.
[0145] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application.
[0146] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, each process of the above-mentioned page code generation method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0147] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0148] 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, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0149] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
[0150] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the present application can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0151] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0152] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0153] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0154] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0155] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard drives, ROM, RAM, magnetic disks, or optical disks.
[0156] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A page code generation method, applied to a server, characterized in that: include: Receive form information representing page development details submitted by a front-end device, wherein the form information includes a front-end framework name, a code storage path, a project name, a code generation rule, a prototype interaction diagram, and multiple user interface UI diagrams, wherein the prototype interaction diagram is used to indicate the interaction between UI pages corresponding to the multiple UI diagrams; Initialize the front-end project according to the front-end framework name, the code storage path and the project name; Generate a front-end project code that supports event interaction functions and can be compiled and built according to the code generation rules, the prototype interaction diagram, and the multiple UI diagrams; The front-end project code is adjusted based on the multiple UI diagrams to generate target front-end codes matching the multiple UI diagrams, wherein the target front-end codes correspond to multiple UI pages to be developed.
2. The method according to claim 1, characterized in that The receiving form information representing page development details submitted by the front-end device includes: Receiving the form information submitted by the front-end device after verifying the form information and passing the verification; Among them, the server performs a secondary check on the form information after receiving the form information, and initializes the front-end project after the check passes.
3. The method according to claim 1, characterized in that The initializing the front-end project according to the front-end framework name, the code storage path and the project name includes: Determine the target framework according to the front-end framework name, and generate a target framework command corresponding to the target framework; Generate a project folder corresponding to a target location according to the code storage path and the project name, wherein the target location is determined based on the code storage path; Execute the target framework command and initialize the front-end project in the project folder.
4. The method according to claim 1 or 3, characterized in that: The code generation rule includes a plurality of functional modules corresponding to the prototype interaction diagram and module introductions corresponding to the plurality of functional modules, and each module corresponds to at least one interaction event; The generating, according to the code generation rule, the prototype interaction diagram and the multiple UI diagrams, a front-end project code that supports the event interaction function and can be compiled and constructed includes: Generate, according to the multiple functional modules, the module introductions, the prototype interaction diagrams and the multiple UI diagrams, a code to be tested that supports jumping between UI pages based on the functional modules and can be compiled and constructed; Generate the front-end project code based on the code to be detected; The code to be detected is generated based on a target model and is located in a project folder corresponding to the initialization of a front-end project. The target model supports code generation, code recognition and processing, and the code generation rule includes identification information corresponding to the target model.
5. The method according to claim 4, characterized in that The generating the front-end project code based on the code to be detected includes: Execute compile, build and package commands on the code to be detected to detect whether the code to be detected runs abnormally; In response to the abnormal operation of the code to be detected, based on the error situation, the target model is used to modify the code to be detected, and the front-end project code is determined when the modified code can run normally; In response to the code to be detected running normally, it is determined that the code to be detected is the front-end project code.
6. The method according to claim 4, characterized in that The process of generating the front-end project code also includes: Detecting whether the UI page to be developed is a mobile terminal page based on the code generation rule; If the UI page to be developed is a mobile terminal page, a target plug-in for making the front-end project code adaptive on the mobile terminal is inserted into the code to be detected.
7. The method according to claim 4, characterized in that The front-end project code includes JS code and Cascading Style Sheet CSS code, and the front-end project code is adjusted based on the multiple UI images to generate target front-end code matching the multiple UI images, including: Compare the multiple UI pages corresponding to the front-end project code with the multiple UI images based on the target model to obtain a comparison result; The target model is used to adjust the style of the CSS code based on the comparison result to generate a target front-end code that matches the multiple UI images.
8. The method according to claim 1, characterized in that: After generating target front-end codes matching the multiple UI diagrams, the method further includes: Sending a prompt message indicating successful code generation to the front-end device; Wherein, the front-end device displays an indication mark indicating that the code is successfully generated based on the prompt information.
9. A page code generation device, applied to a server, characterized in that: include: A receiving module is used to receive form information representing page development details submitted by a front-end device, wherein the form information includes a front-end framework name, a code storage path, a project name, a code generation rule, a prototype interaction diagram, and multiple user interface UI diagrams, wherein the prototype interaction diagram is used to indicate the interaction between UI pages corresponding to the multiple UI diagrams; A processing module, used for initializing the front-end project according to the front-end framework name, the code storage path and the project name; A generation module, used to generate a front-end project code that supports event interaction functions and can be compiled and built according to the code generation rules, the prototype interaction diagram and the multiple UI diagrams; An adjustment generation module is used to adjust the front-end project code based on the multiple UI diagrams to generate target front-end codes matching the multiple UI diagrams, wherein the target front-end codes correspond to multiple UI pages to be developed.
10. An electronic device, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the page code generating method according to any one of claims 1 to 8 when executed by the processor.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the page code generation method according to any one of claims 1 to 8 are implemented.
Citation Information
Cited By
Visual code generation method and device for business travel service page
CN121050722A
