A method for dynamically generating front-end pages

Through the method of dynamically generating front-end pages and using front-end standard componentization technology to convert page development into component development, it solves the problems of reusability and maintenance difficulty in front-end development, achieves efficient component generation and management, and improves user experience and Development efficiency.

CN117234494BActive Publication Date: 2024-09-17KARAMAY HONGYOU SOFTWARE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311157024.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-08
Publication Date
2024-09-17
Estimated Expiration
2043-09-08

Smart Images

  • Figure CN117234494B
    Figure CN117234494B
Patent Text Reader

Abstract

The present invention provides a method for dynamically generating a front-end page, comprising: customizing the front-end standard component development specification; developing and designing layout standard components, sub-layout area standard components and functional standard components; using a standard data source, configuring the layout standard components, sub-layout area standard components and functional standard components respectively according to the actual requirements of the page, and dynamically rendering and generating the front-end page. It has the following advantages: (1) the development method based on pages is converted into a development method based on components, and the components are reusable, thereby improving the code reusability and extensibility, and improving the page development efficiency; (2) using a standard data source, various types of standard components can be dynamically generated into various front-end components that meet the actual page requirements, and components can be dynamically rendered and managed according to different standard data sources, thereby building a more interactive and reusable front-end page application, which has the advantages of high front-end component generation efficiency and high flexibility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of front-ends, and in particular relates to a method for dynamically generating front-end pages. Background Art

[0002] At present, front-end development is mainly carried out on a page-by-page basis, the code lacks reusability, and is difficult to maintain and expand. Summary of the invention

[0003] In view of the defects in the prior art, the present invention provides a method for dynamically generating a front-end page, which can effectively solve the above problems.

[0004] The technical solution adopted by the present invention is as follows:

[0005] The present invention provides a method for dynamically generating a front-end page, comprising the following steps:

[0006] Step 1: Customize the front-end standard component development specifications;

[0007] Step 2, developing and designing layout standard components, sub-layout area standard components and functional standard components according to the front-end standard component development specification;

[0008] Step 3, using a standard data source, and configuring the layout standard components, sub-layout area standard components, and functional standard components respectively according to actual requirements of the page, to obtain the configured layout components, sub-layout area components, and functional components with a hierarchical relationship;

[0009] The specific method is:

[0010] By configuring the properties of the layout standard component, a layout component is obtained, wherein the layout component is associated with the entire page and is used to divide the entire page into different functional areas;

[0011] By configuring the properties of the sub-layout area standard component, a sub-layout area component is obtained, wherein the sub-layout area component is a sub-node of the layout component, each of the sub-layout area components uniquely corresponds to a functional area divided by the layout component, and the sub-layout area component is used to perform page design for the functional area;

[0012] By configuring the properties of the functional standard component, a functional component is obtained, wherein the functional component is a sub-node of the sub-layout area component, and the functional component is used to customize and complete related page functions in the functional area;

[0013] Step 4: Dynamically render and generate the front-end page based on the configured layout components, sub-layout area components, and functional components.

[0014] Preferably, the front-end standard component development specification includes: defining the front-end standard component directory structure, the front-end standard component name specification, the front-end standard component style specification, the front-end standard component interaction specification and the front-end standard component startup entry specification;

[0015] Wherein: the front-end standard component directory structure is used to constrain the front-end standard component basic description file, front-end standard component source code and front-end standard component definition description file that must be included in the front-end standard component development phase; wherein, the front-end standard component basic description file includes the front-end standard component name, version, developer, dependency, and code repository address; the front-end standard component definition description file is used to describe the attribute specification, event specification, interaction specification and data source specification of the front-end standard component;

[0016] The front-end standard component name specification is used to define the name specification of the front-end standard component to ensure the uniqueness of each front-end standard component name;

[0017] The front-end standard component style specification is used to define the overall style specification of the front-end standard component and the interactive animation effect specification with each internal element; at the same time, the nesting and overlay rules between the front-end standard components are constrained;

