Interface generation method, device, computer equipment and storage medium

By acquiring the HTML file generated by the UI design tool, extracting component information and page size information, generating component structure information and rendering the DOM tree, the UI interface is directly generated, solving the problem of low efficiency in UI interface generation in existing technologies and achieving efficient interface development.

CN114398138BActive Publication Date: 2024-09-20PINGAN INT SMART CITY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210059217.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-19
Publication Date
2024-09-20
Estimated Expiration
2042-01-19

AI Technical Summary

Technical Problem

In existing technologies, web development engineers are inefficient when drawing UI interfaces based on UI designers' designs, as they need to manually analyze and write code, resulting in low interface generation efficiency.

Method used

By obtaining the HTML file corresponding to the target UI design draft generated by the UI design tool, extracting component information and page size information, generating component structure information, traversing the DOM tree and performing rendering processing, and directly generating front-end code to implement the UI interface.

Benefits of technology

It eliminates the need for front-end developers to understand UI design drafts, directly generating UI interfaces, thus improving interface generation efficiency and reducing development costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114398138B
    Figure CN114398138B
Patent Text Reader

Abstract

The embodiment of the present application provides an interface generation method, device, computer equipment and storage medium, which are applied to the field of application development technology, including: using a synchronous file reading method to obtain a target html file corresponding to a target UI design drawing; extracting component information of multiple components constituting a target UI interface and page size information of the target UI interface from the target html file; determining the layout information and component style of each component in the target UI interface according to the component information and page size information of each component, and generating component structured information based on the layout information and component style of each component; traversing the component structured information to generate a dom tree, and rendering the dom tree to obtain a front-end code to generate a target UI interface, which can improve the interface generation efficiency. The present application involves blockchain technology, such as writing a target html file into a blockchain for use in scenarios such as generating front-end code according to a target html file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, in particular to the field of application development technology, and specifically to an interface generation method, device, computer equipment and storage medium. Background Art

[0002] Figma is a browser-based collaborative UI (User Interface) design tool. Since its launch, it has been increasingly favored by UI designers due to its cross-platform and cloud storage features. The normal development process of Web (World Wide Web) development engineers is often to first draw a basic UI interface based on the design drawings output by UI designers, and then add interactive events for secondary development. When drawing a basic UI interface based on the design drawings output by UI designers, it mainly depends on Web development engineers to analyze the design drawings and then write corresponding codes to implement the UI interface corresponding to the design drawings, resulting in low interface development efficiency. Summary of the invention

[0003] The embodiments of the present application provide an interface generation method, apparatus, computer device and storage medium, which can improve the efficiency of interface generation.

[0004] On the one hand, an embodiment of the present application provides an interface generation method, the method comprising:

[0005] When a confirmation operation for a target UI design drawing is detected, a target hypertext markup language html file corresponding to the target UI design drawing is obtained by using a synchronous file reading method, wherein the target UI design drawing is generated by a UI design tool and is used to construct a target UI interface;

[0006] Extracting component information of a plurality of components constituting the target UI interface and page size information of the target UI interface from the target html file;

[0007] Determine the layout information and component style of each component in the target UI interface according to the component information of each component and the page size information, and generate component structured information based on the layout information and component style of each component in the target UI interface;

[0008] Traversing the component structured information to generate a document object model DOM tree, and rendering the DOM tree to obtain the front-end code corresponding to the target UI interface;

[0009] The front-end code is called to generate the target UI interface.

[0010] In one aspect, an embodiment of the present application provides an interface generation device, the device comprising:

[0011] an acquisition unit, configured to acquire a target hypertext markup language html file corresponding to the target UI design drawing by a synchronous file reading method when a confirmation operation on the target UI design drawing is detected, wherein the target UI design drawing is generated by a UI design tool and is used to construct a target UI interface;

[0012] A processing unit, used to extract component information of multiple components constituting the target UI interface and page size information of the target UI interface from the target HTML file;

[0013] The processing unit is further used to determine the layout information and component style of each component in the target UI interface according to the component information of each component and the page size information, and generate component structured information based on the layout information and component style of each component in the target UI interface;

[0014] The processing unit is further used to traverse the component structured information to generate a document object model DOM tree, and render the DOM tree to obtain the front-end code corresponding to the target UI interface;

[0015] The processing unit is also used to call the front-end code to generate the target UI interface.

[0016] On the one hand, an embodiment of the present application provides a computer device, including a processor and a memory, wherein the processor and the memory are interconnected, wherein the memory is used to store a computer program, and the computer program includes program instructions, and the processor is configured to call the program instructions to execute the interface generation method described above.

[0017] On one hand, an embodiment of the present application provides a computer-readable storage medium, in which program instructions are stored. When the program instructions are executed, they are used to implement the above-mentioned interface generation method.

[0018] On the one hand, an embodiment of the present application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. When the computer instructions are executed by a processor of a computer device, the above-mentioned interface generation method is executed.

[0019] In an embodiment of the present application, when a confirmation operation for a target UI design drawing is detected, a synchronous file reading method is used to obtain a target hypertext markup language html file corresponding to the target UI design drawing, the target UI design drawing is generated in a UI design tool, and the target UI design drawing is used to construct a target UI interface; component information of multiple components constituting the target UI interface and page size information of the target UI interface are extracted from the target html file; layout information and component style of each component in the target UI interface are determined according to the component information and page size information of each component, and component structured information is generated based on the layout information and component style of each component in the target UI interface; the component structured information is traversed to generate a document object model dom tree, and the dom tree is rendered to obtain the front-end code corresponding to the target UI interface; the front-end code is called to generate the target UI interface, the html file corresponding to the target design drawing can be directly obtained, and the html file can be automatically processed to generate the target UI interface, without the need for a front-end developer to understand the target UI design drawing and then write corresponding code to generate the target UI interface, thereby improving the efficiency of interface generation and reducing development costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0021] Figure 1 It is a schematic diagram of the architecture of an interface generation system provided in an embodiment of the present application;

