0.7.6 • Published 2 years ago

element-easy v0.7.6

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

element-easy

安装

npm install element-easy

使用

依赖:

  • vue >= 2.4.0
  • element-ui
// main.js
import ElementEasy from 'element-easy'
import 'element-easy/lib/element-easy.css'

Vue.use(ElementEasy)
<template>
  <ez-crud
    :thead="crud.thead"
    :actions="crud.actions"
    :pagination="crud.pagination"
    :tools="crud.tools"
    v-bind="crud.options"
  >
    <template>
      <!-- 默认插槽,在表格后面新加列, 以下为示例 -->
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </template>
    >
    <template slot="prepend">
      <!-- 默认插槽,在表格前面新加列, 以下为示例 -->
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </template>

    <template slot="outerActions">
      <!-- 在表格左上的操作按钮后,新增其它按钮,以下为示例 -->
      <el-button type="text" size="small">导入</el-button>
    </template>

    <template slot="innerActions">
      <!-- 在表格内的操作按钮后,新增其它按钮,以下为示例 -->
      <el-button type="text" size="small">按钮</el-button>
    </template>
  </ez-crud>
</template>
export default {
  data() {
    return {
      crud: {
        options: {
          // el-table 参数
        },
        pagination: {
          // el-pagination 参数
          pageSizes: [5, 10, 20],
          pageSize: 5,
          currentPage: 1
        },
        actions: {
          // 各操作选项配置
          label: '操作',
          add: {
            // 新增
            show: true,
            api: (data) => {
              return new Promise((resolve, reject) => {})
            }
          },
          edit: {
            //编辑
            show: () => true,
            api: (data) => {
              return new Promise((resolve, reject) => {})
            }
          },
          delete: {
            // 删除
            show: false,
            showMultiple: () => true,
            api: (data) => {
              return new Promise((resolve, reject) => {})
            }
          },
          list: {
            // 列表
            api: ({ params, currentPage, pageSize }) => {
              return new Promise((resolve, reject) => {})
            }
          },
          details: {
            // 详情
            api: (data) => {
              return new Promise((resolve, reject) => {})
            }
          }
        },
        thead: [
          {
            prop: 'name',
            label: '姓名',
            width: 180,
            searchShow: true,
            form: {
                onChange: (val. form) => { // 新增编辑时,对应控件值改变时触发
                    // val: 值, form: 所有表单元素的值 
                }
            }
          },
          {
            prop: 'food',
            label: '食物',
            width: 200,
            form: {
              type: 'radio',
              options: [
                {
                  value: '黄金糕',
                  label: '黄金糕'
                },
                {
                  value: '双皮奶',
                  label: '双皮奶'
                },
                {
                  value: '蚵仔煎',
                  label: '蚵仔煎'
                },
                {
                  value: '龙须面',
                  label: '龙须面'
                },
                {
                  value: '北京烤鸭',
                  label: '北京烤鸭'
                }
              ]
            },
            searchShow: true,
            searchForm: {
              type: 'select',
              options: [
                {
                  value: '黄金糕',
                  label: '黄金糕'
                },
                {
                  value: '双皮奶',
                  label: '双皮奶'
                },
                {
                  value: '蚵仔煎',
                  label: '蚵仔煎'
                },
                {
                  value: '龙须面',
                  label: '龙须面'
                },
                {
                  value: '北京烤鸭',
                  label: '北京烤鸭'
                }
              ]
            }
          },
          {
            prop: 'address',
            label: '地址',
            form: {
              type: 'textarea'
            }
          },
          {
            prop: 'show',
            label: '状态',
            width: 100,
            form: {
              type: 'switch'
            },
            render: (h, scope) => {
              return <div>{scope.row.show}</div>
            }
          },
          {
            prop: 'date',
            label: '日期',
            width: 150,
            align: 'center',
            form: {
              type: 'date',
              valueFormat: 'yyyy-MM-dd'
            },
            searchShow: true,
            searchForm: {
              type: 'daterange'
            },
            formatter(scope) {
              return scope.row.date
            }
          }
        ]
      }
    }
  }
}

事件

除 el-table 所有事件外,还支持以下:

事件名参数说明
deleteSubmit删除行的所有参数提交删除数据
deleteSuccess删除成功
deleteError删除失败
addSubmit新增表单的所有参数提交新增数据
addClick点击新增按钮
addSuccess新增成功
addError新增失败
editSubmit编辑表单的所有参数提交编辑数据
editSuccess编辑成功
editError编辑失败
closed新增编辑弹框关闭

一级参数

