Disclosure of Invention
The invention provides a page control method and a page control system based on front-end and back-end coordination cooperation, which are used for controlling authority of all resources of an application system, such as function menus of the application system, button controls of all interfaces and the like, wherein the menus are stored in a database, then the front-end requests the interfaces to inquire the system menus, then the dynamic route generates the menus, the problem that the modified menus or menu icons do not need to be modified and can be directly modified on the system is solved, an independent menu module manages and maintains the menus and buttons of the application system, the role-menu authorities of a plurality of systems are managed and maintained in a centralized manner through the mapping of roles and the menus, and on the basis of the menu-level authority control, the operation actions on the page are also managed and maintained, namely unified authority management of operations such as adding, deleting, changing and checking on the page is simple, and the authority control can be more careful and accurate.
The invention provides a page control method based on front-end and back-end coordination cooperation, which is used for controlling authority of resources of an application system, wherein the resources of the application system comprise function menus of the application system and button controls of all interfaces, and the page control method comprises the following steps:
s1, carrying out system menu processing based on a front-end request interface, wherein the system menu processing comprises system menu inquiry, system menu generation and system menu modification;
S2, performing system menu management maintenance based on the system menu processing through a back-end request interface so as to perform menu level authority control, wherein the system menu management maintenance is realized based on a menu module management function module, and the independent menu module management function module is used for maintaining system menus, menu icons and buttons of the application system and centrally managing role-system menu authorities of a plurality of application systems through mapping roles and the system menus;
and S3, based on the menu level authority control, the menu module management function module is used for managing and maintaining the operation action of the page at the same time.
Preferably, the S1 includes:
S11, after all route data are obtained through a front-end request interface, system menu inquiry is carried out based on the route data, wherein the system menu is stored in one or more database tables;
S12, generating the system menu through dynamic routing;
and S13, carrying out menu content modification or menu icon modification on the generated system menu, wherein the menu content modification or the menu icon modification is directly modified on the system menu without modifying codes.
Preferably, the S2 includes:
S21, controlling data, wherein the back-end returns all tiled data corresponding to the routing data through a back-end return interface, and the system menu module management function module generates a menu list based on the tiled data, wherein the menu list comprises fields of menu names, such as menu identification, type, access path, component path, icon, sorting, whether hiding and whether enabling;
S22, performing function layer judgment based on the acquired tiled data, wherein the function layer judgment comprises a user or a user group which can access a specific page or function through authority control in a view function in Django Rest or Flask back-end framework;
S23, performing Vue instruction control, wherein in front-end and back-end separation application of Vue.js, a v-if instruction is used for determining whether to render a menu item or not according to a data set correspondingly formed by rights in the view function;
s24, carrying out interface layer unified interception based on the authentication interceptor, wherein the method comprises the steps of judging whether a user has access to a specific resource or not according to a URL path based on an interception request, and carrying out the interface layer unified interception on the user without access to the specific resource, wherein the specific resource comprises a protected resource and an address which can be accessed without user authentication.
Preferably, the front-end and back-end separation application of the Vue. Js is realized based on vue prototype chains corresponding to the routing data, and a plurality of vue prototype chains are directly connected with the menu management module, so that efficient menu management and page control are realized.
Preferably, the S24 includes:
Confirming whether the access address of the page needs to authenticate the user identity, and if so, configuring the public access address and carrying out a first accessible annotation in the configuration file;
The user identity authentication method comprises the steps of authenticating the user identity based on a double authentication mode of user name authentication and password authentication, and storing records which pass authentication and succeed and fail without passing authentication in the database table;
Configuring a public access address and performing a first accessible annotation in a configuration file under the condition that user identity does not need to be authenticated, wherein configuring the first public access address for an address which can be accessed without user authentication and performing the accessible annotation in the configuration file, and based on the accessible annotation, an unauthenticated user can access the configured first public access address;
The configuring the public access address and making the first accessible annotation in the configuration file includes further including configuring a second public access address for the protected resource and making a conditional access annotation in the configuration file, the accessible annotation being defined based on the condition, only authenticated users having access to the configured second public access address.
Preferably, the authentication interceptor is used for intercepting when a user requests to access the protected resource, and comprises checking whether the URL requested by the user is in a public access address list, allowing access to the protected resource if the URL requested by the user is in the public access address list, checking whether the user passes identity verification if the URL requested by the user is not in the public access address list, allowing access to the protected resource if the URL requested by the user passes the identity verification, and refusing access to the protected resource if the URL requested by the user passes the identity verification.
Preferably, the S3 includes:
s31, packaging the view function based on a decorator;
s32, determining whether to execute the packaged view function based on the authority of the user, wherein the packaged view function is executed and used for simultaneously managing and maintaining the operation actions of the page through the menu module management function module, namely, the operation buttons on the page, namely, the unified authorization management of operations such as adding, deleting, changing, checking and the like.
The second aspect of the present invention provides a page control system based on front-end and back-end coordination cooperation, comprising:
The front-end processing module (101) is used for carrying out system menu processing based on the front-end request interface, wherein the system menu processing comprises system menu inquiry, system menu generation and system menu modification;
The system menu management maintenance is realized based on a menu module management function module, and the independent menu module management function module is used for maintaining a system menu, menu icons and buttons of the application system and centrally managing role-system menu authorities of a plurality of application systems through mapping of roles and the system menu;
And the page control module (103) is used for managing and maintaining the operation actions of the page through the menu module management function module based on the menu level authority control, namely, the operation buttons on the page, namely, the unified authority management of operations such as adding, deleting, changing, checking and the like.
A third aspect of the invention provides an electronic device comprising a processor and a memory, the memory storing a plurality of instructions, the processor being for reading the instructions and performing the method according to the first aspect.
A fourth aspect of the invention provides a computer readable storage medium storing a plurality of instructions readable by a processor and for performing the method of the first aspect.
The method, the system and the electronic equipment provided by the invention have the following beneficial effects:
(1) The invention is based on platform, and can manage menu or finer granularity authority, such as a button, a drop-down frame, an icon and the like through independent menu modules and related technical schemes.
(2) The configurability is improved, and the modification of the menu style and related interface information can be directly completed on the system without modifying the system code.
(3) The integration, sharing and interaction of various information of the page can be realized through menu control on the platform, page display is controlled, and powerful support is provided for platform construction.
Detailed Description
In order to better understand the above technical solutions, the following detailed description will be given with reference to the accompanying drawings and specific embodiments.
Example 1
As shown in fig. 1, in one aspect, the present invention provides a page control method based on front-end and back-end coordination, which is used for performing authority control on resources of an application system, where the resources of the application system include a function menu of the application system and button controls of each interface, and the page control method includes:
s1, carrying out system menu processing based on a front-end request interface, wherein the system menu processing comprises system menu inquiry, system menu generation and system menu modification;
as a preferred embodiment, the S1 includes:
S11, after all route data are obtained through a front-end request interface, system menu inquiry is carried out based on the route data, wherein the system menu is stored in one or more database tables;
in this embodiment, as shown in fig. 2, all the obtained routing data are three, namely, routing data 1, routing data 2 and routing data 3, and the database tables are three, namely, database table 1, database table 2 and database table 3.
S12, generating the system menu through dynamic routing;
and S13, carrying out menu content modification or menu icon modification on the generated system menu, wherein the menu content modification or the menu icon modification is directly modified on the system menu without modifying codes.
S2, performing system menu management maintenance based on the system menu processing through a back-end request interface so as to perform menu level authority control, wherein the system menu management maintenance is realized based on a menu module management function module, and the independent menu module management function module is used for maintaining system menus, menu icons and buttons of the application system and centrally managing role-system menu authorities of a plurality of application systems through mapping roles and the system menus;
The implementation flow diagram of step S2 shown in fig. 2.
As a preferred embodiment, the S2 includes:
S21, controlling data, wherein the back-end returns all tiled data corresponding to the routing data through a back-end return interface, and the system menu module management function module generates a menu list based on the tiled data, wherein the menu list comprises fields of menu names, such as menu identification, type, access path, component path, icon, sorting, whether hiding and whether enabling;
S22, performing function layer judgment based on the obtained tiled data, wherein the function layer judgment comprises a user or a user group which can access a specific page or function through authority control in a view function in Django Rest or Flask back-end framework.
In this embodiment, taking Django Rest back-end frames as an example, the decorator @ permission_ classes in the back-end frames can be used to set the permissions of the function view. The rights of the function view commonly used include:
AllowAny allowing any user to access the view, i.e., without authentication and authorization;
IsAuthenticated requiring the user to authenticate before accessing the view, i.e., the user must log in;
IsAdminUser requiring that the user be an administrator user to access the view;
IsAuthenticatedOrReadOnly requiring the user to perform authentication during write operations (e.g., create, update, delete), while allowing any user access for read-only operations (e.g., get list, view details);
In addition to the above commonly used rights classes, django Rest back-end frameworks also support custom rights classes to meet more complex rights requirements.
S23, performing Vue instruction control, wherein in front-end and back-end separation application of Vue.js, a v-if instruction is used for determining whether to render a menu item or not according to a data set correspondingly formed by rights in the view function;
In this embodiment, the front-end and back-end separation application of the vue.js is implemented based on vue prototype chains corresponding to the routing data. The plurality of vue prototype chains are directly connected with the menu management module, so that efficient menu management and page control are realized.
S24, carrying out interface layer unified interception based on an authentication interceptor, wherein the method comprises the steps of judging whether a user has access to a specific resource or not according to a URL path based on an interception request, and carrying out the interface layer unified interception on the user without access to the specific resource, wherein the specific resource comprises a protected resource and an address which can be accessed without user authentication;
As a preferred embodiment, the S24 includes:
Confirming whether the access address of the page needs to authenticate the user identity, and if so, configuring the public access address and carrying out a first accessible annotation in the configuration file;
The user identity authentication method comprises the steps of authenticating the user identity based on a double authentication mode of user name authentication and password authentication, and storing records which pass authentication and succeed and fail without passing authentication in the database table;
Configuring a public access address and performing a first accessible annotation in a configuration file under the condition that user identity does not need to be authenticated, wherein configuring the first public access address and performing the accessible annotation in the configuration file for an address (such as a login page) which can be accessed without user authentication, and based on the accessible annotation, an unauthenticated user can access the configured first public access address;
As a preferred embodiment, the configuring the public access address and making the first accessible annotation in the configuration file includes further including configuring a second public access address for the protected resource (e.g., a home page or an exit button) and making a conditional access annotation in the configuration file based on which only authenticated users can access the configured second public access address.
As a preferred embodiment, the authentication interceptor is configured to intercept when a user requests access to a protected resource, and includes:
The authentication interceptor checks whether the URL requested by the user is in the public access address list, allows access to the protected resource if the URL requested by the user is in the public access address list, checks whether the user has passed the authentication if the URL requested by the user is not in the public access address list, allows access to the protected resource if the user has passed the authentication, and denies access to the protected resource if the user has passed the authentication.
Through the steps, whether the user has the right to access the specific resource can be effectively judged according to the URL path, so that the network resource is protected from being accessed by unauthorized users.
And S3, based on the menu level authority control, the menu module management function module is used for simultaneously managing and maintaining the operation actions of the page, namely, the operation buttons on the page, namely, the unified authority management of operations such as adding, deleting, changing, checking and the like.
As a preferred embodiment, the S3 includes:
S31, based on the decorator wrapping the view function, in Django Rest back end framework, a simple decorator wrapping view function is provided using the function-based video to ensure that the view function will receive the Request instead of the Django generic HttpRequest object and return a Response instead of the Django generic HttpRequest object, while allowing the way this Request is handled to be set.
The decorator is an api_view decorator, accepting parameters of the HTTP method list to which the view should respond. Authentication u class (.. authentication_class (.+ -.), the @ color_ classes (...) or @ transmission_ classes (..); each decorator has a parameter that must be a list of classes or a tuple of classes.
S32, determining whether to execute the packaged view function based on the authority of the user, wherein the packaged view function is executed and used for simultaneously managing and maintaining the operation actions of the page through the menu module management function module, namely, the operation buttons on the page, namely, the unified authorization management of operations such as adding, deleting, changing, checking and the like.
Example two
As shown in fig. 3-4, the present embodiment provides a page control system based on front-end and back-end coordination cooperation, including:
The front-end processing module 101 is configured to perform system menu processing based on the front-end request interface, where the system menu processing includes system menu query, system menu generation, and system menu modification;
The system menu management maintenance is realized based on a menu module management function module, and the independent menu module management function module is used for maintaining a system menu, menu icons and buttons of the application system and centrally managing role-system menu authorities of a plurality of application systems through mapping of roles and the system menu;
The page control module 103 manages and maintains the operation actions of the page through the menu module management function module based on the menu level authority control, namely, the operation buttons on the page, namely, the unified authority management of operations such as adding, deleting, changing, checking and the like.
The invention also provides a memory storing a plurality of instructions for implementing the method according to the first embodiment.
As shown in fig. 5, the present invention further provides an electronic device, including a processor 301 and a memory 302 connected to the processor 301, where the memory 302 stores a plurality of instructions, and the instructions may be loaded and executed by the processor, so that the processor can execute the method according to the first embodiment.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiments and all such alterations and modifications as fall within the scope of the invention. It will be apparent to those skilled in the art that various modifications and variations can be made to the present invention without departing from the spirit or scope of the invention. Thus, it is intended that the present invention also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.