[0018] The front-end standard component interaction specification is used to impose basic constraints on the control mechanism of unidirectional data flow between parent and child components and the data bus mechanism between sibling components;

[0019] The front-end standard component startup entry specification is used to define the specification at the entry of the front-end standard component startup.

[0020] Preferably, the standard data source describes the properties of the layout standard component, the properties of the sub-layout area standard component and the properties of the function standard component;

[0021] The attributes of the layout standard component include the name of the layout standard component, the unique identifier of the layout standard component, and the unique identifier of the sub-layout area standard component contained in the layout standard component;

[0022] The attributes of the sub-layout area standard component include the name of the sub-layout area standard component, the unique identifier of the sub-layout area standard component, and the unique identifier of the functional standard component included in the sub-layout area standard component;

[0023] The attributes of the functional standard component include the name of the functional standard component, the unique identifier of the functional standard component, the event name and event value mounted by the functional standard component; wherein the event value refers to the business code for calling back the specific execution of the functional standard component.

[0024] Preferably, step 4 is specifically:

[0025] Step 4.1, generating a layout component instance from a configured layout component; generating a sub-layout area component instance from a configured sub-layout area component; generating a functional component instance from a configured functional component;

[0026] Step 4.2, generating a virtual DOM tree according to the hierarchical relationship among the layout component instance, the sub-layout area component instance and the functional component instance; the virtual DOM tree includes a plurality of virtual nodes;

[0027] Mount the layout component instance, sub-layout area component instance and function component instance to the corresponding virtual nodes of the virtual DOM tree respectively to obtain the real DOM tree;

[0028] Step 4.3, traverse the real DOM tree from top to bottom, and when traversing to the layout component instance, execute the layout component instance to divide the entire page into multiple different functional areas;

[0029] Step 4.4, for each functional area, read the corresponding sub-layout area component instance from the real DOM tree, execute the sub-layout area component instance, and render the sub-layout area page content in the functional area of ​​the page;

[0030] Then read each functional component instance under the sub-layout area component instance from the real DOM tree, execute the functional component instance, and render the corresponding functional component in the rendered sub-layout area page content.

[0031] The method for dynamically generating a front-end page provided by the present invention has the following advantages:

[0032] (1) The development method based on pages is transformed into a development method based on components. Components are reusable, thus improving code reusability and extensibility, and improving page development efficiency;

[0033] (2) By using standard data sources, various types of standard components can be dynamically generated into various front-end components that meet actual page requirements. Components can be dynamically rendered and managed according to different standard data sources, thereby building more interactive and reusable front-end page applications. This has the advantages of high front-end component generation efficiency and high flexibility.

[0034] (3) In actual applications, dynamically generated front-end components can be used to dynamically render complex interactive components such as forms, lists, and pop-up windows, providing better user experience and maintainability. Therefore, in appropriate scenarios, the method of dynamically generating front-end components can be fully utilized to improve front-end development efficiency and user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1A schematic diagram of a flow chart of a method for dynamically generating a front-end page provided by the present invention.

[0036] Figure 2 A schematic diagram of a method for dynamically generating a front-end page provided by the present invention;

[0037] Figure 3 A method for dynamically generating a front-end page provided by the present invention is a rendering logic diagram. DETAILED DESCRIPTION

[0038] In order to make the technical problems, technical solutions and beneficial effects solved by the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0039] In order to improve development efficiency, reduce duplicate code, and enhance maintainability and scalability, the present invention adopts front-end standard componentization technology to split the code into smaller components, thereby improving the reusability and maintainability of the code. The present invention is based on the Vue2 framework and supports data transmission between components. The parent component can pass data to the child component, and the child component can receive and use data; various events such as clicks, inputs, mouse movements, etc. can be monitored and associated with methods in the instance. This enables developers to easily handle user interactions; different components can be instantiated according to dynamic component names. Developers can dynamically switch to display different components according to conditions or user interactions, thereby achieving more flexible interface construction; component states and views can be associated, and when the component state changes, the view corresponding to the component is automatically updated, reducing the workload of manual DOM operations.