参数名参数值类型默认值说明
theadArray表头配置,对应 el-table 的 data 属性
actionsObjectcrud 的一些行为配置
paginationObjectel-pagination 配置
toolsObject{ show: true, showControls: true, showRefresh: true }控制表格右上的工具按钮的显示
showSelectionBooleanfalse是否显示多选框
showIndexBooleanfalse是否显示序号
showMessageBooleantrue是否显示操作后的提示
fixedHeightBooleantrue是否固定表头
formSizeStringsmall搜索栏的控件尺寸
heightNumber, Stringcrud 组件高度
safeBottomNumber, String20距离页面底部的安全距离
beforeDeletePromise FunctionMessageBox.confirm删除操作前的回调,默认提示是否确定删除

thead 参数

除 el-table 的 Table-column Attributes 外,还增加以下内容:

参数名参数值类型默认值说明
showBooleantrue是否显示
typeStringinput表单控件类型
tooltipString表格提示信息
addShowBooleantrue新增时,是否显示
defaultAny表单默认值
editShowBooleantrue编辑时,是否显示
searhShowBooleanfalse是否在搜索条件中显示
searchFormObject{ type: 'text'}搜索栏 form 控件属性,可参阅 element ui 的 form 控件文档
formObject{ type: 'text' }新增、编辑时的 form 控件属性,可参阅 element ui 的 form 控件文档
formRulesArray新增、编辑时,表单验证规则,可参阅 element ui 的 form 控件文档

actions 参数

参数名参数值类型默认值说明
showBooleantrue是否显示
alignStringcenter对齐方式
widthNumber, String190
fixedString, Boolean是否固定(true, left, right)
outerStylesObject{ showText: true, showIcon: true, circle: false, plain: true, size: 'small' }表格外的,新增,删除 按钮样式
innerStylesObject{ showText: true, showIcon: false, circle: false, plain: true, size: 'small' }表格内的,编辑,删除 按钮样式
addObject{ show: true,type: 'primary', icon: 'el-icon-plus', text: '新增' }
editObject{ show: true,type: 'warning', icon: 'el-icon-edit', text: '编辑' }
deleteObject{ show: true, showMultiple: true, type: 'danger', icon: 'el-icon-delete', text: '删除'}
detailsObject{}定义 details.api 方法,获取列表数据
listObject{}定义 list.api 方法,获取列表数据
outerStyles 和 innerStyles

支持 el-button 的所有参数外,增加如下

参数名参数值类型说明
showTextBoolean是否显示文本
showIconBoolean是否显示图标
action.add 和 action.edit 和 action.delete 参数
参数名参数值类型默认值说明
showBooleantrue是否显示
showMultipleBooleantrue是否显示多选的删除
typeStringel-button 的 type
iconStringel-button 的 icon
textString按钮文本
apiFunction会接受到提交的信息;需要返回 Promise 函数
// api function 示例
{
    api: function(params) {
        console.log(params)
        return new Promise((resolve, reject) => {
            // todo
        })
    }
}
action.details 和 action.list 参数

支持 Form 表单控件的所有参数外,增加如下

参数名参数值类型默认值说明
apiFunction会接受到提交的信息;需要返回 Promise 函数
// details api function 示例
// 假如 details 接口如下
function getDetails(params) {
    return axios({
      method: 'get',
      url: '',
      params
    }
}

{
    api: function(params) {
        console.log(params)
        return new Promise((resolve, reject) => {
            // 根据需要,从 params 中取出查询参数,传入接口
            getDetails().then((res) => {
                // 假如 res 的值为如下
                res = {
                    code: 200,
                    data: { name: '', age: '' }
                }
                // 则需要 resolve 如下
                resolve(res.data)
            }).catch((err) => {
                reject(err)
            })
        })
    }
}

// list api function 示例
// 假如 list 接口如下
function getList(params) {
    return axios({
      method: 'get',
      url: '',
      params
    }
}

{
    api: function({ params, currentPage, pageSize }) {
        console.log(params, currentPage, pageSize )
        return new Promise((resolve, reject) => {
            // 接口有需要什么参数,可从 api 方法接收到的参数中获取
            getList().then((res) => {
                // 假如 res 的值为如下
                res = {
                    code: 200,
                    data: {
                        total: 100,
                        list: [ { name: '张三', age: '18' }, { name: '李四', age: '18' } ]
                    }
                }
                // 则需要 resolve 如下
                resolve({
                    list: res.data.list,
                    total: res.data.total
                })
            })
        })
    }
}

pagination 参数

支持 el-paginaton 所有参数,部分默认值调整如下

参数名参数值默认值
backgroundBooleantrue
layoutStringprev, pager, next, sizes
0.7.6

2 years ago

0.7.4

2 years ago

0.7.5

2 years ago

0.6.6

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.5.14

2 years ago

0.5.13

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.12

2 years ago

0.5.11

2 years ago

0.5.10

2 years ago

0.5.9

2 years ago

0.5.8

2 years ago

0.5.7

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago