A front-end page code generation method, system and related device
By acquiring design images and project specifications, layout recognition, component mapping, color extraction, and spacing quantification are performed to generate and inspect front-end page code. This solves the problem of insufficient accuracy and consistency in front-end development and achieves code matching and self-verification with project styles.
Patent Information
- Application Number
- CN202611442030.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-16
- Publication Date
- 2026-11-20
AI Technical Summary
In front-end development, there are issues with accuracy and consistency when generating page code from design images. These include inconsistencies in visual estimation of color and distance, inconsistencies in control usage influenced by developers' memories and habits, mismatches between the output of automatic code generation tools and the project style system, and difficulties in code maintenance.
By acquiring design images and project code specifications, we perform layout recognition, component mapping, color extraction, and spacing quantification to generate template code, script code, and style code. We then use a set of checklists to perform code quality checks to ensure that the generated code conforms to project specifications.
It achieves accuracy and consistency in page code, reduces deviations caused by manual judgment, ensures that the generated code matches the project style system, provides a self-verification mechanism and distinguishes the scope of changes, and improves code maintenance efficiency.
Smart Images

Figure CN123137628A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, system and related equipment for generating front-end page code. Background Technology
[0002] In front-end development, the visual effect of a page is usually determined by designers first through images such as page screenshots and prototypes. Developers then write the page code based on these images. Developers need to determine the page's area divisions, the types of controls used, colors, and spacing between elements from the images, and complete the corresponding code within the existing front-end project.
[0003] The above process has the following drawbacks: First, visual quantities such as color and distance in images are usually estimated by the naked eye. Different developers may have different judgments about the same image, leading to discrepancies between the resulting pages and the images. Second, larger front-end projects often have their own collections of controls, color values, and size conventions. These conventions are mostly documented, and their adherence depends on the developers' memory and habits. It is common for the same visual element to be implemented as different controls or with different values on different pages. Third, existing code generation tools often use textual descriptions as input or only output generic code unrelated to the specific project. Their output lacks a correspondence with the project's existing control collections and style systems, requiring developers to rewrite a significant amount of the generated results. Fourth, page code typically consists of templates, scripts, and styles, all of which need to be consistent. When adding or modifying pages, all of these parts must be rewritten, and there is a lack of unified validation methods after modifications. Oversights in attribute settings, naming conventions, etc., are often only discovered during the integration or build phase. Fifth, it is difficult to distinguish between automatically generated code and manually written code when they are stored together, making it difficult to determine the scope of changes during subsequent maintenance.
[0004] Therefore, improving the accuracy and consistency of the process of obtaining front-end page code from design images is a problem that needs to be solved in this field. Summary of the Invention
[0005] In view of this, embodiments of this application provide a front-end page code generation method, system, and related equipment to at least partially solve the problems of insufficient accuracy and consistency in the process of obtaining front-end page code from design images.
[0006] In a first aspect, embodiments of this application provide a method for generating front-end page code, including: Obtain the design image corresponding to the page to be generated, as well as the preset project code specifications; the project code specifications include component specifications, color specifications, spacing specifications, and code organization specifications; The design image is subjected to layout recognition, component mapping, color extraction and spacing quantization to obtain the page structure information, component mapping information, color information and spacing information corresponding to the design image; The page structure information, component mapping information, color information, and spacing information are used as common inputs to generate template code, script code, and style code respectively according to the code organization specifications. The template code, script code, and style code are subjected to code quality checks according to the set of check items to obtain the check results; the set of check items includes check items corresponding to the component specifications, color specifications, spacing specifications, and code organization specifications, respectively. If the inspection results meet the preset qualification conditions, the front-end page code consisting of the template code, the script code, and the style code is output.
[0007] Secondly, embodiments of this application provide a front-end page code generation system, including an image acquisition module, an image parsing module, a code generation module, and a code checking module, each module being used to perform the corresponding steps in the method described in the first aspect above.
[0008] Thirdly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the front-end page code generation method described in the first aspect above.
[0009] Fourthly, embodiments of this application also provide an electronic device, including: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, the executable instruction causing the processor to execute any of the front-end page code generation methods described in the first aspect of embodiments of this application.
[0010] By adopting the above technical solution, this application can achieve the following beneficial technical effects: Firstly, this application does not directly map the design image as a whole visual object into code. Instead, it decomposes it along four dimensions: layout, components, color, and spacing. This allows the spatial structure, element composition, visual values, and size values of the page to be expressed separately, avoiding the bias caused by simply restoring the image based on a general judgment of its overall effect. Furthermore, the template code, script code, and style code are generated separately using the same set of structured information as common input. The three have the same value source, so they can correspond to each other in terms of components, fields, and style classes, reducing inconsistencies caused by writing them separately.
[0011] Secondly, this application introduces project code standards as constraints during the parsing phase: the extracted colors are not directly used as style values, but are first classified into standard color values in the color specification according to color matching rules; the measured pixel spacing is also not used directly, but is first classified into standard spacing values in the spacing specification according to spacing matching rules; the identified page design elements are mapped to standard components in the component specification, while also carrying the attributes of the component as defined in the specification. Therefore, fluctuations in image values caused by drawing precision, scaling ratio, or screenshot distortion are converged to the existing value set of the project before entering the code, ensuring consistent code representation of the same visual element across different pages.
[0012] Third, the set of inspection items used for checking in this application corresponds to the project code specifications used for generation. That is, the same set of specifications serves as both a constraint in the generation stage and a judgment basis in the inspection stage. Oversights in the generation process can be discovered by the same inspection process before output, thus forming a self-verifiable processing link between design image input and page code output, so that the standardization consistency of the output results no longer depends on manual review.
[0013] Fourth, by writing generation identifiers into the three parts of the code, it is possible to distinguish between automatically generated code and manually modified code in subsequent maintenance, providing a basis for determining the scope of changes and statistically analyzing generation quality. Attached Figure Description
[0014] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments are briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0015] Figure 1 A flowchart illustrating the front-end page code generation method provided in this application embodiment; Figure 2 A schematic diagram illustrating the architecture and data flow of the front-end page code generation process provided in this application embodiment; Figure 3 This is a schematic diagram illustrating the process of color extraction and spacing quantization being incorporated into project specifications in an embodiment of this application. Figure 4 This is a flowchart illustrating the code quality check and automatic correction process in an embodiment of this application. Figure 5 This is a schematic diagram of the structure of the front-end page code generation system provided in the embodiments of this application; Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0016] To enable those skilled in the art to better understand the technical solutions of this application, the technical solutions in the embodiments of this application are clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0017] Before describing the specific implementation of this application, several terms used in this application will be explained to facilitate understanding.
[0018] Design images refer to digital images that can demonstrate the visual effect of the page to be generated, including but not limited to prototypes and renderings output by designers, as well as screenshots taken from existing pages. There are no restrictions on the format and resolution of design images.
[0019] Page design elements refer to visual units within a design image that perform a specific interactive or display function, such as input boxes, dropdown lists, date pickers, buttons, tables, pagination bars, pop-ups, tabs, tooltips, labels, and dropdown menus. Page areas, on the other hand, refer to areas on the page comprised of several page design elements arranged in a certain positional relationship, serving the same type of function, such as a search area for entering query criteria or a button area for displaying action buttons.
[0020] Template code, script code, and style code refer to three parts of front-end page code that describe the page structure, page logic, and page style, respectively. Taking a front-end project organized as a single-file component as an example, these three typically correspond to the template section, script section, and style section within the same file, respectively.
[0021] A scope isolation flag is a declaration applied to a style block to limit its scope to the current page component. In some front-end build tools, it is given in the form of the `scoped` keyword. Setting this flag prevents style classes in the style block from affecting other page components, thus avoiding style overriding between pages. A code style checking tool is a tool that performs static analysis on source code to find syntax errors and style issues. In front-end projects, it is usually invoked using the `lint` command; this application uses its invocation results as a basis for checking.
[0022] Example 1 See Figure 1This application provides a method for generating front-end page code. This method can be executed by an electronic device with image processing and code generation capabilities, or it can be integrated as a plugin into an integrated development environment or command-line tool for front-end engineering. This application does not limit the executing entity or the operating environment of this method. For example, see [link to relevant documentation]. Figure 2 The execution of this method can be functionally divided into several stages: image parsing, specification constraints, code generation, and code inspection. Data is transferred between these stages via structured information. The method includes the following steps S101 to St, wherein: Step S101: Obtain the design image corresponding to the page to be generated, as well as the preset project code specifications; wherein, the project code specifications include component specifications, color specifications, spacing specifications, and code organization specifications.
[0023] In this step, the design image corresponding to the page to be generated is first obtained. To maintain the correspondence between the design image and its parsing and generation results, a page identifier can be created for the design image before parsing begins. The subsequently obtained page structure information, component mapping information, color information, spacing information, and generated code are all associated and stored with this page identifier, so that the same page can be traced when it is generated multiple times or maintained in the future.
[0024] The project code style guidelines refer to a set of conventions for coding practices in the current front-end project. Unlike development conventions that exist in document form, the project code style guidelines in this application are stored in a configuration format that can be read by the program, such as in configuration files, configuration tables, or style guidelines libraries, so that they can be directly referenced during code generation. The project code style guidelines include four parts: component guidelines, color guidelines, spacing guidelines, and code organization guidelines.
[0025] Component specifications define the standard components and their attributes that are allowed to be used in the current project. A component specification records the component identifier of a standard component, the element feature template corresponding to that standard component in the design image, and the agreed-upon attribute items and their value ranges that should be carried when the standard component is invoked. For example, in a component library that uses a unified prefix for component naming, the component identifier for the standard component corresponding to input elements is denoted as ai-input, and its conventional attributes include the size attribute (with a value of small) and the clearable attribute (indicating whether a clear button is displayed); dropdown selection elements correspond to ai-select, and their conventional attributes include the size attribute and a style attribute (with a value of searchItem) used to unify the width of search items; date range elements correspond to ai-date-picker, and their conventional attributes include the type attribute (with a value of daterange) and the value-format attribute; button elements correspond to ai-button, where the type attribute of the primary button is set to primary, and the secondary button carries a plain attribute indicating a simple style; table elements correspond to ai-table, and their conventional attributes include the border attribute indicating the display border and the v-loading attribute indicating the loading state; pagination elements correspond to ai-pagination, and their conventional attributes include the layout attribute indicating the pagination bar; tab elements correspond to a combination of ai-tabs and ai-tab-pane, and their conventional attributes include the bound value of the current tab and the tab click event. In addition, elements such as tree dropdowns, pop-ups, tooltips, labels, and dropdown menus also correspond to their respective standard components and agreed-upon attribute items. It should be noted that the component identifiers and attribute names mentioned above are merely examples for illustrative purposes and can be changed accordingly in projects using other component libraries; this application does not impose any limitations on them.
[0026] Color specifications define the standard color values for various color uses within the current project. A color's use refers to its semantic role on a page; for example, the theme color is used for button backgrounds, link text, and selected states; the tooltip background color is used for the background of tooltip areas; the emphasis text color is used for text that needs to be highlighted; the page background color is used for the main content area of the page; and the secondary text color is used for disabled states or supplementary explanatory text. In one optional example, the color specification records the standard color value as #3c86fe, the tooltip background color as #cbe9fb, the tooltip icon color as #0088fe, the emphasis text color as rgb(245,145,35), the page background color as #ffffff, the header text color as #000000, and the secondary text color as #909399.
[0027] Spacing specifications define the standard spacing values for various spacing scenarios within the current project. A spacing scenario refers to the position and function of a given distance on the page. For example, in one optional example, the spacing specifications are as follows: Record query row outer margin is 0.20px (0px top and bottom, 20px left and right); query form label width is 130px; query input box uses a uniform style class, width is 200px; date picker width is 300px; quick time button width is 80px; button area outer margin is 10px + 0.15px (10px top, 0px left and right, 15px bottom); table area outer margin is 0.20px (0px top and bottom, 20px left and right); pagination area top inner margin is 2px; vertical spacing between query rows is 10px; vertical spacing between page modules is 15px.
[0028] Code organization guidelines are used to define the organizational form used when generating code, including the order of page areas in the template section, the writing style of the script section and the data fields and methods that should be included, the style syntax and naming rules used in the style section, and the writing style of component names and style class names, etc.
[0029] The purpose of this embodiment is to determine the visual input and specification input of the page to be generated. The visual input determines what the page should look like, and the specification input determines how the page should be written. Together, they form the basis for subsequent processing, thus eliminating the need for developers to manually translate design images into text descriptions or code frameworks.
[0030] Step S102: Perform layout recognition, component mapping, color extraction, and spacing quantization on the design image to obtain page structure information, component mapping information, color information, and spacing information corresponding to the design image; wherein, the component mapping information includes the component identifier of the target component in the component specification corresponding to the page design element in the design image, and the component attributes agreed upon by the component specification for the target component; the color information includes the target color value obtained by matching the original color value extracted from the design image to the color specification according to a preset color matching rule; the spacing information includes the target spacing value obtained by matching the pixel spacing measured in the design image to the spacing specification according to a preset spacing matching rule.
[0031] This step analyzes the design image along four dimensions. These four dimensions are not isolated but rather describe the same design image from four perspectives: the page's spatial structure, element composition, visual value, and size value. The results of this analysis collectively constitute a structured description of the design image. These are explained in detail below.
[0032] First, perform layout recognition to obtain page structure information.
[0033] Layout recognition refers to the process of dividing page regions from a design image and determining the relationships between these regions. In one optional implementation, the boundaries of the regions in the design image are first identified to obtain the page regions contained within the design image. Region boundaries can be determined by performing grayscale conversion, edge detection, and connected component analysis on the design image, based on the projection distribution of pixels in the horizontal and vertical directions; alternatively, a pre-trained layout analysis model can be used to infer the design image, outputting the bounding rectangle of each page region. This application does not limit the specific method for identifying region boundaries.
[0034] Secondly, the region type of each page area is determined according to a preset set of region types. This set includes query areas, button areas, table areas, and pagination areas, and may also include at least one of the following: tooltip areas, breadcrumb areas, and tab areas. The region type can be determined based on the type and quantity of page design elements contained within it. For example: an area containing groups of input elements and text labels is considered a query area; an area with a grid of rows and columns and bold text in the first row is considered a table area; an area containing page number sequences is considered a pagination area; and an area at the top of the page with a background color different from the page background color and containing icons and explanatory text is considered a tooltip area.
[0035] Next, based on the positional relationship of each page area within the design image, the arrangement order and hierarchical relationship of each page area are determined, and the spacing relationship between adjacent page areas is obtained to acquire page structure information. For pages containing multiple query conditions, they can be further grouped into different query rows based on the vertical coordinates of each query element, allowing page structure information to be reflected at the row level. For example, if a design image contains, from top to bottom, a background-colored tooltip, three rows of query conditions, a row of operation buttons, a data table, and a pagination bar, the layout recognition result is: the page contains a tooltip area, a query area, a button area, a table area, and a statistics and pagination area arranged in sequence, with the query area containing three query rows. This result is used to determine the generation order of each area in the template code, ensuring that the generated page is structurally consistent with the design image.
[0036] Second, perform component mapping to obtain component mapping information.
[0037] Component mapping refers to the process of mapping page design elements identified in design images to standard components in component specifications, and further determining the attributes that the standard components should carry. Component mapping emphasizes a two-level correspondence from page design elements to standard components, and then to component attributes: it not only determines which component should be used, but also simultaneously determines the agreed attribute values for that component in this project.
[0038] In one optional implementation, page design elements in the design image are first identified, and element features of each page design element are extracted. These element features include shape features, size features, and internal composition features. Shape features include, for example, the shape of the element's border, the roundness of its corners, and whether it has a background color. Size features include, for example, the aspect ratio of the element and its relative size within its area. Internal composition features include, for example, whether the element contains placeholder text, drop-down arrow icons, calendar icons, or multiple tab blocks connected by separators. The extracted element features are then matched with feature templates of standard components in the component specification. The standard component with the highest matching degree is determined as the target component corresponding to the page design element. For example, a rectangular element with a downward arrow on the right is matched as a drop-down selection standard component; a rounded rectangle with a filled background and short text inside is matched as a main button; and similar elements with only a border and no filled background are matched as secondary buttons.
[0039] Finally, the agreed-upon attribute items of the target component are read from the component specification, and the attribute values of each agreed-upon attribute item are determined based on the element state presented in the design image, thus obtaining the component mapping information. Element state refers to the observable state of the element presented in the image, such as whether a button is grayed out, whether a table displays border lines, and whether a page count selector and a jump input box appear in a pagination bar. For example, when the pagination bar simultaneously displays "Previous Page," "Page Number," "Next Page," a page count selector, a jump input box, and "Total Count," the layout attribute of the pagination standard component is determined to include values for prev, pager, next, sizes, jumper, and total. Through the above processing, the same page design element is mapped to the same standard component and carries the same agreed-upon attributes in different pages and different batches of generation, thereby avoiding implementation differences caused by developers selecting components individually.
[0040] Third, color matching and spacing quantization are performed to obtain color information and spacing information respectively.
[0041] Color extraction refers to the process of obtaining representative colors from design images and assigning them to the standard color values defined in the color specification. Spacing quantization refers to the process of measuring distances across a page based on the pixels of the design image and assigning them to the standard spacing values defined in the spacing specification. The key to both is that the values obtained from the image are not directly written into the code, but are first assigned to the standard values. This is because design images often experience color value drift and size fluctuations during drawing, exporting, scaling, or screenshotting. If the extracted original color values and measured pixel spacing are used directly, different pages within the same project will display many similar but different colors and sizes, rendering the project's existing color system and size conventions ineffective. See also... Figure 3 In one optional implementation, the process includes the following steps S301 to S309.
[0042] Step S301: Perform pixel sampling on the design image and cluster the sampled pixel color values to obtain a candidate color value set. Clustering can be performed using K-means clustering or peak extraction based on color histograms, with the aim of converging the numerous pixel color values in the image into a limited number of representative candidate color values.
[0043] Step S302: Determine the color application of each candidate color value based on its location within the page area and the associated page design element in the design image. Since the page area division and page design element identification results have already been obtained, each candidate color value can be located on a specific area and element; for example, candidate color values distributed over a large area at the bottom of the prompt area are determined as the prompt background color, candidate color values located in the main button's filled area are determined as the theme color, and candidate color values located on grayed-out buttons or auxiliary explanatory text are determined as secondary text colors.
[0044] Step S303: Calculate the distance between the candidate color values and the standard color values in the color specification in the color space. To ensure that the calculation results are consistent with the human eye's perception of color differences, the candidate color values and standard color values can be first converted from the red-green-blue color space to a uniform color space, and then the Euclidean distance between them in this color space can be calculated as the color difference. In cases where high precision is not required, the Euclidean distance can also be calculated directly in the red-green-blue color space.
[0045] Step S304: The standard color value with the smallest distance and less than the preset color difference threshold is determined as the target color value corresponding to the color application. If the distance between the candidate color value and each standard color value is not less than the preset color difference threshold, the default color value configured for the color application in the color specification is determined as the target color value, and a color value deviation prompt message is generated. The preset color difference threshold is used to limit the range of inclusion. Its value can be set according to the minimum distance between adjacent standard color values in the engineering color system to avoid a candidate color value being incorrectly included in an adjacent standard color value. The color value deviation prompt message is used to inform the user that the color has not been included in the existing color system, so that the user can judge whether to modify the design or expand the color specification, thereby ensuring that the specification itself can be maintained in an orderly manner as the project evolves.
[0046] Step S305: Using the pixel coordinates of the design image as a reference, measure the pixel spacing between page elements and page areas, and determine the spacing scenario corresponding to each pixel spacing. The spacing scenario is determined by the elements or areas connected at both ends of the distance. For example, the distance between the left boundary of the query area and the left boundary of the page corresponds to the left and right margins of the query row, and the width of the label text area in the query form corresponds to the form label width scenario.
[0047] Step S306: Find the candidate standard spacing value corresponding to the spacing scenario in the spacing specification. One or more candidate standard spacing values can be configured under the same spacing scenario. For example, under the area spacing scenario, two values of 10px and 15px can be configured at the same time.
[0048] Step S307: Calculate the difference between the pixel spacing and each candidate standard spacing value.
[0049] Step S308: The candidate standard spacing value with the smallest difference that is less than a preset spacing threshold is determined as the target spacing value corresponding to the spacing scenario; if all differences are not less than the preset spacing threshold, the pixel spacing is retained as the target spacing value, and a spacing deviation prompt message is generated. The measured value is retained here instead of the default value because size deviations often correspond to special design arrangements, and directly covering them with the standard value may cause page structure distortion.
[0050] Step S309: Color information is composed of the purpose of each color and its target color value, and spacing information is composed of the scene of each spacing and its target spacing value. At this point, the colors and distances in the image no longer exist in the form of pixel values, but rather in a correspondence of "color purpose - target color value" and "spacing scene - target spacing value," which can be directly referenced by style code.
[0051] After the analysis across the four dimensions described above, the design images are transformed into four types of structured information: page structure information, component mapping information, color information, and spacing information. These four types of information together constitute a complete description of the page to be generated: page structure information answers which areas the page comprises and in what order; component mapping information answers which components are implemented in each area and with what attributes; and color and spacing information answer what values these components should use. Furthermore, since color and spacing information have already been incorporated into the project's existing value set before generation, and component mapping information already carries the project's existing component attributes, these four types of information are themselves intermediate representations constrained by project code standards.
[0052] Step S103: Using the page structure information, component mapping information, color information, and spacing information as common inputs, generate template code, script code, and style code respectively according to the code organization specifications.
[0053] This step splits the front-end page code into three parts: template code, script code, and style code, which are generated separately. It should be noted that although the three parts describe the page structure, page logic, and page style respectively, they all use the same set of structured information obtained in step S102 as input. Therefore, the three parts naturally correspond in terms of component composition, data fields, and style class names, and no alignment processing is required after generation.
[0054] Regarding template code generation, template code snippets are generated sequentially according to the arrangement order of page areas in the page structure information. Each template code snippet contains the component identifier and component attributes corresponding to that page area from the component mapping information. Taking a typical list query page as an example, the template code is organized in the order of the prompt area, query area, button area, table area, and statistics and pagination area. The prompt area uses a container node carrying a prompt style class, and its generation is determined by whether the area exists in the page structure information. It is also configured with display conditions controlled by the explicit / implicit fields in the script code. The query area generates form nodes row by row according to the query rows. The label width of each form node is taken from the form label width in the spacing information. Each query item generates a corresponding input, dropdown, or date component according to the component mapping information. The button area generates button components according to the division of primary and secondary buttons in the component mapping information. The table area generates table components and carries border and loading status attributes as agreed. The statistics and pagination area organizes statistical text and pagination components in a left-right distribution.
[0055] Regarding script code generation, the script code is generated according to the script structure agreed upon in the code organization specification. This script structure includes data fields corresponding to each page area and methods corresponding to event properties in the component properties. In an optional implementation, the script code adopts a method of organizing components using option objects (i.e., the Options API method). This method declares the component's data, methods, lifecycle hooks, etc., as properties of separate objects. Its structure is relatively fixed, facilitating generation by the program according to a template and ensuring consistency within the same project. Correspondingly, the code organization specification can stipulate that a combined approach that concentrates logic in a single initialization function should not be used. In the data section, data fields are set according to the page area composition. For example, a field representing the display status of the tooltip area (denoted as tsScreening) is set for the tooltip area; a field representing the expanded status of more filters and an object field representing the query conditions (denoted as moreScreening and queryInfo, respectively) are set for the query area; fields representing the loading status, table data, and selected items (denoted as listLoading, tableData, and selection, respectively) are set for the table area; and a field representing the total number of data entries (denoted as total) is set for the pagination area. In the method section, methods are set according to the event attributes in the component properties. For example, query and reset methods correspond to the click events of the query and reset buttons; handling methods correspond to the page count change event and current page change event of the pagination component; and handling methods correspond to the selection change event of the table component. Since the data fields and methods are derived from the page areas and component properties, every field and method referenced in the template code is defined in the script code, and there are no dangling references between the template and the script.
[0056] Regarding style code generation, style code is generated according to the style syntax and naming rules agreed upon in the code organization specification. The target color value from the color information and the target spacing value from the spacing information are written into the style code, and a scope isolation identifier is set for the style code. In an optional implementation, the style code is written using Cascading Style Sheets Extended Syntax (i.e., SCSS syntax), which supports nesting and variables, and is nested according to the area hierarchy in the page structure information, so that the structure of the style code corresponds to the structure of the template code. Style class names are named in all lowercase with hyphens separating words (i.e., kebab-case naming convention), or in the format of "block-element-modifier". In terms of values, the background color of the root container is taken from the page background color in the color information, the left and right margins of the query area are taken from the target spacing values of the left and right margins of the query row in the spacing information, the background color of the tooltip area is taken from the tooltip background color in the color information, and the pagination area is laid out in a right-aligned manner and uses the target spacing value of the inner margin above the pagination area.
[0057] Furthermore, after generating the template code, script code, and style code respectively, generation identifiers are written into each of the three code parts according to the comment syntax of the corresponding code type. These generation identifiers include a start identifier and an end identifier. A generation identifier is a pair of comments written into the code to indicate that the code it encloses was automatically generated by this method. Since the comment syntax used for the template segment, script segment, and style segment are different, they need to be written according to code type: the template code uses the markup language's comment syntax, the script code uses the script language's line comment syntax, and the style code uses the stylesheet's comment syntax. In one example, the start identifier is AI-GENERATED-BEGIN, and the end identifier is AI-GENERATED-END. The generation identifier can also further include the page identifier, generation time, and the version number of the project code specification it is based on for subsequent traceability.
[0058] Step S104: Perform code quality checks on the template code, the script code, and the style code according to the set of checks, and obtain the check results.
[0059] The set of check items in this step corresponds to the project code specification obtained in step S101. That is, each check item in the check item set uses a specific specification item from the project code specification as the basis for judgment. This correspondence means that the same set of specifications is used twice in this application: as constraints during generation in step S103, and as the basis for judgment before output in this step. Because the basis used twice is from the same source, deviations caused by incomplete parsing results, missing attributes, or missing template splicing during the generation process can be identified by the check step before output using the same standard, without relying on manual review by developers.
[0060] In one optional implementation, component prefix checks, button size checks, table border checks, and pagination layout checks are set in accordance with the component specification. These checks are used to verify whether all components used in the template code are standard components in the component specification, whether the size attributes of button components conform to the convention, whether table components carry the agreed border attributes, and whether the layout attributes of pagination components conform to the convention. The pass criterion for the component prefix check is that there are no third-party components other than standard components or interactive controls implemented with native tags in the template code.
[0061] Corresponding to the color specifications and spacing specifications, set up color value compliance checks and form attribute checks. The former is used to check whether the color values written in the style code are all standard color values in the color specifications, and the latter is used to check whether the label width of form components and the style class of query items conform to the values agreed in the spacing specifications.
[0062] Corresponding to the code organization standards, style isolation checks, template redundancy checks, component naming checks, style naming checks, and code style tool checks are set up. These checks are used to verify whether the style code has scope isolation markers, whether there are redundant wrapper nodes in the template code that do not perform rendering, whether the component names and style class names declared in the script code conform to the agreed writing style (e.g., component names use PascalCase writing style with the first letter of each word capitalized and no separators), and to call the project's existing code style checking tool to perform static checks on the generated code. The pass standard is that the tool does not output error level reports. In addition, a generation identifier check is set up to check whether paired start and end identifiers are written in all three parts of the code.
[0063] The results of each check item can be given in the form of "pass" or "fail". For check items that fail, the corresponding code type and code location information are further recorded. The code location information is, for example, line number, node path or style selector path.
[0064] Step S105: If the inspection result meets the preset qualification conditions, output the front-end page code composed of the template code, the script code and the style code.
[0065] In one optional implementation, when all check items in the check item set pass the check, the check result is determined to meet the preset qualification conditions. The template code, script code, and style code are then combined into the front-end page code corresponding to the page to be generated and output. The output can be either writing the front-end page code into a page file in a specified directory of the front-end project or returning the front-end page code to the caller. This application does not limit the output format. If there are check items that fail the check, the failed check items and their corresponding code location information are output so that the user can process them accordingly. In another optional implementation, the preset qualification conditions can also be set as follows: all check items at the mandatory level pass, while check items at the prompt level are allowed to fail. In this case, the failed items at the prompt level are output at the same time as the front-end page code, thus leaving room for adjustment in the strictness of the specification constraints. After outputting the front-end page code, the generated code and manually modified code in the front-end page code can be distinguished according to the aforementioned generation identifier, providing a basis for determining the scope of changes and the statistics of generation quality in subsequent maintenance.
[0066] For ease of understanding, a complete processing example is provided here in this application embodiment. For instance, a design image corresponds to a list query page, which, from top to bottom, consists of a light blue prompt bar, three rows of query conditions, a row of operation buttons consisting of fill and stroke buttons, a data table with grid lines, and a row of statistical text and a pagination bar at the bottom. The processing flow is as follows: Step S101 is executed to obtain the design image and establish a page identifier for it, while simultaneously reading the project code specifications; Step S102 is executed to identify the layout, obtaining the prompt area, query area (containing three query rows), button area, table area, and statistical and pagination areas and their arrangement order; component mapping maps each query item to standard components of input type, dropdown selection type, date range type, and tree dropdown type, respectively, carrying their respective agreed attributes; the fill button is mapped to the main button, the stroke button to the secondary button, and the data table and pagination bar are mapped to... For standard table and pagination components, color extraction assigns the tooltip background color to the standard color value of the tooltip background color and the fill button background color to the standard color value of the theme color. Spacing quantification measures the measured left and right outer margins of the query area to 19 pixels, which is less than the candidate standard spacing value of 20 pixels for this scenario. Therefore, 20 pixels is taken as the target spacing value. Steps S103 to S105 are executed to generate three parts of code according to the above structured information and code organization specifications and write the generation identifier. After all checks pass, the corresponding front-end page code is output. The final page corresponds to the design image in terms of area composition, component types, color values, and size values, and all values fall within the existing specification set of the project.
[0067] Example 2 Based on Embodiment 1, this embodiment provides several optional implementation methods. All of the following optional implementation methods are based on the method described in Embodiment 1, and can be implemented individually or in combination without conflict, without changing the main flow of the method described in Embodiment 1.
[0068] Furthermore, in an optional embodiment of this application, after obtaining the inspection result, the method further includes: if the inspection result does not meet the preset qualification condition, determining the failed inspection items and their corresponding code types; locating the code segment related to the inspection item in the code corresponding to the code type based on the failed inspection item; correcting the located code segment according to the specification item corresponding to the failed inspection item in the project code specification, and accumulating the number of corrections; if the number of corrections does not reach the preset upper limit, returning to execute the code quality check until the inspection result meets the preset qualification condition or the number of corrections reaches the preset upper limit.
[0069] SeeFigure 4 This optional implementation includes the following steps S401 to S406. Step S401: Perform code quality checks according to the set of check items to obtain the check results for each item; if the check results meet the preset passing conditions, proceed to step S405 and output the front-end page code; otherwise, proceed to step S402. Step S402: Determine the failed check items and their corresponding code types; each check item is associated with one or more of template code, script code, or style code during setup. For example, the style isolation check item is associated with style code, the button size check item is associated with template code, and the component naming check item is associated with script code.
[0070] Step S403: Based on the failed check items, locate the code segment related to that check item in the corresponding code. Location can be based on the code location information recorded during the check phase, or it can be obtained by searching the node path after parsing the code segment. The parsing refers to the process of converting the code text into an abstract syntax tree. An abstract syntax tree is an intermediate form that represents the syntax of code in a tree structure. Each node corresponds to a syntactic unit in the code. Searching and modifying by node can avoid the problem of accidentally modifying text with the same name when modifying code by text replacement.
[0071] Step S404: Correct the located code segment according to the corresponding specification item of the check item, and accumulate the number of corrections. The correction actions are pre-configured one-to-one with the check items. For example: when the style isolation check item fails, add a scope isolation identifier to the style segment; when the button size check item fails, rewrite the size attribute of the button node to the value agreed in the component specification; when the color value compliance check item fails, rewrite the color value at this location to the nearest standard color value in the color specification; when the generation identifier check item fails, add a pair of generation identifiers to the missing code segment; when the template redundancy check item fails, delete the redundant wrapping node and move its child nodes up. For check items whose correction results cannot be uniquely determined according to the specification, such as some semantic issues reported by the code style tool check items, they can be marked as non-automatically correctable items and directly included in the output information without entering the correction process.
[0072] Step S405: When the inspection result meets the preset qualification conditions, output the front-end page code. Step S406: When the number of corrections reaches the preset limit and the inspection result still does not meet the preset qualification conditions, stop the correction and output the information of the failed inspection items; the purpose of setting the preset limit is to avoid the process from going back and forth between "correction-inspection-correction" without stopping when there are mutual constraints between the correction actions of several inspection items.
[0073] This optional implementation extends the "generate-check-output" processing link in Embodiment 1 into a closed link of "generate-check-correct-recheck-output". Deviations in the generation stage are corrected in the same processing process, further reducing the workload of manually checking for standardization issues.
[0074] Furthermore, in an optional embodiment of this application: after outputting the front-end page code, the method further includes: when the page to be generated needs to be embedded as tab content in the parent page, parsing the template code of the parent page, determining the tab component used to carry the tab in the parent page and its existing tab list; adding a tab page board node in the tab component, configuring a page name and a tab identifier for the tab page board node, and introducing the page component corresponding to the page to be generated into the tab page board node; introducing the page component into the script code of the parent page, and completing the registration according to the component registration method agreed in the code organization specification; adding a branch corresponding to the tab identifier in the tab switching processing logic of the parent page.
[0075] The parent page refers to a page that already exists in the project and is used to host multiple child pages in the form of tabs. Parsing the parent page can be achieved by converting its template code into an abstract syntax tree and then retrieving nodes of standard tab components. The names and identifiers of existing tabs are obtained from the attributes of each tab panel node under that node. Before configuring the identifier for a new tab, the identifier to be used is compared with the identifiers in the existing tab list. If the same identifier already exists, a suffix is appended according to preset rules to ensure the uniqueness of tab identifiers within the same parent page. After adding a corresponding branch to the tab switching processing logic, when a tab is switched to the new tab, the parent page can execute the corresponding processing for that tab, such as triggering data loading for the child page.
[0076] It should be noted that, since Implementation Example 1 already sets a scope isolation flag when generating the style code, the styles of newly added page components will not affect the parent page or pages under other tabs, and there is no need to handle style conflicts separately during the integration process. Furthermore, the above-mentioned changes to the parent page can be made by saving an original copy of the parent page before the changes are made. If the integrated parent page fails the code quality check, the changes can be rolled back based on this copy to avoid damaging existing pages.
[0077] Furthermore, in another optional implementation of this application, determining the standard component with the highest matching degree as the target component corresponding to the page design element includes: if the matching degree of the standard component with the highest matching degree is not less than a preset confidence threshold, determining the standard component as the target component; if the matching degree of the standard component with the highest matching degree is less than the preset confidence threshold, outputting a preset number of candidate standard components in descending order of matching degree, and determining the standard component corresponding to the received selection result as the target component; and writing the correspondence between the element features of the page design element and the selection result into the feature template of the corresponding standard component in the component specification.
[0078] This optional implementation addresses situations where page design elements with similar appearances are difficult to distinguish uniquely. For example, a secondary button with only a border and an input box without focus are visually similar, and a radio button with a dropdown arrow and a tree-shaped dropdown are also difficult to distinguish when collapsed. Forcibly selecting the component with the highest matching degree in such cases may result in incorrect component mapping, which will then manifest in the subsequently generated template code, script code, and style code. By introducing a confidence threshold, elements that are difficult to determine are instead selected by the user from candidate components, preventing errors from spreading across these three parts of the code. Simultaneously, this selection result is fed back to the feature template in the component specification, enabling subsequent identification of similar elements to directly match the target, thus allowing the component specification to be gradually improved during use.
[0079] Furthermore, in an optional embodiment of this application, the project code specification carries a specification version number, and the generation identifier contains the specification version number on which the code was generated; the method further includes: when the project code specification is updated from a first specification version to a second specification version, retrieving generated code in the project whose specification version number is the first specification version based on the generation identifier; performing code quality checks on the retrieved generated code according to the check item set corresponding to the second specification version; for generated code whose check results do not meet the preset qualification conditions, regenerating the code within the generation identifier interval where the generated code is located according to the second specification version, and retaining the code outside the generation identifier interval.
[0080] This optional implementation utilizes the location capability of the generation identifier. The components, colors, or spacing conventions of a project often change during its evolution. After these changes, the page code that has already been generated and stored deviates from the new conventions. Because the generation identifier defines the scope of the automatically generated code with paired comments and records the version of the specification it is based on, the code that needs to be reviewed can be retrieved in batches, and the scope of regeneration can be limited to within the generation identifier range, thus preserving manual modifications outside this range.
[0081] Furthermore, in an optional embodiment of this application, the project code specification further includes a set of prohibited rules, which is used to indicate the writing styles that are prohibited from appearing in the generated code; the method further includes: excluding the writing styles indicated by the set of prohibited rules during the process of generating template code, script code and style code respectively; and setting check items in the check item set corresponding to each prohibited rule in the set of prohibited rules.
[0082] In one example, the prohibited rules set includes: prohibiting the use of combinatorics in script code that concentrates logic in a single initialization function; prohibiting the direct use of third-party components outside the component specification or the implementation of interactive controls using native tags in template code; prohibiting the definition of values that conflict with standard color values and standard spacing values in style code, bypassing the existing style system of the project; prohibiting the wrapping of template nodes that do not perform rendering functions outside of tag page panel nodes; prohibiting the output of code lacking a build identifier or without setting a scope isolation identifier; prohibiting the overwriting of files with the same name that already exist in the project without confirmation; prohibiting the use of fonts outside the project font list; and prohibiting the introduction of third-party dependencies outside the project dependency list. The prohibited rules set and the check item set work together to form constraints at two levels: the build stage avoids non-compliant code based on the prohibited rules, and the check stage confirms the final result, thereby reducing the possibility of non-compliant code entering the project.
[0083] Example 3 See Figure 5 This application also provides a front-end page code generation system 50 for executing the front-end page code generation method described in Embodiment 1 above. The system includes: Image acquisition module 501 is used to acquire the design image corresponding to the page to be generated, as well as the preset project code specifications; the project code specifications include component specifications, color specifications, spacing specifications and code organization specifications; Image parsing module 502 is used to perform layout recognition, component mapping, color extraction, and spacing quantization on the design image to obtain page structure information, component mapping information, color information, and spacing information corresponding to the design image. The component mapping information includes the component identifier of the target component in the component specification corresponding to the page design element, and the component attributes defined by the component specification. The color information and spacing information are respectively the extracted original color value and the measured pixel spacing, matched to the color specification and spacing specification according to a preset matching rule to obtain the target color value and target spacing value. The code generation module 503 is used to take the page structure information, the component mapping information, the color information and the spacing information as common inputs, and generate template code, script code and style code respectively according to the code organization specifications; The code inspection module 504 is used to perform code quality checks on the template code, the script code, and the style code according to the set of inspection items, obtain inspection results, and output the front-end page code composed of the template code, the script code, and the style code if the inspection results meet the preset qualification conditions; the set of inspection items includes inspection items corresponding to the component specifications, the color specifications, the spacing specifications, and the code organization specifications, respectively.
[0084] In one optional embodiment, the code generation module 503 is further configured to write generation identifiers into the template code, the script code, and the style code respectively; the code inspection module 504 is further configured to, if the inspection result does not meet the preset qualification conditions, locate the code segment related to the failed inspection item and correct it according to the corresponding specification item, and re-execute the code quality inspection after correction. In another optional embodiment, the system may further include a page integration module ( Figure 5 (not shown in the image), used to perform the processing described in the optional implementation method two above when the page to be generated needs to be embedded as tab content in the parent page.
[0085] The modules described above can be deployed in the same electronic device or in different electronic devices and work together via a network. Each module can be implemented in software or in hardware with corresponding processing logic. For details of the processing performed by each module in the above system embodiments, please refer to the corresponding descriptions in the foregoing method embodiments; they will not be repeated here.
[0086] Example 4 See Figure 6 This application also provides an electronic device 60, including a processor 601, a memory 602 and a communication interface 603, which are connected by a bus 604.
[0087] The memory 602 stores a computer program that can be executed by the processor 601. When the processor 601 executes the computer program, it implements the front-end page code generation method described in Embodiment 1 above.
[0088] The communication interface 603 is used for data interaction between the electronic device and external devices, such as receiving design images, reading project code specifications, or outputting front-end page code to the code repository where the front-end project is located.
[0089] Furthermore, embodiments of this application also provide a computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the front-end page code generation method described in Embodiment 1 above. The computer-readable storage medium includes, but is not limited to, read-only memory, random access memory, magnetic disks, or optical disks, and other media capable of storing program code. Embodiments of this application also provide a computer program product comprising a computer program that, when executed by a processor, implements the front-end page code generation method described in Embodiment 1 above.
[0090] It should be noted that the specific content of the component specifications, color specifications, spacing specifications, code organization specifications, and checklist sets described in this application can all be configured according to the front-end technology stack and development conventions adopted by different projects; the component identifiers, attribute names, color values, spacing values, data field names, and method names appearing in the specification are merely examples for illustrative purposes and do not constitute a limitation of this application. Some steps in the above embodiments can be adjusted in execution order or combined without affecting the technical effect. For example, after layout recognition, component mapping, color extraction, and spacing quantization are completed, the other three can be executed in parallel.
[0091] This application has now described specific embodiments of the subject matter. In some cases, the actions described in the claims can be performed in a different order and still achieve the desired result; furthermore, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing can be advantageous.
[0092] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects; moreover, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical disc read-only memory, optical storage, etc.) containing computer-usable program code. For ease of description, the above apparatus is described in terms of functionality, divided into various modules. In implementing this application, the functions of each module can be implemented in one or more software and / or hardware components.
[0093] The various embodiments in this specification are described in a progressive manner. For the same or similar parts between the various embodiments, please refer to each other. Each embodiment focuses on describing the differences from other embodiments. In particular, for the system embodiments, since they are basically similar to the method embodiments, the description is relatively simple. For the relevant parts, please refer to the description of the method embodiments.
[0094] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0095] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for generating front-end page code, characterized in that, include: Obtain the design image corresponding to the page to be generated, as well as the preset project code specifications; wherein, the project code specifications include component specifications, color specifications, spacing specifications, and code organization specifications; The design image is subjected to layout recognition, component mapping, color extraction and spacing quantization to obtain the page structure information, component mapping information, color information and spacing information corresponding to the design image; The page structure information, component mapping information, color information, and spacing information are used as common inputs to generate template code, script code, and style code respectively according to the code organization specifications. The template code, script code, and style code are subjected to code quality checks according to the set of check items to obtain the check results; the set of check items includes check items corresponding to the component specifications, color specifications, spacing specifications, and code organization specifications, respectively. If the inspection results meet the preset qualification conditions, the front-end page code consisting of the template code, the script code, and the style code is output.
2. The front-end page code generation method according to claim 1, characterized in that, The step of performing layout recognition on the design image to obtain the page structure information corresponding to the design image includes: Identify the region boundaries in the design image to obtain the page regions contained in the design image; The region type of each page region is determined according to a preset set of region types. The set of region types includes query region, button region, table region, and pagination region, and also includes at least one of prompt region, breadcrumb region, and tab region. Based on the positional relationship of each page region in the design image, the arrangement order and hierarchical relationship of each page region are determined, and the spacing relationship between adjacent page regions is obtained to obtain the page structure information.
3. The front-end page code generation method according to claim 1, characterized in that, The component mapping of the design image includes: Identify page design elements in the design image and extract element features of each page design element; the element features include the shape features, size features and internal composition features of the page design elements; The element features are matched with the feature templates of each standard component in the component specification, and the standard component with the highest matching degree is determined as the target component corresponding to the page design element. The component mapping information is obtained by reading the agreed-upon attribute items of the target component from the component specification and determining the attribute values of each agreed-upon attribute item based on the element state of the page design element presented in the design image.
4. The front-end page code generation method according to claim 1, characterized in that, The step of extracting color schemes from the design image includes: The design image is sampled pixel by pixel, and the sampled pixel color values are clustered to obtain a set of candidate color values; Based on the page area and page design element where the candidate color values in the candidate color value set are located in the design image, the color usage corresponding to each candidate color value is determined. Calculate the distance between the candidate color value and each standard color value in the color specification in the color space, and determine the standard color value with the smallest distance that is less than a preset color difference threshold as the target color value corresponding to the color application; If the distances are not less than the preset color difference threshold, the default color value configured for the purpose of the color in the color specification is determined as the target color value, and a color value deviation prompt message is generated.
5. The front-end page code generation method according to claim 1, characterized in that, The spacing quantization of the design image includes: Using the pixel coordinates of the design image as a reference, the pixel spacing between page elements and between page areas is measured, and the spacing scene corresponding to each pixel spacing is determined. Search the spacing specifications for candidate standard spacing values that correspond to the spacing scenario. The candidate standard spacing value with the smallest difference from the pixel spacing and the difference being less than a preset spacing threshold is determined as the target spacing value corresponding to the spacing scenario. If the difference is not less than the preset spacing threshold, the pixel spacing is retained as the target spacing value, and a spacing deviation prompt message is generated.
6. The front-end page code generation method according to claim 1, characterized in that, The generation of template code, script code, and style code according to the code organization specifications includes: According to the arrangement order of each page area in the page structure information, template code fragments corresponding to each page area are generated sequentially, and the component identifier and component attribute corresponding to the page area in the component mapping information are written into each template code fragment to obtain the template code. The script code is generated according to the script structure agreed in the code organization specification. The script structure includes data fields corresponding to each of the page areas and methods corresponding to the event attributes in the component properties. The style code is generated according to the style syntax and style naming rules agreed in the code organization specification. The target color value in the color information and the target spacing value in the spacing information are written into the style code, and a scope isolation identifier is set for the style code.
7. The front-end page code generation method according to claim 1, characterized in that, After generating the template code, script code, and style code respectively, the method further includes: In the template code, the script code, and the style code, generation identifiers are written according to the comment syntax of the corresponding code type. The generation identifiers include a start identifier and an end identifier. The set of inspection items also includes a generation identifier inspection item, which is used to check whether the generation identifier is written in the template code, the script code, and the style code. After outputting the front-end page code, the generated code and manually modified code in the front-end page code are distinguished according to the generation identifier.
8. The front-end page code generation method according to claim 1, characterized in that, The set of inspection items includes: a component prefix inspection item for checking whether the components in the template code belong to the standard components in the component specification; a style isolation inspection item for checking whether the style code sets a scope isolation identifier; a form attribute inspection item for checking whether the label width and style class of form components conform to the spacing specification; a button size inspection item for checking the size attribute of button components; a table border inspection item for checking the border attribute of table components; a pagination layout inspection item for checking the layout attribute of pagination components; a template redundancy inspection item for checking whether there are redundant wrapping nodes in the template code; a component naming inspection item for checking the component naming method; a style naming inspection item for checking the style class naming method; and a code style tool inspection item for calling the code style inspection tool to perform static inspection on the front-end page code. When the inspection result meets the preset qualification conditions, the step of outputting front-end page code consisting of the template code, the script code, and the style code includes: If all the inspection results in the set of inspection items are passed, it is determined that the inspection result meets the preset qualification condition, and the front-end page code is output; if there are inspection items with failed results, the failed inspection items and their corresponding code location information are output.
9. A front-end page code generation system, characterized in that, include: The image acquisition module is used to acquire the design image corresponding to the page to be generated, as well as the preset project code specifications; wherein, the project code specifications include component specifications, color specifications, spacing specifications, and code organization specifications; The image parsing module is used to perform layout recognition, component mapping, color extraction, and spacing quantification on the design image to obtain the page structure information, component mapping information, color information, and spacing information corresponding to the design image. The code generation module is used to take the page structure information, the component mapping information, the color information, and the spacing information as common inputs, and generate template code, script code, and style code respectively according to the code organization specifications; The code inspection module is used to perform code quality checks on the template code, the script code, and the style code according to the set of inspection items, obtain inspection results, and output the front-end page code composed of the template code, the script code, and the style code if the inspection results meet the preset qualification conditions; the set of inspection items includes inspection items corresponding to the component specifications, the color specifications, the spacing specifications, and the code organization specifications, respectively.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the front-end page code generation method as described in any one of claims 1 to 8.