[0040] The present invention provides a method for dynamically generating a front-end page, referring to Figure 1 , Figure 2 and Figure 3 , including the following steps:

[0041] Step 1: Customize the front-end standard component development specifications;

[0042] Specifically, the front-end standard component development specifications include: defining the front-end standard component directory structure, front-end standard component name specifications, front-end standard component style specifications, front-end standard component interaction specifications and front-end standard component startup entry specifications; by customizing the front-end standard component development specifications, it can be ensured that the generated standard components have good maintainability and extensibility.

[0043] Wherein: the front-end standard component directory structure is used to constrain the front-end standard component basic description file, front-end standard component source code and front-end standard component definition description file that must be included in the front-end standard component development phase; wherein, the front-end standard component basic description file includes the front-end standard component name, version, developer, dependency, and code repository address; the front-end standard component definition description file is used to describe the attribute specification, event specification, interaction specification and data source specification of the front-end standard component;

[0044] The front-end standard component name specification is used to define the name specification of the front-end standard component to ensure the uniqueness of each front-end standard component name;

[0045] The front-end standard component style specification is used to define the overall style specification of the front-end standard component and the interactive animation effect specification with each internal element; at the same time, the nesting and overlay rules between the front-end standard components are constrained;

[0046] The front-end standard component interaction specification is used to impose basic constraints on the control mechanism of unidirectional data flow between parent and child components and the data bus mechanism between sibling components;

[0047] The front-end standard component startup entry specification is used to define the specification at the entry of the front-end standard component startup.

[0048] An embodiment is described below:

[0049] The specific implementation can be based on a front-end development framework, such as Vue, where package.json is the basic description file of the front-end standard component, which mainly includes the name, version, developer, dependency, code repository address and other information of the front-end standard component; the directory structure src is the directory for storing the source code; the component .vue file is the source code of the functional component to be developed; the component .json is the component definition description file, which describes the component's properties, events, interactions, data sources and other information in detail; the public directory structure is used to store the description file of the overall component style and the interactive animation effects of the internal elements; index.js is the component startup entry information, which is the entry point for the component to start, usually the root element, usually fixed code.

[0050] Among them, the component dependencies in the basic description file of the front-end standard components need to be downloaded locally and stored in a directory with a fixed path in the development environment, and stored in mode_modules in the Vue framework; the component dependency relationship is usually a tree structure, and the download of dependent packages should depend on the framework Webpack, etc.

[0051] The front-end standard component name specification provides guiding suggestions for the front-end standard component name, focusing on constraining the uniqueness and non-repetitiveness of the front-end standard component name to avoid conflicts; the front-end standard component name should also be meaningful, and it is recommended to use English and avoid abbreviations. For example, if the oil field field starts with OilField, "-" should be used for connection as much as possible. In places where the "-" connector is not supported, it is recommended to use camel case.

[0052] The style specification of the front-end standard components constrains the rules of style control names, nesting, and overriding between the internal elements of the front-end standard components and the front-end standard components, and formulates rules for global and local style overriding and conflict resolution. The class name of the internal element of the front-end standard component should have a unique control tag, which is consistent with the name of the front-end standard component to ensure the uniqueness of the root element class name of the front-end standard component; element nesting should avoid too high a nesting level, and generally the nesting level should not exceed three levels; too high a nesting level is inconvenient to search and consumes unnecessary browser resources; use the correct tags, each element has a start and end tag to ensure the normal display and nesting relationship of the page; the start and end tags of the elements use corresponding indents to improve readability and make the element hierarchy clearer; when writing global styles, the outermost layer uses the class name of the root element to nest, indicating that the current style is only effective within the scope of the root element class name; local styles need to set the scoped scope in the style attribute in the specific vue file.

