Disclosure of Invention
Aiming at the defects in the prior art, the invention provides a method, a device, a medium and equipment for mapping a proprietary component to a cross-platform development system, which can map the proprietary component to the cross-platform development system, reduce the development cost, save the development time and realize zero-cost switching among different program libraries or services.
The invention provides a method for mapping a proprietary component to a cross-platform development system, which comprises the following steps:
referencing a virtual component pre-registered based on a specific function in a cross-platform development system;
converting the virtual interface in the virtual component into a corresponding real interface according to a conversion rule in the virtual component;
and calling a special component corresponding to the specific function according to the real interface, and mapping the special component into the cross-platform development system.
Optionally, before the step of referencing the virtual component pre-registered based on the specific function in the cross-platform development system, the method further includes:
establishing a virtual component based on a specific function;
registering the virtual component in a cross-platform development system.
Optionally, the establishing a virtual component based on a specific function includes:
setting a virtual interface based on a specific function;
configuring virtual implementation code in the virtual interface;
setting a conversion rule for converting the virtual interface into a real interface;
and packaging the virtual interface and the conversion rule to generate a virtual component.
Optionally, before the step of setting the virtual interface based on the specific function, the method further includes:
judging whether the component based on the specific function is a visual component or not;
if so, creating a visual area of the component; then executing the step of setting a virtual interface based on a specific function;
and if not, executing the step of setting the virtual interface based on the specific function.
Optionally, the setting a virtual interface based on a specific function includes:
directly writing a virtual interface based on a specific function; or,
setting a component interface based on a configuration file of a specific function;
and generating a virtual interface according to the configuration file.
Optionally, after the step of referencing the virtual component pre-registered based on the specific function in the cross-platform development system, the method further includes:
calling a virtual interface in the virtual component;
testing and debugging the virtual interface in the cross-platform development system.
Optionally, the method according to claim 1, after the step of referencing the virtual component pre-registered based on the specific function in the cross-platform development system, further comprising:
judging whether the virtual component is a visual component or not;
if yes, placing the virtual component in a window design area; then, the step of converting the virtual interface in the virtual component into a corresponding real interface according to the conversion rule in the virtual component is executed;
if not, directly executing the step of converting the virtual interface in the virtual component into the corresponding real interface according to the conversion rule in the virtual component.
In a second aspect, the present invention provides an apparatus for mapping proprietary components to a cross-platform development system, comprising:
the component reference module is used for referencing virtual components which are registered in advance based on specific functions in the cross-platform development system;
the interface conversion module is used for converting the virtual interface in the virtual component into a corresponding real interface according to the conversion rule in the virtual component;
and the component mapping module is used for calling the special component corresponding to the specific function according to the real interface and mapping the special component to the cross-platform development system.
In a third aspect, the present invention provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a method of mapping proprietary components to a cross-platform development system in the first aspect.
In a fourth aspect, the present invention provides an apparatus for mapping proprietary components to a cross-platform development system, comprising: memory, a processor and a computer program stored on the memory and executable on the processor, the processor when executing the program implementing a method of the first aspect of mapping proprietary components to a cross-platform development system.
The invention provides a method for mapping a proprietary component to a cross-platform development system, which is characterized in that a virtual component based on a specific function is introduced, a conversion rule in the virtual component is utilized to convert a virtual interface in the virtual component into a corresponding real interface, the real interface is utilized to call the proprietary component, and then the proprietary component can be mapped to the cross-platform development system, so that the development cost can be reduced, the development time can be saved, and zero-cost switching between different program libraries or services can be realized.
The device for mapping the proprietary component to the cross-platform development system, the computer-readable storage medium and the equipment for mapping the proprietary component to the cross-platform development system have the same beneficial effects and the same inventive concept as the method for mapping the proprietary component to the cross-platform development system.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings. The following examples are only for illustrating the technical solutions of the present invention more clearly, and therefore are only examples, and the protection scope of the present invention is not limited thereby.
It is to be noted that, unless otherwise specified, technical or scientific terms used herein shall have the ordinary meaning as understood by those skilled in the art to which the invention pertains.
The invention provides a method, a device, a medium and equipment for mapping a proprietary component to a cross-platform development system. Embodiments of the present invention will be described below with reference to the drawings.
Referring to fig. 1, fig. 1 is a flowchart of a method for mapping a proprietary component to a cross-platform development system according to an embodiment of the present invention, where the method for mapping a proprietary component to a cross-platform development system according to the embodiment includes:
step S101: virtual components that are pre-registered based on a specific function are referenced in a cross-platform development system.
Step S102: and converting the virtual interface in the virtual component into a corresponding real interface according to the conversion rule in the virtual component.
Step S103: and calling a special component corresponding to the specific function according to the real interface, and mapping the special component into the cross-platform development system.
Wherein the specific function may be any type of function. Such as payment functions, storage functions, inquiry functions, functions of various hardware devices, and the like.
The specific component refers to a specific component corresponding to a specific function. May include software specific components and hardware device specific components. Proprietary components of the software may include: proprietary components of payment functions, proprietary components of storage functions, and the like. Hardware devices include, but are not limited to: bluetooth, development version, temperature sensor, unmanned aerial vehicle etc. equipment.
The virtual component can completely simulate components of any type and any platform, and can simulate not only software but also hardware equipment.
The cross-platform development system can be any cross-platform development system. For example, applet, Android, iOS, etc. platforms.
The virtual interface refers to an api (application programming interface) corresponding to the virtual component, and may include: functions, methods, attributes, etc. The virtual interface of the virtual component of each function type is a unified interface. For example, the virtual interface of the payment function is uniform and can be used in any cross-platform development system.
Wherein, the real interface refers to an application programming interface which can call the proprietary component. May include interfaces programmed in languages such as JavaScript, Java, Kotlin, Swift, Objective-C, C + +, and the like.
The conversion rule refers to a code rule for converting a virtual interface into a real interface. The conversion rules include function names, parameter values, defaults, asynchronizations, synchronizations, etc. The form of the conversion rule includes XML, JSON format, and the like. The conversion rules may be code in a variety of programming languages, including JavaScript, Java, Swift, and the like.
In the prior art, a special component applied to a specific cross-platform development system needs to be developed again in a new platform environment if the special component needs to be applied to another cross-platform development system; the invention converts the virtual interface in the virtual component into the corresponding real interface by using the conversion rule in the virtual component by using the virtual component based on the specific function, calls the special component by using the real interface, and further maps the special component into the cross-platform development system, thereby reducing the development cost, saving the development time and realizing zero-cost switching between different program libraries or services.
In a specific embodiment provided by the present invention, before the step of referencing virtual components pre-registered based on specific functions in the cross-platform development system, the method further includes: establishing a virtual component based on a specific function; registering the virtual component in a cross-platform development system.
The virtual components also need to be established before the proprietary components are mapped with the virtual components. The virtual component includes a virtual interface and a transformation rule. The virtual interfaces of the same specific function are consistent, and the conversion rule is different due to different cross-platform development systems.
When establishing a virtual component based on a specific function, the method may include: setting a virtual interface based on a specific function; configuring virtual implementation code in the virtual interface; setting a conversion rule for converting the virtual interface into a real interface; and packaging the virtual interface and the conversion rule to generate a virtual component.
When setting a virtual interface based on a specific function, one of the following two ways may be adopted:
the first method comprises the following steps: the interface code of the virtual component is written directly, and the interface code can be written by any programming language such as JavaScript, Python, PHP and the like. The interface code mainly comprises a plurality of functions, classes and variables.
And the second method comprises the following steps: setting a component interface based on a configuration file of a specific function; and generating a virtual interface according to the configuration file. Writing a configuration file for describing functions in the assembly through JSON or XML format, and generating a virtual assembly interface code according to the configuration file.
Both of these ways are within the scope of the present invention.
In a specific embodiment provided by the present invention, before the step of setting the virtual interface based on the specific function, the method may further include: judging whether the component based on the specific function is a visual component or not; if so, creating a visual area of the component; then executing the step of setting a virtual interface based on a specific function; and if not, executing the step of setting the virtual interface based on the specific function.
Before the virtual interface is set, whether the virtual component needing to be established is a visual component can be judged, if yes, a visual area of the component is established, and then the virtual interface is written. If not, directly writing the virtual interface.
Any visual component, such as a button, label, list, video player, etc., will have a rectangular or other shaped area, and a virtual component is no exception. If the real component mapped by the virtual component is a visual component (such as a dedicated player of an Android or iOS platform), the virtual component also needs to have a visual area, which can describe the position, size, background color, frame and other information of the virtual component. If the virtual component is a simple virtual component, a complete visualization function can be realized, if the virtual component is a complex virtual component, only basic functions need to be realized, even a rectangular frame is directly placed, and a visualization area of the virtual component is mainly used for setting relevant attributes (such as position, size and the like) of a real component and does not need to be completely the same as the functions of the real component.
In a specific embodiment provided by the present invention, after the virtual interface is set, a virtual implementation code needs to be set in the virtual interface.
By virtual implementation, it is meant an implementation that simulates a real component, typically only the results of the real component are simulated. For non-visual components, it is mainly composed of some APIs (functions, attributes, etc.), for example, the uploadfiletoalloyloud function in real components is used to upload local files to the airy cloud server. The same function (the same return value and the same parameter) is also provided for the virtual component corresponding to the virtual component, but the uploadfiletoalloyloud function of the virtual component does not need to actually upload the file to the Alice cloud server, and only needs to simulate the process. And if the upload FileToAllound function is uploaded successfully, returning true, otherwise, returning false. But also the local file path to be uploaded needs to be passed in through the parameters. The local files can be copied from one local directory to another in the uploadfiletoalloud function of the virtual component to simulate the process of uploading to the Alice cloud.
The API in the virtual component may be simulated in any feasible manner, and the function (or other API) in the virtual component may or may not be consistent with the interface of the real component, as long as the function is converted when the function is converted into the call of the real component. For example, the function corresponding to the virtual component may be uploadFile, and may be automatically converted to uploadfiletoalloy during the conversion.
Virtual implementations include implementations that are correct and implementations that simulate exceptions. The method is characterized in that the implementation of the simulation exception is completed through a function (such as error or other names) which causes the exception, when virtual implementation code is written, the function which causes the exception is called to complete the simulation exception, the function is set in a cross-platform development system to determine whether the exception can be triggered or not (the exception triggering function is notified through json, xml files or sockets and any other modes), and if the exception triggering is closed, the exception triggering function does not trigger the exception. For example, an exception triggering function may be used using the following code.
If an exception trigger is opened through the cross-platform development system, an error function is called to trigger an exception, and how to do the exception after the exception is triggered is required according to the API of the simulated real component, for example, the exception returns-1 in the example, and correctly returns 0, the exception is set in the corresponding function of the virtual component.
After the App is tested by using the virtual component, conversion is needed, and the virtual component, other codes and the UI are converted into source codes of a real platform. If a virtual component is encountered during conversion, the virtual component needs to be converted into a code of a corresponding platform for calling a real component, such as a code of an applet, an Android, an iOS and other platforms. These codes include, but are not limited to, codes in JavaScript, Java, Kotlin, Swift, Objective-C, C + +, and the like. How to convert depends on defined conversion rules, including but not limited to function names, parameter values, default values, asynchronous, synchronous, etc., and the form of conversion rules includes but not limited to XML, JSON format, and code of various programming languages (including but not limited to JavaScript, Java, Swift, etc.).
The conversion rule can be written by the user, or provided by the service provider. All within the scope of the invention.
After the virtual component is established, the virtual component needs to be registered in a cross-platform development system, including an XML, JSON configuration file manner, and a code (including but not limited to JavaScript, Java, Swift, etc.) manner.
In a specific embodiment provided by the present invention, after the step of referencing the virtual component pre-registered based on the specific function in the cross-platform development system, the method may further include: calling a virtual interface in the virtual component; testing and debugging the virtual interface in the cross-platform development system.
When using virtual components, the virtual interfaces need to be tested and debugged to ensure availability of the virtual interfaces.
In a specific embodiment provided by the present invention, after the step of referencing the virtual component pre-registered based on the specific function in the cross-platform development system, the method may further include: judging whether the virtual component is a visual component or not; if yes, placing the virtual component in a window design area; then, the step of converting the virtual interface in the virtual component into a corresponding real interface according to the conversion rule in the virtual component is executed; if not, directly executing the step of converting the virtual interface in the virtual component into the corresponding real interface according to the conversion rule in the virtual component.
Before the virtual component is used, whether the virtual component is a visual component needs to be judged, if yes, the virtual component needs to be placed on a visual designer, and if not, debugging test work can be carried out, or a virtual interface is directly converted according to a conversion rule.
If the virtual component is judged to be the visual component, the virtual component is placed on the visual designer, then debugging and testing are carried out on the virtual component, or the virtual interface is directly converted according to the conversion rule, which is all within the protection scope of the invention.
The invention can map real components with virtual components, including but not limited to mapping functions, methods, attributes, UI effects, etc. of real components; virtual implementation of the real component by the virtual component, including but not limited to simulation of return value, parameter transmission, UI, etc. of API corresponding to the real component in the virtual implementation; simulating the abnormal condition by using an abnormal trigger function in the virtual implementation, wherein the abnormal condition comprises but is not limited to the interaction between a cross-platform development system and the abnormal trigger function in various modes (json, xml configuration files, socket communication and the like); the code using the virtual component is converted to the corresponding code using the real component according to a json, xml or other format conversion description file. Including but not limited to function return values, function parameters, asynchronous, synchronous, etc.
The invention solves the following two technical problems:
1. the virtual components can be completely simulated on any type and any platform, so that Hybird App and any other cross-platform development technology can be embedded into the virtual components and run and tested. And finally, automatically replacing the virtual component with the real component when the object code is generated. The development efficiency is greatly improved, and the error probability is reduced.
2. The same class of applications can be abstracted through virtual components, such as the aforementioned OSS services. A unified interface for the virtual components may be used at development time. This can solve several problems as follows.
(1) These abstracted services can be tested by the nature of the virtual components. Because the virtual component adopts a virtual implementation mode, development can be completed without running real services, for example, real accounts can be simulated for development and testing without real OSS accounts, because some services are not easy to build real testing environments and may cost money.
(2) If a user wants to switch the same kind of service, for example, the user intends to switch from the ari cloud to the Tencent cloud, only the corresponding conversion rule needs to be used for regenerating once again, only a few seconds to a few minutes are needed, and the conversion cost can be almost ignored. That is, the switching can be performed at zero cost, so that the own system is not in a strong coupling relationship with any service.
(3) If the user wants to use more similar services, the user can write conversion rules by himself and then convert, so that all systems using the virtual components can be completely switched in a short time.
(4) The service provider can also define the conversion rule by itself according to the requirement of the virtual component, so that the system can enable all applications using the virtual component to use the service provided by the service provider only by loading the new conversion rule.
Based on the same inventive concept as the method for mapping the proprietary component to the cross-platform development system, correspondingly, the embodiment of the present invention further provides an apparatus for mapping the proprietary component to the cross-platform development system, as shown in fig. 2. Because the device embodiment is basically similar to the method embodiment, the description is simpler, and the relevant points can be referred to partial description of the method embodiment.
The invention provides a device for mapping a proprietary component to a cross-platform development system, which comprises the following steps:
a component referencing module 101 configured to reference a virtual component that is registered in advance based on a specific function in a cross-platform development system;
an interface conversion module 102, configured to convert a virtual interface in the virtual component into a corresponding real interface according to a conversion rule in the virtual component;
the component mapping module 103 is configured to invoke a proprietary component corresponding to the specific function according to the real interface, and map the proprietary component into the cross-platform development system.
In a specific embodiment provided by the present invention, the apparatus further includes:
the component establishing module is used for establishing a virtual component based on a specific function;
and the component registration module is used for registering the virtual component in the cross-platform development system.
In a specific embodiment provided by the present invention, the component establishing module includes:
an interface setting unit for setting a virtual interface based on a specific function;
the implementation code configuration unit is used for configuring virtual implementation codes in the virtual interfaces;
the conversion rule setting unit is used for setting a conversion rule for converting the virtual interface into a real interface;
and the virtual component generating unit is used for packaging the virtual interface and the conversion rule to generate a virtual component.
In a specific embodiment provided by the present invention, the component establishing module further includes:
a first judgment unit configured to judge whether or not a component based on a specific function is a visual component;
if so, creating a visual area of the component; then executing the content of the interface setting unit;
and if not, executing the content of the interface setting unit.
In a specific embodiment provided by the present invention, the interface setting unit includes:
the first interface setting subunit is used for directly writing a virtual interface based on a specific function; or,
the second interface setting subunit is used for setting the configuration file of the component interface based on the specific function; and generating a virtual interface according to the configuration file.
In a specific embodiment provided by the present invention, the apparatus further includes:
the interface calling module is used for calling a virtual interface in the virtual component;
and the debugging module is used for testing and debugging the virtual interface in the cross-platform development system.
In a specific embodiment provided by the present invention, the apparatus further includes:
the second judgment module is used for judging whether the virtual component is a visual component or not;
if yes, placing the virtual component in a window design area; then executing the content of the interface conversion module 102;
if not, the content of the interface conversion module 102 is directly executed.
In the above, the invention provides a device for mapping a proprietary component to a cross-platform development system.
Based on the same inventive concept as the method for mapping the proprietary component to the cross-platform development system, correspondingly, the embodiment of the present invention further provides a computer readable storage medium, on which a computer program is stored, which when executed by a processor implements the method for mapping the proprietary component to the cross-platform development system.
As can be seen from the foregoing technical solutions, in the computer-readable storage medium provided in this embodiment, a computer program is stored thereon, and when the program is executed by a processor, the program can convert a virtual interface in a virtual component into a corresponding real interface by referring to the virtual component based on a specific function, and using a conversion rule in the virtual component, and call a proprietary component by using the real interface, so that the proprietary component can be mapped into a cross-platform development system, which can reduce development cost, save development time, and implement zero-cost switching between different libraries or services.
Based on the same inventive concept as the above method for mapping a proprietary component to a cross-platform development system, correspondingly, an embodiment of the present invention further provides an apparatus for mapping a proprietary component to a cross-platform development system, including: memory, processor and computer program stored on the memory and executable on the processor, characterized in that the processor implements a method of mapping proprietary components to a cross-platform development system as described above when executing the program.
According to the technical scheme, the device for mapping the proprietary component to the cross-platform development system provided by the embodiment converts the virtual interface in the virtual component into the corresponding real interface by referring to the virtual component based on the specific function and utilizing the conversion rule in the virtual component, and calls the proprietary component by utilizing the real interface, so that the proprietary component can be mapped to the cross-platform development system, the development cost can be reduced, the development time can be saved, and zero-cost switching between different program libraries or services can be realized.