A view component and method for building a data-driven table
By designing the data-driven table view component in the Web backend management system, using the view-model structure and the Vue3.0 framework, we solve the code redundancy and maintenance problems in the development of table-type business pages, and realize the dynamic display and display of tables. Efficient development improves development efficiency.
Patent Information
- Application Number
- CN202410674509.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-29
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-05-29
AI Technical Summary
In the Web backend management system, as the amount of platform code increases, the development of table-type business pages involves repeated definitions of attributes and methods, DOM duplication when rendering data in tables, and repeated definitions of theme styles, resulting in code redundancy and difficulty in maintenance. Development efficiency is low.
Design a data-driven table view component that uses a view-model structure to encapsulate the table component, including a parameter adjustment module, a listening module and a function selection module. It uses the Vue attribute transparent transmission feature and the ElementPlus library to implement the component based on the Vue3.0 framework. Dynamic display, reducing code redundancy and improving development efficiency.
The dynamic display of the table can be realized by passing the data model through the parent component. The components are highly cohesive, reducing the amount of code writing, improving development efficiency, reducing the difficulty of code maintenance, and improving developer productivity.
Smart Images

Figure CN118245031B
Abstract
Description
Technical Field
[0001] The present application relates to the field of Web front-end software development, and specifically to a view component and method for building a data-driven table. Background Art
[0002] In the current Web backend management system, there are a large number of report-type data display pages. In order to improve development efficiency, the Element Plus component library is often used. Because of its beautiful UI, rich components, and easy to use, it is the preferred component library for front-end development. The table component it provides is usually used to achieve the rendering of table-type business needs. With the increase in the amount of platform code, there will be a large number of table-type business pages, which will cause some problems, such as repeated definitions of attributes and methods, repeated DOM duplication when rendering data in the table, and repeated definitions of table theme styles when changing styles. This will cause the code to be too redundant, difficult to maintain, and low development efficiency. Summary of the invention
[0003] The table view component developed in this application encapsulates the table component according to the view-model structure. The component is the view, which is the interface for displaying data, and the model is the data to be displayed. By passing in the corresponding data, the interface that needs to be expressed can be presented without understanding the rendering processing logic in the view. Its technical solution is:
[0004] A view component for building a data-driven table, including a parameter adjustment module, a listening module and a function selection module. It takes el-table as the root tag, uses the Vue attribute transparent transmission feature to inherit the original attributes of el-table, encapsulates the table component based on el-table in the ElementPlus library, and configures a front-end development environment based on the Vue3.0 framework;
[0005] in,
[0006] Parameter adjustment module: Use the Vue macro command defineProps to define the parameters that need to be passed in, and use the props variable to accept the parameters so that they can be called inside the component;
[0007] Listening module: add a listener watch function inside the component, use this function to trigger the callback function every time the tableColumnData parameter status changes, use the array method filter function to filter out the columns to be displayed according to the isVisible property value, and define a columnData responsive variable to accept the new value after filtering for subsequent use;
[0008] Function selection module: select corresponding functions according to needs and render table style.
[0009] Preferably, the parameter adjustment module includes:
[0010] tableData is JSON data of Array type, which is the data source for table rendering, that is, the required model data;
[0011] rowKey is of String type, which is the unique identifier of table tr. It is used to track each loop node and use Vue's VNode feature to improve the rendering of component content when the model changes.
[0012] showSelection is a Boolean type that controls whether to enable the multi-select function of the table. The default value is false;
[0013] tableColumnData is JSON data of Array type, which is used to configure the header of each column in the table and the display content of the column.
[0014] Preferably, the function selection module includes:
[0015] The keyValue attribute is of String type, which defines the key of each column that needs to display the tableData data;
[0016] The thName attribute is of String type, which defines the name of each column header, i.e. the content of table th;
[0017] The slotName attribute is of String type, which defines the name of the slot and is used to assign a unique ID to the slot. When this value is passed in, a named slot is generated inside the component. The named slot is defined in the parent component.<template#name> The slot content provides the contained outlet;
[0018] The isVisible property is of Boolean type and controls the table columns that need to be displayed;
[0019] The width attribute is of Number type, which controls the cell width ratio. If not passed, it will adapt according to the content.
[0020] The formatter attribute is of Function type, which is used to format the cell content when the rendered content does not meet expectations; the className attribute is of String type, and according to the preset style class name in the component, the corresponding class name is passed in to control the cell style;
[0021] dataLoading is of Boolean type. When requesting data source and component rendering, a loading animation is displayed.
[0022] selectedIds is of Array type, which is a collection of rowKey. When a value is passed, the corresponding row will be automatically selected.
[0023] themeClassName is of String type, and you can pass in the class name of a preset theme style to switch the table theme style.
[0024] Preferably, the Vue macro command defineEmits is used inside the component to define the events triggered inside the component that the parent component listens to, and an emit variable is defined to accept the events that need to be provided to the parent component for calling, that is, emit('someEvent') can be used to customize the triggering event, and the parent component can listen to the event through v-on, including:
[0025] The cellClick event is triggered by clicking a table cell;
[0026] The rowClick event is triggered by clicking a table row;
[0027] The selectionChange event is triggered when the table multi-select function is enabled and checked or canceled;
[0028] Among them, tableData, rowKey, dataLoading, cellClick, rowClick, and selectionChange are bound to the el-table tag as attributes; two el-table-columns are separated, one is the selection type, which is enabled by the showSelection control, and the other is the loop body of the columnData responsive data. The corresponding value during the loop is used as the attribute value, and a dynamic slot named slotName is placed inside to provide an outlet for the slot content provided by the parent component.
[0029] Preferably, introduce the encapsulated table view component in main.js and register the component in the Vue context using the app.component('table', table) method.
[0030] A method for constructing a data-driven table view component includes the following steps:
[0031] S1. Based on the front-end development environment of Vue3.0 framework, set el-table as the root tag and use the Vue attribute transparent transmission feature to inherit the original attributes of el-table;
[0032] S2. Encapsulate the table component based on el-table in the Element Plus library and introduce the Element Plus component library;
[0033] S3. Define the parameters that need to be passed in, configure the data source, set the tracking flag, and select the function.
[0034] Preferably, the parameters to be input in step S2 include the following:
[0035] Define the parameters that need to be passed in: Use the Vue macro command defineProps inside the component to define the parameters that need to be passed in, and use the props variable to accept the parameters so that they can be called inside the component, including:
[0036] tableData is JSON data of Array type, which is the data source for table rendering, that is, the required model data;
[0037] rowKey is of String type, which is the unique identifier of table tr. It is used to track each loop node and use Vue's VNode feature to improve the rendering of component content when the model changes.
[0038] showSelection is of Boolean type, which controls whether to enable the multi-select function of the table, and can be false by default;
[0039] tableColumnData is JSON data of Array type, which is used to configure the header of each column in the table and the display content of the column;
[0040] Preferably, setting the function selection in step S2 includes the following contents:
[0041] The keyValue attribute is of String type, which defines the key of each column that needs to display the tableData data;
[0042] The thName attribute is of String type, which defines the name of each column header, i.e. the content of table th;
[0043] The slotName property is of String type, which defines the name of the slot and is used to assign a unique ID to the slot. When this value is passed in, a named slot is generated inside the component. This named slot is defined in the parent component.<template #name> The slot content provides the contained outlet;
[0044] The isVisible property is of Boolean type and controls the table columns that need to be displayed;
[0045] The width attribute is of Number type, which controls the cell width ratio. If not passed, it will adapt according to the content.
[0046] The formatter attribute is of Function type, which is used to format the cell content when the rendered content does not meet expectations; the className attribute is of String type, and according to the preset style class name in the component, the corresponding class name is passed in to control the cell style;
[0047] dataLoading is of Boolean type. When requesting data source and component rendering, a loading animation is displayed.
[0048] selectedIds is of Array type, which is a collection of rowKey. When a value is passed, the corresponding row will be automatically selected.
[0049] themeClassName is of String type, and can be used to pass in the class name of a preset theme style to switch the table theme style;
[0050] Use the Vue macro command defineEmits inside the component to define the events triggered inside the component that the parent component can listen to. Define an emit variable to accept the events that need to be provided to the parent component to call. You can use emit('someEvent') to customize the triggering event. The parent component can listen to the event through v-on, including:
[0051] The cellClick event is triggered by clicking a table cell;
[0052] The rowClick event is triggered by clicking a table row;
[0053] The selectionChange event is triggered when the table multi-select function is enabled and checked or canceled.
[0054] Preferably, a listener watch function is added inside the component, and the function is used to trigger the callback function every time the state of the tableColumnData parameter changes. The array method filter function is used to filter out the columns to be displayed according to the isVisible attribute value. At this time, a columnData responsive variable is defined to accept the new value after filtering for subsequent use;
[0055] Among them, tableData, rowKey, dataLoading, cellClick, rowClick, and selectionChange are bound to the el-table tag as attributes; the el-table tag is divided into two el-table-columns, one is the selection type, which is enabled by the showSelection control, and the other is the loop body of the columnData responsive data. The corresponding value during the loop is used as the attribute value, and a dynamic slot named slotName is placed inside to provide an outlet for the slot content provided by the parent component.
[0056] Preferably, the table component introduces the Element Plus component library and configures the front-end development environment based on the Vue3.0 framework.
[0057] Compared with the prior art, the present invention has the following beneficial effects:
[0058] The above applications can meet various scenarios. According to the view-model structure, the dynamic display of the table can be realized only through the data model passed in by the parent component, and the high cohesion of the components is achieved, which reduces the amount of code written, makes the code easier to maintain, and improves development efficiency. Pay less attention to the implementation of view components and pay more attention to the changes in data models to meet business needs, which greatly improves the productivity of developers. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1 This is the flow chart of this application.
[0060] Figure 2 This is a schematic diagram of the structure of this application. DETAILED DESCRIPTION
[0061] In order to facilitate understanding of the present application, the present application will be described more fully below with reference to the relevant drawings. Embodiments of the present application are provided in the drawings. However, the present application can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present application more thorough and comprehensive.
[0062] Figure 2 As shown, a view component for building a data-driven table includes a parameter adjustment module, a listening module and a function selection module. It takes el-table as the root tag, uses the Vue attribute transparent transmission feature to inherit the original attributes of el-table, encapsulates the table component based on el-table in the Element Plus library, and configures a front-end development environment based on the Vue3.0 framework.
[0063] in,
[0064] Parameter adjustment module: Use the Vue macro command defineProps to define the parameters that need to be passed in, and use the props variable to accept the parameters so that they can be called inside the component;
[0065] Listening module: add a listener watch function inside the component, use this function to trigger the callback function every time the tableColumnData parameter status changes, use the array method filter function to filter out the columns to be displayed according to the isVisible property value, and define a columnData responsive variable to accept the new value after filtering for subsequent use;
[0066] Function selection module: select corresponding functions according to needs and render table style.
[0067] Specific steps, such as Figure 1 As shown in the figure, a method for building a data-driven table view component is as follows:
[0068] S1. Development environment:
[0069] S11. Configure the front-end development environment based on the Vue3.0 framework, set el-table as the root tag, and use the Vue attribute pass-through feature to inherit the original attributes of el-table.
[0070] S2. Encapsulate the table component based on el-table in the Element Plus library; and introduce the Element Plus component library.
[0071] S3. Define the parameters that need to be passed in, configure the data source, set the tracking flag, and select the function.
[0072] Use the Vue macro command defineProps inside the component to define the parameters that need to be passed in, and use the props variable to accept the parameters so that they can be called inside the component, including:
[0073] tableData is JSON data of Array type, which is the data source for table rendering, that is, the required model data;
[0074] rowKey is of String type, which is the unique identifier of table tr. It is used to track each loop node and utilize Vue's VNode feature to improve the rendering of component content when the model changes.
[0075] showSelection is of Boolean type, which controls whether to enable the multi-select function of the table, and can be false by default;
[0076] tableColumnData is JSON data of Array type, which is used to configure the header of each column in the table and the display content of the column.
[0077] Feature selection includes the following:
[0078] The keyValue attribute is of String type, which defines the key of each column that needs to display the tableData data; the thName attribute is of String type, which defines the name of each column header, that is, the content of the table th; the slotName attribute is of String type, which defines the name of the slot, which is used to assign a unique ID to the slot. When this value is passed in, a named slot will be generated inside the component. This named slot is defined in the parent component.<template #name> The slot content provides an outlet for storage; the isVisible property is of Boolean type, which controls the table columns that need to be displayed; the width property is of Number type, which controls the cell width ratio. If not passed, it will adapt according to the content; the formatter property is of Function type, which is used to format the cell content when the rendered content does not meet expectations; the className property is of String type, which passes in the corresponding class name according to the preset style class name in the component to control the cell style;
[0079] dataLoading is of Boolean type. When requesting data source and component rendering, a loading animation is displayed.
[0080] selectedIds is of Array type, which is a collection of rowKey. When a value is passed, the corresponding row will be automatically selected.
[0081] themeClassName is of String type, and you can pass in the class name of a preset theme style to switch the table theme style.
[0082] Use the Vue macro command defineEmits inside the component to define the events triggered inside the component that the parent component can listen to. Define an emit variable to accept the events that need to be provided to the parent component to call. You can use emit('someEvent') to customize the triggering event. The parent component can listen to the event through v-on, including:
[0083] The cellClick event is triggered by clicking a table cell;
[0084] The rowClick event is triggered by clicking a table row;
[0085] The selectionChange event is triggered when the table multi-select function is enabled and checked or canceled.
[0086] Add a listener watch function inside the component, use this function to trigger the callback function every time the tableColumnData parameter status changes, use the array method filter function to filter out the columns to be displayed according to the isVisible property value, and define a columnData responsive variable to accept the new value after filtering for subsequent use.
[0087] Based on the above parameters and events, tableData, rowKey, dataLoading, cellClick, rowClick, selectionChange are bound to the el-table tag as attributes. Two el-table-columns are separated, one is the selection type, enabled by the showSelection control, and the other is the loop body of the columnData responsive data. The corresponding value during the loop is used as the attribute value, and a dynamic slot named slotName is placed inside to provide an outlet for the slot content provided by the parent component.
[0088] Introduce the encapsulated table view component in main.js, and use the app.component('table',table) method to register the component in the Vue context environment, which can be directly referenced by the project globally.
[0089] S4. Use components. When a page introduces a component, the corresponding model, i.e., data, is passed in. The view can then render the appropriate view interface according to the defined data model.
[0090] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus dynamic random access memory (Rambus DRAM, referred to as RDRAM), and interface dynamic random access memory (DRDRAM).
[0091] In the description of this specification, the description with reference to the terms "some embodiments", "other embodiments", "ideal embodiments", etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic descriptions of the above terms do not necessarily refer to the same embodiment or example.
[0092] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0093] The above-mentioned embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
Claims
1. A view component for building a data-driven table, characterized in that: It includes parameter adjustment module, listening module and function selection module. It takes el-table as the root tag, uses the Vue attribute transparent transmission feature to inherit the original attributes of el-table, encapsulates the table component based on el-table in the Element Plus library, and configures the front-end development environment based on the Vue3.0 framework. in, Parameter adjustment module: Use the Vue macro command defineProps to define the parameters that need to be passed in, and use the props variable to accept the parameters so that they can be called inside the component; Listening module: add a listener watch function inside the component, use this function to trigger the callback function every time the tableColumnData parameter status changes, use the array method filter function to filter out the columns to be displayed according to the isVisible property value, and define a columnData responsive variable to accept the new value after filtering for subsequent use; Use the Vue macro command defineEmits inside the component to define the events triggered inside the component that the parent component listens to. Define an emit variable to accept the events that need to be provided to the parent component for calling. You can use emit('someEvent') to customize the triggering event. The parent component can listen to the event through v-on. tableData, rowKey, dataLoading, cellClick, rowClick, selectionChange are bound to the el-table tag as attributes; two el-table-columns are separated, one is the selection type, enabled by the showSelection control, and the other is the loop body of the columnData responsive data. The corresponding value during the loop is used as the attribute value, and a dynamic slot named slotName is placed inside to provide an outlet for the slot content provided by the parent component; Function selection module: select corresponding functions according to needs and render table style.
2. A view component for constructing a data-driven table according to claim 1, characterized in that: The parameter adjustment module includes: tableData is JSON data of Array type, which is the data source for table rendering, that is, the required model data; rowKey is of String type, which is the unique identifier of table tr. It is used to track each loop node and use Vue's VNode feature to improve the rendering of component content when the model changes. showSelection is a Boolean type that controls whether to enable the multi-select function of the table. The default value is false; tableColumnData is JSON data of Array type, which is used to configure the header of each column in the table and the display content of the column.
3. A view component for constructing a data-driven table according to claim 1, characterized in that: The function selection module includes: The keyValue attribute is of String type, which defines the key of each column that needs to display the tableData data; The thName attribute is of String type, which defines the name of each column header, i.e. the content of table th; The slotName attribute is of String type, which defines the name of the slot and is used to assign a unique ID to the slot. When this value is passed in, a named slot is generated inside the component. The named slot is defined in the parent component.<template #name> The slot content provides the contained outlet; The isVisible property is of Boolean type and controls the table columns that need to be displayed; The width attribute is of Number type, which controls the cell width ratio. If not passed, it will adapt according to the content. The formatter attribute is of Function type, which is used to format the cell content when the rendered content does not meet expectations; the className attribute is of String type, and according to the preset style class name in the component, the corresponding class name is passed in to control the cell style; dataLoading is of Boolean type. When requesting data source and component rendering, a loading animation is displayed. selectedIds is of Array type, which is a collection of rowKey. When a value is passed, the corresponding row will be automatically selected. themeClassName is of String type, and you can pass in the class name of a preset theme style to switch the table theme style.
4. A view component for constructing a data-driven table according to claim 3, characterized in that: The cellClick event is triggered by clicking a table cell; The rowClick event is triggered by clicking a table row; The selectionChange event is triggered when the table multi-select function is enabled and checked or canceled.
5. A view component for constructing a data-driven table according to claim 4, characterized in that: Import the encapsulated table view component into main.js and use the app.component('table', table) method to register the component in the Vue context.
6. A method for constructing a data-driven table view component, characterized in that: The following steps are involved: S1. Based on the front-end development environment of Vue3.0 framework, set el-table as the root tag and use the Vue attribute transparent transmission feature to inherit the original attributes of el-table; S2. Encapsulate the table component based on el-table in the Element Plus library and introduce the Element Plus component library; S3. Define the parameters that need to be passed in, configure the data source, set the tracking flag and function selection; Add a listener watch function inside the component, use this function to trigger the callback function every time the tableColumnData parameter status changes, use the array method filter function to filter out the columns to be displayed according to the isVisible property value, and define a columnData responsive variable to accept the new value after filtering for subsequent use; Among them, tableData, rowKey, dataLoading, cellClick, rowClick, and selectionChange are bound to the el-table tag as attributes; the el-table tag is divided into two el-table-columns, one is the selection type, which is enabled by the showSelection control, and the other is the loop body of the columnData responsive data. The corresponding value during the loop is used as the attribute value, and a dynamic slot named slotName is placed inside to provide an outlet for the slot content provided by the parent component.
7. A method for constructing a data-driven table view component according to claim 6, characterized in that: The parameters that need to be passed in step S2 include the following: Define the parameters that need to be passed in: Use the Vue macro command defineProps inside the component to define the parameters that need to be passed in, and use the props variable to accept the parameters so that they can be called inside the component, including: tableData is JSON data of Array type, which is the data source for table rendering, that is, the required model data; rowKey is of String type, which is the unique identifier of table tr. It is used to track each loop node and use Vue's VNode feature to improve the rendering of component content when the model changes. showSelection is of Boolean type, which controls whether to enable the multi-select function of the table, and can be false by default; tableColumnData is JSON data of Array type, which is used to configure the header of each column in the table and the display content of the column.
8. A method for constructing a data-driven table view component according to claim 6, characterized in that: The function selection in step S2 includes the following: The keyValue attribute is of String type, which defines the key of each column that needs to display the tableData data; The thName attribute is of String type, which defines the name of each column header, i.e. the content of table th; The slotName property is of String type, which defines the name of the slot and is used to assign a unique ID to the slot. When this value is passed in, a named slot is generated inside the component. This named slot is defined in the parent component.<template #name> The slot content provides the contained outlet; The isVisible property is of Boolean type and controls the table columns that need to be displayed; The width attribute is of Number type, which controls the cell width ratio. If not passed, it will adapt according to the content. The formatter attribute is of Function type, which is used to format the cell content when the rendered content does not meet expectations; the className attribute is of String type, and according to the preset style class name in the component, the corresponding class name is passed in to control the cell style; dataLoading is of Boolean type. When requesting data source and component rendering, a loading animation is displayed. selectedIds is of Array type, which is a collection of rowKey. When a value is passed, the corresponding row will be automatically selected. themeClassName is of String type, and can be used to pass in the class name of a preset theme style to switch the table theme style; Use the Vue macro command defineEmits inside the component to define the events triggered inside the component that the parent component can listen to. Define an emit variable to accept the events that need to be provided to the parent component to call. You can use emit('someEvent') to customize the triggering event. The parent component can listen to the event through v-on, including: The cellClick event is triggered by clicking a table cell; The rowClick event is triggered by clicking a table row; The selectionChange event is triggered when the table multi-select function is enabled and checked or canceled.
9. A method for constructing a data-driven table view component according to claim 6, characterized in that: The table component introduces the Element Plus component library and configures the front-end development environment based on the Vue3.0 framework.
