Disclosure of Invention
To overcome the problems in the related art, the present invention provides a method and an apparatus for generating a component object.
According to a first aspect of embodiments of the present invention, there is provided a method of generating a component object, the method comprising:
acquiring code for describing webpage components from the code of the webpage;
acquiring component identification and parameter information of a webpage component from code for describing the webpage component; the parameter information comprises at least one attribute identifier of the webpage component and attribute information corresponding to each attribute identifier;
acquiring a component model corresponding to the webpage component according to the component identifier; the component model comprises each attribute identifier and an attribute information position corresponding to each attribute identifier; for the attribute information position corresponding to each attribute identifier, the attribute information position is used for filling in the attribute information corresponding to the attribute identifier;
and generating a component object according to the parameter information and the component model.
Wherein, the attribute information corresponding to the attribute identifier is an attribute value corresponding to the attribute identifier or a calculation method for calculating the attribute value corresponding to the attribute identifier;
wherein the obtaining code for describing the web page components from the code of the web page comprises:
searching a first preset character string and a second preset character string in the code of the webpage;
acquiring a character string between the first preset character string and the second preset character string;
and combining the first preset character string, the character string positioned between the first preset character and the second preset character, and the second preset character string into a code for describing the webpage component.
Wherein, the obtaining of the component model corresponding to the webpage component according to the component identifier includes:
acquiring a corresponding relation between a component identifier of a preset webpage component and an identifier of a component model;
searching the identification of the component model corresponding to the component identification of the webpage component from the corresponding relation;
and acquiring the component model corresponding to the identifier of the searched component model from a pre-stored component model library.
Wherein, the number of the obtained component models is one, and the generating of the component object according to the parameter information and the component model includes:
generating a blank component object;
filling the content included in the component model into the blank component object to obtain a reference component object;
and for the attribute information corresponding to each attribute identification, filling the attribute information into the attribute information position corresponding to the attribute identification included in the reference component object to obtain the component object.
The method for generating the component object according to the parameter information and the component model includes:
generating a blank component object;
detecting whether a plurality of component models with at least one same attribute identifier exist in the obtained component models;
when a plurality of component models have at least one same attribute identifier, creating a target number of mutually independent blank sub-objects in the blank component object, wherein the target number is the same as the number of the obtained component models; for each component model, filling contents included in the component model into a blank sub-object to obtain a first reference component object; and for the attribute information corresponding to each attribute identifier, filling the attribute information into the attribute information position corresponding to the attribute identifier in the first reference component object to obtain the component object.
When any two component models do not have the same attribute identification, filling the content in each component model into the blank component object to obtain a second reference component object; and for the attribute information corresponding to each attribute identifier, filling the attribute information into the attribute information position corresponding to the attribute identifier in the second reference component object to obtain the component object.
Further, the method further comprises:
detecting whether the code of the webpage contains an update character string for updating the component object;
when the code of the webpage contains an update character string for updating the component object; and updating the component object according to the updating character string.
According to a second aspect of embodiments of the present invention, there is provided an apparatus for generating a component object, the apparatus comprising:
the first acquisition module is used for acquiring codes for describing webpage components from the codes of the webpage;
the second acquisition module is used for acquiring the component identification and the parameter information of the webpage component from the code for describing the webpage component; the parameter information comprises at least one attribute identifier of the webpage component and attribute information corresponding to each attribute identifier;
a third obtaining module, configured to obtain, according to the component identifier, a component model corresponding to the web component; the component model comprises each attribute identifier and an attribute information position corresponding to each attribute identifier; for the attribute information position corresponding to each attribute identifier, the attribute information position is used for filling in the attribute information corresponding to the attribute identifier;
and the generating module is used for generating the component object according to the parameter information and the component model.
Wherein, the attribute information corresponding to the attribute identifier is an attribute value corresponding to the attribute identifier or a calculation method for calculating the attribute value corresponding to the attribute identifier;
wherein the first obtaining module comprises:
the first searching unit is used for searching a first preset character string and a second preset character string in the codes of the webpage;
the first acquiring unit is used for acquiring a character string between the first preset character string and the second preset character;
and the composition module is used for composing the first preset character string, the character string positioned between the first preset character and the second preset character string into a code for describing the webpage component.
Wherein the third obtaining module comprises:
the second acquisition unit is used for acquiring the corresponding relation between the component identification of the preset webpage component and the identification of the component model;
the second searching unit is used for searching the identification of the component model corresponding to the component identification of the webpage component from the corresponding relation;
and the third obtaining unit is used for obtaining the component model corresponding to the identifier of the searched component model from a prestored component model library.
Wherein, the component model that obtains is one, the generate module includes:
a first generating unit for generating a blank component object;
a first filling unit, configured to fill contents included in the component model into the blank component object to obtain a reference component object;
and the second filling-in unit is used for filling the attribute information corresponding to each attribute identifier into the attribute information position corresponding to the attribute identifier in the reference component object to obtain the component object.
Wherein, the parameter information who obtains is a plurality of and the subassembly model that obtains is a plurality of, the generation module includes:
a second generating unit that generates a blank component object;
the detection unit is used for detecting whether a plurality of component models with at least one same attribute identifier exist in the acquired component models;
a third filling unit, configured to create, when there are multiple component models having at least one same attribute identifier, a target number of mutually independent blank sub-objects in the blank component object, where the target number is the same as the number of the obtained component models; for each component model, filling contents included in the component model into a blank sub-object to obtain a first reference component object; and for the attribute information corresponding to each attribute identifier, filling the attribute information into the attribute information position corresponding to the attribute identifier in the first reference component object to obtain the component object.
A fourth filling unit, configured to fill, when any two component models do not have the same attribute identifier, the content included in each component model into a blank component object to obtain a second reference component object; and for the attribute information corresponding to each attribute identifier, filling the attribute information into the attribute information position corresponding to the attribute identifier in the second reference component object to obtain the component object.
Further, the apparatus further comprises:
the detection module is used for detecting whether the codes of the webpage contain an update character string for updating the component object;
the updating module is used for updating the component object when the code of the webpage contains an updating character string; and updating the component object according to the updating character string.
The technical scheme provided by the embodiment of the invention can have the following beneficial effects: by the method, in the process of writing a webpage code, if a technician writes a code for describing the webpage component, the technician does not need to write all the codes of the webpage component into the webpage code in advance, only needs to write the component identifier and the parameter information of the webpage component, when the terminal acquires the webpage code and finds the code for describing the webpage component in the webpage code, the component identifier and the parameter information are acquired from the code for describing the webpage component, then the component model which is required by the generation of the webpage component and is generated in advance is acquired according to the component identifier, then the component object is generated by using the parameter information and the acquired component model, and then the component is generated by using the component object. The technical personnel do not need to write all the codes of the webpage components into the codes of the webpage in advance, only need to write the component identification and the parameter information of the webpage components, and the writing amount of the component identification and the parameter information of the webpage components is far less than all the codes of the webpage components, so that the labor cost can be reduced.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention, as claimed.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the invention, as detailed in the appended claims.
FIG. 1 is a flow diagram illustrating a method of generating a component object, as shown in FIG. 1, including the following steps, in accordance with an exemplary embodiment.
In step S101, code describing a web page component is acquired from code of a web page;
when a user needs to obtain a web page, the user may input a URL (Uniform Resource Locator) of the web page to be obtained in the terminal, and the terminal obtains the URL input by the user, obtains a code of the web page corresponding to the URL from the web server according to the URL input by the user, and then renders the code of the web page, so that the web page content included in the web page may be displayed in the display screen of the terminal.
If the code for describing the webpage component is included in the code of the webpage, the code for describing the webpage component needs to be rendered, but the code for describing the webpage component needs to be acquired from the code of the webpage first.
Specifically, the step can be implemented by the following process, including:
11) searching a first preset character string and a second preset character string in the code of the webpage;
when the code for describing the webpage components is to be written in the process of writing the code for describing the webpage components in the server in advance, the technician distinguishes the code for describing the webpage components from other codes by using the preset character strings, for example, a first preset character string is added before the code for describing the webpage components and at a position next to the code for describing the webpage components, and a second preset character string is added after the code for describing the webpage components and at a position next to the code for describing the webpage components, so that the code for describing the webpage components and the codes of other webpages except the code for describing the webpage components can be distinguished in the codes of the webpages by the first preset character string and the second preset character string.
Typically, the second predetermined string is preceded by an identifier, such as identifier "/", that is the same string as the first predetermined string. For example, assuming that the first predetermined string is alert, the second predetermined string is/alert.
For example, assume that the code for a web page is: module ("panda. payload", "oc. lazyload > ]), direct (panda. settagname", "alert type" ("dager" text "/alert [" $ complex ', "$ part'," $ timeout ', "$ ocLazyLoad', function ($ complex, $ part, $ timeout, $ ocLazyLoad) { return: 'E', }, and the first predetermined string is alert, the second predetermined string is/alert.
12) Acquiring a character string between a first preset character string and a second preset character;
for example, a character string type between a first preset character string alert and a second preset character string/alert is obtained as "danger" text "hello" in the code of the above-described web page.
13) And forming a code for describing the webpage assembly by the first preset character string, the character string between the first preset character string and the second preset character string.
For example, a first preset character string alert, a character string type between the first preset character and a second preset character, and a second preset character string/alert are combined to form a code alert type for describing a web page component, which is "danger" text ═ hello "/alert.
In step S102, acquiring component identification and parameter information of the web page component from the code for describing the web page component;
the parameter information of the webpage component comprises at least one attribute identifier of the webpage component and attribute information corresponding to each attribute identifier; for any attribute information corresponding to an attribute identifier, the attribute information is an attribute value corresponding to the attribute identifier or a calculation method for calculating the attribute value corresponding to the attribute identifier.
In this embodiment of the present invention, when writing a code for describing a web page component in advance, a technician may use a first preset character string as a component identifier of the web page component, and for any attribute identifier and attribute information corresponding to the attribute identifier, associate the attribute identifier and the attribute information corresponding to the attribute identifier with a third character string, where, for example, the third preset character string may be: filling the attribute identifier in a position which is before and next to the third preset character string, including the attribute information by using a double quotation mark, and filling the attribute identifier in a position which is after and next to the third preset character string; the above operation is performed for each of the other attribute identifications and attribute information.
Therefore, the component identifier of the webpage component can be obtained according to the first preset character string, and each attribute identifier of the webpage component and attribute information respectively corresponding to each component identifier can be obtained according to the third preset character string.
Therefore, in this step, the first preset character string may be used as the component identifier of the web page component, and a third preset character string is searched in the code for describing the web page component, for each found third preset character string, the character string before and immediately adjacent to the third preset character string is used as an attribute identifier of the web page component, the character string after and immediately adjacent to the third preset character string and included by the double quotation mark "" is used as attribute information corresponding to the attribute identifier, and the above operations are all performed for each found other third preset character string.
For example, in the above-obtained code alert type for describing the web page component, "danger" text "/alert, a first preset character string alert is used as the component identifier of the web page component, and a third preset character string is found, and two third preset character strings are found.
Wherein, a character string before and immediately after the first third preset character string is type, and a character string included by the double quotation mark after and immediately after the first third preset character string is danger, so that it is possible to regard type as an attribute identification of the web page component and regard danger as attribute information corresponding to the attribute identification type, where the attribute information danger is an attribute value corresponding to the attribute component identification type.
A character string before and immediately after the second third preset character string is a text, and a character string included by the double quotation mark "" after and immediately after the second third preset character string is a hello, so that the text can be used as an attribute identification of the web page component, and the hello can be used as attribute information corresponding to the attribute identification text, wherein the attribute information hello is an attribute value corresponding to the attribute identification text.
In step S103, acquiring a component model corresponding to the web component according to the component identifier of the web component;
wherein, the component model comprises at least one attribute identifier and an attribute information position corresponding to each attribute identifier,
and for the attribute information position corresponding to any attribute identifier, filling the attribute information corresponding to the attribute identifier. The same is true for each of the other attributes identifying the corresponding attribute location.
The component model corresponding to the web page component acquired in this step includes each attribute identifier in the parameter information of the acquired web page component and the attribute information position corresponding to each attribute identifier.
In another embodiment of the present invention, the attribute information position may include placeholder information; the placeholder information may be a placeholder, etc.
The technical personnel can set the corresponding relation between the component identification of the preset webpage component and the identification of the component model, and in the corresponding relation, the component identification of each webpage component corresponds to the identification of at least one component model, namely each webpage component corresponds to at least one component model.
Thus, the step may specifically be: acquiring a corresponding relation between a component identifier of a preset webpage component and an identifier of a component model; searching the identification of the component model corresponding to the component identification of the webpage component from the corresponding relation; and acquiring the component model corresponding to the identifier of the searched component model from a pre-stored component model library.
In step S104, a component object is generated from the parameter information of the web page component and the acquired component model.
In the first case, if the obtained component model is one, the step may specifically be:
21) generating a blank component object;
22) filling the content in the acquired component model into the blank component object to obtain a reference component object;
wherein, the content included in the component model can be copied; and filling the copied content into the blank component object to obtain the reference component object.
23) And for the attribute information corresponding to each attribute identification, filling the attribute information into the attribute information position corresponding to the attribute identification included in the reference assembly object to obtain the assembly object.
And for the attribute information corresponding to any attribute identifier, searching an attribute information position for filling the attribute information in the reference assembly object according to the attribute identifier, and filling the attribute information in the searched attribute information position. And executing the operation on the attribute information corresponding to each attribute identifier.
In another embodiment of the present invention, if the searched attribute information position contains the placeholder information, the placeholder information in the searched attribute information position needs to be deleted first, and then the attribute information is filled into the searched attribute information position.
For example, assume that the generated blank component object is: component Object { }, and the obtained Component model is: the method includes the steps of generating a Component Model, generating a Component Object, and generating a Component Object, wherein the Component Model is { type [ [ type ] ] ', text [ [ text ] ]' } is equal occupancy information, the Component Model is equal to content type [ [ type ] ] ', text [ [ text ] ] and { } in the Component Object is blank, and the Component Object is { type [ [ type ] ]', text }.
Then, according to the attribute identification type, in the reference Component Object { type [ [ type ] ] ', text [ [ text ] ]' }, an attribute information position for filling in the attribute information danger corresponding to the attribute identification type is searched, and the attribute information position corresponding to the attribute identification type in the reference Component Object is taken as an attribute information position for filling in the attribute information danger corresponding to the attribute identification type, that is, the position where the placeholder information [ [ type ] ] is taken as an attribute information position for filling in the attribute information danger corresponding to the attribute identification type, and then the placeholder information [ [ type ] ] is deleted at the attribute information position for filling in the attribute information danger corresponding to the attribute identification type, and the attribute information danger corresponding to the attribute identification type is filled in the attribute information position.
Finally, according to the attribute identification text, searching an attribute information position for filling attribute information hello corresponding to the attribute identification text in the reference Component Object { type '[ [ type ] ]' }, and the attribute information position corresponding to the attribute identification text in the reference component object is used as the attribute information position for filling the attribute information hello corresponding to the attribute identification text, namely, the position where the position occupying information [ [ text ] ] is used as the attribute information position for filling the attribute information hello corresponding to the attribute identification text, then deleting the placeholder information [ text ] at the attribute information position for filling the attribute information hello corresponding to the attribute identification text, filling the attribute information hello corresponding to the attribute identification text into the attribute information position, this may result in a Component Object of type of dalger, text of hello'.
In the second case, if there are a plurality of parameter information and a plurality of component models, the step may specifically be:
31) generating a blank component object;
32) detecting whether a plurality of component models have at least one same attribute identifier in the obtained component models;
33) when a plurality of component models have at least one same attribute identifier, if the content in the acquired component model is directly added into a blank component object, the parameter information with the same plurality of attribute identifiers exists in the component object, so that a conflict may exist, and therefore, in order to avoid the conflict, a plurality of mutually independent blank sub-objects are created in the blank component object, and the number of the targets is the same as that of the acquired component models; for any component model, filling the content included in the component model into a blank sub-object, and for each other component model, executing the operation; adding contents in different component models in different blank sub-objects to finally obtain a first reference component object; and for the attribute information corresponding to any attribute identifier, filling the attribute information into the attribute information position corresponding to the attribute identifier in the first reference component object, and executing the operation for the attribute information corresponding to each other attribute identifier to finally obtain the component object.
Because the sub-objects are independent, the parameter information in any two sub-objects is also independent, and further, the situation of conflict does not exist.
For example, assume that the generated blank component object is: the obtained code for describing the web page Component is: the alert type is "danger" text "hello" class is "button"/alert; and the number of the obtained component models is two, wherein the first component model is as follows: a Component Model { [ type ] ] ', text [ [ text ] ]' }, and a second Component Model is: a Component Model { [ type ] ] ', class [ [ class ] ]' }.
The attribute identification type of the parameter information of one first Component model is the same as the attribute identification type of one parameter information of the second Component model, so in order to avoid conflict, two mutually independent blank sub-objects are created in a blank Component Object { }; then, adding the content in the first Component model to the first blank child Object, and adding the content in the second Component model to the second blank child Object, resulting in a Component Object { (type ═ pointer "text ═ hello" }; component Object { type ═ danger "class ═ button } }.
34) And when any two component models do not have the same attribute identification, if the obtained content in the component models is directly added into blank component objects, finally, the parameter information with the same attribute identification does not exist in the component objects, so that the conflict possibly does not exist. Therefore, the content included in each component model can be filled into the blank component object to obtain a second reference component object; and for the attribute information corresponding to any attribute identifier, filling the attribute information into the attribute information position corresponding to the attribute identifier in the second reference component object, and executing the operation for each piece of other parameter information to finally obtain the component object.
Through the mode of the embodiment shown in fig. 1 of the invention, in the process of writing a code of a webpage, if a technician needs to write a code for describing a webpage component, the technician does not need to write all codes of the webpage component into the code of the webpage in advance, but only needs to write a component identifier and parameter information of the webpage component, when a terminal acquires the code of the webpage and finds the code for describing the webpage component in the code of the webpage, the component identifier and parameter information are acquired from the code for describing the webpage component, then an assembly model which is required to be used by the webpage component and is generated in advance is acquired according to the component identifier, then a component object is generated by using the parameter information and the acquired assembly model, and then the assembly object is used to generate the assembly. The technical personnel do not need to write all the codes of the webpage components into the codes of the webpage in advance, only need to write the component identification and the parameter information of the webpage components, and the writing amount of the component identification and the parameter information of the webpage components is far less than all the codes of the webpage components, so that the labor cost can be reduced.
In another embodiment of the present invention, the technician may subsequently update the component object, for example, add some parameter information to the component object, delete some parameter information, or modify some parameter information, and in general, to save the update operation, the technician writes the code for updating the component object at the end of the code of the web page.
Therefore, after step S104, the method further includes: detecting whether a code of a webpage contains an updating character string for updating a component object; when the code of the webpage contains an update character string for updating the component object; and updating the component object according to the updating character string.
For example, assuming that a technician needs to delete parameter information whose attribute is identified as type in a component object, a code for deleting the parameter information whose attribute is identified as type is written at the end of the code of the web page: for example, when detecting this segment of code, according to the string type in the statement, the attribute information corresponding to the attribute identification type and the attribute identification type is searched for in the generated Component Object { type ═ dager ', text ═ hello }, then the attribute information controller corresponding to the attribute identification type and the attribute identification type is deleted in the generated Component Object { type ═ dager', text ═ hello }, and the updated Component Object is obtained { text ═ hello }, thus implementing updating of the Component Object.
FIG. 2 is a block diagram illustrating an apparatus for generating a component object in accordance with an example embodiment. Referring to fig. 2, the apparatus includes:
a first obtaining module 11, configured to obtain, from a code of a web page, a code for describing a web page component;
a second obtaining module 12, configured to obtain a component identifier and parameter information of a web page component from a code for describing the web page component; the parameter information comprises at least one attribute identifier of the webpage component and attribute information corresponding to each attribute identifier;
a third obtaining module 13, configured to obtain, according to the component identifier, a component model corresponding to the webpage component; the component model comprises each attribute identifier and an attribute information position corresponding to each attribute identifier; for the attribute information position corresponding to each attribute identifier, the attribute information position is used for filling in the attribute information corresponding to the attribute identifier;
and a generating module 14, configured to generate a component object according to the parameter information and the component model.
By means of the embodiment shown in fig. 2 of the present invention, in the process of writing a code of a web page, if a technician needs to write a code for describing a web page component, the technician does not need to write all codes of the web page component into the code of the web page in advance, but only needs to write a component identifier and parameter information of the web page component, when a terminal obtains the code of the web page and finds the code for describing the web page component in the code of the web page, obtains the component identifier and parameter information from the code for describing the web page component, then obtains a component model that is needed to be used for generating the web page component and has been generated in advance according to the component identifier, then generates a component object by using the parameter information and the obtained component model, and then generates a component by using the component object. The technical personnel do not need to write all the codes of the webpage components into the codes of the webpage in advance, only need to write the component identification and the parameter information of the webpage components, and the writing amount of the component identification and the parameter information of the webpage components is far less than all the codes of the webpage components, so that the labor cost can be reduced.
Wherein, the attribute information corresponding to the attribute identifier is an attribute value corresponding to the attribute identifier or a calculation method for calculating the attribute value corresponding to the attribute identifier;
wherein, the first obtaining module 11 includes:
the first searching unit is used for searching a first preset character string and a second preset character string in the codes of the webpage;
the first acquiring unit is used for acquiring a character string between the first preset character string and the second preset character;
and the composition module is used for composing the first preset character string, the character string positioned between the first preset character and the second preset character string into a code for describing the webpage component.
Wherein the third obtaining module 13 includes:
the second acquisition unit is used for acquiring the corresponding relation between the component identification of the preset webpage component and the identification of the component model;
the second searching unit is used for searching the identification of the component model corresponding to the component identification of the webpage component from the corresponding relation;
and the third obtaining unit is used for obtaining the component model corresponding to the identifier of the searched component model from a prestored component model library.
Wherein, the number of the obtained component models is one, and the generating module 14 includes:
a first generating unit for generating a blank component object;
a first filling unit, configured to fill contents included in the component model into the blank component object to obtain a reference component object;
and the second filling-in unit is used for filling the attribute information corresponding to each attribute identifier into the attribute information position corresponding to the attribute identifier in the reference component object to obtain the component object.
Wherein, the obtained parameter information is a plurality of and the obtained component model is a plurality of, the generating module 14 includes:
a second generating unit that generates a blank component object;
the detection unit is used for detecting whether a plurality of component models with at least one same attribute identifier exist in the acquired component models;
a third filling unit, configured to create, when there are multiple component models having at least one same attribute identifier, a target number of mutually independent blank sub-objects in the blank component object, where the target number is the same as the number of the obtained component models; for each component model, filling contents included in the component model into a blank sub-object to obtain a first reference component object; and for the attribute information corresponding to each attribute identifier, filling the attribute information into the attribute information position corresponding to the attribute identifier in the first reference component object to obtain the component object.
A fourth filling unit, configured to fill, when any two component models do not have the same attribute identifier, the content included in each component model into a blank component object to obtain a second reference component object; and for the attribute information corresponding to each attribute identifier, filling the attribute information into the attribute information position corresponding to the attribute identifier in the second reference component object to obtain the component object.
Further, the apparatus further comprises:
the detection module is used for detecting whether the codes of the webpage contain an update character string for updating the component object;
the updating module is used for updating the component object when the code of the webpage contains an updating character string; and updating the component object according to the updating character string.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Other embodiments of the invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the invention and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the invention being indicated by the following claims.
It will be understood that the invention is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the invention is limited only by the appended claims.