Page parameter transmission callback method and electronic equipment
By providing page passing methods in the React Native technology, the problem of separation and parameter logic separation between pages is solved, and the high readability and security of the code are achieved, which is convenient for later maintenance.
Patent Information
- Application Number
- CN202411444122.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-01-28
AI Technical Summary
In React Native technology, the logical separation between page jumps and parameters transfers is not conducive to later code maintenance, poor code readability and low security.
Provide a page -to -return adjustment method. The target page defines the required parameters and uses the annotation marker parameter type. The parameter is returned to the source page. The source page generates the start method to receive and process the operation results of the target page.
The logic of jumping between pages is associated with the logic of passing parameters, which improves the readability and security of the code, and facilitates the maintenance of the later code.
Smart Images

Figure CN119376787A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and in particular relates to a page parameter transfer callback method and an electronic device. Background Art
[0002] React Native (hereinafter referred to as RN) is an open source cross-platform mobile application development framework, a framework for developing Android and IOS apps. The main programming language is JavaScript, and the UI uses JSX (a UI description language similar to XML). It has Native user experience and retains React development efficiency. In the related RN technology, the logical separation between page jumps and parameter passing is not conducive to later code maintenance, and the code readability is poor and the security is low.
[0003] In response to the above problems, a page parameter transmission callback method and an electronic device of the present application are proposed. Summary of the invention
[0004] In order to solve the shortcomings of the prior art, the present application provides a page parameter passing callback method and electronic device, which can solve the logical separation between page jumping and parameter passing of RN technology in the related technology, which is not conducive to later code maintenance, poor code readability and low security.
[0005] The technical effects to be achieved by this application are achieved through the following solutions: In a first aspect, the present application provides a page parameter transfer callback method, comprising: The target page defines the required parameters, marks the parameter types of the parameters with annotations, and returns the parameters to the source page; A start method is generated in the source page, and the start method has a corresponding start annotation tag; The target page receives the target parameters transmitted from the source page, performs relevant operations based on the target parameters, obtains operation results, and returns the operation results to the source page.
[0006] In some embodiments, the target parameters include a mobile phone number and a password.
[0007] In some embodiments, returning the operation result to the source page includes: The target page adds a completion annotation tag to the operation result; Add the name of the return parameter, the type of the return parameter and the corresponding return source page name in the completion annotation tag.
[0008] In some embodiments, the method further comprises: The source page receives the operation result returned by the target page; After script compilation, the name of the returned source page in the completion annotation tag is obtained; Determine whether the returned source page name is the same as the class page name of the source page. If the returned source page name is the same as the class page name of the source page, generate a target start method in the source page; if the returned source page name is not the same as the class page name of the source page, it means that there is no corresponding class page and the corresponding target start method cannot be generated.
[0009] In some embodiments, generating a target start method in the source page includes: The target start method having a start annotation tag is generated on the source page, and the name of the target start method is: start target page.
[0010] In some embodiments, before the target page defines the required parameters, the method further includes: Define data types and common annotation tags; Among them, commonly used annotations include a start annotation tag and an end annotation tag. The start annotation tag is used to mark the page jump method, and the end annotation tag is used to close the page and return parameters.
[0011] In some embodiments, the operation result includes a token.
[0012] In some embodiments, the source page is a main page, and the target page is a login page; or, the source page is a login page, and the target page is a main page.
[0013] In a second aspect, the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any one of the methods described above when executing the computer program.
[0014] In a third aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement any of the methods described above.
[0015] A page parameter passing callback method and an electronic device are provided through an embodiment of the present application. When the parameter passing parameters of a target page are changed, all page start methods are updated in batches after script compilation, and the parameter types and parameter names are consistent with those defined in the target page, thereby realizing the logical association between page jumps and parameter passing, facilitating later code maintenance, and achieving the technical effect of high code readability and high security. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present application or the existing technical solutions, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0017] Figure 1 A schematic diagram of a related RN technology in an embodiment of the present application; Figure 2 This is a flow chart of a page parameter transfer callback method in an embodiment of the present application; Figure 3 This is an example of a page parameter callback method in an embodiment of the present application. Figure 1 ; Figure 4 This is an example of a page parameter callback method in an embodiment of the present application. Figure 2 ; Figure 5 It is a schematic block diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0019] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in one or more embodiments of the present application should be understood by people with ordinary skills in the field to which the present application belongs. The "first", "second" and similar words used in one or more embodiments of the present application do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0020] In the relevant RN technology, the communication between different pages is carried out through Listener. Figure 1 FIG. 1 is a schematic diagram of a related RN technology in an embodiment of the present application. Figure 1 As shown, it includes the main page (MainScreen) and sub-pages AX (SubScreenA, SubScreenB, ..., SubScreenX).
[0021] 1. MainScreen (main page) sends Message to all subpages; 2. Add a listener when the SubScreen (sub-page) starts, so as to realize the Message interaction between the main page and the sub-page.
[0022] 3. The principle of message interaction between sub-pages is the same as above.
[0023] The disadvantages of the above method are: 1. The logic of jumping and passing parameters between pages is separated, which is not conducive to later code maintenance and the readability of the code is poor.
[0024] 2. The logic separation of page return parameters and page jumps; for example, when sub-page A jumps to sub-page B (parameters need to be passed from A to B, and B needs to return to A after processing. The traditional method is to listen to the parameters returned by B through the Listener. The data type and parameter meaning require the developer to manually read the code on page B for analysis. This makes the code less readable and not conducive to later code maintenance).
[0025] 3. RN is a weak language. When using a listener to accept the parameters returned by the previous page, if the parameter format is incorrect due to human factors, no error will be reported during the compilation phase.
[0026] 4. If the parameter type or number of the receiving parameter page changes, the jump method of the jump page will be changed with a large workload, which is not conducive to maintenance. For example: the source page (HomeScreen1) jumps to the target page (LoginScreen); HomeScreen2 jumps to LoginScreen, etc. Since the parameters required for LoginScreen change, the traditional method requires manual changes to both HomeScreen1 and HomeScreen2.
[0027] 5. The above page jump method and the listening page callback logic are separated, that is, the codes are not together and are separated.
[0028] Therefore, it is necessary to adopt a page parameter passing callback method provided by the present application to solve the above problem of insecure data type jump between the two pages and the problem of logical separation between direct page jump and data callback.
[0029] Various non-limiting implementations of the present application are described in detail below in conjunction with the accompanying drawings.
[0030] First, refer to Figure 2 , the page parameter passing callback method of this application is explained in detail.
[0031] In a first aspect, the present application provides a page parameter transfer callback method, comprising: S1. The target page defines the required parameters, and uses annotations to mark the parameter types of the parameters, and returns the parameters to the source page; For example, the required parameters are defined on the LoginScreen login page, and the parameter type is marked with annotations, such as @string phoneNum. This annotation is used to find the relevant annotations for translation in the Python script during the compilation phase.
[0032] S2, generating a start method in the source page, wherein the start method has a corresponding start annotation tag; S3. The target page receives the target parameters transmitted from the source page, performs relevant operations based on the target parameters, obtains operation results, and returns the operation results to the source page.
[0033] In this application, when the parameter passing of the target page changes, all page start methods will be updated in batches after script compilation. The parameter type and parameter name are consistent with those defined in the target page, realizing the logical association between page jumps and parameter passing, which is beneficial to the later code maintenance, and has the technical effect of high code readability and high security.
[0034] Figure 3This is an example of a page parameter callback method in an embodiment of the present application. Figure 1 ;like Figure 3 As shown, the scenario of jumping from the source page (HomeScreen) to the target page (LoginScreen) can be used as an example for explanation. It should be noted that this is an exemplary example, and the same is true if jumping from LoginScreen to HomeScreen.
[0035] Specifically, HomeScreen1, HomeScreen2, etc. are used as source pages. The source page initiates a page jump action, passes a target parameter to the target page, and accepts and processes the result returned by the target page after the target page is processed.
[0036] Exemplarily, LoginScreen is a login page, which, as a target page, receives parameters passed from the source page, returns the completion result to the source page after processing is completed, and closes this page.
[0037] In some embodiments, the target parameters include a mobile phone number and a password. HomeScreen transmits the mobile phone number and the password to LoginScreen. LoginScreen logs in after receiving the parameters and returns the operation result (eg, token) to HomeScreen after successful login.
[0038] In some embodiments, returning the operation result to the source page includes: The target page adds a completion annotation tag to the operation result; illustratively, if the operation result (for example, login result) needs to be returned to the source page, a @finish tag, ie, a completion annotation tag, needs to be added.
[0039] Add the name of the return parameter, the type of the return parameter and the corresponding return source page name in the completion annotation tag.
[0040] For example, the name and type of the return parameter and the source page name are added to the @finish annotation tag (for subsequent comparison with the class page name. If they are inconsistent, the relevant class page will not be matched, and the relevant target start method will not be generated.
[0041] In some embodiments, the method further comprises: The source page receives the operation result returned by the target page; After script compilation, the name of the returned source page in the completion annotation tag is obtained; Determine whether the name of the returned source page is the same as the class page name of the source page. If the name of the returned source page is the same as the class page name of the source page, generate a target start method in the source page; if the name of the returned source page is not the same as the class page name of the source page, it means that there is no corresponding class page and the corresponding target start method cannot be generated; generate the target start method with a start annotation tag on the source page, and the name of the target start method is: start target page Specifically, after script compilation, a start method will be generated in the source page configured in @finish. The naming rule of the start method is: it starts with start and is followed by the target page name. For example, if HomeScreen1 jumps to LoginScreen, after script compilation, a method with the @start tag will be generated in the HomeScreen1 page, and the method name is startLoginScreen.
[0042] When the LoginScreen page receives parameters and returns parameter changes, the compilation script will traverse the @start tags and batch change the corresponding start methods, thereby realizing the logical association between page jumps and parameter transfer.
[0043] In some embodiments, before the target page defines the required parameters, the method further includes: Define data types and common annotation tags; Among them, commonly used annotations include a start annotation tag and an end annotation tag. The start annotation tag is used to mark the page jump method, and the end annotation tag is used to close the page and return parameters.
[0044] In some embodiments, the source page is a main page, and the target page is a login page; or, the source page is a login page, and the target page is a main page.
[0045] Figure 4 This is an example of a page parameter callback method in an embodiment of the present application. Figure 2 ;refer to Figure 4 To describe another embodiment of the present application.
[0046] First define the data type and common annotation tags; The data types include: @int: integer, @string: string, @obj: object, @json: json object.
[0047] Commonly used annotation tags include: @star: used to mark the page jump method, @finish: used to close the page and return parameters.
[0048] The target page defines all required parameters and parameter annotations; Returns parameters and parameter annotations to the source page; Write compilable Python scripts; Traverse the project directory structure and find js files that meet Python rules; Generate a start method on the source page and have a @start tag, which is used for subsequent updates.
[0049] The method of this application can be implemented as follows: 1. Solve the problem of logical separation between traditional page jump parameter passing and result return receiving parameters.
[0050] 2. To solve the problem of poor parameter readability in traditional methods, the method of this application can clearly understand the parameter type and its meaning.
[0051] 3. When the target page's parameter changes, all page start methods will be updated in batches after script compilation, and the parameter type and parameter name will remain consistent with those defined in the target page.
[0052] It should be noted that the method of one or more embodiments of the present application can be performed by a single device, such as a computer or server. The method of this embodiment can also be applied to a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of one or more embodiments of the present application, and the multiple devices will interact with each other to complete the described method.
[0053] It should be noted that the above describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0054] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, the present application also discloses an electronic device; Specifically, Figure 5A schematic diagram of the hardware structure of an electronic device for a page parameter transfer callback method provided in this embodiment is shown, and the device may include: a processor 410, a memory 420, an input / output interface 430, a communication interface 440, and a bus 450. The processor 410, the memory 420, the input / output interface 430, and the communication interface 440 are connected to each other in communication within the device through the bus 450.
[0055] The processor 410 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.
[0056] The memory 420 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 420 may store an operating system and other application programs. When the technical solution provided in the embodiment of the present application is implemented by software or firmware, the relevant program code is stored in the memory 420 and is called and executed by the processor 410.
[0057] The input / output interface 430 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0058] The communication interface 440 is used to connect a communication module (not shown in the figure) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (for example, USB, network cable, etc.) or a wireless mode (for example, mobile network, WIFI, Bluetooth, etc.).
[0059] The bus 450 includes a path that transmits information between the various components of the device (eg, the processor 410 , the memory 420 , the input / output interface 430 , and the communication interface 440 ).
[0060] It should be noted that, although the above device only shows the processor 410, the memory 420, the input / output interface 430, the communication interface 440 and the bus 450, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiment of the present application, and does not necessarily include all the components shown in the figure.
[0061] The electronic device of the above embodiment is used to implement the corresponding page parameter transfer callback method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0062] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, one or more embodiments of the present application also provide a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the page parameter passing callback method described in any of the above embodiments.
[0063] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0064] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the page parameter passing callback method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0065] A person skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present application (including the claims) is limited to these examples. In line with the concept of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of different aspects of one or more embodiments of the present application as described above, which are not provided in detail for the sake of simplicity.
[0066] In addition, to simplify the description and discussion, and in order not to make one or more embodiments of the present application difficult to understand, the well-known power / ground connections to the integrated circuit (IC) chip and other components may or may not be shown in the provided figures. In addition, the device may be shown in the form of a block diagram to avoid making one or more embodiments of the present application difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform on which one or more embodiments of the present application will be implemented (that is, these details should be fully within the scope of understanding of those skilled in the art). Where specific details (e.g., circuits) are set forth to describe exemplary embodiments of the present application, it is obvious to those skilled in the art that one or more embodiments of the present application can be implemented without these specific details or with changes in these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.
[0067] Although the present application has been described in conjunction with specific embodiments of the present application, many alternatives, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the discussed embodiments.
[0068] One or more embodiments of the present application are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present application should be included in the scope of protection of the present application.
Claims
1. A page parameter transfer callback method, characterized in that: The method comprises: The target page defines the required parameters, marks the parameter types of the parameters with annotations, and returns the parameters to the source page; A start method is generated in the source page, and the start method has a corresponding start annotation tag; The target page receives the target parameters transmitted from the source page, performs relevant operations based on the target parameters, obtains operation results, and returns the operation results to the source page.
2. The page parameter transfer callback method according to claim 1, characterized in that: The target parameters include a mobile phone number and a password.
3. The page parameter transfer callback method according to claim 1 or 2, characterized in that: The returning the operation result to the source page includes: The target page adds a completion annotation tag to the operation result; Add the name of the return parameter, the type of the return parameter and the corresponding return source page name in the completion annotation tag.
4. The page parameter transfer callback method according to claim 3, characterized in that: The method further comprises: The source page receives the operation result returned by the target page; After script compilation, the name of the returned source page in the completion annotation tag is obtained; Determine whether the returned source page name is the same as the class page name of the source page. If the returned source page name is the same as the class page name of the source page, generate a target start method in the source page; if the returned source page name is not the same as the class page name of the source page, it means that there is no corresponding class page and the corresponding target start method cannot be generated.
5. The page parameter transfer callback method according to claim 4, characterized in that: The generating a target start method in the source page includes: The target start method having a start annotation tag is generated on the source page, and the name of the target start method is: start target page.
6. The page parameter transfer callback method according to claim 5, characterized in that: Before the target page defines the required parameters, it also includes: Define data types and common annotation tags; Among them, commonly used annotations include a start annotation tag and an end annotation tag. The start annotation tag is used to mark the page jump method, and the end annotation tag is used to close the page and return parameters.
7. The page parameter transfer callback method according to claim 4, characterized in that: The operation result includes a token.
8. The page parameter transfer callback method according to claim 1, characterized in that: The source page is a main page, and the target page is a login page; or, the source page is a login page, and the target page is a main page.
9. An electronic device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the method according to any one of claims 1 to 8.