Method, electronic device and medium for automatically constructing front-end interface
By automatically building the front-end interface, using global configuration files and page generation tools, the front-end interface is dynamically generated, which solves the problems of cumbersome component combination and inconsistent code for front-end developers, and improves development efficiency and code consistency.
Patent Information
- Application Number
- CN202011133296.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-21
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2040-10-21
AI Technical Summary
When front-end developers develop new functions, they need to recombine components into a new interface. The process is cumbersome and due to different habits, the code is not unified and there is a lack of unified interface generation tools.
Provides a method to automatically build a front-end interface by creating a global configuration file, importing page generation tools, generating new page files based on configuration information, and dynamically inserting functional modules to establish associations. It supports multiple template rules and quickly generates a unified interface.
It realizes the rapid generation of a unified interface, reduces the combination time of developers, improves development efficiency, and ensures the unity of the code.
Smart Images

Figure CN112394930B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer software technology, and in particular to a method, electronic equipment and medium for automatically constructing a front-end interface. Background Art
[0002] In front-end engineering development, when a project develops to a certain stage, common components and tools have been basically perfected. When developing new functions, it is cumbersome to reassemble various components into a new interface. In addition, sometimes different developers have different habits and use different development methods, resulting in a variety of codes for the same interface. In order to omit this combination process and ensure the uniformity of the code, front-end developers hope to have a tool that can generate a unified interface based on template rules. Summary of the invention
[0003] The present invention aims to solve the following technical problems at least to some extent:
[0004] After the front-end developers get the requirements and design drafts, they write the interface based on the design drafts, and there is no unified interface generation tool.
[0005] In a first aspect, an embodiment of the present invention provides a method for automatically constructing a front-end interface, comprising:
[0006] In response to receiving a first instruction from a user, creating a global configuration file in a designated directory of the front-end project code, the global configuration file having configuration information of a new page to be generated;
[0007] In response to receiving a second instruction from the user, generating a new page file based on the configuration information;
[0008] In response to receiving the third instruction from the user, calling a page generation tool, importing the global configuration file into a function module of the front-end project code, so as to establish an association between the function module and the new page file;
[0009] According to the type and configuration information of the new page, the new page file is inserted into a designated folder to dynamically generate a front-end interface.
[0010] In some examples, in response to receiving the third instruction from the user, calling the page generation tool, importing the global configuration file in the function module of the front-end project code to establish an association between the function module and the new page file, includes:
[0011] In response to placing a placeholder in the functional module;
[0012] Calling the first method of the page generation tool, and importing corresponding configuration information in the global configuration file into the plurality of function modules respectively;
[0013] The second method of the page generation tool is called to perform data processing on the corresponding configuration information respectively to establish an association between the function module and the new page file.
[0014] In some examples, respectively processing the corresponding configuration information to establish an association between the functional module and the new page file includes:
[0015] Convert the corresponding configuration information into strings respectively;
[0016] After inserting the string into the insertion position of the placeholder of the corresponding functional module, converting the string into an object to form a corresponding new functional module;
[0017] Output the new function module to the corresponding path.
[0018] In some examples, in response to receiving the second instruction from the user, generating a new page file based on the configuration information includes:
[0019] A new page file is generated based on the semantic template library carrying the new page type and the page generation tool in the second instruction.
[0020] In some examples, generating a new page file based on a semantic template library carrying a new page type and a page generation tool in the second instruction includes:
[0021] If the new page type is a multi-page, after the main page is generated, the module names of the sub-pages and the titles of the sub-pages in the configuration information are traversed to generate a plurality of sub-pages.
[0022] In some examples, before the responding to receiving the second instruction from the user, the method further includes:
[0023] Determine the name and / or routing name of the file created by the user;
[0024] Determining whether the file name and / or route name meets a preset standard according to the page generation tool;
[0025] If the preset criteria are met, a file representing the new page is created, and the user is notified to select the type of the new page.
[0026] In some examples, inserting the new page file into a designated folder according to the type and configuration information of the new page to dynamically generate a front-end interface includes:
[0027] If the type of the new page is a single page, inserting the new page file into the designated folder, the designated folder being established based on the parent file address in the configuration information;
[0028] If the type of the new page is multi-page, the main page and the sub-page are inserted into the designated folder, and the designated folder is established based on the parent file address in the configuration information.
[0029] In some examples, the configuration information includes at least one of the following:
[0030] Parent file address, routing file address, breadcrumb navigation address, parent menu name, left menu file path, creator of the current file, file title, whether there is a drawer, list request interface address, add interface address, edit interface address, delete interface address, sub-page module name, sub-page title.
[0031] In a second aspect, an embodiment of the present invention provides an electronic device, including:
[0032] processor, and
[0033] a memory communicatively connected to the processor, wherein:
[0034] The memory stores computer instructions that can be executed by the processor, and the instructions are executed by the processor to implement the method for automatically constructing a front-end interface as described in the first aspect.
[0035] In a third aspect, an embodiment of the present invention provides a non-volatile computer storage medium storing computer instructions, wherein the instructions are configured to execute the method for automatically constructing a front-end interface as described in the first aspect.
[0036] Beneficial effects:
[0037] The embodiment of the present invention can support a variety of different template rules. After entering a command, the combined components and methods can be quickly generated into an interface according to the template rules, thereby ensuring the uniformity of the code, saving the developer's time in recombining components, and improving development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0039] Figure 1 A schematic diagram of a logical framework provided for an embodiment of the present invention;
[0040] Figure 2 A schematic diagram of a flow chart of a method for automatically constructing a front-end interface provided by an embodiment of the present invention;
[0041] Figure 3A schematic diagram of the framework structure of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to more clearly illustrate the overall concept of the present application, a detailed description is given below in an illustrative manner in conjunction with the accompanying drawings.
[0043] In the front-end interface of the ICE controller, most of the interfaces are based on the same design template. Front-end developers get the design template and use public components and methods to write the interface. Developers have different habits, so the codes they write are also different, making page writing time-consuming and laborious.
[0044] The purpose of the embodiments of the present invention is to quickly generate interface codes, ensure the consistency of the codes, and reduce the development time of front-end personnel.
[0045] The specific scheme of the embodiment of the present invention is introduced below in conjunction with the accompanying drawings.
[0046] Figure 1 A logical framework diagram provided for an embodiment of the present invention, such as Figure 1 As shown, the developer installs a page generation tool (zash-cli) on the front end, and generates pages based on some template files and data processing methods of zash-cli.
[0047] Page types include single page and multiple pages. When developers use zash-cli to generate new pages, they can choose to use the template files corresponding to single page or multiple pages.
[0048] The developer adds a configuration file in the root directory of the project. The configuration file mainly includes the following configuration information: parent file address, routing file address, breadcrumb navigation address, parent menu name, left menu file path, creator of the current file, file title, whether there is a drawer, list request interface address, new interface address, edit interface address, delete interface address, sub-page module name, and sub-page title.
[0049] In some practical applications of the embodiments of the present invention, the corresponding codes include:
[0050] / **
[0051] *Automatically generate configuration information for the file
[0052] *@param parentFolderPath parent file address, relative to the root path
[0053] *@param routerPath routing file address
[0054] *@param breadPath breadcrumb navigation address
[0055] *@param parentName parent menu name
[0056] *@param leftMenuPath left menu file path
[0057] * @param author The creator of the current file
[0058] *@param title file title, related to the prompt information of addition, deletion and modification
[0059] *@param isDrawer indicates whether there is a drawer. The default value is true, indicating that the add, delete and modify functions are available.
[0060] *@param getUrl list request interface address
[0061] *@param addUrlAdd new interface address
[0062] *@param editUrl edit interface address
[0063] *@param deleteUrl delete interface address
[0064] *@param childrenValues module name of the sub-page
[0065] *@param childrenNames sub-page titles
[0066] *@author XXXX
[0067] *@createtime 2020-XX-XX
[0068] * /
[0069] exports.conf={
[0070] parentFolderPath:'src / views / Content / SFC',
[0071] routerPath:'src / router / routes.js',
[0072] breadPath:'src / components / BreadLink / config.js',
[0073] parentName:'Network Service',
[0074] leftMenuPath:'src / views / Home / LeftMenu / LeftMenu.config.js',
[0075] author:'XXXX',
[0076] title:'Test 1',
[0077] isDrawer:true,
[0078] getUrl:”,
[0079] addUrl:”,
[0080] editUrl:”,
[0081] deleteUrl:”,
[0082] / / The following is a multi-page configuration
[0083] childrenValues:['child1','child2','child3','child4'],
[0084] childrenNames:['subpage 1', 'subpage 2', 'subpage 3', 'subpage 4']
[0085] };
[0086] Figure 2 A schematic diagram of a method flow chart provided by an embodiment of the present invention, such as Figure 2 As shown, the method of automatically building the front-end interface includes:
[0087] S201 In response to receiving a first instruction from a user, a global configuration file is created in a designated directory of the front-end project code, where the global configuration file has configuration information of a new page to be generated.
[0088] In some examples, the specified directory refers to the root directory of the front-end project code.
[0089] S202: In response to receiving a second instruction from the user, generating a new page file based on the configuration information.
[0090] Specifically, a new page file is generated based on the page type carried in the second instruction and a semantic template library of a page generation tool, wherein the semantic template library includes a variety of template files.
[0091] In a specific implementation, after determining the type of page, read single.handlebars (single page template file) or multiple.handlebars (multiple page template file) under template, write the configuration items of the configuration file into handlebars, and generate the index.vue template file. If the page type is multiple pages, in addition to generating the main page index.vue, it is also necessary to traverse childrenValues and childrenNames in pageConf.js, and generate multiple sub-pages according to the sub-page template file (child.handlebars). The module name is determined by childrenValues, and the module title is determined by childrenNames.
[0092] In some other embodiments of the embodiments of the present invention, before receiving the second instruction from the user, the method further includes:
[0093] Determine the name and / or routing name of the file created by the user;
[0094] Users can enter the cli command zash create AAA in the current folder, where AAA represents the file name and route name of the new page to be created. Use fs.existsSync in zash-cli to determine whether AAA is repeated in the specified folder of the external project, and the folder path is parentFolderPath. If there is no duplication, the following options appear: Single means generating a common single page, and Multiple means generating a common page with TAB.
[0095] Determining, according to the page generation tool, whether the folder name and / or route name meets a preset standard;
[0096] If the preset standard is met, the designated folder for accommodating the new page file is created, and the user is notified to select the type of the new page.
[0097] In some embodiments, the preset standard may be whether there is duplication in the file name or the route name. If there is no duplication, the standard is met.
[0098] S203: In response to receiving the third instruction from the user, calling a page generation tool, importing the global configuration file into a function module of the front-end project code, so as to establish an association between the function module and the new page file.
[0099] In this embodiment, the developer can assist in adding placeholders, and the steps include:
[0100] In response to placing a placeholder in the functional module;
[0101] Invoke the first mode of the page generation tool, and import corresponding configuration information in the global configuration file into the plurality of function modules respectively;
[0102] The second method of calling the page generation tool is to perform data processing on the corresponding configuration information respectively to establish an association between the function module and the new page file.
[0103] In an actual application, the second mode of the page generation tool is called to perform data processing on the corresponding configuration information, including:
[0104] Convert the corresponding configuration information into strings respectively;
[0105] After inserting the string into the insertion position of the placeholder of the corresponding functional module, converting the string into an object to form a corresponding new functional module;
[0106] Output the new function module to the corresponding path.
[0107] In one example, the insertion position may be before or after the placeholder.
[0108] In a practical application, the project includes a routing module (router.js), a breadcrumb module (breadcrumb.js) and a left menu module (leftMenu.js). The following takes the routing module as an example for introduction.
[0109] Place placeholders in the routing module, such as " / / $f". Import the configuration file (pageConf.js file) through zash-cli's require(path.resolve(cwd,'pageConf.js')).conf, get the routerPath value inside, and then read the router.js content specified by the routerPath path through fs.readFileSync, JSON.stringify the read router.js content, insert it in front of the corresponding placeholder through string insertion, and finally format the processed string with JSON.parse, and output the formatted router.js content to the path specified by routerPath through fs.outputFileSync, that is, write it into a new router.js file.
[0110] The breadcrumb module, left menu module and other functions of the new page are also dynamically inserted in the above way, so I will not go into details here.
[0111] S204 inserts the new page file into a designated folder according to the type and configuration information of the new page to dynamically generate a front-end interface.
[0112] The types of new pages include single pages and multiple pages. If the type of the new page is a single page, the new page file is inserted into the designated folder, and the designated folder is established based on the parent file address in the configuration information; if the type of the new page is multiple pages, the main page and the child page are inserted into the designated folder, and the designated folder is established based on the parent file address in the configuration information.
[0113] In a specific application scenario, the parentFolderPath path in the configuration file (pageConf.js) is obtained. If it is a single page, a BBB folder is generated in the parentFolderPath path, and the index.vue file generated by single.handlebars is placed in the BBB folder. If it is multiple pages, a CCC folder is generated in the parentFolderPath path, and the index.vue file generated by multiple.handlebars is placed in the CCC folder, and the multiple sub-pages generated in the second step are also placed in the CCC folder. At this point, the dynamic generation function of single and multiple pages is completed.
[0114] Based on the same idea, the embodiment of the present invention also provides a corresponding electronic device and a non-volatile computer storage medium.
[0115] Figure 3 A schematic diagram of the framework structure of an electronic device provided by an embodiment of the present invention, such as Figure 3 As shown, the electronic device includes: a processor, and a memory communicatively connected to the processor, wherein the memory stores computer instructions executable by the processor, and the instructions are executed by the processor to implement the above-mentioned method of automatically constructing a front-end interface.
[0116] An embodiment of the present invention further provides a non-volatile computer storage medium storing computer instructions, wherein the instructions are configured to execute the method for automatically constructing a front-end interface as described above.
[0117] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0118] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the application.
Claims
1. A method for automatically constructing a front-end interface, characterized in that: include: In response to receiving a first instruction from a user, creating a global configuration file in a designated directory of the front-end project code, the global configuration file having configuration information of a new page to be generated; In response to receiving a second instruction from the user, generating a new page file based on the configuration information; In response to receiving the third instruction from the user, calling a page generation tool, importing the global configuration file into a function module of the front-end project code, so as to establish an association between the function module and the new page file; According to the type and configuration information of the new page, insert the new page file into a designated folder to dynamically generate a front-end interface; The calling of the page generation tool in response to receiving the third instruction from the user, and importing the global configuration file into the function module of the front-end project code to establish an association between the function module and the new page file, includes: In response to placing a placeholder in the functional module; Invoke the first mode of the page generation tool, and import corresponding configuration information in the global configuration file into the plurality of function modules respectively; The second mode of calling the page generation tool is to perform data processing on the corresponding configuration information respectively, so as to establish an association between the function module and the new page file; The respectively performing data processing on the corresponding configuration information to establish the association between the functional module and the new page file includes: Convert the corresponding configuration information into strings respectively; After inserting the string into the insertion position of the placeholder of the corresponding functional module, converting the string into an object to form a corresponding new functional module; Output the new function module to the corresponding path; In response to receiving the second instruction from the user, generating a new page file based on the configuration information, including: Generate a new page file based on the semantic template library carrying the new page type and page generation tool in the second instruction; The generating a new page file based on the semantic template library carrying the new page type and the page generation tool in the second instruction includes: If the new page type is a multi-page, after generating the main page, the module name of the sub-page and the title of the sub-page in the configuration information are traversed to generate multiple sub-pages; The method of inserting the new page file into a designated folder according to the type and configuration information of the new page to dynamically generate a front-end interface includes: If the type of the new page is a single page, inserting the new page file into the designated folder, the designated folder being established based on the parent file address in the configuration information; If the type of the new page is multi-page, the main page and the sub-page are inserted into the designated folder, and the designated folder is established based on the parent file address in the configuration information.
2. The method according to claim 1, characterized in that Before the response receives the second instruction from the user, the method further includes: Determine the name and / or routing name of the file created by the user; Determining whether the file name and / or route name meets a preset standard according to the page generation tool; If the preset criteria are met, a file representing the new page is created, and the user is notified to select the type of the new page.
3. The method according to claim 1, characterized in that The configuration information includes at least one of the following: Parent file address, routing file address, breadcrumb navigation address, parent menu name, left menu file path, creator of the current file, file title, whether there is a drawer, list request interface address, add interface address, edit interface address, delete interface address, sub-page module name, sub-page title.
4. An electronic device, characterized in that ,include: processor, and a memory communicatively connected to the processor, wherein: The memory stores computer instructions that can be executed by the processor, and the instructions are used by the processor to execute the method according to any one of claims 1 to 3.
5. A non-volatile computer storage medium storing computer instructions, characterized in that: The instructions are configured to execute the method according to any one of claims 1 to 3.
