A method, apparatus, and equipment for operating multi-sub-application aggregation
By managing permission codes and routing path changes through sub-application registry and unified interception chain routing guards, the problems of permission code naming conflicts and listener leakage in the aggregated operation of multiple sub-applications are solved, and the normal operation and state consistency of the main application are achieved.
Patent Information
- Application Number
- CN202611303396.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-26
- Publication Date
- 2026-11-17
AI Technical Summary
When multiple sub-applications are merged and compiled into a main application installation package, the lack of a unified namespace management for permission codes leads to problems such as difficulty in timely detection of permission code naming conflicts, difficulty in detecting configuration errors during the main application startup phase, scattered page permission judgment logic, inconsistent permission verification entry points, insufficient sub-application domain recognition capabilities, and listener leaks.
Permission verification is performed by obtaining permission code information from the sub-application registry, a global route permission index is established, and route guards with a unified interception chain are used for permission verification. Route path changes and lifecycle hooks are managed in a unified manner, and login state and status data are shared to avoid each sub-application implementing its own permission judgment and listener.
It enables timely detection of permission code anomalies during the main application startup phase, unified management of permission verification and routing path changes, avoids logic fragmentation and listener leakage, and ensures the normal operation and state consistency of the main application.
Smart Images

Figure CN123116261A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of application software, and more particularly to a method, apparatus, and device for operating multiple sub-application aggregation. Background Technology
[0002] Currently, multiple sub-applications are compiled and installed into a main application package. However, the lack of a unified namespace management for the permission codes of these sub-applications leads to naming conflicts and other defects. During the main application startup phase (including the development phase), configuration errors are difficult to detect in a timely manner, causing the main application to malfunction. Furthermore, page permission judgment logic is typically implemented independently by each sub-application and scattered within their respective systems, resulting in inconsistent permission verification entry points and the inability of the interface to automatically respond after permission changes. The main application framework lacks the ability to identify sub-application domains, requiring each sub-application to independently listen for route changes and execute corresponding logic, which can easily lead to problems such as listener leaks. Summary of the Invention
[0003] This application provides a method, apparatus, and device for running multi-sub-application aggregation to solve at least one problem existing in related technologies. The technical solution is as follows: In a first aspect, embodiments of this application provide a method for running multi-sub-application aggregation, including: In response to the main application's startup command, the permission code information of each sub-application is obtained through the sub-application registry. The permission code information is verified during the registration of the sub-application. After the permission code verification is successful, the global routing permission index of all sub-applications is determined, and the main application enters the normal operation state. When the main application is in normal operation, in response to the change of the route path from the first route path to the second route path, the route guard of the unified interception chain performs permission verification based on the second route path and the global route permission index. When the permission verification passes, the page corresponding to the second route path is displayed. Based on the first routing path, the second routing path, and the preset routing prefix, determine the sub-application domain switching result corresponding to the routing path change; Based on the sub-application domain switching result, the lifecycle hook is triggered, and the corresponding business logic of the lifecycle hook is executed.
[0004] In one implementation, obtaining the permission code information of each sub-application through the sub-application registry and verifying the permission code information during sub-application registration includes: By accessing the sub-application registry, obtain the permission code information reported by each sub-application. The permission code information includes all the permission codes that the sub-application has and the permission codes required for the routing path. When registering a sub-application, obtain the sub-application identifier of the sub-application, and perform permission code verification based on the sub-application identifier, all permission codes, and the required permission codes for the routing path. The permission code verification includes at least one of the following: format verification, prefix verification, uniqueness verification, and routing path reference consistency verification. The permission code verification passes when all types of verifications pass.
[0005] In one implementation, format validation: checks whether all permission codes contain illegal characters; Prefix verification: Verify whether the prefix in all permission codes is a sub-application identifier; Uniqueness check: Check whether all permission codes within a sub-application are duplicated, and whether all permission codes across different sub-applications are duplicated; Routing path reference consistency check: Verify whether the required permission code exists among all permission codes.
[0006] In one implementation, the global routing permission index includes the routing paths of each sub-application and the permission codes corresponding to the routing paths; the permission verification based on the second routing path and the global routing permission index via the unified interception chain routing guard includes: By using route guards in a unified interception chain, a matching route path is determined from the global route permission index based on the second route path; The permission code corresponding to the matched route path is matched with the permission set of the user logged in to the main application; if the match is successful, the permission verification passes.
[0007] In one embodiment, the method further includes at least one of the following: The authentication module of the unified interception chain stores the access token after the user logs into the main application and enables all sub-applications to share the login state, and automatically refreshes the access token when the access token meets the refresh conditions. By using a unified interception chain for button permissions, the display or hiding of page elements is controlled based on whether the permission verification passes. By using a unified interception chain HTTP interceptor, redirect to a network error page when there is no response status code, or redirect to a server error page when the backend server returns an error status code, while retaining the page stack before the redirection. If a matching route path does not exist for the second route path, the user is redirected to a route mismatch exception page using a unified interception chain route guard.
[0008] In one implementation, the method for determining the sub-application domain switching result corresponding to the route path change based on the first route path, the second route path, and the preset route prefix includes: The first routing path and the second routing path are respectively matched with the preset routing prefix using the longest prefix to determine the first sub-application name of the sub-application domain of the first routing path and the second sub-application name of the sub-application domain of the second routing path. The first sub-application name is compared with the second sub-application name. If the first sub-application name is different from the second sub-application name, the sub-application domain switching result corresponding to the route path change is determined to be a sub-application domain switching that has occurred; if the first sub-application name is the same as the second sub-application name, the sub-application domain switching result corresponding to the route path change is determined to be a sub-application domain switching that has not occurred.
[0009] In one implementation, the step of triggering a lifecycle hook and executing the corresponding business logic based on the sub-application domain switching result includes: When the sub-application domain switching result is that a sub-application domain switching has occurred, the lifecycle hook for leaving is triggered to execute the cleanup business logic of the sub-application corresponding to the first route path, and the lifecycle hook for entering is triggered to execute the initialization business logic of the sub-application corresponding to the second route path. When the sub-application domain switching result is that no sub-application domain switching has occurred, the lifecycle hook for same-domain route change is triggered, and the update business logic of the sub-application corresponding to the second route path is executed.
[0010] In one embodiment, the method further includes: When a sub-application is registered, multilingual entries are registered in the sub-application registry. The multilingual entries of each sub-application are merged into a global dictionary by language dimension through the sub-application registry, and the current language identifier is stored. In response to a language switching command, the current language identifier is updated through the sub-application registry, and the corresponding multilingual entries are retrieved from the global dictionary based on the updated current language identifier, and each sub-application is notified to refresh the corresponding interface. And / or, In response to the main application's startup command, the plugins declared by each sub-application through the configuration file are loaded. The main application manages the state data generated after the plugins run, so that each sub-application shares the same state. The application runtime events are orchestrated in a unified manner through the hook system. Each sub-application subscribes to the hook system, and the main application notifies the sub-applications when an application runtime event occurs.
[0011] Secondly, embodiments of this application provide an apparatus for running multi-sub-application aggregation, comprising: The registration module is used to respond to the main application's startup command, obtain the permission code information of each sub-application through the sub-application registry, and verify the permission code information when registering the sub-application. After the permission code verification is successful, the global routing permission index of all sub-applications is determined, and the main application enters the normal operation state. The interception module is used to respond to the change of the route path from the first route path to the second route path when the main application is in normal operation. It uses the route guard of the unified interception chain to perform permission verification based on the second route path and the global route permission index. When the permission verification is successful, the page corresponding to the second route path is displayed. The determination module is used to determine the sub-application domain switching result corresponding to the route path change based on the first route path, the second route path, and the preset route prefix. The execution module is used to trigger lifecycle hooks and execute the corresponding business logic based on the sub-application domain switching results.
[0012] In one implementation, the interception module is further configured to: The authentication module of the unified interception chain stores the access token after the user logs into the main application and enables all sub-applications to share the login state, and automatically refreshes the access token when the access token meets the refresh conditions. By using a unified interception chain for button permissions, the display or hiding of page elements is controlled based on whether the permission verification passes. By using a unified interception chain HTTP interceptor, redirect to a network error page when there is no response status code, or redirect to a server error page when the backend server returns an error status code, while retaining the page stack before the redirection. If a matching route path does not exist for the second route path, the user is redirected to a route mismatch exception page using a unified interception chain route guard.
[0013] In one implementation, the execution module is further configured to: When a sub-application is registered, multilingual entries are registered in the sub-application registry. The multilingual entries of each sub-application are merged into a global dictionary by language dimension through the sub-application registry, and the current language identifier is stored. In response to a language switching command, the current language identifier is updated through the sub-application registry, and the corresponding multilingual entries are retrieved from the global dictionary based on the updated current language identifier, and each sub-application is notified to refresh the corresponding interface. And / or, In response to the main application's startup command, the plugins declared by each sub-application through the configuration file are loaded. The main application manages the state data generated after the plugins run, so that each sub-application shares the same state. The application runtime events are orchestrated in a unified manner through the hook system. Each sub-application subscribes to the hook system, and the main application notifies the sub-applications when an application runtime event occurs.
[0014] Thirdly, embodiments of this application provide an electronic device, including: a processor and a memory, wherein the memory stores instructions that are loaded and executed by the processor to implement the methods in any of the above-described embodiments.
[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed, implements the methods in any of the above-described embodiments.
[0016] The beneficial effects of the above technical solution include at least the following: By obtaining permission code information for each sub-application through the sub-application registry during the main application startup phase, and verifying the permission codes during sub-application registration, the global route permission index for all sub-applications is determined upon successful verification, allowing the main application to enter normal operation. This approach detects permission code anomalies during application startup. During normal operation, in response to route changes from the first to the second route path, a unified interception chain's route guard performs permission verification based on the second route path and the global route permission index. Upon successful verification, the page corresponding to the second route path is displayed. This convergence of permission interception logic to the route guard avoids the pitfalls of each sub-application implementing its own permission checks. This addresses the issues of scattered logic and inconsistent states in multi-sub-application scenarios. It determines the sub-application domain switching result corresponding to the route path change based on the first route path, the second route path, and the preset route prefix. Lifecycle hooks are triggered based on these results, executing the corresponding business logic. This allows each sub-application to execute its business logic based on the lifecycle hooks during a switch, eliminating the need for each sub-application to register its own route listener to detect the switch event. Ultimately, permission code verification, permission interception, lifecycle hook triggering of sub-application switching results, and business logic execution all converge within the main application framework. This resolves the issues of inconsistent states and data leaks caused by scattered logic and listeners in multi-sub-application aggregation scenarios.
[0017] The above overview is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments, and features described above, these aspects, embodiments, and features will become readily apparent from the accompanying drawings and the following detailed description. Attached Figure Description
[0018] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the various drawings denote the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings depict only some embodiments disclosed in this application and should not be construed as limiting the scope of this application.
[0019] Figure 1 This is a flowchart illustrating the steps of a method for running multi-sub-application aggregation according to an embodiment of this application. Figure 2This is a structural block diagram of a multi-sub-application aggregation operating device according to an embodiment of this application; Figure 3 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation
[0020] In the following description, only certain exemplary embodiments are briefly described. As those skilled in the art will recognize, the described embodiments can be modified in various ways without departing from the spirit or scope of this application. Therefore, the drawings and description are considered to be exemplary in nature and not restrictive.
[0021] Reference Figure 1 The flowchart illustrates a method for running multi-sub-application aggregation according to an embodiment of this application. The method is executed by the main application's base / main application framework (hereinafter referred to as the main framework). The method for running multi-sub-application aggregation may include at least steps S100-S400: S100: In response to the startup command of the main application, obtain the permission code information of each sub-application through the sub-application registry, and verify the permission code information when registering the sub-application.
[0022] Once the permission code verification passes, the global route permission index for all sub-applications is determined, and the main application enters normal operation. Understandably, if the permission code verification fails, an error message is displayed. Therefore, permission code anomalies can be detected and handled promptly during the startup / development phase of the main application.
[0023] S200: When the main application is in normal operation, in response to the change of the routing path from the first routing path to the second routing path, the unified interception chain routing guard performs permission verification based on the second routing path and the global routing permission index. When the permission verification passes, the page corresponding to the second routing path is displayed.
[0024] S300: Based on the first routing path, the second routing path, and the preset routing prefix, determine the sub-application domain switching result corresponding to the routing path change.
[0025] S400: Based on the sub-application domain switching result, trigger the lifecycle hook and execute the business logic corresponding to the lifecycle hook.
[0026] The technical solution of this application embodiment obtains the permission code information of each sub-application through the sub-application registry during the main application startup phase. Permission code verification is performed during sub-application registration. Upon successful verification, the global routing permission index for all sub-applications is determined, and the main application enters normal operation. This allows permission code anomalies to be detected during application startup. During normal operation, in response to route path changes from the first to the second route path, the unified interception chain's route guard performs permission verification based on the second route path and the global routing permission index. Upon successful verification, the page corresponding to the second route path is displayed. This convergence of permission interception logic to the route guard prevents each sub-application from implementing its own separate implementation. The problem of scattered logic and inconsistent states caused by permission checks is addressed by determining the sub-application domain switching result corresponding to the route path change based on the first route path, the second route path, and the preset route prefix. Lifecycle hooks are triggered based on the sub-application domain switching result, and the corresponding business logic is executed. This allows each sub-application to execute its corresponding business logic based on the lifecycle hooks when a switch occurs, eliminating the need for each sub-application to register its own route listener to detect the switch event. Ultimately, permission code verification, permission interception, lifecycle hook triggering of sub-application switching results, and business logic execution are all converged within the main application framework, resolving the issues of inconsistent states and memory leaks caused by scattered logic and listeners in multi-sub-application aggregation scenarios.
[0027] For example, for ease of explanation, the main application is the Smart Factory Mobile Platform App, which includes at least two sub-applications, such as sub-applications A, B, and C. These are compiled and merged into the Smart Factory Mobile Platform installation package. After installation, the Smart Factory Mobile Platform (i.e., the main application) can be launched. For instance, A could be the production management sub-application (preset route prefix mes / production, developed by the production team, including pages such as production dashboard, production work order list, and work order reporting); B could be the personnel center sub-application (preset route prefix iidp / user, developed by the HR team, including pages such as login, personal profile, and my attendance); and C could be the equipment inspection sub-application (preset route prefix eam / inspect, developed by the equipment team, including pages such as inspection tasks and inspection execution). The Smart Factory Mobile Platform App's bottom TabBar contains four bottom navigation tabs, such as Home (A's production dashboard), Work Orders (A), Inspection (C), and My (B).
[0028] In one implementation, step S100 includes steps S110-S130: S110. Obtain the permission code information reported by each sub-application through the sub-application registry.
[0029] Optionally, in response to the main application's launch command, including but not limited to clicks, voice commands, etc., the installed main application is operated to trigger the main application's launch command. In response to the launch command, each sub-application calls the registration method new SubApp(appId).register({...}) in its respective configuration file to report the relevant information of the sub-application. The relevant information reported by each sub-application is received and obtained through the SubAppRegistry of the base (BaseApp, which can also be called the main application framework, used to provide unified governance services for the operation of each sub-application).
[0030] Optionally, the relevant information includes, but is not limited to, the sub-application identifier (appId), the permission code list (permissions), the protected route list (protectedRoutes), and multilingual messages. The permission code list (permissions) includes all permission codes possessed by the sub-application. The protected route list (protectedRoutes) includes the route paths of pages requiring access permissions and the corresponding permission codes for those routes. For example, it can be configured that accessing A's production work order list and work order reporting page requires a corresponding permission code, and C's inspection task page requires a corresponding permission code, etc. Furthermore, the permission code information includes, but is not limited to, all permission codes possessed by each sub-application and the required permission codes corresponding to the route paths in the protected route list (protectedRoutes); one permission code can be used for one or more corresponding pages.
[0031] S120. When registering a sub-application, obtain the sub-application identifier of the sub-application, and perform permission code verification based on the sub-application identifier, all permission codes, and the required permission codes for the routing path.
[0032] Optionally, when registering a sub-application, the sub-application identifier is obtained, namely the sub-application identifier appId reported through the sub-application registry mentioned above. Based on the sub-application identifier appId, all permission codes, and the required permission codes for the routing path, permission code verification is performed.
[0033] The permission code verification includes at least one of the following: format verification, prefix verification, uniqueness verification, and routing path reference consistency verification. If all types of verification pass, the permission code verification passes; if any one type of verification fails, the permission code verification fails. This application's embodiments involve all these types of verification; other embodiments may involve one or more of them. Specifically: 1. Format Validation: This checks all permission codes for illegal characters. Specifically, it checks all permission codes in the permissions section of each sub-application for any illegal characters. If no illegal characters are found, the format validation of the corresponding sub-application's permission code passes. For example, illegal characters include underscores, spaces, Chinese characters, and other special symbols.
[0034] 2. Prefix verification: Verify whether the prefix in all permission codes is the sub-application identifier.
[0035] In this embodiment of the application, the prefix of the permission code is designed to be the sub-application identifier appId of the corresponding sub-application. Therefore, if the prefix of each permission code in all permissions is the sub-application identifier of the corresponding sub-application, the prefix verification of the corresponding sub-application permission code passes.
[0036] 3. Uniqueness check: Check whether all permission codes within a sub-application are duplicated, and whether all permission codes across different sub-applications are duplicated.
[0037] In this embodiment of the application, for each sub-application's permissions, it verifies whether all permission codes within the sub-application are duplicated, and checks whether the permission codes between different sub-applications are duplicated. If there are no duplicates, the uniqueness verification of the corresponding sub-application's permission code passes.
[0038] 4. Routing path reference consistency check: Check whether the required permission code exists in all permission codes.
[0039] In this embodiment of the application, for each sub-application, it is verified whether the required permission code exists in all permission codes of the permissions of the sub-application. If it exists, it means that the setting is correct and the routing path reference consistency verification of the corresponding sub-application permission code passes.
[0040] In this embodiment, after the permission code verification passes, the global route permission index (routePermissionIndex) for all sub-applications is determined, and the main application enters normal operation. Specifically, after the permission code verification passes, the sub-application registry organizes and stores the contents of the protected route lists for all sub-applications, ultimately forming a global route permission index stored in the sub-application registry. This global route permission index includes the route paths of each sub-application and the corresponding permission codes. More specifically, it includes the route paths of all pages requiring access permissions in all sub-applications and the corresponding permission codes (required permission codes). Since some pages are publicly accessible and do not require access permissions, they do not have corresponding required permission codes. Therefore, the global route permission index allows for global management of the permission codes (required permission codes) of all sub-applications. Subsequent unified interception chain route guards only need to utilize the global route permission index in the sub-application registry to query the required permissions based on the route path and the required permission code. For example, when you enter a page, based on the page's route path such as / eam / inspect / pages / inspect / execute, you can find that the required permission code is eam_inspect.task.execute, which means that the current page requires the eam_inspect.task.execute permission.
[0041] Therefore, through the embodiments of this application, permission code configuration errors are exposed and the source of conflict is pointed out during the registration / startup / development period, which solves the problems of lack of unified namespace management, non-standard format, cross-application conflicts, and exposure only when the main application is running in related technologies.
[0042] In one implementation, in step S200, when the main application is in normal operation, if a user operation triggers a page switch (e.g., from the currently displayed first page (corresponding to the first routing path) to the second page (corresponding to the second routing path), the main application, in response to this routing path change from the first to the second routing path, will perform permission verification through the unified interception chain's route guard, based on the second routing path and the global routing permission index. Specifically, this includes steps S210-S220: S210. Through the route guard of the unified interception chain, determine the matching route path from the global route permission index based on the second route path.
[0043] Optionally, the unified interception chain's route guard determines whether the second route path is in the whitelist. If not, it checks if the user is logged in. If logged in, the unified interception chain's route guard matches the second route path against the global route permission index to determine if a matching route exists. If a matching route exists, it's considered a match, indicating that the second route path requires permission. Conversely, if no matching route exists, it means the second route path doesn't require permission, and the user can directly redirect to the page displaying the second route path.
[0044] S220. Match the permission code corresponding to the matched route path with the permission set of the user logged in to the main application.
[0045] Optionally, in the global route permission index, the permission code corresponding to the matched route path can be determined based on the matched route path. This permission code is then matched against the permission set of the user logged into the main application. If the user's permission set contains a permission code identical to the one corresponding to the matched route path, the match is successful, the permission verification passes, and the page corresponding to the second route path is displayed, achieving a successful switch from the first page to the second page. Otherwise, the permission verification fails, the second page is not displayed, and the user is redirected to a permission-invalid page (e.g., a 403 error page), while retaining the page stack of the first page. The user can click "back" to return to the first page without losing the first route path. It should be noted that when a user logs into the main application, they send their login credentials (such as username and password) to the backend server to verify their identity, and then receive an access token and the user's permission set.
[0046] In this embodiment, a unified interception chain is designed in the base of the main application. The runtime behavior / events of each sub-application are handled uniformly through the unified interception chain, so that each sub-application does not need to implement permission judgment and runtime behavior monitoring logic separately. This avoids the logic dispersion and state inconsistency caused by each sub-application implementing permission judgment and monitoring separately, which affects the normal operation of the main application.
[0047] Optionally, in addition to route guards, the designed unified interception chain also includes, but is not limited to, an authentication module, button permission rules, and an HTTP interceptor, specifically enabling the following functions: 1. Through the authentication module of the unified interception chain, after the user logs into the main application, the access token is stored and the login state is shared by all sub-applications, and the access token is automatically refreshed when the access token meets the refresh conditions.
[0048] Optionally, through the authentication module of the unified interception chain, after a user logs into the main application, the access token returned by the backend server is stored. The access token is stored in the Auth singleton in the base (the module responsible for authentication), allowing all sub-applications to share the login state without the need to manage the login state of each sub-application separately. When the access token meets the refresh conditions, such as when the access token is about to expire (less than 5 minutes), the access token in the Auth of the base is automatically refreshed. For example, if a user simultaneously triggers two API requests, one for the work order list and the other for the inspection task, and the token has expired, after the access token is automatically refreshed, since all sub-applications share the login state, the two concurrent requests share the same access token refresh. After the refresh is completed, each request is replayed, and the user is unaware of the change, ensuring continued normal operation.
[0049] 2. By using a unified interception chain for button permission rules, the display or hiding of page elements is controlled based on whether the permission verification passes.
[0050] Optionally, the display or hiding of page elements can be controlled based on whether permission verification passes. For example, if a user clicks the "Inspection (C)" tab from the "Work Order (A)" tab in the bottom TabBar of the app, and the route guard in S220 confirms that the permission verification has passed, the page with the second route path, such as "Inspection (C)," will be displayed. At this point, the button permissions of each button element in the unified interception chain's button permission rules will be further matched with the logged-in user's permission set. If the match is successful, the corresponding button element will be displayed; otherwise, the corresponding button element will be hidden. The page responds automatically without the need for manual refresh or rendering.
[0051] 3. Using a unified interception chain HTTP interceptor, redirect to a network error page when there is no response status code, or redirect to a server error page when the backend server returns an error status code, while retaining the page stack before the redirection.
[0052] Optionally, when a user switches to a second page from the first page, network errors such as no signal or inability to send requests may occur. In this case, the HTTP interceptor of the unified interception chain intercepts the no-response status code and redirects the user to a network error page. Alternatively, when the backend server returns an error status code, the HTTP interceptor intercepts the error status code (e.g., 500), redirects the user to a server error page, and retains the page stack before the redirection. The original page can be returned through the page stack. In some implementations, the redirection to the server error page may also carry the source page parameters.
[0053] 4. Using the unified interception chain for route guarding, if no matching route path exists for the second route path, redirect to the route mismatch exception page.
[0054] Optionally, if a user might access a page that has been removed from the app store via an invalid link or a QR code, and since the main application no longer has the corresponding page, the unified interception chain's route guard determines that there is no matching route path in the second route path (and there is no matching route path in the whitelist). In this case, the unified interception chain's route guard redirects the user to a route mismatch error page, such as a 404 error page.
[0055] In this embodiment, regardless of the number of sub-applications, runtime interception is performed based on a unified interception chain of the base / main framework, and the token and permission set are shared. This solves the problems of inconsistent states and concurrent race conditions caused by scattered token and permission caches, as well as the problems of lack of coordination and easy confusion in authentication, permission, route interception, HTTP interception and exception handling, and the inability to respond in a unified manner. It also avoids repeated token refresh, refresh race conditions and repeated token entry into the database.
[0056] In one implementation, step S300 includes steps S310-S320: S310. Perform longest prefix matching between the first routing path and the second routing path and the preset routing prefix respectively to determine the first sub-application name of the sub-application domain of the first routing path and the second sub-application name of the sub-application domain of the second routing path.
[0057] In this embodiment, the routing path for each sub-application is designed to include a preset routing prefix corresponding to the sub-application. For example, the preset routing prefixes for A, B, and C are mes / production, iidp / user, and eam / inspect, respectively, and the corresponding sub-application names (appName) are the names of A, B, and C. For instance, in this embodiment, the preset routing prefix is directly used as the name of the corresponding sub-application. The preset routing prefix can be obtained by changing the separator in the sub-application identifier. For example, the sub-application identifier can be mes-production, and changing the separator yields the preset routing prefix mes / production. Optionally, the base / main application framework can read the preset routing prefix (root prefix) of each sub-application from the _uniConfig.subPackages configuration of the UniApp compilation artifact (which exists in the memory of the terminal with the main application installed after installation).
[0058] Optionally, the first routing path and the second routing path are respectively matched with the preset routing prefix using the longest prefix, thereby determining the sub-application domain (i.e., which sub-application) of the first routing path and the first sub-application name of that sub-application domain, and determining the sub-application domain of the second routing path and the second sub-application name of that sub-application domain.
[0059] S320. Compare the first sub-application name with the second sub-application name. If the first sub-application name and the second sub-application name are different, determine that the sub-application domain switching result corresponding to the route path change has occurred. If the first sub-application name and the second sub-application name are the same, determine that the sub-application domain switching result corresponding to the route path change has not occurred.
[0060] Optionally, the first sub-application name is compared with the second sub-application name. If the first sub-application name and the second sub-application name are different, the sub-application domain switching result corresponding to the route path change is determined to have occurred. For example, it may be a switch from A to C, which is a page switch between different sub-applications. If the first sub-application name and the second sub-application name are the same, the sub-application domain switching result corresponding to the route path change is determined to have not occurred. For example, it may be a click within A, switching from one page in A to another page within A, which does not involve a sub-application switch.
[0061] In one embodiment, step S400 includes steps S410-S420: S410. When the sub-application domain switching result is that a sub-application domain switching has occurred, the lifecycle hook for leaving is triggered to execute the cleanup business logic of the sub-application corresponding to the first route path, and the lifecycle hook for entering is triggered to execute the initialization business logic of the sub-application corresponding to the second route path.
[0062] Optionally, when the sub-application domain switching result is a sub-application domain switch, such as switching from sub-application A (mes / production) to sub-application C (eam / inspect), the lifecycle hook for leaving sub-application A is triggered: `subapp:leave({appName:"mes / production"})`. Then, the cleanup business logic of the sub-application corresponding to the first route path is executed, such as including but not limited to cleaning up the resources of sub-application A (e.g., turning off timers, clearing A's cache, requests, etc.). Additionally, the lifecycle hook for entering sub-application C (eam / inspect) is triggered, executing the initialization business logic of the sub-application corresponding to the second route path, such as preloading, including but not limited to initializing C's resources (e.g., required dictionary data, event tracking, titles, page elements, TabBar highlighting switching from homepage to inspection, etc.).
[0063] S420. When the sub-application domain switching result is that no sub-application domain switching has occurred, the lifecycle hook of the same domain route change is triggered, and the update business logic of the sub-application corresponding to the second route path is executed.
[0064] Optionally, when the sub-application domain switching result is that no sub-application domain switching has occurred, the lifecycle hook of the same domain route change is triggered, and the update business logic of the sub-application corresponding to the second route path is executed, such as, but not limited to, notifications or lightweight operations for internal page switching (such as counting page visits, updating page titles, recording page dwell time, etc.), without having to repeat the sub-application-level preloading.
[0065] Therefore, through the embodiments of this application, by using the sub-application domain identification and lifecycle hook mechanism with preset route prefixes, a unified entry / exit / route change signal is provided for sub-applications under a single UniApp instance, solving the problems of duplicate registration, listener leakage and manual synchronization caused by each sub-application registering its own route listener.
[0066] In one embodiment, the multi-sub-application aggregation running method of this application embodiment may further include steps S510 and S520, without limiting the execution order, and other embodiments may include one of them: S510. When a sub-application is registered, multilingual entries are registered in the sub-application registry. The multilingual entries of each sub-application are merged into a global dictionary by language dimension through the sub-application registry, and the current language identifier is stored. In response to a language switching command, the current language identifier is updated through the sub-application registry, and the corresponding multilingual entries are retrieved from the global dictionary based on the updated current language identifier. Each sub-application is then notified to refresh its corresponding interface.
[0067] Optionally, during sub-application registration, multilingual glossary messages are registered with the sub-application registry. These messages are obtained by receiving relevant information reported by each sub-application during registration. For example, if Chinese, English, and Japanese are supported, the multilingual glossary messages will contain the translations of the corresponding sub-application glossaries for those three languages. Then, the multilingual glossaries from each sub-application are merged into a global glossary library by language dimension through the sub-application registry. This is done incrementally by locale dimension, for example, merging Chinese translations together, English translations together, and Japanese translations together. A globally unique current language identifier, state.locale (i.e., the language currently selected by the main application), is maintained as a single trusted source for language state. This language identifier is stored locally for restoration upon the next startup of the main application.
[0068] When a language switch is required, the user issues a language switch command. In response to the command, the current language identifier `state.locale` is updated through the sub-application registry (e.g., from Chinese to English). Based on the updated `state.locale`, the corresponding multilingual terminology is retrieved from the global terminology library (e.g., the English translation terminology). Then, the `onLocaleChange` callback notifies all sub-applications to refresh uniformly and display the translated terminology. This prevents a situation where one sub-application's page changes to English while another sub-application's page remains in Chinese.
[0069] In some implementations, if an error is found in the translation of a term, a corrected term package (carrying the version and SHA256 digest) can be dynamically distributed via a backend server. This term package is stored in a sandbox directory. The main application prioritizes the hot-updated terms from the term package in the sandbox directory, following a sandbox directory priority and static rollback strategy. If no hot-updated term is found, it statically rolls back to search for the corresponding translation in the current global term library, subsequently adding the hot-updated term to the global term library as well. It should be noted that the sandbox directory priority mechanism is used to override business terms in sub-applications, while translations of framework elements such as bottom tabs and system pop-ups (placeholder terms in pages.json and uni-app framework terms) are not allowed to be dynamically distributed and corrected by the backend server. They are allowed to be fixed during initial compilation to avoid erroneous overwriting during dynamic distribution. Among them, the sandbox directory priority and static rollback strategy are used to cover business terms in sub-applications without modifying the framework translation, thereby separating business terms from framework translation and solving the problems of mixed business terms and framework translation leading to dynamic updates mistakenly covering the framework layer and inconsistent interface performance when switching between different sub-applications due to inconsistent language states.
[0070] S520: In response to the main application's startup command, load the plugins declared by each sub-application through the configuration file. The main application manages the state data generated after the plugins run, so that each sub-application shares the same state. The application runtime events are orchestrated in a unified manner through the hook system. Each sub-application subscribes to the hook system, and the main application notifies the sub-applications when an application runtime event occurs.
[0071] Optionally, in response to the main application's startup command, plugins declared by each sub-application through the `plugins` field of the configuration file `apps.config.js` are loaded. The types of plugins are not limited, including but not limited to login plugins / auth-impl.ts (e.g., implementing the actual logic for login, logout, and token refresh, and connecting to the enterprise's unified identity authentication platform), permission plugins iam-impl.ts (e.g., obtaining the user's permission set), and language plugins (injecting language switch listeners and refreshing translations during language switches). All plugins are declared through `defineBasePlugin`, and `applyPlugins` runs them stably according to a preset execution priority order (enforce). The main application (e.g., the base / main framework) centrally manages the state data generated after the plugins run, such as writing state data to reactive fields in the base / main framework, allowing each sub-application to share the same state (data). This eliminates the need for each sub-application to store its own state / variables, avoiding state chaos, and ultimately ensuring that tokens, permissions, languages, etc., have only one state across the entire main application. Furthermore, since each sub-application subscribes to the same state (data), any state change in A, B, or C will be broadcast to all subscribers, namely A, B, and C.
[0072] In this embodiment, a hookable system is used to uniformly orchestrate application runtime events. These events include main application startup, foreground / background switching for each sub-application, page errors, sub-application entry / exit, etc. Each event in the hook system has a corresponding hook (e.g., a callback function). Sub-applications subscribe to the hook system, so the main application notifies the sub-applications when an application runtime event occurs. Sub-applications do not need to register their own route listeners, avoiding duplicate registrations and listener leaks. This solves the problem of dual-track operation of the main application and sub-application states, and the difficulty in broadcasting state changes, caused by sub-applications relying on their own global variables or internal singletons. For example, to report event tracking when entering a specific sub-application, one only needs to subscribe to the sub-application entry hook in the hook system.
[0073] Reference Figure 2 The diagram illustrates a structural block diagram of a multi-sub-application aggregation operating apparatus according to an embodiment of this application. The apparatus may include: The registration module is used to respond to the main application's startup command, obtain the permission code information of each sub-application through the sub-application registry, and verify the permission code information when registering the sub-application. After the permission code verification is successful, the global routing permission index of all sub-applications is determined, and the main application enters the normal operation state. The interception module is used to respond to the change of the route path from the first route path to the second route path when the main application is in normal operation. It uses the route guard of the unified interception chain to perform permission verification based on the second route path and the global route permission index. When the permission verification is successful, the page corresponding to the second route path is displayed. The determination module is used to determine the sub-application domain switching result corresponding to the route path change based on the first route path, the second route path, and the preset route prefix. The execution module is used to trigger lifecycle hooks and execute the corresponding business logic based on the sub-application domain switching results.
[0074] In one implementation, the interception module is further configured to: The authentication module of the unified interception chain stores the access token after the user logs into the main application and enables all sub-applications to share the login state, and automatically refreshes the access token when the access token meets the refresh conditions. By using a unified interception chain for button permissions, the display or hiding of page elements is controlled based on whether the permission verification passes. By using a unified interception chain HTTP interceptor, redirect to a network error page when there is no response status code, or redirect to a server error page when the backend server returns an error status code, while retaining the page stack before the redirection. If a matching route path does not exist for the second route path, the user is redirected to a route mismatch exception page using a unified interception chain route guard.
[0075] In one implementation, the execution module is further configured to: When a sub-application is registered, multilingual entries are registered in the sub-application registry. The multilingual entries of each sub-application are merged into a global dictionary by language dimension through the sub-application registry, and the current language identifier is stored. In response to a language switching command, the current language identifier is updated through the sub-application registry, and the corresponding multilingual entries are retrieved from the global dictionary based on the updated current language identifier, and each sub-application is notified to refresh the corresponding interface. And / or, In response to the main application's startup command, the plugins declared by each sub-application through the configuration file are loaded. The main application manages the state data generated after the plugins run, so that each sub-application shares the same state. The application runtime events are orchestrated in a unified manner through the hook system. Each sub-application subscribes to the hook system, and the main application notifies the sub-applications when an application runtime event occurs.
[0076] The functions of each module in the device of this application embodiment can be found in the corresponding description in the above method, and will not be repeated here.
[0077] Reference Figure 3The diagram illustrates a structural block diagram of an electronic device according to an embodiment of this application. The electronic device includes a memory 310 and a processor 320. The memory 310 stores instructions that can be executed on the processor 320. The processor 320 loads and executes these instructions to implement the multi-sub-application aggregation method described in the above embodiment. The number of memories 310 and processors 320 can be one or more.
[0078] In one embodiment, the electronic device further includes a communication interface 330 for communicating with external devices and exchanging data. If the memory 310, processor 320, and communication interface 330 are implemented independently, they can be interconnected via a bus to communicate with each other. This bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. This bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0079] Optionally, in a specific implementation, if the memory 310, processor 320 and communication interface 330 are integrated on a single chip, the memory 310, processor 320 and communication interface 330 can communicate with each other through an internal interface.
[0080] This application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the multi-sub-application aggregation running method provided in the above embodiments.
[0081] This application also provides a chip, which includes a processor for calling and executing instructions stored in a memory, causing a communication device on which the chip is installed to execute the method provided in this application.
[0082] This application also provides a chip, including: an input interface, an output interface, a processor, and a memory. The input interface, output interface, processor, and memory are connected through an internal connection path. The processor is used to execute code in the memory. When the code is executed, the processor is used to execute the method provided in the application embodiment.
[0083] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. General-purpose processors can be microprocessors or any conventional processor. It is worth noting that the processor can be a processor supporting the Advanced Reduced Instruction Set Computing (RISC) machine (ARM) architecture.
[0084] Further, optionally, the aforementioned memory may include read-only memory and random access memory, and may also include non-volatile random access memory. The memory may be volatile or non-volatile, or may include both. Non-volatile memory may include read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which serves as an external cache. Many forms of RAM are available by way of example, but not limitation. Examples include static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0085] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to this application is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another.
[0086] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of those different embodiments or examples.
[0087] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "a plurality of" means two or more, unless otherwise explicitly specified.
[0088] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process. Furthermore, the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functionality involved.
[0089] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-included system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).
[0090] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. All or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware, the program being stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiments.
[0091] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. This storage medium can be a read-only memory, a disk, or an optical disk, etc.
[0092] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various variations or substitutions within the technical scope disclosed in this application, and these should all be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for running multi-sub-application aggregation, characterized in that, include: In response to the main application's startup command, the permission code information of each sub-application is obtained through the sub-application registry. The permission code information is verified during the registration of the sub-application. After the permission code verification is successful, the global routing permission index of all sub-applications is determined, and the main application enters the normal operation state. When the main application is in normal operation, in response to the change of the route path from the first route path to the second route path, the route guard of the unified interception chain performs permission verification based on the second route path and the global route permission index. When the permission verification passes, the page corresponding to the second route path is displayed. Based on the first routing path, the second routing path, and the preset routing prefix, determine the sub-application domain switching result corresponding to the routing path change; Based on the sub-application domain switching result, the lifecycle hook is triggered, and the corresponding business logic of the lifecycle hook is executed.
2. The method for running multi-sub-application aggregation according to claim 1, characterized in that: The step of obtaining permission code information for each sub-application through the sub-application registry and verifying the permission code information during sub-application registration includes: By accessing the sub-application registry, obtain the permission code information reported by each sub-application. The permission code information includes all the permission codes that the sub-application has and the permission codes required for the routing path. When registering a sub-application, obtain the sub-application identifier of the sub-application, and perform permission code verification based on the sub-application identifier, all permission codes, and the required permission codes for the routing path. The permission code verification includes at least one of the following: format verification, prefix verification, uniqueness verification, and routing path reference consistency verification. The permission code verification passes when all types of verifications pass.
3. The method for running multi-sub-application aggregation according to claim 2, characterized in that: Format validation: Validate all permission codes for illegal characters; Prefix verification: Verify whether the prefix in all permission codes is a sub-application identifier; Uniqueness check: Check whether all permission codes within a sub-application are duplicated, and whether all permission codes across different sub-applications are duplicated; Routing path reference consistency check: Verify whether the required permission code exists among all permission codes.
4. The method for running multi-sub-application aggregation according to claim 1, characterized in that: The global route permission index includes the route paths of each sub-application and the permission codes corresponding to the route paths; The route guarding via the unified interception chain, which performs permission verification based on the second route path and the global route permission index, includes: By using route guards in a unified interception chain, a matching route path is determined from the global route permission index based on the second route path; The permission code corresponding to the matched route path is matched with the permission set of the user logged in to the main application; if the match is successful, the permission verification passes.
5. The method for running multi-sub-application aggregation according to claim 4, characterized in that: The method further includes at least one of the following: The authentication module of the unified interception chain stores the access token after the user logs into the main application and enables all sub-applications to share the login state, and automatically refreshes the access token when the access token meets the refresh conditions. By using a unified interception chain for button permissions, the display or hiding of page elements is controlled based on whether the permission verification passes. By using a unified interception chain HTTP interceptor, redirect to a network error page when there is no response status code, or redirect to a server error page when the backend server returns an error status code, while retaining the page stack before the redirection. If a matching route path does not exist for the second route path, the user is redirected to a route mismatch exception page using a unified interception chain route guard.
6. The method for running multi-sub-application aggregation according to claim 1, characterized in that: The method for determining the sub-application domain switching result corresponding to the route path change based on the first route path, the second route path, and the preset route prefix includes: The first routing path and the second routing path are respectively matched with the preset routing prefix using the longest prefix to determine the first sub-application name of the sub-application domain of the first routing path and the second sub-application name of the sub-application domain of the second routing path. The first sub-application name is compared with the second sub-application name. If the first sub-application name is different from the second sub-application name, the sub-application domain switching result corresponding to the route path change is determined to be a sub-application domain switching that has occurred; if the first sub-application name is the same as the second sub-application name, the sub-application domain switching result corresponding to the route path change is determined to be a sub-application domain switching that has not occurred.
7. The method for running multi-sub-application aggregation according to claim 6, characterized in that: The step of triggering the lifecycle hook and executing the corresponding business logic based on the sub-application domain switching result includes: When the sub-application domain switching result is that a sub-application domain switching has occurred, the lifecycle hook for leaving is triggered to execute the cleanup business logic of the sub-application corresponding to the first route path, and the lifecycle hook for entering is triggered to execute the initialization business logic of the sub-application corresponding to the second route path. When the sub-application domain switching result is that no sub-application domain switching has occurred, the lifecycle hook for same-domain route change is triggered, and the update business logic of the sub-application corresponding to the second route path is executed.
8. The method for running multi-sub-application aggregation according to claim 1, characterized in that: The method further includes: When a sub-application is registered, multilingual entries are registered in the sub-application registry. The multilingual entries of each sub-application are merged into a global dictionary by language dimension through the sub-application registry, and the current language identifier is stored. In response to a language switching command, the current language identifier is updated through the sub-application registry, and the corresponding multilingual entries are retrieved from the global dictionary based on the updated current language identifier, and each sub-application is notified to refresh the corresponding interface. And / or, In response to the main application's startup command, the plugins declared by each sub-application through the configuration file are loaded. The main application manages the state data generated after the plugins run, so that each sub-application shares the same state. The application runtime events are orchestrated in a unified manner through the hook system. Each sub-application subscribes to the hook system, and the main application notifies the sub-applications when an application runtime event occurs.
9. An operating device for multi-sub-application aggregation, characterized in that, include: The registration module is used to respond to the main application's startup command, obtain the permission code information of each sub-application through the sub-application registry, and verify the permission code information when registering the sub-application. After the permission code verification is successful, the global routing permission index of all sub-applications is determined, and the main application enters the normal operation state. The interception module is used to respond to the change of the route path from the first route path to the second route path when the main application is in normal operation. It uses the route guard of the unified interception chain to perform permission verification based on the second route path and the global route permission index. When the permission verification is successful, the page corresponding to the second route path is displayed. The determination module is used to determine the sub-application domain switching result corresponding to the route path change based on the first route path, the second route path, and the preset route prefix. The execution module is used to trigger lifecycle hooks and execute the corresponding business logic based on the sub-application domain switching results.
10. An electronic device, characterized in that, include: A processor and a memory, wherein instructions are stored in the memory and loaded and executed by the processor to implement the method as claimed in any one of claims 1-8.
