React component automatic generation method and device, equipment and medium
Through the unified conversion of icon files and the construction of component library, the problem of time-consuming and error-prone traditional manual conversion is solved, the automated generation of React components and efficient management of component libraries are realized, and the development efficiency and user experience are improved.
Patent Information
- Application Number
- CN202411153267.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-12-03
AI Technical Summary
In the traditional way, developers need to manually convert SVG files into React components and manage them, which is time-consuming and error-prone, and lacks a unified component library interface, resulting in complex integration and use, which easily leads to version inconsistency and quality problems.
Provides a method of automatic generation of React components, which can be used to collect icon files, convert them to SVG format, and convert SVG format files into React component format files, and build a React icon component library for users to access and use.
It realizes the automated generation of user-defined components, improves development efficiency, ensures the timeliness and consistency of components, and improves user experience.
Smart Images

Figure CN119065708A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Web front-end development, and in particular to a method, device, equipment and medium for automatically generating a React component. Background Art
[0002] In modern web development, the use of SVG icons and React components has become mainstream. Due to its vector characteristics, SVG icons can maintain high-quality display at different resolutions, while React components are favored by developers because of their componentization and reusability.
[0003] However, in the traditional way, developers need to manually convert each SVG file into a React component and manage it, which is usually a time-consuming and error-prone process. At the same time, manually managing and maintaining a large number of icon files and component libraries can easily lead to version inconsistencies and quality issues. In addition, there is usually a lack of a unified component library interface in the process of converting SVG to React components, which makes integration and use complicated. Summary of the invention
[0004] Based on this, the present invention provides a method, device, equipment and medium for automatically generating React components to solve the problem that SVG files are not intelligent and efficient when converting React components.
[0005] In a first aspect, an embodiment of the present invention provides a method for automatically generating a React component, the method comprising:
[0006] Collecting icon files uploaded by the target user to the file storage system, and storing the collected icon files in the first memory; wherein the file format of the icon files includes a non-SVG format or an SVG format;
[0007] After the icon files of various file formats stored in the first memory are uniformly converted into SVG format files, an operation of converting each SVG format file into a React component format file is performed, and the React component format files obtained by the successful conversion are stored in the second memory;
[0008] The React component format files stored in the second memory are assembled into a React icon component library for publishing, so that the target user can access and use the React icon component library.
[0009] In a second aspect, an embodiment of the present invention further provides a device for automatically generating a React component, the device comprising:
[0010] An icon file collection module is used to collect icon files uploaded by target users to the file storage system, and store the collected icon files in the first memory; wherein the file format of the icon files includes a non-SVG format or an SVG format;
[0011] a format conversion module, configured to convert the icon files of various file formats stored in the first memory into SVG format files, convert the SVG format files into React component format files, and store the successfully converted React component format files into the second memory;
[0012] The component library publishing module is used to assemble the React component format files stored in the second memory into a React icon component library for publishing, so that the target user can access and use the React icon component library.
[0013] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute a method for automatically generating a React component according to any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement a method for automatically generating a React component according to any embodiment of the present invention when executed.
[0018] The technical solution of the embodiment of the present invention supports converting icon files in various formats uploaded by users into SVG format files. At the same time, by establishing a first memory and a second memory, the successfully converted React component format files are screened out, and a React icon component library is constructed based on the data in the second memory. Finally, users can successfully use the automatically generated exclusive chart components in their projects. The whole process generates custom components for each target user, improves development efficiency, ensures timeliness and consistency of user use, and enhances user experience.
[0019] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0021] Figure 1 is a flowchart of a method for automatically generating a React component according to Embodiment 1 of the present invention;
[0022] Figure 2 is a flowchart of another method for automatically generating a React component according to Embodiment 2 of the present invention;
[0023] Figure 3 is a structural diagram of a React component automatic generation device provided according to Embodiment 3 of the present invention;
[0024] Figure 4 It is a structural schematic diagram of an electronic device for implementing a method for automatically generating a React component according to an embodiment of the present invention. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] Embodiment 1
[0028] Figure 1 This is a flowchart of a method for automatically generating a React component provided in the first embodiment of the present invention. This embodiment is applicable to the case of converting a user's custom icon into a React component. The method can be executed by a device for automatically generating a React component. The device can be implemented in the form of hardware and / or software. The device can be configured in the LogEasy product. Figure 1 As shown, the method includes:
[0029] S110, collecting icon files uploaded by the target user to the file storage system, and storing the collected icon files in the first memory; wherein the file format of the icon files includes a non-SVG format or an SVG format.
[0030] In real enterprise-level development, the use of icon components is indispensable. Currently, most front-end frameworks provide a variety of React components and built-in corresponding icons, but this often cannot fully meet the requirements of enterprises. Enterprises need to apply custom icons of their own unique elements to components to generate characteristic applications. Therefore, in an embodiment of the present invention, enterprise users will upload custom icon elements to the file storage system in advance, and the first memory is a memory for storing all custom icon elements of the current target user.
[0031] S120. After the icon files of various file formats stored in the first memory are uniformly converted into SVG format files, an operation of converting each SVG format file into a React component format file is performed, and the React component format files obtained by successful conversion are stored in the second memory.
[0032] As a vector graphic, SVG will not be distorted or blurred due to scaling. Secondly, SVG is based on XML and can be easily edited and customized through a text editor, and allows graphics to be created in a declarative manner, which is very consistent with the concept of React. Therefore, in an embodiment of the present invention, if the original icon file uploaded by the user is in SVG format, the SVG can be directly converted to the React component format, but if it contains non-SVG format files, it is necessary to first convert the non-SVG format files into SVG format files before converting the React components. Different from the first memory, the second memory is a memory for storing React component format files.
[0033] Optionally, performing the operation of converting each SVG format file into a React component format file, and storing the successfully converted React component format file into the second storage device, may include:
[0034] Extract the attribute value of the React attribute of each SVG format file, and obtain the first type of SVG format files whose attribute value is empty or false;
[0035] Execute the operation of converting each SVG format file of the first category into a React component format file;
[0036] Obtain the first-class React component format file obtained by successful format conversion, and set the attribute value of the React attribute of each first-class React component format file to a true value;
[0037] Each file in the first memory whose attribute value of the React attribute is true is stored in the second memory as a React component format file obtained by successful conversion.
[0038] The React attribute represents a flag or mark, which is used to determine whether a certain state corresponding to the current attribute exists. Accordingly, in the embodiment of the present invention, isReactFlag can be used to represent the React attribute. When the attribute value of isReactFlag is a true value, it means that the React attribute exists, that is, the React component format file to which the React attribute belongs exists, that is, the SVG format file is successfully converted into the React component format file, wherein the SVG format file successfully converted into the React component format file is called a first-category format file.
[0039] Furthermore, performing the operation of converting each SVG format file of the first category into a React component format file may include:
[0040] Parse the first type of SVG format file and convert the first type of SVG format file into JSX syntax;
[0041] The JSX syntax is imported into a specific format conversion script to generate a React component format file corresponding to the first type of SVG format file.
[0042] A syntax extension called JSX is introduced in React components. Tools such as SVGR can parse SVG format files, extract SVG vector graphics codes, and convert them into legal JSX language format, so as to embed vector graphics in React components.
[0043] Optionally, before storing each file in the first storage device having a true value of the attribute value of the React attribute in the second storage device as a successfully converted React component format file, the method may further include:
[0044] After obtaining the attribute value of the React attribute of each second-category SVG format file that fails in format conversion and setting it uniformly to a false value, an exception log corresponding to each second-category SVG format file is generated, and the exception log is provided to the administrator side, so that the administrator side can perform repair on each second-category SVG format file;
[0045] When receiving the repaired second-category SVG format files fed back by the administrator, converting each of the repaired second-category SVG format files into a React component format file;
[0046] The second-type React component format files obtained by successful format conversion are obtained, and the attribute value of the React attribute of each second-type React component format file is set to a true value.
[0047] For the SVG format files that are not successfully converted, they are recorded as second-class SVG format files, and the React attribute values are set to false. At the same time, the generated exception log records the date, time, code location, error code and other information. The administrator needs to analyze and repair the corresponding second-class SVG format files in conjunction with the exception log. At this time, the repaired second-class SVG format files with all React attribute values as false are converted into React component format files again, and the React attribute values that are successfully converted into React component format files are updated to true values and stored in the second memory.
[0048] S130: assemble the React component format files stored in the second memory into a React icon component library and publish it, so that the target user can access and use the React icon component library.
[0049] At this time, the second memory stores all the data successfully converted into React component format files for the current user, which are integrated into an overall React chart component library for the current target user to reference in his React project, and realize customized display of icons by setting component properties.
[0050] In an embodiment of the present invention, it supports converting icon files in various formats uploaded by users into SVG format files. At the same time, by establishing a first memory and a second memory, the successfully converted React component format files are screened out, and a React icon component library is constructed based on the data in the second memory, thereby finally enabling users to successfully use automatically generated exclusive chart components in their projects. The entire process generates custom components for each target user, while improving development efficiency, ensuring timeliness and consistency of user use, and enhancing user experience.
[0051] Embodiment 2
[0052] Figure 2 This is a flowchart of another method for automatically generating a React component provided in the second embodiment of the present invention. This embodiment is refined based on the first embodiment. Figure 2 As shown, the method includes:
[0053] S210, collecting icon files uploaded by the target user to the file storage system, and storing the collected icon files in the first memory; wherein the file format of the icon files includes a non-SVG format or an SVG format.
[0054] S220: Extract the attribute value of the SVG identification attribute of each icon file stored in the first memory, and obtain each target icon file whose attribute value is empty.
[0055] When a user uploads an icon file for the first time and the icon file is first stored in the first storage file, the SVG identification attribute of each icon file is empty. Since the icon file uploaded by the user may be in multiple formats, the attribute value of the SVG identification attribute under the SVG format file can be updated to a true value by first identifying the SVG format file in the first storage. For icon files whose attribute value of the SVG identification attribute is still empty, it means that the corresponding icon file is not a SVG format file.
[0056] S230: If the file format of the target icon file currently being processed is not in SVG format, after converting the target icon file currently being processed into an SVG format file, set the attribute value of the SVG identification attribute of the target icon file currently being processed to a true value.
[0057] In the embodiment of the present invention, isSvgFlag can be used to represent the SVG identification attribute. When the attribute value of isSvgFlag is a true value, it indicates that the SVG attribute exists, that is, the SVG format file to which the SVG identification attribute belongs exists. In addition to the SVG icon file of the original uploaded file, if the non-SVG format file is successfully converted into an SVG format file, the attribute value of the SVG identification attribute after the successful conversion into the SVG format file is also updated to true.
[0058] Optionally, convert the currently processed target icon file into an SVG format file, including:
[0059] Use the OpenCV function in the pre-installed opencv-python visual library to read the target icon file currently being processed, and convert the target icon file currently being processed into a grayscale image;
[0060] The potrace algorithm is used to decompose the grayscale image into a plurality of vector paths, and an SVG format file is generated according to the plurality of vector paths.
[0061] In the embodiment of the present invention, the target icon file currently being processed can be a common image format such as PNG, JPG, etc. In order to make the image conversion simpler and more accurate, the target icon file needs to be grayed out first. As an open source library, OpenCV provides many image processing operators and functions. The functions provided by OpenCV can be used to convert the target icon file into a grayscale image. The obtained grayscale image is a bitmap mode, that is, only black and white are used to represent the pixels in the image. The potrace algorithm, as a bitmap contour vectorization algorithm, can output the image as an SVG format file by path decomposition, finding the optimal polygon, constructing a vector contour, and optimizing the curve.
[0062] S240: If the file format of the target icon file currently being processed is the SVG format, directly set the attribute value of the SVG identification attribute of the target icon file currently being processed to a true value.
[0063] S250: Execute an operation of converting each SVG format file into a React component format file, and store the successfully converted React component format file into a second memory.
[0064] All files stored in the second memory are React component format files and the attribute values of the SVG identification attributes are true values. It should be noted that SVG format files that have not been successfully converted into React component format files are still stored in the first memory.
[0065] S260, reading the data of each React component format file, and defining each React component format file in the same root component file to form a React icon component library.
[0066] S270: Import the React chart component library as a packaged entry file into a front-end packaging tool to generate a new unified export file.
[0067] React, as a mainstream framework for front-end development, can be applied to any web application. In an embodiment of the present invention, the React component format file generated by the icon file uploaded by the target user can be defined in the same root component file, such as APP.js, Next.js or Index.js, etc., which depends on the project configuration. At this time, several React component format files under the root component file are integrated into a React chart component library, modularizing several components. The component module is referenced through construction tools such as Webpack or Rollup, and the component module can be used in a variety of development environments based on the generated unified export file.
[0068] In the embodiment of the present invention, the conversion of non-SVG format files and SVG identification attribute values are further explained. By storing different format files in the first memory and the second memory, different operations can be performed on files in different memories. Therefore, the embodiment of the present invention not only provides an automated method for automatically generating React components from SVG format files, but also provides a method for automatically identifying and converting icon files uploaded by users in non-SVG formats to generate React components that meet the requirements, thereby reducing manual intervention and achieving a high degree of intelligence and automation.
[0069] Embodiment 3
[0070] Figure 3 A schematic diagram of the structure of a three-dimensional model reconstruction device for an object provided in Example 3. Figure 3 , the device comprises:
[0071] The icon file collection module 310 is used to collect the icon files uploaded by the target user to the file storage system, and store the collected icon files in the first memory; wherein the file format of the icon files includes non-SVG format or SVG format;
[0072] The format conversion module 320 is used to convert the icon files of various file formats stored in the first memory into SVG format files, perform an operation of converting each SVG format file into a React component format file, and store the successfully converted React component format files into the second memory;
[0073] The component library publishing module 330 is used to assemble the React component format files stored in the second memory into a React chart component library for publishing, so that the target user can access and use the React chart component library.
[0074] In an embodiment of the present invention, it supports converting icon files in various formats uploaded by users into SVG format files. At the same time, by establishing a first memory and a second memory, the successfully converted React component format files are screened out, and a React icon component library is constructed based on the data in the second memory, thereby finally enabling users to successfully use automatically generated exclusive chart components in their projects. The entire process generates custom components for each target user, while improving development efficiency, ensuring timeliness and consistency of user use, and enhancing user experience.
[0075] Based on the above embodiments, the format conversion module 320 includes:
[0076] An SVG attribute value extraction unit, used to extract the attribute value of the SVG identification attribute of each icon file stored in the first memory, and obtain each target icon file whose attribute value is empty;
[0077] The first format conversion unit is used for converting the target icon file being processed into an SVG format file if the file format of the target icon file being processed is not in SVG format, and setting the attribute value of the SVG identification attribute of the target icon file being processed to a true value;
[0078] The SVG attribute value setting unit is used to directly set the attribute value of the SVG identification attribute of the target icon file currently being processed to a true value if the file format of the target icon file currently being processed is the SVG format.
[0079] Based on the above embodiments, the first format conversion unit is specifically used for:
[0080] Use the OpenCV function in the pre-installed opencv-python visual library to read the target icon file currently being processed, and convert the target icon file currently being processed into a grayscale image;
[0081] Convert the converted grayscale image into a bitmap;
[0082] The bitmap is decomposed into a plurality of vector paths by using a potrace algorithm, and an SVG format file is generated according to the plurality of vector paths.
[0083] Based on the above embodiments, the format conversion module 320 further includes:
[0084] A React attribute extraction unit, used for extracting attribute values of the React attributes of each SVG format file, and obtaining the first type of SVG format files whose attribute values are empty or false;
[0085] A second format conversion unit, used to convert each SVG format file of the first category into a React component format file;
[0086] A React attribute value setting unit, used for obtaining the first-class React component format file obtained by successful format conversion, and setting the attribute value of the React attribute of each first-class React component format file to a true value;
[0087] The second memory storage unit is used to store each file in the first memory whose attribute value of the React attribute is true as a React component format file obtained by successful conversion into the second memory.
[0088] On the basis of the above embodiments, the second memory storage unit further includes a repair subunit for second-type SVG format files, which is used for obtaining attribute values of the React attributes of each second-type SVG format file that failed in format conversion and setting them uniformly to false values before storing each file whose attribute value of the React attribute in the first memory is a true value in the second memory as a successfully converted React component format file, generating an exception log corresponding to each second-type SVG format file, and providing the exception log to the administrator end, so that the administrator end can perform repair on each second-type SVG format file;
[0089] When receiving the repaired second-category SVG format files fed back by the administrator, converting each of the repaired second-category SVG format files into a React component format file;
[0090] The second-type React component format files obtained by successful format conversion are obtained, and the attribute value of the React attribute of each second-type React component format file is set to a true value.
[0091] Based on the above embodiments, the second format conversion unit is specifically used to: parse the first type of SVG format file and convert the first type of SVG format file into JSX syntax;
[0092] The JSX syntax is imported into a specific format conversion script to generate a React component format file corresponding to the first type of SVG format file.
[0093] Based on the above embodiments, the component library publishing module 330 further includes:
[0094] The React icon component library constituent unit is used to read the data of each React component format file and define each React component format file in the same root component file to form a React icon component library;
[0095] The export file generation unit is used to import the React chart component library as a packaged entry file into a front-end packaging tool to generate a new unified export file.
[0096] A React component automatic generation device provided in an embodiment of the present invention can execute a React component automatic generation method provided in any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution method.
[0097] Embodiment 4
[0098] Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) 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 invention described and / or required herein.
[0099] like Figure 4 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0100] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0101] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a method for automatically generating a React component.
[0102] That is: collecting icon files uploaded by the target user to the file storage system, and storing the collected icon files in the first memory; wherein the file format of the icon files includes a non-SVG format or an SVG format;
[0103] After the icon files of various file formats stored in the first memory are uniformly converted into SVG format files, an operation of converting each SVG format file into a React component format file is performed, and the React component format files obtained by the successful conversion are stored in the second memory;
[0104] The React component format files stored in the second memory are assembled into a React icon component library for publishing, so that the target user can access and use the React icon component library.
[0105] In some embodiments, a method for automatically generating a React component may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method for automatically generating a React component described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute a method for automatically generating a React component by any other appropriate means (e.g., by means of firmware).
[0106] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), 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.
[0107] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0108] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0109] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device 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 a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0110] The systems and techniques described herein may be implemented in a computing system that includes backend 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 frontend 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 backend components, middleware components, or frontend 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), a blockchain network, and the Internet.
[0111] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS servers.
[0112] 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 described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0113] The above specific implementations do not constitute a limitation on the protection scope of the present invention. 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 modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for automatically generating React components. It is characterized in that include: Collecting icon files uploaded by the target user to the file storage system, and storing the collected icon files in the first memory; wherein the file format of the icon files includes a non-SVG format or an SVG format; After the icon files of various file formats stored in the first memory are uniformly converted into SVG format files, an operation of converting each SVG format file into a React component format file is performed, and the React component format files obtained by the successful conversion are stored in the second memory; The React component format files stored in the second memory are assembled into a React icon component library for publishing, so that the target user can access and use the React icon component library.
2. The method according to claim 1, It is characterized in that Converting icon files of various file formats stored in the first memory into SVG format files uniformly includes: Extracting the attribute value of the SVG identification attribute of each icon file stored in the first memory, and acquiring each target icon file whose attribute value is empty; If the file format of the target icon file currently being processed is not in SVG format, after converting the target icon file currently being processed into an SVG format file, the attribute value of the SVG identification attribute of the target icon file currently being processed is set to a true value; If the file format of the target icon file currently being processed is the SVG format, the attribute value of the SVG identification attribute of the target icon file currently being processed is directly set to a true value.
3. The method according to claim 2, It is characterized in that Convert the currently processed target icon file to an SVG format file, including: Use the OpenCV function in the pre-installed opencv-python visual library to read the target icon file currently being processed, and convert the target icon file currently being processed into a grayscale image; Convert the converted grayscale image into a bitmap; The bitmap is decomposed into a plurality of vector paths by using a potrace algorithm, and an SVG format file is generated according to the plurality of vector paths.
4. The method according to claim 1, It is characterized in that Executing an operation of converting each SVG format file into a React component format file, and storing the successfully converted React component format file into a second memory, including: Extract the attribute value of the React attribute of each SVG format file, and obtain the first type of SVG format files whose attribute value is empty or false; Execute the operation of converting each SVG format file of the first category into a React component format file; Obtain the first-class React component format file obtained by successful format conversion, and set the attribute value of the React attribute of each first-class React component format file to a true value; Each file in the first memory whose attribute value of the React attribute is true is stored in the second memory as a React component format file obtained by successful conversion.
5. The method according to claim 4, It is characterized in that Before storing each file in the first memory whose attribute value of the React attribute is true as a successfully converted React component format file in the second memory, the method further includes: After obtaining the attribute value of the React attribute of each second-category SVG format file that fails in format conversion and setting it uniformly to a false value, an exception log corresponding to each second-category SVG format file is generated, and the exception log is provided to the administrator side, so that the administrator side can perform repair on each second-category SVG format file; When receiving the repaired second-category SVG format files fed back by the administrator, converting each of the repaired second-category SVG format files into a React component format file; The second-type React component format files obtained by successful format conversion are obtained, and the attribute value of the React attribute of each second-type React component format file is set to a true value.
6. The method according to claim 4 or 5, It is characterized in that The operation of converting each SVG format file of the first category into a React component format file is performed, including: Parse the first type of SVG format file and convert the first type of SVG format file into JSX syntax; The JSX syntax is imported into a specific format conversion script to generate a React component format file corresponding to the first type of SVG format file.
7. The method according to any one of claims 1 to 5, It is characterized in that The React component format files stored in the second memory are assembled into a React icon component library for publishing, including: Read the data of each React component format file, and define each React component format file in the same root component file to form a React icon component library; The React chart component library is imported into the front-end packaging tool as a packaged entry file to generate a new unified export file.
8. A React component automatic generation device, It is characterized in that include: An icon file collection module is used to collect icon files uploaded by target users to the file storage system, and store the collected icon files in the first memory; wherein the file format of the icon files includes a non-SVG format or an SVG format; a format conversion module, configured to convert the icon files of various file formats stored in the first memory into SVG format files, convert the SVG format files into React component format files, and store the successfully converted React component format files into the second memory; The component library publishing module is used to assemble the React component format files stored in the second memory into a React icon component library for publishing, so that the target user can access and use the React icon component library.
9. An electronic device, It is characterized in that The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute a method for automatically generating a React component according to any one of claims 1 to 7.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement a method for automatically generating a React component according to any one of claims 1 to 7 when executed.
