1.0.9 • Published 3 years ago

el-powerful-table v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

el-powerful-table

主要功能:分页多选,批量操作

vue2.0 的 element-ui 二次开发表格组件

使用方法

npm i el-powerful-table
//main.ts
import Vue from 'vue'
import App from './App.vue'
import ElementUI from "element-ui";
import powerfulTable from "el-powerful-table";

Vue.use(ElementUI)
Vue.use(powerfulTable)

new Vue({
  el: '#app',
  render: h => h(App)
})

//*.vue
<powerful-table :list="list" :total="total" :header="header"></powerful-table>

powerful-table Attributes 表格组件

参数说明类型可选值默认值
list当前数据array--
header表格头部数据array--
total分页总条数number-0
tableName表格名(用于缓存表格的分页) 已废弃number-1
layout组件布局,子组件名用逗号分隔string详情参考element 分页total, sizes, prev, pager, next
pageSizes每页显示个数选择器的选项设置array-10, 20, 30
selectData选中的数据array--
selectCompare选中数据和列表数据相比较的参数[0]选中数据参数,[1]列表数据参数array-'id','id'
isSelect是否显示多选booleanfalse/truefalse
isPagination是否显示分页器booleanfalse/truefalse
operateData批量操作object-{}

operateData 批量操作

如果表格有 header.props.typeinput 的则需要先填写该行数据,在选中该行,否则会出现获取不到 input 的值

参数说明类型可选值默认值
value下拉选中值string-null
size按钮和下拉框大小stringmedium / small / minismall
type按钮的类型stringprimary / success / warning / danger / info / textprimary
disabled禁用booleantrue / falsefalse
icon按钮上图标string--
style按钮样式object--
operates批量操作下拉框数据arrayobject--

operates 批量操作下拉框数据

参数说明类型可选值默认值
label批量操作下拉框显示文字string--
value批量操作下拉框值string--

// 参数示例
const operateData = {
  value: 0,
  operates:[{
    label: '删除',
    value: 0
  }]
}

查看JSON参数

header 表格头部数据

参数说明类型可选值默认值
overflowTooltip当内容过长被隐藏时显示booleantrue / falsefalse
label显示的标题string--
minWidth对应列的最小宽度string-100
width对应列的宽度string--
sortable排序boolean / string'custom' / true / falsefalse
headerAlign表头对齐方式stringleft / center / rightcenter
props单元格数据arrayobject--

props 单元格数据

参数说明类型可选值默认值
prop数据 key 值string--
child当 prop 值是对象是用到 仅支持 type 为 textstring--
type数据类型stringimage / text / switch / btn / video / inputtext
data每个类型不一样 data 里值也不一样, type 为 btn 时数据类型为 arrayobjectobject--
filter过滤,只支持 type 为 text、tagarrayobject--
text数据左侧显示的文字。(例:文字:数据)string--
reserve当 prop 值 渲染数据为空时可用 reserve 代替空数据string--
style包裹组件外面那一层 div 样式object--
// 假设有一个这样的数据
const data = {
  my:{
    name: 'red'
  },
  myBrother: 'yellow'
}

// 参数示例
[{
  label: '我',
  props:[{
    type: 'text',
    text: '我的名字',
    prop: 'my',
    child: 'name',
    reserve: '我只有在数据空时显示',
    filter:[{
      key: 'red',
      value: 'black'
    }]
  }]
},
{
  label: '我的兄弟',
  props:[{
    prop: 'myBrother',
  }]
}]

filter 过滤

参数说明类型可选值默认值
key单元格里的数据string--
value需要替换的值string--
// 参数示例
{
  label: '筛选',
  props:[{
    prop: 'name',
    filter:[{
      key: '1',
      value: '替换1'
    }]
  }]
}

data 类型数据

type != 'text' 的并且没有 data 情况下 都建议写上 data:{}

//示例
{
  type: 'image',
  prop:'image',
  data:{}
}

type == image(图片)

参数说明类型可选值默认值
preview预览booleantrue/falsetrue
lazy懒加载booleantrue/falsetrue
zIndex图片预览层级number-6000
style图片自定义样式object--
fit图片如何适应容器框,同原生object-fitstringfill / contain / cover / none / scale-down-
//示例
{
  label: "图片", //显示的标题
  props: [
    {
      type: "image",
      prop: "imageUrl",
      data: {
        style: {
          width: "120px",
          height: "120px",
          borderRadius: "10px",
        },
        lazy: true,
        preview: true,
      },
    },
  ],
}

type == btn(操作按钮)

参数说明类型可选值默认值
tip提示文字string--
style按钮样式object--
icon按钮上图标string--
disabled按钮是否禁用booleantrue/falsefalse
type按钮类型stringprimary / success / warning / danger / info / textprimary
size按钮大小stringmedium / small / minismall
condi控制按钮显示隐藏object--
emit自定义方法名string--
// 参数示例
{
    label: "操作", //显示的标题
    props: [
      {
        type: "btn",
        data: [
          {
            tip: "编辑",
            type: "info",
            icon: "el-icon-edit-outline",
            text: "U",
            emit: "update",
            condi: {
              // 此时 name == 1 时才会显示
              prop: 'name',
              value: '1'
            }
          },
          {
            tip: "删除",
            type: "danger",
            text: "D",
            icon: "el-icon-delete",
            emit: "remove",
          },
        ],
      },
    ],
  }

condi(判断是否显示按钮)

参数说明类型可选值默认值
prop根据判断的 propstring--
value根据判断的 prop 的 valuestring / number--

type == switch(开关)

参数说明类型可选值默认值
activeColor打开时的背景色string--
inactiveColor关闭时的背景色string--
inactiveText关闭时的文字描述string--
activeText关闭时的文字描述string--
activeValue打开时的值number-1
inactiveValue关闭时的值number-0
disabled是否禁用booleantrue/falsefalse
style开关自定义样式object--
//示例
{
    label: "开关", //显示的标题
    overflowTooltip: false,
    props: [
      {
        prop: "switchVal",
        type: "switch",
        data: {
          inactiveText: "关闭",
          activeText: "开启",
          activeValue: 1,
          inactiveValue: 0
        },
      },
    ],
  }

type == input(输入框)

参数说明类型可选值默认值
style输入框样式object--
size输入框大小stringmedium / small / minismall
placeholder输入框文字描述string--
disabled输入框是否禁用booleantrue/falsefalse
slot输入框前置或后置stringprepend / append-
symbolslot 文字或者符合string--
//示例
{
  label: "价格", //显示的标题
  props: [
    {
      prop: "price",
      type: "input",
      data: {
        slot: "prepend",
        symbol: "¥",
        style: { width: "100%" },
      },
    },
  ],
}

type == video(视频)

参数说明类型可选值默认值
style视频样式object--
poster封面 url 路径string--
loop循环播放booleantrue/falsefalse
style图片自定义样式object--
//示例
{
  label: "视频", //显示的标题
  props: [
    {
      prop: "videoUrl",
      type: "video",
      data: {
        cover: "",
        style: {
          width: "120px",
          height: "120px",
          borderRadius: "10px",
          border: "1px solid #ccc",
        },
      },
    },
  ],
}

type == iconfont(图标)

参数说明类型可选值默认值
class样式类array--
style图标自定义样式object--
//示例
{
  type: 'iconfont',
  prop:'icon',
  data:{
    class: ['viteicon','vitestar'],
    style: {
      background: 'yellow'
    }
  }
}

type == rate(评分)

参数说明类型可选值默认值
max最大数值number-5
style自定义样式object--
colors颜色数组array-'#F7BA2A', '#F7BA2A', '#F7BA2A'
iconClass颜色数组array-'el-icon-star-on', 'el-icon-star-on', 'el-icon-star-on'
allowHalf是否允许半选booleantrue/falsefalse
showText是否显示辅助文字,若为真,则会从 texts 数组中选取当前分数对应的文字内容boolean-false
showScore是否显示当前分数,show-score 和 show-text 不能同时为真booleantrue/falsefalse
texts辅助文字数组array-'极差', '失望', '一般', '满意', '惊喜'
//示例
{
  label: "评分", //显示的标题
  props: [
    {
      type: "rate",
      prop: "rate",
      data: {
        allowHalf: true,
        showText: true,
        colors: ['red', 'yellow', 'green']
      },
    },
  ],
}

type == href(超链接)

参数说明类型可选值默认值
style自定义样式object--
target跳转类型string-'_blank'
type主题类型string-'primary'
underline是否显示下划线booleantrue/falsefalse
prop超链接文字该显示哪个 prop 的值 否则为 text 的值string-
//示例
{
  label: "超链接", //显示的标题
  props: [
    {
      type: "href",
      prop: "href",
      data: {
        prop: 'name',
      },
    },
  ],
}

type == slot(插槽)

参数说明类型可选值默认值
slotName插槽名称string-'default'
//示例
{
  label: "slot(插槽)", //显示的标题
  props: [
    {
      type: "slot",
      slotName: "A",
    },
  ],
}

//vue
<powerful-table>
  <template #A="{ row,index }">
    <div>
      <el-image
        style="width: 100px; border-radius: 10px"
        :src="row.imageUrl"
      ></el-image>
    </div>
  </template>
</powerful-table>

type == tag

参数说明类型可选值默认值
type类型string'primary / success / warning / danger / info''primary'
effect主题string'dark / light / plain''light'
color背景颜色string--
hit是否描边boolean-false
filter查看详情array--

//示例
{
  label: "标签", //显示的标题
  props: [
    {
      prop: "tag",
      type: "tag",
      data: {
        effect: 'dark',
        // type: 'success'
      }
    },
  ],
}

Event

方法名说明参数
sizeChange分页器切换{ pageNum , pageSize },selectArr(所有页中选中的数据)
sortCustom远程排序column
batchOperate批量操作{ids , selection , rows}
自定义方法名-{row , index }
switchChange开关组件操作row
1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago