Front-end code generation method and device
By obtaining and analyzing the view element attribute information in the UI view interface, building a DOM tree and using Flex layout and margin style derivation, the problems of complex layout derivation and poor code readability in the existing technology are solved, and high-quality and capable Front-end code with strong readability adapts to complex page layouts.
Patent Information
- Application Number
- CN202410980680.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-15
- Publication Date
- 2024-11-15
AI Technical Summary
The existing layout derivation algorithm is complex in logic, poor efficiency, poor code readability, and in the case of complex page layout and irregular visual design drafts, it is impossible to effectively generate high-quality front-end UI view code, resulting in low layout restoration and universality. Poor performance.
By obtaining the view element attribute information in the target UI view interface, determining the row correlation and column correlation between subview elements, building a DOM tree, generating complete front-end code, using Flex layout and margin style derivation, simplifying the code structure , improve code readability and adaptability.
The generated front-end code is more in line with development specifications, improves code readability and efficiency, and can adapt to complex page layouts to achieve higher quality UI view code generation.
Smart Images

Figure CN118963732A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, specifically to the field of computer software technology, and in particular to a front-end code generation method and device. Background Art
[0002] With the development of Internet technology, front-end intelligence has become an inevitable trend. Building a platform that automatically converts UI (User Interface) drafts into code can not only improve the efficiency of front-end development, but also liberate front-end productivity and reduce labor costs. However, how to intelligently, efficiently, and with high quality and fidelity generate maintainable UI view code from UI artwork in one click, among which, accurately restoring the page layout is particularly important.
[0003] The limitations of existing layout deduction algorithms are not only the complex logic of the deduction process, poor deduction efficiency, and poor code readability, but also the use of margin maigin to achieve relative positioning in the style deduction process, and there is no better way to derive layout styles. In actual application scenarios, the layout structure of elements in the page is complex and nested layer by layer, resulting in low page restoration of the existing page layout deduction method. In addition, the visual design draft that is not standardized directly affects the result of page layout deduction, so it is necessary to formulate UI design rules in advance, or to compulsorily increase layout, etc. However, these restrictive conditions lead to poor general performance of the layout deduction method and its inability to adapt to complex application scenarios. Summary of the invention
[0004] Embodiments of the present application provide a front-end code generation method, apparatus, device, and storage medium.
[0005] According to the first aspect, an embodiment of the present application provides a front-end code generation method, the method comprising: obtaining attribute information of each view element in a target UI view interface; determining the child view elements corresponding to the same parent view element based on the attribute information of each view element; determining the nodes of different levels of the DOM tree corresponding to the parent view element except the root node, alternately based on the row correlation information and the column correlation information between the child view elements, until the leaf node is a separate child view element, and obtaining the DOM tree; generating a complete front-end code corresponding to the target UI view interface based on the DOM tree.
[0006] According to the second aspect, an embodiment of the present application provides a front-end code generation device, which includes: an acquisition module, configured to acquire attribute information of each view element in a target UI view interface; a determination module, configured to determine the child view elements corresponding to the same parent view element based on the attribute information of each view element; a construction module, configured to determine the nodes of different levels of the DOM tree corresponding to the parent view element except the root node alternately based on the row correlation information and the column correlation information between the child view elements, until the leaf node is a separate child view element, and a DOM tree is obtained; a generation module, configured to generate a complete front-end code corresponding to the target UI view interface based on the DOM tree.
[0007] According to the third aspect, an embodiment of the present application provides an electronic device, which includes one or more processors; a storage device, on which one or more programs are stored, and when the one or more programs are executed by the one or more processors, the one or more processors implement a front-end code generation method as in any embodiment of the first aspect.
[0008] According to a fourth aspect, an embodiment of the present application provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements a front-end code generation method as in any embodiment of the first aspect.
[0009] The present application obtains the attribute information of each view element in the target UI view interface; determines the child view elements corresponding to the same parent view element based on the attribute information of each view element; determines the nodes of different levels of the DOM tree corresponding to the parent view element except the root node according to the row correlation information and the column correlation information between the child view elements alternately, until the leaf node is a separate child view element, thereby obtaining a DOM tree; generates a complete front-end code corresponding to the target UI view interface based on the DOM tree, that is, according to the attribute information of the view elements, analyzes the node relationship, generates a DOM tree with a row and column structure, and finally generates the front-end code according to the DOM tree, so that the generated front-end code is more in line with the specifications of front-end code development and has higher readability.
[0010] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0012] Figure 2 is a flowchart of an embodiment of a front-end code generation method according to the present application;
[0013] Figure 3 is a flowchart of another embodiment of the front-end code generation method according to the present application;
[0014] Figure 4 It is a schematic diagram of an application scenario of the front-end code generation method according to the present application;
[0015] Figure 5 is a flowchart of another embodiment of the front-end code generation method according to the present application;
[0016] Figure 6 is a schematic diagram of an embodiment of a front-end code generation device according to the present application;
[0017] Figure 7 It is a structural diagram of a computer system suitable for implementing a server of an embodiment of the present application. DETAILED DESCRIPTION
[0018] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0019] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0020] Figure 1 An exemplary system architecture 100 is shown to which an embodiment of the front-end code generation method of the present application can be applied.
[0021] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0022] The terminal devices 101, 102, 103 interact with the server 105 via the network 104 to receive or send messages, etc. Various communication client applications, such as shopping applications, communication applications, etc., may be installed on the terminal devices 101, 102, 103.
[0023] Terminal devices 101, 102, 103 can be hardware or software. When terminal devices 101, 102, 103 are hardware, they can be various electronic devices with display screens, including but not limited to mobile phones and laptops. When terminal devices 101, 102, 103 are software, they can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules (for example, used to provide front-end code generation services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0024] Server 105 can be a server that provides various services, for example, obtaining attribute information of each view element in the target UI view interface; determining the sub-view elements corresponding to the same parent view element based on the attribute information of each view element, and there is no local overlapping relationship between the sub-view elements; determining the nodes of different levels of the DOM tree corresponding to the parent view element except the root node based on the row correlation information and column correlation information between the sub-view elements alternately, until the leaf node is a separate sub-view element, and obtaining the DOM tree; generating the complete front-end code corresponding to the target UI view interface based on the DOM tree.
[0025] It should be noted that the server 105 can be hardware or software. When the server 105 is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or it can be implemented as a single server. When the server is software, it can be implemented as multiple software or software modules (for example, used to provide front-end code generation services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0026] It should be noted that the front-end code generation method provided in the embodiment of the present disclosure can be executed by the server 105, can be executed by the terminal devices 101, 102, 103, or can be executed by the server 105 and the terminal devices 101, 102, 103 in cooperation with each other. Accordingly, the various parts (such as various units, sub-units, modules, sub-modules) included in the front-end code generation device can be all set in the server 105, can be all set in the terminal devices 101, 102, 103, or can be set in the server 105 and the terminal devices 101, 102, 103 respectively.
[0027] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.
[0028] Figure 2 A flow chart 200 of an embodiment of a front-end code generation method applicable to the present application is shown. In this embodiment, the front-end code generation method includes the following steps:
[0029] Step 201, obtaining the attribute information of each view element in the target UI view interface.
[0030] In this embodiment, the execution subject (such as Figure 1 The server 105 or terminal devices 101, 102, 103 shown in the figure can directly obtain the UI view interface of the front-end code to be generated, that is, the attribute information of each view element in the target UI view interface, or the UI view interface can be converted into JSON data first, and then the attribute information of each view element can be obtained from the JSON data. This application does not limit this.
[0031] The attribute information of the view element may include at least one of the following: an identifier of the view element, absolute positioning information (x, y), a width width, and a height height.
[0032] Specifically, the execution entity may first convert the target UI view interface into JSON data. The JSON data corresponding to each view element in the UI view interface may include the view element's identifier, absolute positioning information (x, y), width width, height and other attribute information.
[0033] Here, the absolute positioning information is generally used to indicate the positioning information of the view element relative to the upper left corner of the target UI view interface.
[0034] Step 202: Determine the child view elements corresponding to the same parent view element based on the attribute information of each view element.
[0035] In this embodiment, the executing entity may directly compare the absolute positioning information, height, and width of each pair of view elements in each view element to determine the child view element corresponding to the same parent view element; or may compare the absolute positioning information, height, and width of each pair of view elements in each view element in order of the area of each view element from large to small to determine the child view element corresponding to the same parent view element. This application does not limit this.
[0036] It should be noted that there is no local overlapping relationship between the determined child view elements corresponding to the same parent view element.
[0037] Here, the superposition relationship between the subview elements can be determined based on whether the number of superimposed pixels between the subview elements is greater than or equal to a preset pixel number threshold. The pixel number threshold can be determined based on experience, actual needs and specific application scenarios, and this application does not limit this.
[0038] Specifically, the number of pixels of sub-view element A and sub-view element B is 1000, the number of superimposed pixels is 1, the pixel number threshold is 50, and the number of superimposed pixels is less than the pixel number threshold. Therefore, there is no local superposition relationship between sub-view element A and sub-view element B.
[0039] In addition, for sub-view elements that have a complete overlapping relationship, that is, the absolute positioning information, width, and height of the two sub-view elements are the same, the two sub-view elements are merged into one sub-view element.
[0040] Step 203, alternately determine the nodes of different levels of the DOM tree corresponding to the parent view element except the root node based on the row correlation information and the column correlation information between the sub-view elements, until the leaf node is a separate sub-view element, and obtain the DOM tree.
[0041] In this embodiment, after the execution subject obtains the child view element corresponding to the same parent view element, it can first determine the nodes of the second level of the DOM tree corresponding to the parent view element except the root node (first level) based on the row correlation information between the child views, and then determine the nodes of the third level of the DOM tree except the parent node based on the column correlation information between the child views, and so on, until the leaf node is a separate child view element to obtain the DOM tree; it can also first determine the nodes of the second level of the DOM tree corresponding to the parent view element except the root node based on the column correlation information between the child views, and then determine the nodes of the third level of the DOM tree except the root node based on the row correlation information between the child views, and so on, until the leaf node is a separate child view element to obtain the DOM tree, which is not limited in this application.
[0042] The row correlation information between subview elements is used to indicate the relative position relationship of each subview element corresponding to the same parent view in the row direction. The column correlation information between subview elements is used to indicate the relative position relationship of each subview element corresponding to the same parent view in the column direction.
[0043] Here, when the executing entity determines the nodes of the current level based on the row correlation information between sub-view elements, the sub-view elements corresponding to the parent node of the previous level and in the same row are classified as a node of the level; when the executing entity determines the nodes of the current level based on the column correlation information between view elements, the sub-view elements corresponding to the parent node of the previous level and in the same column are classified as a node of the level, until the leaf node is a separate sub-view element.
[0044] Specifically, Figure 3As shown, the execution subject obtains the sub-view elements A, B, C, D, E, F, G, H corresponding to the same parent view element 301 in the target UI view interface, wherein the row correlation information 302 between the sub-view elements is {H:G, A:C, D:C, B:C, E:C} (H:G indicates that the sub-view element H is located in the row where the sub-view element G is located, A:C, D:C, B:C, E:C indicates that the sub-view elements A, B, D, E are all located in the row where the sub-view element C is located); each sub-view element The column correlation information 303 between them is {G:F, H:F, C:F, B:G, A:B, E:H, D:E} (G:F, H:F, C:F means that sub-view elements G, H, C are located in the column where sub-view element F is located, B:G means that sub-view element B is located in the column where sub-view element G is located, A:B means that sub-view element A is located in the column where sub-view element B is located, E:H means that sub-view element E is located in the column where sub-view element H is located, and D:E means that sub-view element D is located in the column where sub-view element E is located).
[0045] Further, the execution subject determines the parent view element 301 as the root node of the first level of the DOM tree 304, and determines the nodes of the second level of the DOM tree 304, namely, nodes ABCDE, node F and node GH, according to the row correlation information 302 {H:G, A:C, D:C, B:C, E:C} between the subview elements, wherein nodes ABCDE are classified by the subview elements A, B, C, D, E in the same row, node F is classified by the subview element F located alone in a row, and node GH is classified by the subview elements G and H in the same row. The execution subject continues to determine the nodes of the third level of the DOM tree 304 according to the column correlation information 303 {G:F, H:F, C:F, B:G, A:B, E:H, D:E} between the subview elements. Here, the non-leaf nodes of the second level are the parent nodes of the nodes of the third level. The execution subject determines the nodes AB, C, DE, G and H of the third level according to the column correlation information 303 between the subview elements and the parent node of the previous level. Among them, nodes AB, C and DE are child nodes of nodes ABCDE, node AB is obtained by classifying the subview elements A and B located in the same column, node DE is obtained by classifying the subview elements D and E located in the same column, node G and node H are child nodes of node GH, node G is obtained by classifying the subview element G located in a single column, and node H is obtained by classifying the subview element H located in a single column.
[0046] Furthermore, the execution subject determines nodes A, B, C and D of the fourth level of the DOM tree 304 according to the row correlation information 302 between the non-leaf nodes and the subview elements of the third level. So far, the leaf nodes of the DOM tree 304 are all separate subview elements.
[0047] It should be pointed out that the row correlation information can be obtained directly by comparing the vertical coordinates and heights of the absolute positioning information of each sub-view element; it can also be obtained by comparing the vertical coordinates and heights of the absolute positioning information of each sub-view element in order from large to small. The present application does not limit this.
[0048] The column correlation information can be obtained directly by comparing the horizontal coordinates and widths of the absolute positioning information of each sub-view element; it can also be obtained by comparing the horizontal coordinates and widths of the absolute positioning information of each sub-view element in order from large to small. This application does not limit this.
[0049] In some optional methods, the row correlation information is obtained by comparing the vertical coordinates and heights in the absolute positioning information of each sub-view element in descending order of height of each sub-view element to obtain the row correlation information between the sub-view elements.
[0050] In this implementation, the attribute information includes: the vertical coordinate and height in the absolute positioning information of the view element. The execution entity can compare the vertical coordinates and heights in the absolute positioning information of each sub-view element in descending order of the height of each view element to obtain the row correlation information between the sub-view elements.
[0051] Specifically, the execution entity can construct a one-dimensional column matrix H*1 with the same height as the target UI view interface, and sort each subview element from large to small according to the height height, and fill each subview element into the one-dimensional matrix in sequence according to the ordinate and height in the absolute positioning information according to the sorting result, and record the relative position information of each subview element in the matrix in terms of height. For example, the attribute information of subview element M is {id:M y:5h:30}, and the attribute information of subview element N is {id:N y:10h:20}. Subview elements M and N are sorted in terms of height as subview element M>subview element N. According to the above sorting, the ordinate and height in the absolute positioning information of each subview element are compared in sequence to obtain N:{M:20}, that is, subview element N occupies 20 pixels at the height of subview element M, that is, subview element M and subview element N are located in the same row.
[0052] This implementation method compares the ordinate and height in the absolute positioning information of each sub-view element in descending order of height, and obtains the row correlation information between the sub-view elements, thereby avoiding a loop to compare the relative position relationship in height between each sub-view element, reducing the number of recursive code loops, and reducing the time complexity of the algorithm.
[0053] In some optional methods, the column correlation information is obtained by comparing the horizontal coordinates and widths in the absolute positioning information of each sub-view element in descending order of the width of each sub-view element to obtain the column correlation information between the sub-view elements.
[0054] In this implementation, the attribute information includes: the horizontal coordinate and width in the absolute positioning information of the view element. The execution entity can compare the horizontal coordinates and widths in the absolute positioning information of each sub-view element in descending order of the width of each view element to obtain the column correlation information between the sub-view elements.
[0055] Specifically, the execution entity can construct a one-dimensional row matrix 1*W with the same width as the target UI view interface, and sort the sub-view elements from large to small according to the width Width, and fill each sub-view element into the one-dimensional row matrix in turn according to the horizontal coordinate and width in the absolute positioning information according to the sorting result, and record the relative position information of the width of each sub-view element in the matrix. For example, the attribute information of sub-view element P is {id:M x:5w:20}, and the attribute information of sub-view element Q is {id:Q x:5w:10}. Sub-view elements P and Q are sorted according to width as sub-view element P>sub-view element Q. According to the above sorting, the horizontal coordinate and width in the absolute positioning information of each sub-view element are compared in turn to obtain Q:{P:10}, that is, sub-view element Q occupies 10 pixels on the width of sub-view element P, that is, sub-view element M and sub-view element N are located in the same column.
[0056] This implementation method compares the horizontal coordinate and width in the absolute positioning information of each view element in order of width from large to small, and obtains the column correlation information between each sub-view element, thereby avoiding looping and comparing the relative position relationship in width between each sub-view element, reducing the number of recursive code loops, and reducing the time complexity of the algorithm.
[0057] Step 203: Generate complete front-end code corresponding to the target UI view interface based on the DOM tree.
[0058] In this embodiment, after obtaining the DOM tree, the execution entity can directly perform style deduction based on the DOM tree to generate a complete front-end code corresponding to the target UI view interface; or, based on the DOM tree, further determine the sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree, and perform style deduction based on the DOM tree and the sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree to generate a complete front-end code corresponding to the target UI view interface. This application does not limit this.
[0059] Here, the execution entity may use the view layout method in the existing technology or future development technology to derive the style, for example, Flex layout and margin layout in CSS (Cascading Style Sheets), and this application does not limit this.
[0060] Among them, Flex is the FlexiableBox, which is mainly used for flexible layout.
[0061] In some optional methods, a complete front-end code corresponding to a target UI view interface is generated based on a DOM tree, including: using a Flex layout to perform style derivation on the DOM tree to obtain a derived DOM tree; and generating a complete front-end code corresponding to the target UI view interface based on the derived DOM tree.
[0062] In this implementation, the execution subject can use Flex layout to derive the style of the DOM tree, and the main axis alignment can be divided into three types: start, center, and end. After obtaining the derived DOM tree, the complete front-end code corresponding to the target UI view interface is further generated based on the derived DOM tree.
[0063] Specifically, using Flex layout, taking the row structure as an example, the row center line m = (2y + h) / 2 (y is used to indicate the top margin of the view element, and h is used to indicate the height of the view element) of the parent view element and the child view element is calculated. If the m value of the child view element is smaller than the m value of the parent view element, the start alignment is adopted; if the m value of the child view element is greater than the m value of the parent view element, the end alignment is adopted; if the m value of the child view element is approximately equal to the m value of the parent view element, the center alignment is adopted.
[0064] This implementation uses Flex layout to derive style for a DOM tree with a row and column structure, that is, it uses row layout div (flex-directive: row) and column layout div (flex-dierctive: column) to achieve style control. Compared with the margin style, it can not only implement complex page styles simply and completely, but also adapt to screens of different sizes in a responsive manner.
[0065] In some optional methods, a complete front-end code corresponding to the target UI view interface is generated based on the DOM tree, including: style deduction based on the DOM tree and sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree, to generate a complete front-end code corresponding to the target UI view interface.
[0066] In this implementation, after obtaining the DOM tree with a row and column structure, the execution entity can further determine the relative positioning information of the sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree, and perform style deduction based on the DOM tree and the relative positioning information of the sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree, to generate a complete front-end code corresponding to the target UI view interface.
[0067] This implementation method generates a complete front-end code corresponding to the target UI view interface by performing style deduction based on the DOM tree and the sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree. It fully considers the sub-view elements that have an overlapping relationship with the sub-view elements, and ensures the integrity of the generated front-end code.
[0068] Continue to see Figure 4 , Figure 4 It is a schematic diagram of an application scenario of the front-end code generation method according to this embodiment.
[0069] exist Figure 4 In the application scenario, the execution subject 401 obtains the attribute information of each view element in the target UI view interface; based on the attribute information of each view element, the sub-view element U, sub-view element V and sub-view element W corresponding to the same parent view element 402 are determined. Further, the execution subject classifies the sub-view elements U and sub-view elements V in the same column as nodes UV of the second level of the DOM tree corresponding to the parent view element except the root node (first level) according to the column correlation information between the sub-view elements, and classifies the sub-view element W in a single column as nodes W of the second level. The execution subject continues to classify the sub-view elements U and sub-view elements V in different rows as nodes U and V of the third level respectively according to the row correlation information between the sub-view elements, where the node UV is the parent node of the node U and the node V. At this time, the leaf node is a separate sub-view element, and a DOM tree 403 is obtained. The execution subject generates a complete front-end code 404 corresponding to the target UI view interface based on the DOM tree 403.
[0070] The front-end code generation method disclosed in the present invention obtains the attribute information of each view element in the target UI view interface; determines the child view elements corresponding to the same parent view element based on the attribute information of each view element; determines the nodes of different levels of the DOM tree corresponding to the parent view element except the root node according to the row correlation information and the column correlation information between the child view elements alternately, until the leaf node is a separate child view element, thereby obtaining the DOM tree; generates the complete front-end code corresponding to the target UI view interface based on the DOM tree, so that the generated front-end code is more in line with the development habits and has higher readability.
[0071] Further references Figure 5, which shows Figure 2 The process 500 of another embodiment of the front-end code generation method shown in FIG. In this embodiment, the attribute information includes: the absolute positioning information, height and width of the view element. The process 500 of the front-end code generation method of this embodiment may include the following steps:
[0072] Step 501: Obtain attribute information of each view element in the target UI view interface.
[0073] In this embodiment, the implementation details and technical effects of step 501 can refer to the description of step 201 and will not be repeated here.
[0074] Step 502 : Compare the absolute positioning information, length and width of each view element in descending order of area of each view element, and determine the child view element corresponding to the same parent view element.
[0075] In this embodiment, the execution entity may compare the absolute positioning information, length, and width of each view element in order of area from large to small, and determine the child view elements corresponding to the same parent view element.
[0076] Specifically, the executing entity can construct a matrix that is the same size as the target UI view interface. For example, if the target UI view interface is 1280*980, then construct a 1280*980 matrix and sort the view elements in the target UI view interface from large to small according to their area width*height. According to the sorting results, fill each sub-view element into the matrix in sequence according to the absolute positioning information, width and height, and record the relative position information of each sub-view element in the matrix. For example, the attribute information of view element A is {id:A x:0y:0w:100h:20}, the attribute information of view element B is {id:B x:10y:5w:80h:10}, and the attribute information of view element C is {id:C x:10y:17w:5h:3}. View elements A, B, and C are sorted according to area as view element A>view element B>view element C. The view elements are compared in pairs according to the size of their areas, and the results are B: {A:800}, that is, view element B is a subview of view element A and occupies 800 pixels of view element A, and C: {A:15}, that is, view element C is a subview of view element A and occupies 15 pixels of view element A. Further, it can be determined that view element B and view element C are both subviews of parent view element A, and there is no local overlay relationship between view element B and view element C.
[0077] Step 503: extracting structural features and content features of the nodes of the user relationship graph.
[0078] In this embodiment, the implementation details and technical effects of step 503 may refer to the description of step 203 and will not be repeated here.
[0079] Step 504: Input the structural features and content features into a preset user family relationship prediction model to obtain a classification result of whether the user has a family relationship.
[0080] In this embodiment, the implementation details and technical effects of step 504 can refer to the description of step 204 and will not be repeated here.
[0081] from Figure 5 It can be seen that Figure 2 Compared with the corresponding embodiments, the process 500 of the front-end code generation method in this embodiment embodies comparing the absolute positioning information, length and width of each view element in the order of the area of each view element from large to small, determining the child view elements corresponding to the same parent view element, and generating a DOM tree and further generating front-end code based on the child view elements corresponding to the same parent view element, avoiding cyclic traversal and comparison of the relative position relationship between each view element, reducing the number of code recursive loops, reducing the time complexity of the algorithm, and thereby improving the efficiency of generating front-end code.
[0082] Further references Figure 6 As an implementation of the methods shown in the above figures, the present application provides an embodiment of a front-end code generation device, which is similar to Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0083] like Figure 6 As shown, the front-end code generation device 600 of this embodiment includes: an acquisition module 601, a determination module 602, a construction module 603 and a generation module 604.
[0084] The acquisition module 601 may be configured to acquire the attribute information of each view element in the target UI view interface.
[0085] The determination module 602 may be configured to determine the child view elements corresponding to the same parent view element based on the attribute information of each view element.
[0086] The construction module 603 can be configured to determine the nodes of different levels of the DOM tree corresponding to the parent view element except the root node according to the row correlation information and the column correlation information between the sub-view elements alternately, until the leaf node is a separate sub-view element, and obtain the DOM tree.
[0087] The generation module 604 may be configured to generate a complete front-end code corresponding to the target UI view interface based on the DOM tree.
[0088] In some optional embodiments of this embodiment, the determination module is further configured to: compare the absolute positioning information, length and width of each view element in order of the area of each view element from large to small, and determine the child view element point corresponding to the same parent view element.
[0089] In some optional methods of this embodiment, the row correlation information is obtained in the following manner: the vertical coordinate and height in the absolute positioning information of each sub-view element are compared in descending order of the height of each sub-view element to obtain the row correlation information between the sub-view elements.
[0090] In some optional methods of this embodiment, the column correlation information is obtained in the following manner: the horizontal coordinates and widths in the absolute positioning information of each sub-view element are compared in descending order of the width of each sub-view element to obtain the column correlation information between the sub-view elements.
[0091] In some optional modes of this embodiment, the generation module is further configured to: use Flex layout to derive the style of the DOM tree to obtain a derived DOM tree; and generate a complete front-end code corresponding to the target UI view interface based on the derived DOM tree.
[0092] In some optional methods of this embodiment, style deduction is performed based on the DOM tree and the sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree to generate a complete front-end code corresponding to the target UI view interface.
[0093] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
[0094] like Figure 7 , is a block diagram of an electronic device according to the front-end code generation method of an embodiment of the present application.
[0095] 700 is a block diagram of an electronic device according to the front-end code generation method of an embodiment of the present application. Electronic devices are intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Electronic devices can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples, and are not intended to limit the implementation of the present application described herein and / or required.
[0096] like Figure 7 As shown, the electronic device includes: one or more processors 701, a memory 702, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 701 is taken as an example.
[0097] The memory 702 is a non-transient computer-readable storage medium provided in the present application. The memory stores instructions executable by at least one processor to enable the at least one processor to execute the front-end code generation method provided in the present application. The non-transient computer-readable storage medium of the present application stores computer instructions, which are used to enable a computer to execute the front-end code generation method provided in the present application.
[0098] The memory 702 is a non-transient computer-readable storage medium that can be used to store non-transient software programs, non-transient computer executable programs and modules, such as program instructions / modules corresponding to the front-end code generation method in the embodiment of the present application (for example, the attached Figure 6 The processor 701 executes various functional applications and data processing of the server by running the non-transient software programs, instructions and modules stored in the memory 702, that is, the front-end code generation method in the above method embodiment is implemented.
[0099] The memory 702 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the use of the electronic device generated by the front-end code, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 702 may optionally include a memory remotely arranged relative to the processor 701, and these remote memories may be connected to the electronic device generated by the front-end code via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0100] The electronic device of the front-end code generation method may further include: an input device 703 and an output device 704. The processor 701, the memory 702, the input device 703 and the output device 704 may be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.
[0101] The input device 703 can receive input digital or character information, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a track ball, a joystick, and other input devices. The output device 704 may include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor). The display device may include, but is not limited to, a liquid crystal display (LCD), a light emitting diode (LED) display, and a plasma display. In some embodiments, the display device may be a touch screen.
[0102] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, dedicated ASICs (application specific integrated circuits), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0103] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for programmable processors and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or means (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0104] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0105] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0106] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0107] According to the technical solution of the embodiment of the present application, the generated front-end code is more in line with development habits and has higher readability.
[0108] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0109] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A front-end code generation method, the method comprising: Get the attribute information of each view element in the target UI view interface; Determine, based on the attribute information of each view element, sub-view elements corresponding to the same parent view element, where no local overlapping relationship exists between the sub-view elements; Determine nodes at different levels of the DOM tree corresponding to the parent view element except the root node according to the row correlation information and the column correlation information between the child view elements alternately, until the leaf node is a separate child view element, and obtain a DOM tree, wherein the DOM tree includes nodes at at least four different levels except the root node; Generate the complete front-end code corresponding to the target UI view interface based on the DOM tree.
2. The method according to claim 1, wherein: The attribute information includes: absolute positioning information, height and width of the view element, and determining the child view element corresponding to the same parent view element based on the attribute information of each view element includes: According to the order of the area of each view element from large to small, the absolute positioning information, length and width of each view element are compared to determine the child view element corresponding to the same parent view element.
3. The method according to claim 1, wherein: The attribute information includes: the ordinate and height in the absolute positioning information of the view element, and the row correlation information is obtained in the following manner: According to the descending order of the heights of the subview elements, the ordinates and heights in the absolute positioning information of the subview elements are compared to obtain the row correlation information between the subview elements.
4. The method according to claim 1, wherein: The attribute information includes: the horizontal coordinate and width in the absolute positioning information of the view element, and the column correlation information is obtained in the following manner: According to the width of each sub-view element from large to small, the horizontal coordinate and the width in the absolute positioning information of each sub-view element are compared to obtain the column correlation information between the sub-view elements.
5. The method according to any one of claims 1 to 4, wherein: The generating of the complete front-end code corresponding to the target UI view interface based on the DOM tree includes: Using Flex layout to perform style derivation on the DOM tree to obtain a derived DOM tree; Generate the complete front-end code corresponding to the target UI view interface based on the derived DOM tree.
6. The method according to any one of claims 1 to 4, wherein: The complete front-end code corresponding to the target UI view interface generated based on the DOM tree includes: Style deduction is performed based on the DOM tree and the sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree to generate a complete front-end code corresponding to the target UI view interface.
7. A front-end code generation device, the device comprising: An acquisition module is configured to acquire attribute information of each view element in the target UI view interface; a determination module configured to determine, based on the attribute information of each view element, sub-view elements corresponding to the same parent view element, wherein no local overlapping relationship exists between the sub-view elements; A construction module is configured to determine nodes at different levels of the DOM tree corresponding to the parent view element except the root node according to the row correlation information and the column correlation information between the child view elements alternately, until the leaf node is a separate child view element, and obtain a DOM tree, wherein the DOM tree includes nodes at at least four different levels except the root node; The generation module is configured to generate a complete front-end code corresponding to the target UI view interface based on the DOM tree.
8. The device according to claim 7, wherein: The determination module is further configured to: According to the order of the area of each view element from large to small, the absolute positioning information, length and width of each view element are compared to determine the child view element point corresponding to the same parent view element.
9. The device according to claim 7, wherein: The attribute information includes: the ordinate and height in the absolute positioning information of the view element, and the row correlation information is obtained in the following manner: According to the descending order of the heights of the subview elements, the ordinates and heights in the absolute positioning information of the subview elements are compared to obtain the row correlation information between the subview elements.
10. The device according to claim 7, wherein: The attribute information includes: the horizontal coordinate and width in the absolute positioning information of the view element, and the column correlation information is obtained in the following manner: According to the width of each sub-view element from large to small, the horizontal coordinate and the width in the absolute positioning information of each sub-view element are compared to obtain the column correlation information between the sub-view elements.
11. The device according to any one of claims 7 to 10, wherein: The generation module is further configured to: Using Flex layout to perform style derivation on the DOM tree to obtain a derived DOM tree; Generate the complete front-end code corresponding to the target UI view interface based on the derived DOM tree.
12. The device according to any one of claims 7 to 10, wherein: The generation module is further configured to: Style deduction is performed based on the DOM tree and the sub-view elements that have a local overlapping relationship with the leaf nodes of the DOM tree to generate a complete front-end code corresponding to the target UI view interface.
13. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor so that the at least one processor can perform the method according to any one of claims 1 to 6.
14. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 6.