[0053] The front-end standard component interaction specification is basically constrained by the control mechanism of unidirectional data flow between parent and child components and the data bus mechanism between sibling components. The interaction between parent and child components adopts the props attribute transmission or calling the child component method; the interaction between child components and parent components adopts the event bubbling method (emit); the event bus method of interaction between sibling components needs to ensure that the event name must be unique, and the naming specification of "component name_event name" can be adopted, and both the component name and the event name use uppercase letters.

[0054] Step 2, developing and designing layout standard components, sub-layout area standard components and functional standard components according to the front-end standard component development specification;

[0055] Step 3, using a standard data source, and configuring the layout standard components, sub-layout area standard components, and functional standard components respectively according to actual requirements of the page, to obtain the configured layout components, sub-layout area components, and functional components with a hierarchical relationship;

[0056] In this application, the standard data source describes the properties of the layout standard component, the properties of the sub-layout area standard component, and the properties of the functional standard component; by designing a standard data source that conforms to the standard data format, the property configuration information of the front-end standard component is described. The standard data source contains the type, name, event, method and other information of the front-end standard component, so as to dynamically generate and customize components with different functions in the future.

[0057] In the present application, the standard data source adopts a standard data format, which constrains the data structure used to be a hierarchical data structure, and can be used to represent data with a hierarchical relationship, such as a tree data structure.

[0058] In this application, the standard data source includes the configuration layout standard component name, the sub-layout area standard component name, the layout standard component unique identifier, the function standard component name, the function standard component attribute data, the function standard component event data, the function standard component unique identifier, etc.

[0059] The role of layout standard component names and functional standard component names is as follows: component instantiation requires a component name, which is used to instantiate a component option object into a reusable component instance. The specific implementation can be based on a front-end development framework, such as Vue, where the component element dynamically renders different components by binding the component name through the is attribute; the slot element dynamically generates sub-layout area components by binding the sub-layout area component name through the named attribute.

[0060] The attributes of the layout standard component include the name of the layout standard component, the unique identifier of the layout standard component, and the unique identifier of the sub-layout area standard component contained in the layout standard component;

[0061] The attributes of the sub-layout area standard component include the name of the sub-layout area standard component, the unique identifier of the sub-layout area standard component, and the unique identifier of the functional standard component included in the sub-layout area standard component;

[0062] The attributes of the functional standard component include the name of the functional standard component, the unique identifier of the functional standard component, the event name and event value mounted by the functional standard component; wherein the event value refers to the business code for calling back the specific execution of the functional standard component.

[0063] Functional standard components receive functional standard component attribute data through the props attribute and use this data in the component. The type option is used to verify the type of the received data. The required option is used to specify whether a certain attribute data is required. The validator attribute is used to perform more complex verification on the received data.

[0064] Functional standard components use the $on method to register listeners for custom events. The $on method receives two parameters. The first parameter is the event name in the functional component event data, and the second parameter is the event value in the functional component event data. The event value is of String type and needs to be converted into function type before it can be used as a callback function. When using the $on method, ensure that the event listener is unbound correctly to avoid memory leaks. Use the $off method to unbind the event listener.

[0065] The specific configuration method is:

[0066] Configuration: By configuring the properties of the layout standard component, a layout component is obtained, wherein the layout component is associated with the entire page and is used to divide the entire page into different functional areas;

[0067] By configuring the properties of the sub-layout area standard component, a sub-layout area component is obtained, wherein the sub-layout area component is a sub-node of the layout component, each of the sub-layout area components uniquely corresponds to a functional area divided by the layout component, and the sub-layout area component is used to perform page design for the functional area;

[0068] By configuring the properties of the functional standard component, a functional component is obtained, wherein the functional component is a sub-node of the sub-layout area component, and the functional component is used to customize and complete related page functions in the functional area;