[0022] Figure 2 It is a flowchart of an interface generation method provided in an embodiment of the present application;

[0023] Figure 3 This is a schematic diagram of the layout of multiple components in a UI interface provided by an embodiment of the present application;

[0024] Figure 4 It is a structural schematic diagram of an interface generation device provided in an embodiment of the present application;

[0025] Figure 5 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0027] The embodiment of the present application can acquire and process the target UI design diagram based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0028] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0029] The embodiment of the present application provides an interface generation scheme. The interface generation scheme can be executed by a computer device, and the general principle of the interface generation scheme is as follows: when a user or an enterprise wants to generate a UI interface (UserInterface, user interface), it can provide demand information about the UI interface, and the demand information can be the interface function of the UI interface (such as the UI interface is used to display data, collect data, etc.), or the demand information can be related information on the layout requirements of the UI interface, etc. Then, the UI interface can be designed in a UI design tool (such as a figma design tool) according to the requirement information of the UI interface, and after the design of the target UI design drawing corresponding to the UI interface is completed, the target html (Hyper Text Markup Language) file corresponding to the target UI design drawing is obtained, and the component information of multiple components constituting the target UI interface and the page size information of the target UI interface are extracted from the target html file; then, the layout information and component style of each component in the target UI interface are determined according to the component information and page size information of each component, and component structured information is generated based on the layout information and component style of each component in the target UI interface; then, the component structured information is traversed to generate a dom (Document Object Model) tree, and the dom tree is rendered to obtain the front-end code corresponding to the target UI interface; finally, the front-end code is called to generate the target UI interface.

[0030] Through the above-mentioned interface generation scheme, the target html file corresponding to the target UI design drawing can be directly obtained, and the target html file can be automatically processed to generate the target UI interface. There is no need for the front-end developer to understand the target UI design drawing and then write the corresponding code to generate the target UI interface, which improves the efficiency of interface generation and reduces development costs.

[0031] Based on the interface generation solution provided above, this application embodiment provides an interface generation system, see Figure 1 , the interface generation system may include at least one terminal device 101 and a server 102. The terminal device 101 may run a UI design tool, in which different types of components may be provided. In the UI design tool, the user may design the required target UI interface according to the provided components, and obtain the target UI design drawing corresponding to the target UI interface. After obtaining the target UI design drawing, the user may trigger a confirmation operation or a cancellation operation on the target UI design drawing. When the server 102 detects a confirmation operation for the target UI design drawing, it may obtain a target html file corresponding to the target UI design drawing, and generate a front-end code for implementing the target UI interface based on the target html file. Among them, the terminal device 101 and the server 102 may be directly or indirectly connected via wired or wireless communication, which is not limited in this application. The terminal device may be a smart device such as a mobile phone, a tablet computer, a laptop computer, a PDA, a mobile internet device (MID), a wearable device, etc. The above-mentioned servers include multiple servers (also called nodes), which can be independent physical servers or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), as well as big data and artificial intelligence platforms.

[0032] In one embodiment, the above interface generation scheme can be executed by the terminal device 101. The interface generation scheme can be: when the user triggers the confirmation operation for the target UI design corresponding to the target UI interface, the terminal device 101 detects the confirmation operation for the target UI design, and then can obtain the target html file corresponding to the target UI design from the server 102, and extract the component information of the multiple components constituting the target UI interface and the page size information of the target UI interface from the target html file, and determine the layout information and component style of each component in the target UI interface based on the component information and page size information of each component, and generate component structured information based on the layout information and component style of each component in the target UI interface, traverse the component structured information to generate a document object model dom tree, and render the dom tree to obtain the front-end code corresponding to the target UI interface, and call the front-end code to generate the target UI interface. Then the target UI interface and the front-end code can be stored in the server 102.

[0033] In another embodiment, the above-mentioned interface generation scheme can be executed by the server 102, and the interface generation scheme can be: designing a target UI design drawing corresponding to the target UI interface in the UI design tool provided by the terminal device 101, and after detecting the confirmation operation for the target UI design drawing, the terminal device 101 can send the detected confirmation operation for the target UI design drawing to the server 102, and then the server 102 can obtain the target html file corresponding to the target UI design drawing, and then the server 102 can generate the target UI interface according to the specific implementation process of the above-mentioned terminal device 101 generating the target UI interface according to the target html file, and display the generated target UI interface through the terminal device 101.

[0034] Through the above-mentioned interface generation scheme and interface generation system, the html file corresponding to the target UI design drawing can be directly obtained, and the component information of the component and the page size information of the UI interface can be automatically determined for the html file. The target UI interface is generated based on the component information and the page size information. There is no need for the front-end developer to understand the target design drawing and then write the corresponding code to generate the target UI interface, which improves the interface generation efficiency and reduces the development cost.

[0035] Based on the above interface generation scheme and interface generation system, please refer to Figure 2 , Figure 2 A flowchart of an interface generation method provided in an embodiment of the present application. The interface generation method can be executed by a computer device, which can be a terminal device 101 or a server 102. The interface generation method described in the embodiment of the present application can include the following steps S201-S205:

[0036] S201. When a confirmation operation for a target UI design drawing is detected, a target hypertext markup language html file corresponding to the target UI design drawing is obtained by a synchronous file reading method. The target UI design drawing is generated by a UI design tool and is used to construct a target UI interface.

[0037] Among them, the UI design tool is a browser-based collaborative UI design tool, for example, the UI design tool can be a figma design tool, a sketch design tool, etc. The UI design tool can support the export of html files, and components with different functions are provided in the UI design tool. The target UI design drawing is a web version of the UI design drawing, and the target UI design drawing includes multiple components that constitute the target UI interface. The synchronous file reading method can be the fs.readFilesSync method provided by node.js. The target UI interface can be a medical UI interface related to the medical platform, such as a medical data management interface; or, the target UI interface can be a game interface, a music interface, an instant messaging interface, etc., which is not limited in this application.

[0038] In one embodiment, a UI design tool may include multiple UI design drawings, each of which can be used to create a UI interface. The user can select a target UI design drawing from multiple UI design drawings and trigger a confirmation operation on the target UI design drawing. The computer device can then detect the confirmation operation on the target UI design drawing. Among them, the method of triggering the confirmation operation of the target UI design drawing can be clicking on the target UI design drawing, double-clicking the target UI design drawing, a specific gesture (such as an OK gesture), etc.; or, the method of triggering the confirmation operation of the target UI design drawing can be a voice-triggered method, such as voice input "Confirm target UI design drawing", the computer device can perform voice recognition on the "Confirm target UI design drawing", and trigger the confirmation operation on the target UI design drawing based on the voice recognition result "Confirm".

[0039] In one embodiment, a computer device can select appropriate components in a UI design tool according to the UI interface requirements of a certain user or enterprise to generate a target UI design drawing corresponding to the target UI interface in real time, and after generating the target UI design drawing, a confirmation button and a cancel button can be displayed. When the user triggers the confirmation button, the computer device can detect the confirmation operation for the target UI design drawing; when the user triggers the cancel button, the computer device can detect the cancel operation for the target UI design drawing. When the cancel operation is detected, it means that the target UI design drawing needs to be modified or the user or enterprise has canceled the target UI design drawing. In one embodiment, a confirmation button and a cancel button are always displayed in the UI design tool, and the confirmation button or the cancel button can be clicked at any time. The embodiments of the present application are not limited to this.

[0040] S202, extracting component information of multiple components constituting the target UI interface and page size information of the target UI interface from the target HTML file. The components may be input boxes, various buttons, TextView (text class) and other components, the component information may include the width, height, position coordinates, component name, component type, component attributes and the like of the components, and the page size information may include the size of the target UI interface (such as width and height).

[0041] It can be seen from step S201 that the target UI design drawing includes multiple components that constitute the target UI interface. Therefore, the target html file obtained by the computer device includes multiple components and component information of each component, and page size information of the target UI interface. The computer device can obtain the component information of the multiple components that constitute the target UI interface and the page size information of the target UI interface from the target html file.

[0042] In one embodiment, the specific implementation of step S202 can be: first, the target html file is converted into a coding format using a variable-length character encoding rule to obtain a target format conversion result corresponding to the target html file, wherein the long character encoding rule is a variable-length character encoding for Unicode. It can be used to represent any character in the Unicode standard, and the variable-length character encoding rule can be a utf-8 (Universal Character Set / Unicode Transformation Format, 8 bits) encoding rule, a utf-16 encoding rule, etc., which is not limited in the embodiment of the present application. The variable-length character encoding rule can facilitate the later acquisition of component information of the component from the format conversion result. Then the computer device can obtain the component information of multiple components for constructing the target UI interface and the page size information of the target UI interface from the format conversion result.

[0043] In one embodiment, the computer device can use a regular matching method to obtain component information of multiple components that construct the target UI interface and page size information of the target UI interface from the target format conversion result. As an implementation method, the computer device can obtain a regular expression for regular matching, and the regular expression can be used to indicate the target starting position and target ending position for obtaining the component information of each component and the page size information of the UI interface. It can be understood that: the above regular expression can be used for any UI interface to determine the component information of each component constituting any UI interface and the target starting position and target ending position of the page size information of the arbitrary UI interface, that is, the html file corresponding to the UI design drawing of any UI interface is processed as above to obtain the format conversion result, and the target starting position and target ending position of the component information of each component and the page size information of the UI interface in the format conversion result are the same. It should be noted that the target starting position and target ending position mentioned in this application can not only refer to the actual position in the format conversion result, but also refer to a certain character because the format conversion result corresponds to a string. As another implementation method, the computer device can obtain a regular expression corresponding to the UI interface type, and the regular expression is used to indicate the target starting position and target ending position for obtaining the component information of each component and the page size information of the UI interface. At this time, it can be understood that: the regular expressions of the same UI interface type are the same, and the target starting position and target ending position in the component information of each component and the page size information of the UI interface indicated by the regular expression are the same; the regular expressions of different UI type interfaces are different. For example, the regular expression of UI interface type 1 is used to indicate the target starting position 1 and target ending position 2 for obtaining the component information of each component and the page size information of the UI interface; the regular expression of UI interface type 2 is used to indicate the target starting position 3 and target ending position 4 for obtaining the component information of each component and the page size information of the UI interface.

[0044] As another implementation, the UI interface is composed of multiple components, and the component information of different types of components may be located in different positions in the format conversion result. In this case, the computer device can obtain a regular expression corresponding to the component type, and the regular expression of the component type is used to indicate the target starting position and target ending position for obtaining the component information of each component and the page size information of the UI interface. As another implementation, each html file may correspond to a regular expression, and the computer device can obtain the regular expression of the target html file, and the regular expression of the target html file is used to indicate the target starting position and target ending position for obtaining the component information of each component and the page size information of the target UI interface. As an implementation, the computer device can also obtain a regular expression corresponding to a file type, and the file type is an html file type. Each html file includes one or more script tags. The component information of each component and the page size information of the UI interface are stored in one or more script tags. In this case, the regular expression obtained by the computer device is / <script>\s?var\sFILE_DAtA\s=\s(.+),\bPAGED_FRAMES / 。计算机设备可以根据正则表达式可以确定目标起始位置为script,并确定目标结束位置为PAGED_FRAME。

[0045] 然后,在获取到正则表达式之后,计算机设备可以根据正则表达式在目标格式转换结果中确定目标起始位置和目标结束位置,并从目标起始位置和目标结束位置之间的字符信息中提取目标UI界面中每个组件的组件信息和目标UI界面的页面尺寸信息。承接上述例子,计算机设备通过上述变长字符编码对目标html编码处理后,目标html文件的目标格式转换结果对应有一系列字符串,而每个组件的组件信息和页面尺寸信息在script标签中同样也是对应着一串字符串对应的字符信息,计算机设备可以确定目标格式转换结果中的目标起始位置scrip和目标结束位置PAGED_FRAMES,并从scrip和PAGED_FRAMES之间的字符串对应的字符信息提取出每个组件的组件信息和页面尺寸信息,当根据正则表达式查找完成所有的起始位置为script,结束位置为PAGED_FRAMES之间的字符串对应的字符信息之后,最终得到多个组件的组件信息和页面尺寸信息。在实际应用过程中,目标起始位置和目标结束位置之间的字符串对应的字符信息可以认为包括了需要提取的每个组件的组件信息以及目标UI界面的页面尺寸信息。

[0046] S203、根据每个组件的组件信息和页面尺寸信息确定每个组件在目标UI界面中的布局信息和组件样式,并基于每个组件在目标UI界面中的布局信息和组件样式生成组件结构化信息。

[0047] 其中,布局信息可以包括组件在目标UI界面中的位置坐标、组件的组件高度和宽度,组件样式可以包括动画样式、背景样式、形状样式等等,当该组件包含字体时,该组件样式还可以包括字体样式等等。组件结构化信息可以是指json树或者json数组。

[0048] 在一个实施例中,根据每个组件的组件信息和页面尺寸信息确定每个组件在目标UI界面中的布局信息和组件样式的具体实现方式可以是:根据每个组件的组件信息和页面尺寸信息确定各个组件之间的组件关系以及每个组件在目标UI界面的布局信息;具体的,该页面尺寸信息包括界面宽度和界面高度,组件信息包括组件的位置坐标、组件高度和组件宽度。计算机设备可以根据目标UI界面的界面高度和界面宽度构成坐标体系,根据每个组件的位置坐标、组件宽度和组件高度对每个组件进行排序,得到各个组件之间的组件关系以及每个组件在目标UI界面的布局信息。例如,每个组件的位置坐标可以用(x,y)表示,x值从左到右递增,y值从下到上递增,也就是x值较大的在右侧,y值较大到的在上方,设2个组件,组件1的位置坐标为(0,0),组件高度为1,组件宽度为2;组件2的位置坐标(3,4),组件高度为3,组件宽度为1,计算机设备根据目标UI界面的界面高度和界面宽度构成坐标体系,根据2个组件的位置坐标、组件高度和组件宽度对每个组件排序,得到如图3所示的组件关系和每个号组件的布局信息。然后计算机设备可以根据各个组件之间的组件关系以及每个组件在目标UI界面的布局信息确定每个组件的组件样式。例如,2个组件的组件关系为:组件2在组件1在右上方,计算机设备可以根据每个组件在目标UI界面的布局信息和2个组件之间的组件关系可以确定组件1的组件样式和组件2的组件样式可以均为矩形框。

[0049] 在一个实施例中,计算机设备基于每个组件在所述目标UI界面中的布局信息和组件样式生成组件结构化信息的具体实现方式可以是根据每个组件在目标UI界面中的布局信息和组件样式,采用公共组件flex Container对每个组件进行布局处理,得到所述目标UI界面的弹性布局;并根据弹性布局配置每个组件的组件样式字段、布局信息字段和第一组件属性字段,其中每个组件的第一组件属性字段可以基于每个组件的组件信息确定的,第一组件属性字段包括组件的大小、组件类型、组件名等等信息;然后计算机设备可以根据每个组件的组件样式字段、布局信息字段和第一组件属性字段生成组件结构化信息。其中,弹性布局可以称为flex布局,Flex布局的主要思想是使父容器能够调节子项目的宽度 / 高度 / 排列方式等等;flex布局中包括12属性,其中作用于父容器有6大属性。作用于子项目有6大属性,在本申请实施例中,Flex布局的子项目为组件;计算机设备可以根据布局信息和组件样式,采用flex Container中的属性进行布局处理,得到目标UI界面的弹性布局,其中,弹性布局包括调节后的各组件的组件样式和布局信息。然后计算机设备可以根据调节后的各组件的组件样式和布局信息可以配置每个组件的组件样式字段的字段信息、布局信息字段的字段信息,以及第一组件属性字段的字段信息。

