├── index.js ├── package.json ├── LICENSE ├── components └── index.vue └── README.md /index.js: -------------------------------------------------------------------------------- 1 | import Component from "./components/index.vue"; 2 | 3 | function install (Vue, options = {}) { 4 | if (install.installed) return; 5 | install.installed = true; 6 | 7 | Vue.component("vue-pro-table", Component); 8 | } 9 | Component.install = install; 10 | 11 | // auto plugin install 12 | let GlobalVue = null; 13 | if (typeof window !== "undefined") { 14 | GlobalVue = window.Vue; 15 | } else if (typeof global !== "undefined") { 16 | GlobalVue = global.vue; 17 | } 18 | if (GlobalVue) { 19 | GlobalVue.use(Component); 20 | } 21 | 22 | // export default 23 | export default Component; 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-pro-table", 3 | "version": "1.1.1", 4 | "description": "一个基于ElementUI封装的table列表页组件,将包含搜索、列表、分页等功能的页面封装成一个组件", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/huzhushan/vue-pro-table.git" 12 | }, 13 | "keywords": [ 14 | "vue-pro-table" 15 | ], 16 | "author": "huzhushan@126.com", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/huzhushan/vue-pro-table/issues" 20 | }, 21 | "homepage": "https://github.com/huzhushan/vue-pro-table#readme" 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 ZSEN 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /components/index.vue: -------------------------------------------------------------------------------- 1 | 9 | 224 | 422 | 472 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-pro-table 2 | 3 | > 本组件是基于 vue2 开发,如果你正在使用 vue3,请点击[vue3-pro-table](https://github.com/huzhushan/vue3-pro-table)查看 vue3 版的 pro-table 组件 4 | 5 | 一个基于 ElementUI 封装的 table 列表页组件,将包含搜索、列表、分页等功能的页面封装成一个组件 6 | 7 | ## 特性 8 | 9 | - 将搜索、列表、分页三者的交互逻辑封装到组件中,节省开发者代码量 10 | - 配置化的请求函数,自动发送请求,自动获取请求参数,自动显示 loading 效果 11 | - 配置化的表格项,跟 el-table-column 的配置属性类似 12 | - 配置化的搜索表单,支持大部分表单元素 13 | - 配置化的分页,跟 el-pagination 的配置属性类似 14 | - 自定义是否显示搜索和分页 15 | - 自定义标题栏和工具栏 16 | - 丰富的插槽提供功能扩展 17 | 18 | ## 使用 19 | 20 | ### 安装和引入 21 | 22 | 安装 23 | 24 | ```js 25 | // npm 26 | npm install vue-pro-table 27 | // yarn 28 | yarn add vue-pro-table 29 | ``` 30 | 31 | 引入 32 | 33 | > 该组件依赖 element-ui,需要自行引入 34 | > 35 | > ```js 36 | > import ElementUI from "element-ui"; 37 | > import "element-ui/lib/theme-chalk/index.css"; 38 | > Vue.use(ElementUI); 39 | > ``` 40 | 41 | ```js 42 | // 引入vue-pro-table 43 | import VueProTable from "vue-pro-table"; 44 | Vue.use(VueProTable); 45 | ``` 46 | 47 | ### 快速使用 48 | 49 | ```vue 50 | 58 | 59 | 92 | ``` 93 | 94 | 预览效果 95 | 96 | > 默认不包含搜索表单 97 | 98 | ![列表页](https://raw.githubusercontent.com/huzhushan/pics/master/vue-pro-table/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20210226101705.png) 99 | 100 | ### 请求函数配置 101 | 102 | - request,请求列表数据的函数 103 | 104 | > 组件加载的时候会自动执行 request 函数,并在加载过程中显示 loading 效果 105 | 106 | - 函数接收参数:包含搜索表单的所有字段和分页的 pageNum 和 pageSize 107 | 108 | - 函数必须返回一个对象,包含: 109 | - data: 列表数据的数组 110 | - total:总数,用于分页 111 | 112 | ### 表格配置 113 | 114 | - border 表格是否有边框。布尔值,默认为 false 115 | 116 | - columns 属性的配置,是一个数组 117 | 118 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 119 | | --------- | ------------------------------------------------------------------------------------------- | ---------------------- | ---------------------- | ------ | 120 | | label | 对应 el-table-column 的 label | string | - | - | 121 | | type | 对应 el-table-column 的 type | string | selection/index/expand | - | 122 | | prop | 对应 el-table-column 的 prop | string | - | - | 123 | | width | 对应 el-table-column 的 width | string,number | - | - | 124 | | minWidth | 对应 el-table-column 的 min-width | string,number | - | - | 125 | | align | 对应 el-table-column 的 align | string | left/center/right | left | 126 | | fixed | 对应 el-table-column 的 fixed | string, boolean | true, left, right | - | 127 | | sortable | 对应 el-table-column 的 sortable | boolean | false/true | false | 128 | | filters | 对应 el-table-column 的 filters | Array[{ text, value }] | - | - | 129 | | tdSlot | 单元格要自定义内容时,可以通过此属性配置一个插槽名称,并且是作用域插槽,可以接收 scope 数据 | string | - | - | 130 | | labelSlot | 表头要自定义内容时,可以通过此属性配置一个插槽名称,并且是作用域插槽,可以接收 scope 数据 | string | - | - | 131 | 132 | - row-key 属性配置 133 | 134 | 对应 el-table 的 row-key,默认值是'id' 135 | 136 | ### 搜索配置 137 | 138 | - search 属性的配置,是一个对象 139 | 140 | > 如果不想显示搜索表单,可以不配置 search 或者 search 设置为 false 141 | 142 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 143 | | ---------- | ----------------------------------------------------------------------------------------- | ----------------- | ------ | ------ | 144 | | labelWidth | label 文字长度 | string | - | - | 145 | | inputWidth | 表单项长度 | string | - | - | 146 | | fields | 表单字段列表,包含 text,select,radio,checkbox,datetime 等类型,所有字段类型配置见下表 | Array[{字段类型}] | - | - | 147 | 148 | - fields 列表的字段类型配置 149 | 150 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 151 | | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------- | ------ | 152 | | type | 字段类型 | string | text,textarea,select,radio,radio-button,checkbox,checkbox-button,number,date,daterange,datetime,datetimerange | text | 153 | | label | label 文本 | string | - | - | 154 | | name | 搜索时的提交的参数名称 | string | - | - | 155 | | style | 额外的样式 | object | - | - | 156 | | defaultValue | 默认值 | - | - | | 157 | | options | 当 type 是 select,radio,radio-button,checkbox,checkbox-button 时的枚举选项 | Array[{name, value}] | - | - | 158 | | filterable | 当 type 是 select 时,下拉框是否支持模糊搜索 | boolean | true, false | false | 159 | | multiple | 当 type 是 select 时,下拉框是否支持多选 | boolean | true, false | false | 160 | | transform | 搜索前对表单数据进行转换,比如表单数据是数组,但是搜索的时候需要传递字符串。它是一个函数,默认参数是字段的 value,需要返回转换后的结果 | function(value) | - | - | 161 | | trueNames | 当 type 是 daterange,datetimerange 时,开始时间和结束时间是在一个数组里面,但是搜索时可能需要两个字段,这时就需要把开始时间和结束时间分别赋值给两个字段,这两个字段的名称就是通过 trueNames 配置,它是一个数组,例如:trueNames: ['startTime', 'endTime'] | Array[string] | | | 162 | | min | 当 type 是 number 时的最小值 | number | - | - | 163 | | max | 当 type 是 number 时的最大值 | number | - | - | 164 | 165 | ### 分页配置 166 | 167 | - pagination 属性的配置,是一个对象 168 | 169 | > 如果不想显示分页,将 pagination 设置为 false 170 | 171 | | 参数 | 说明 | 类型 | 可选值 | 默认值 | 172 | | --------- | ---------------------------- | ------------- | --------------------------------------- | --------------------------------------- | 173 | | layout | 组件布局 | string | total, sizes, prev, pager, next, jumper | total, sizes, prev, pager, next, jumper | 174 | | pageSize | 每页显示条目个数 | number | - | 10 | 175 | | pageSizes | 每页显示个数选择器的选项设置 | Array[number] | - | [10, 20, 30, 40, 50, 100] | 176 | 177 | ### 标题栏配置 178 | 179 | > 表格上方有一个标题栏,标题栏左侧显示一个标题,右侧是一个可自定义的工具栏 180 | 181 | - hide-title-bar 182 | 183 | 是否隐藏标题栏,布尔值 184 | 185 | - title 186 | 187 | 表格标题 188 | 189 | - 自定义表格标题 190 | 191 | 提供一个具名插槽 title,来自定义标题的内容 192 | 193 | - 工具栏 194 | 195 | 工具栏默认是空的,提供一个具名插槽 toolbar,来自定义工具栏的内容 196 | 197 | ### 事件 198 | 199 | - selectionChange 200 | 201 | 如果 columns 中配置了 type 为 selection 的列,可以通过该事件得到已选择的行,参数是一个数组 202 | 203 | ### 组件内部方法 204 | 205 | - refresh 206 | 207 | 配置 ref 属性,可以通过 ref 获取组件后调用组件内部的**refresh**方法刷新列表 208 | 209 | ### 完整用法 210 | 211 | ```vue 212 | 283 | 284 | 491 | ``` 492 | 493 | 效果: 494 | 495 | ![完整用法](https://raw.githubusercontent.com/huzhushan/pics/master/vue-pro-table/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20210302144535.png) 496 | --------------------------------------------------------------------------------