[0069] In terms of specific implementation, it is realized through the front-end standard component dynamic generation module, that is, the front-end standard component dynamic generation module parses the standard data source, realizes the data transmission of attributes and the dynamic mounting of events according to the parsed standard data, and dynamically generates layout components, sub-layout area components and functional components;

[0070] Furthermore, in the specific implementation, Vue uses the render function to describe the rendering result of the component; by receiving the createElement method as a parameter, creating a DOM element by calling the method, and finally returning the DOM element representing the component rendering result, dynamic and flexible rendering logic is implemented.

[0071] Furthermore, the createElement method receives two parameters, the first of which is the tag name of the tag creation node used to generate the layout component. The tag name can be a string representing an HTML tag name, such as 'div', 'p', etc.; it can also be a component option object used to render the component. Furthermore, the component element in Vue dynamically renders different components by binding the component name through the is attribute. The second parameter is an attribute object used to set the attributes, events, etc. bound to the functional component to be created. The attributes of the attribute object will be used as HTML attributes or DOM attributes; camel case nomenclature is used to specify the attribute name, such as: class, style, onClick; the corresponding attribute refers to strings, numbers, Boolean values, objects, etc., depending on the type of the attribute; if there is no parameter, this data can be ignored. Functional component attribute data can be set as functional component attributes.

[0072] Furthermore, Vue receives functional component attribute data through the props attribute and uses this data in the component. It verifies the type of the received data through the type option, specifies whether a certain attribute data is required through the required option, and performs more complex validation on the received data through the validator attribute.

[0073] In the present application, the principles of dynamically generating functional components and dynamically generating sub-layout area components are the same as the principles of dynamically generating layout area components, and will not be repeated here.

[0074] Step 4: Dynamically render and generate the front-end page based on the configured layout components, sub-layout area components, and functional components.

[0075] The specific steps of this step are:

[0076] Step 4.1, generating a layout component instance from a configured layout component; generating a sub-layout area component instance from a configured sub-layout area component; generating a functional component instance from a configured functional component;

[0077] Step 4.2, generating a virtual DOM tree according to the hierarchical relationship among the layout component instance, the sub-layout area component instance and the functional component instance; the virtual DOM tree includes a plurality of virtual nodes;

[0078] Mount the layout component instance, sub-layout area component instance and function component instance to the corresponding virtual nodes of the virtual DOM tree respectively to obtain the real DOM tree;

[0079] Step 4.3, traverse the real DOM tree from top to bottom, and when traversing to the layout component instance, execute the layout component instance to divide the entire page into multiple different functional areas;

[0080] Step 4.4, for each functional area, read the corresponding sub-layout area component instance from the real DOM tree, execute the sub-layout area component instance, and render the sub-layout area page content in the functional area of ​​the page;

[0081] Then read each functional component instance under the sub-layout area component instance from the real DOM tree, execute the functional component instance, and render the corresponding functional component in the rendered sub-layout area page content.

[0082] The method for dynamically generating a front-end page provided by the present invention has the following advantages:

[0083] (1) The development method based on pages is transformed into a development method based on components. Components are reusable, thus improving code reusability and extensibility, and improving page development efficiency;

[0084] (2) By using standard data sources, various types of standard components can be dynamically generated into various front-end components that meet actual page requirements. Components can be dynamically rendered and managed according to different standard data sources, thereby building more interactive and reusable front-end page applications. This has the advantages of high front-end component generation efficiency and high flexibility.

[0085] (3) In practical applications, dynamically generated front-end components can be used to dynamically render complex interactive components such as forms, lists, and pop-up windows, providing better user experience and maintainability. Therefore, in appropriate scenarios, the method of dynamically generating front-end components can be fully utilized to improve front-end development efficiency and user experience.

[0086] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be considered as the scope of protection of the present invention.

Claims