[0050] 在一个实施例中,计算机设备根据每个组件的组件样式字段布局信息字段和第一组件属性字段生成组件结构化信息的具体实现方式可以是:计算机设备基于每个组件的组件样式字段、布局信息字段和第一组件属性字段生成初始结构化信息;可以获取提取指示信息,该提取指示信息用于指示获取目标字段的字段信息,其中,目标字段可以是上述组件样式字段、布局信息字段和第一组件属性字段中的一个或多个;然后从初始结构化信息中提取该提取指示信息所指示的目标字段的字段信息,并将提取到的目标字段的字段信息生成组件结构化信息。其中,通过提取指示信息可以提取想要的字段的字段信息,同时还可以去除无用字段的字段信息。例如,在生成组件结构化信息的时候,可以只需要每个组件的组件样式字段的字段信息和第一组件属性字段的字段信息,计算机设备获取的提取指示信息可以用于指示获取该组件样式字段的字段信息和第一组件属性字段的字段信息;然后从初始结构化信息提取组件样式字段的字段信息以及第一组件属性字段的字段信息,并根据提取到的组件样式字段的字段信息以及第一组件属性字段的字段信息生成组件结构化信息。

[0051] 在一个实施例中,可能存在UI设计工具中使用的组件的组件名称与前端使用的组件名称对应不上的情况,在这种情况下,根据组件结构化信息无法生成前端代码,基于此,上述构成目标UI界面的多个组件均为UI设计工具中的组件,计算机设备可以基于每个组件的组件样式字段、布局信息字段和第一组件属性字段生成组件结构化信息的具体实现方式可以是:针对构成目标UI界面的多个组件中的目标组件,计算机设备根据UI设计工具包括的组件与前端包括的组件之间的对应关系,判断目标组件的组件属性是否与相对应目标前端组件的组件属性相同,其中,组件属性至少包括以下一种:组件名和组件类型;若目标组件的组件属性与相对应目标前端组件的组件属性不相同,则为目标组件添加第二组件属性字段,第二组件属性字段的字段信息包括目标前端组件的组件属性;然后基于每个组件的组件样式字段、布局信息字段、第一组件属性字段和所述第二组件属性字段生成组件结构化信息。通过增加第二组件属性字段不仅能够生成前端代码,并调用该前端代码时不会出现保存,而且保留第一组件属性字段可以方便后续从UI设计工具中查找第一组件属性字段所指示的组件。

[0052] S204、遍历组件结构化信息生成文档对象模型dom树,并对dom树进行渲染处理,得到目标UI界面对应的前端代码。

[0053] 在具体实现中,计算机设备可以利用解析器解析组件结构化信息,并基于解析结果确定dom树的父节点和父节点对应的子节点,然后根据父节点对应的信息和子节点对应的信息构建dom树。然后计算机设备可以对dom树进行渲染处理,可以理解为将dom树中每个节点上的信息转换成前端能够识别的格式的信息,即生成前端代码,以使得可以直接运行该前端代码就可以生成目标UI界面。在一个实施例中,计算机设备对dom树进行渲染处理的具体实现方式可以是:计算机设备接收CSS(Cascading Style Sheet,式级联样式表)解析器对组件结构化信息进行解析得到的CSS样式信息,并将CSS样式信息和DOM树上的节点的信息进行渲染,得到前端代码

[0054] S205、调用前端代码生成目标UI界面。

[0055] 在一个实施例中,在生成目标UI界面之后,计算机设备可以向区块链节点发送前端代码和目标UI界面对应的目标UI设计图,区块链节点可以对前端代码和目标UI设计图进行合法性验证,并在合法性验证通过后,将前端代码和目标UI设计图生成区块,并将该区块发送到区块链其他节点进行共识,并在共识通过后,将该区块保存到区块链中。

[0056] 在本申请实施例中,当检测到针对目标UI设计图的确认操作时,采用同步读取文件方法获取目标UI设计图对应的目标超文本标记语言html文件,目标UI设计图是在UI设计工具生成的,目标UI设计图用于构建目标UI界面;从目标html文件中提取构成目标UI界面的多个组件的组件信息和目标UI界面的页面尺寸信息;根据每个组件的组件信息和页面尺寸信息确定每个组件在目标UI界面中的布局信息和组件样式,并基于每个组件在目标UI界面中的布局信息和组件样式生成组件结构化信息;遍历组件结构化信息生成文档对象模型dom树,并对dom树进行渲染处理,得到目标UI界面对应的前端代码;调用前端代码生成目标UI界面,以直接获取该目标设计图对应的html文件,并自动对html文件进行处理,生成目标UI界面,无需前端开发师对该目标UI设计图进行理解,然后编写相应代码来生成目标UI界面,提高了界面开发的效率,降低开发成本。

[0057] 基于上述界面生成方法实施例的描述,本申请实施例还公开了一种界面生成装置,该界面生成装置可以是运行于上述所提及的计算机设备中的一个计算机程序(包括程序代码)。该界面生成装置可以执行图2所示的方法。请参见图4,所述界面生成装置可以运行如下单元:

[0058] 获取单元401,用于当检测到针对目标UI设计图的确认操作时,采用同步读取文件方法获取所述目标UI设计图对应的目标超文本标记语言html文件,所述目标UI设计图是通过UI设计工具生成的,所述目标UI设计图用于构建目标UI界面;

[0059] 处理单元402,用于从所述目标html文件中提取构成所述目标UI界面的多个组件的组件信息和所述目标UI界面的页面尺寸信息;

[0060] 所述处理单元402,还用于根据每个组件的组件信息和所述页面尺寸信息确定所述每个组件在所述目标UI界面中的布局信息和组件样式,并基于所述每个组件在所述目标UI界面中的布局信息和组件样式生成组件结构化信息;

[0061] 所述处理单元402,还用于遍历所述组件结构化信息生成文档对象模型dom树,并对所述dom树进行渲染处理,得到所述目标UI界面对应的前端代码;

[0062] 所述处理单元402,还用于调用所述前端代码生成所述目标UI界面。

[0063] 在一个实施例中,所述处理单元在从所述目标html文件中提取构成所述目标UI界面的多个组件的组件信息和所述目标UI界面的页面尺寸信息时,可具体用于:

[0064] 采用变长字符编码规则对所述目标html文件进行编码格式转换,得到所述目标html文件对应的目标格式转换结果;

[0065] 从所述目标格式转换结果中,获取构建所述目标UI界面的多个组件的组件信息和所述目标UI界面的页面尺寸信息。

[0066] 在一个实施例中,所述处理单元402在从所述目标格式转换结果中,获取构建所述目标UI界面的多个组件的组件信息和所述目标UI界面的页面尺寸信息时,可具体用于:

[0067] 获取正则表示式,所述正则表达式用于指示获取每个组件的组件信息和UI界面的页面尺寸信息的目标起始位置和目标结束位置;

[0068] 根据所述正则表达式在所述目标格式转换结果中确定所述目标起始位置和所述目标结束位置,并从所述目标起始位置和所述目标结束位置之间的字符信息中提取所述目标UI界面中每个组件的组件信息和所述目标UI界面的页面尺寸信息。

[0069] 在一个实施例中,所述处理单元402在根据每个组件的组件信息和所述页面尺寸信息确定所述每个组件在所述目标UI界面中的布局信息和组件样式时,可具体用于:

[0070] 根据每个组件的组件信息和所述页面尺寸信息确定各个组件之间的组件关系以及所述每个组件在所述目标UI界面的布局信息;

[0071] 根据所述各个组件之间的组件关系以及所述每个组件在所述目标UI界面的布局信息确定所述每个组件的组件样式。

[0072] 在一个实施例中,所述处理单元在基于所述每个组件在所述目标UI界面中的布局信息和组件样式生成组件结构化信息时,可具体用于:

[0073] 根据每个组件在所述目标UI界面中的布局信息和组件样式,采用公共组件flexContainer对所述每个组件进行布局处理,得到所述目标UI界面的弹性布局;

[0074] 根据所述弹性布局配置所述每个组件的组件样式字段、布局信息字段和第一组件属性字段;

[0075] 根据所述每个组件的组件样式字段、布局信息字段和第一组件属性字段生成组件结构化信息。

[0076] 在一个实施例中,所述处理单元402在根据所述每个组件的组件样式字段、布局信息字段和第一组件属性字段生成组件结构化信息时,可具体用于:

[0077] 基于所述每个组件的组件样式字段、布局信息字段和第一组件属性字段生成初始结构化信息;

[0078] 获取提取指示信息,所述提取指示信息用于指示获取目标字段的字段信息;

[0079] 从所述初始结构化信息提取所述提取指示信息所指示的目标字段的字段信息,并将提取到的目标字段的字段信息生成组件结构化信息。

[0080] 在一个实施例中,所述多个组件为UI设计工具中的组件;所述处理单元402在根据所述每个组件的组件样式字段、布局信息字段和第一组件属性字段生成组件结构化信息时,可具体用于:

[0081] 针对所述多个组件中的目标组件,根据所述UI设计工具包括的组件与前端包括的组件之间的对应关系,判断所述目标组件的组件属性是否与相对应目标前端组件的组件属性相同,所述组件属性至少包括以下一种:组件名和组件类型;

[0082] 若所述目标组件的组件属性与相对应目标前端组件的组件属性不相同,则为所述目标组件添加第二组件属性字段,所述第二组件属性字段的字段信息包括所述目标前端组件的组件属性;

[0083] 基于所述每个组件的组件样式字段、布局信息字段、第一组件属性字段和所述第二组件属性字段生成组件结构化信息。

[0084] 可以理解的是,本实施例的界面生成装置的各功能单元可根据上述方法实施例图2中的方法具体实现,其具体实现过程可以参照上述方法实施例图2的相关描述,此处不再赘述。

[0085] 进一步地,请参见图5,图5是本申请实施例提供的一种计算机设备的结构示意图。上述图2对应实施例中的计算机设备可以为图5所示的计算机设备。如图5所示,计算机设备可以包括:处理器501和存储器504,可选地,计算机设备还可以包括输入设备502和输出设备503。上述处理器501、输入设备502、输出设备503和存储器504通过总线505连接。存储器504用于存储计算机程序,所述计算机程序包括程序指令,处理器501用于执行存储器504存储的程序指令。

[0086] 在本申请实施例中,处理器501通过运行存储器504中的可执行程序代码,执行如下操作:

[0087] 当检测到针对目标UI设计图的确认操作时,采用同步读取文件方法获取所述目标UI设计图对应的目标超文本标记语言html文件,所述目标UI设计图是在UI设计工具生成的,所述目标UI设计图用于构建目标UI界面;

[0088] 从所述目标html文件中提取构成所述目标UI界面的多个组件的组件信息和所述目标UI界面的页面尺寸信息;

[0089] 根据每个组件的组件信息和所述页面尺寸信息确定所述每个组件在所述目标UI界面中的布局信息和组件样式,并基于所述每个组件在所述目标UI界面中的布局信息和组件样式生成组件结构化信息;

[0090] 遍历所述组件结构化信息生成文档对象模型dom树,并对所述dom树进行渲染处理,得到所述目标UI界面对应的前端代码;

[0091] 调用所述前端代码生成所述目标UI界面。

[0092] 在一个实施例中,所述处理器501在从所述目标html文件中提取构成所述目标UI界面的多个组件的组件信息和所述目标UI界面的页面尺寸信息时,可具体用于:

[0093] 采用变长字符编码规则对所述目标html文件进行编码格式转换,得到所述目标html文件对应的目标格式转换结果;

[0094] 从所述目标格式转换结果中,获取构建所述目标UI界面的多个组件的组件信息和所述目标UI界面的页面尺寸信息。

[0095] 在一个实施例中,所述处理器501在从所述目标格式转换结果中,获取构建所述目标UI界面的多个组件的组件信息和所述目标UI界面的页面尺寸信息时,可具体用于:

[0096] 获取正则表示式,所述正则表达式用于指示获取每个组件的组件信息和UI界面的页面尺寸信息的目标起始位置和目标结束位置;

[0097] 根据所述正则表达式在所述目标格式转换结果中确定所述目标起始位置和所述目标结束位置,并从所述目标起始位置和所述目标结束位置之间的字符信息中提取所述目标UI界面中每个组件的组件信息和所述目标UI界面的页面尺寸信息。

[0098] 在一个实施例中,所述处理器501在根据每个组件的组件信息和所述页面尺寸信息确定所述每个组件在所述目标UI界面中的布局信息和组件样式时,可具体用于:

[0099] 根据每个组件的组件信息和所述页面尺寸信息确定各个组件之间的组件关系以及所述每个组件在所述目标UI界面的布局信息;

[0100] 根据所述各个组件之间的组件关系以及所述每个组件在所述目标UI界面的布局信息确定所述每个组件的组件样式。

[0101] 在一个实施例中,所述处理器501在基于所述每个组件在所述目标UI界面中的布局信息和组件样式生成组件结构化信息时,可具体用于:

[0102] 根据每个组件在所述目标UI界面中的布局信息和组件样式,采用公共组件flexContainer对所述每个组件进行布局处理,得到所述目标UI界面的弹性布局;

[0103] 根据所述弹性布局配置所述每个组件的组件样式字段、布局信息字段和第一组件属性字段;

[0104] 根据所述每个组件的组件样式字段、布局信息字段和第一组件属性字段生成组件结构化信息。

[0105] 在一个实施例中,所述处理器501在根据所述每个组件的组件样式字段、布局信息字段和第一组件属性字段生成组件结构化信息时,可具体用于:

[0106] 基于所述每个组件的组件样式字段、布局信息字段和第一组件属性字段生成初始结构化信息;

[0107] 获取提取指示信息,所述提取指示信息用于指示获取目标字段的字段信息;

[0108] 从所述初始结构化信息提取所述提取指示信息所指示的目标字段的字段信息,并将提取到的目标字段的字段信息生成组件结构化信息。

[0109] 在一个实施例中,所述多个组件为UI设计工具中的组件;所述处理器501在根据所述每个组件的组件样式字段、布局信息字段和第一组件属性字段生成组件结构化信息时,可具体用于:

[0110] 针对所述多个组件中的目标组件,根据所述UI设计工具包括的组件与前端包括的组件之间的对应关系,判断所述目标组件的组件属性是否与相对应目标前端组件的组件属性相同,所述组件属性至少包括以下一种:组件名和组件类型;

[0111] 若所述目标组件的组件属性与相对应目标前端组件的组件属性不相同,则为所述目标组件添加第二组件属性字段,所述第二组件属性字段的字段信息包括所述目标前端组件的组件属性;

[0112] 基于所述每个组件的组件样式字段、布局信息字段、第一组件属性字段和所述第二组件属性字段生成组件结构化信息。

[0113] 应当理解,在本申请实施例中,所称处理器501可以是中央处理单元(CentralProcessing Unit,CPU),该处理器501还可以是其他通用处理器、数字信号处理器(DigitalSignal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。

[0114] 该存储器504可以包括只读存储器和随机存取存储器,并向处理器501提供指令和数据。存储器504的一部分还可以包括非易失性随机存取存储器。

[0115] 该输入设备502可以包括键盘等,并向处理器501输入界面需求;该输出设备503可以包括显示器等。

[0116] 具体实现中,本申请实施例中所描述的处理器501、输入设备502、输出设备503和存储器504可执行上述所有实施例中描述的实现方式,也可执行上述装置中所描述的实现方式,在此不再赘述。

[0117] 本申请实施例中提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令被处理器执行时,可执行上述所有实施例中所执行的步骤。

[0118] 本申请实施例还提供一种计算机程序产品或计算机程序,计算机程序产品或计算机程序包括计算机指令,计算机指令存储在计算机可读存储介质中,计算机指令被计算机设备的处理器执行时,执行上述所有实施例中的方法。

[0119] 本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)或随机存储记忆体(Random AccessMemory,RAM)等。需要强调的是,为进一步保证上述数据的私密和安全性,上述所涉及的目标慢性病的知识图谱还可以存储于一区块链的节点中。其中,本申请所指区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链(Blockchain),本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层等。

[0120] 以上所揭露的仅为本申请一种较佳实施例而已,当然不能以此来限定本申请之权利范围,本领域普通技术人员可以理解实现上述实施例的全部或部分流程,并依本申请权利要求所作的等同变化,仍属于发明所涵盖的范围。< / script>

Claims

1. An interface generation method, characterized in that: include: When a confirmation operation for a target UI design drawing is detected, a target html file corresponding to the target UI design drawing is obtained by using a synchronous file reading method, wherein the target UI design drawing is generated by a UI design tool and is used to construct a target UI interface; Extracting component information of a plurality of components constituting the target UI interface and page size information of the target UI interface from the target html file; Determine the layout information and component style of each component in the target UI interface according to the component information of each component and the page size information, and generate component structured information based on the layout information and component style of each component in the target UI interface; Traversing the component structured information to generate a document object model DOM tree, and rendering the DOM tree to obtain the front-end code corresponding to the target UI interface; Calling the front-end code to generate the target UI interface; The step of extracting component information of multiple components constituting the target UI interface and page size information of the target UI interface from the target HTML file includes: Using variable-length character encoding rules to convert the encoding format of the target HTML file to obtain a target format conversion result corresponding to the target HTML file; Acquire component information of multiple components for constructing the target UI interface and page size information of the target UI interface from the target format conversion result; The step of determining the layout information and component style of each component in the target UI interface according to the component information of each component and the page size information includes: Determine the component relationship between the components and the layout information of each component on the target UI interface according to the component information of each component and the page size information; Determining a component style of each component according to the component relationship between the components and the layout information of each component on the target UI interface; The generating component structured information based on the layout information and component style of each component in the target UI interface includes: According to the layout information and component style of each component in the target UI interface, a common component flexContainer is used to perform layout processing on each component to obtain a flexible layout of the target UI interface; Configure the component style field, the layout information field and the first component attribute field of each component according to the elastic layout; Component structured information is generated according to the component style field, the layout information field and the first component attribute field of each component.

2. The method according to claim 1, characterized in that The step of acquiring component information of a plurality of components for constructing the target UI interface and page size information of the target UI interface from the target format conversion result includes: Obtain a regular expression, where the regular expression is used to indicate a target starting position and a target ending position for obtaining component information of each component and page size information of the UI interface; The target start position and the target end position are determined in the target format conversion result according to the regular expression, and component information of each component in the target UI interface and page size information of the target UI interface are extracted from character information between the target start position and the target end position.

3. The method according to claim 1, characterized in that The generating component structured information according to the component style field, the layout information field and the first component attribute field of each component includes: Generate initial structured information based on the component style field, the layout information field and the first component attribute field of each component; Acquire extraction instruction information, where the extraction instruction information is used to indicate the acquisition of field information of a target field; The field information of the target field indicated by the extraction indication information is extracted from the initial structured information, and component structured information is generated from the extracted field information of the target field.

4. The method according to claim 1, characterized in that: The multiple components are components in a UI design tool; generating component structured information according to a component style field, a layout information field, and a first component attribute field of each component includes: For a target component among the multiple components, judging whether a component attribute of the target component is the same as a component attribute of a corresponding target front-end component according to a correspondence between components included in the UI design tool and components included in the front-end, wherein the component attribute includes at least one of the following: a component name and a component type; If the component attribute of the target component is different from the component attribute of the corresponding target front-end component, a second component attribute field is added to the target component, and the field information of the second component attribute field includes the component attribute of the target front-end component; Component structural information is generated based on the component style field, the layout information field, the first component attribute field and the second component attribute field of each component.

5. An interface generation device, characterized in that: include: An acquisition unit, configured to acquire a target html file corresponding to the target UI design drawing by a synchronous file reading method when a confirmation operation on the target UI design drawing is detected, wherein the target UI design drawing is generated by a UI design tool and is used to construct a target UI interface; A processing unit, used to extract component information of multiple components constituting the target UI interface and page size information of the target UI interface from the target HTML file; The processing unit is further used to determine the layout information and component style of each component in the target UI interface according to the component information of each component and the page size information, and generate component structured information based on the layout information and component style of each component in the target UI interface; The processing unit is further used to traverse the component structured information to generate a document object model DOM tree, and render the DOM tree to obtain the front-end code corresponding to the target UI interface; The processing unit is further used to call the front-end code to generate the target UI interface; Wherein, when the processing unit extracts the component information of the multiple components constituting the target UI interface and the page size information of the target UI interface from the target html file, it can be specifically used to: Using variable-length character encoding rules to convert the encoding format of the target HTML file to obtain a target format conversion result corresponding to the target HTML file; Acquire component information of multiple components for constructing the target UI interface and page size information of the target UI interface from the target format conversion result; Wherein, when the processing unit determines the layout information and component style of each component in the target UI interface according to the component information of each component and the page size information, it can be specifically used to: Determine the component relationship between the components and the layout information of each component on the target UI interface according to the component information of each component and the page size information; Determining a component style of each component according to the component relationship between the components and the layout information of each component on the target UI interface; Wherein, when the processing unit generates the component structured information based on the layout information and component style of each component in the target UI interface, it can be specifically used to: According to the layout information and component style of each component in the target UI interface, a common component flexContainer is used to perform layout processing on each component to obtain a flexible layout of the target UI interface; Configure the component style field, the layout information field and the first component attribute field of each component according to the elastic layout; Component structured information is generated according to the component style field, the layout information field and the first component attribute field of each component.

6. A computer device, characterized in that: comprising a memory for storing a computer program; The processor calls the computer program in the memory to execute the interface generation method according to any one of claims 1 to 4.

7. A computer storage medium, characterized in that: The computer storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, the interface generation method according to any one of claims 1 to 4 is executed.