1. A method for dynamically generating a front-end page, characterized in that: The following steps are involved: Step 1: Customize the front-end standard component development specifications; The front-end standard component development specification includes: defining the front-end standard component directory structure, the front-end standard component name specification, the front-end standard component style specification, the front-end standard component interaction specification and the front-end standard component startup entry specification; Wherein: the front-end standard component directory structure is used to constrain the front-end standard component basic description file, front-end standard component source code and front-end standard component definition description file that must be included in the front-end standard component development phase; wherein, the front-end standard component basic description file includes the front-end standard component name, version, developer, dependency, and code repository address; the front-end standard component definition description file is used to describe the attribute specification, event specification, interaction specification and data source specification of the front-end standard component; The front-end standard component name specification is used to define the name specification of the front-end standard component to ensure the uniqueness of each front-end standard component name; The front-end standard component style specification is used to define the overall style specification of the front-end standard component and the interactive animation effect specification with each internal element; at the same time, the nesting and overlay rules between the front-end standard components are constrained; The front-end standard component interaction specification is used to impose basic constraints on the control mechanism of unidirectional data flow between parent and child components and the data bus mechanism between sibling components; The front-end standard component startup entry specification is used to define the specification at the entry of the front-end standard component startup; Step 2, developing and designing layout standard components, sub-layout area standard components and functional standard components according to the front-end standard component development specification; Step 3, using a standard data source, and configuring the layout standard components, sub-layout area standard components, and functional standard components respectively according to actual requirements of the page, to obtain the configured layout components, sub-layout area components, and functional components with a hierarchical relationship; The specific method is: By configuring the properties of the layout standard component, a layout component is obtained, wherein the layout component is associated with the entire page and is used to divide the entire page into different functional areas; By configuring the properties of the sub-layout area standard component, a sub-layout area component is obtained, wherein the sub-layout area component is a sub-node of the layout component, each of the sub-layout area components uniquely corresponds to a functional area divided by the layout component, and the sub-layout area component is used to perform page design for the functional area; By configuring the properties of the functional standard component, a functional component is obtained, wherein the functional component is a sub-node of the sub-layout area component, and the functional component is used to customize and complete related page functions in the functional area; Step 4: Dynamically render and generate the front-end page according to the configured layout components, sub-layout area components and functional components; Step 4 is as follows: Step 4.1, generating a layout component instance from a configured layout component; generating a sub-layout area component instance from a configured sub-layout area component; generating a functional component instance from a configured functional component; Step 4.2, generating a virtual DOM tree according to the hierarchical relationship among the layout component instance, the sub-layout area component instance and the functional component instance; the virtual DOM tree includes a plurality of virtual nodes; Mount the layout component instance, sub-layout area component instance and function component instance to the corresponding virtual nodes of the virtual DOM tree respectively to obtain the real DOM tree; Step 4.3, traverse the real DOM tree from top to bottom, and when traversing to the layout component instance, execute the layout component instance to divide the entire page into multiple different functional areas; Step 4.4, for each functional area, read the corresponding sub-layout area component instance from the real DOM tree, execute the sub-layout area component instance, and render the sub-layout area page content in the functional area of ​​the page; Then read each functional component instance under the sub-layout area component instance from the real DOM tree, execute the functional component instance, and render the corresponding functional component in the rendered sub-layout area page content.

2. A method for dynamically generating a front-end page according to claim 1, characterized in that: The standard data source describes the properties of the layout standard component, the properties of the sub-layout area standard component and the properties of the function standard component; The attributes of the layout standard component include the name of the layout standard component, the unique identifier of the layout standard component, and the unique identifier of the sub-layout area standard component contained in the layout standard component; The attributes of the sub-layout area standard component include the name of the sub-layout area standard component, the unique identifier of the sub-layout area standard component, and the unique identifier of the functional standard component included in the sub-layout area standard component; The attributes of the functional standard component include the name of the functional standard component, the unique identifier of the functional standard component, the event name and event value mounted by the functional standard component; wherein the event value refers to the business code for calling back the specific execution of the functional standard component.