1.0.5 • Published 2 years ago

base-elsa-vue v1.0.5

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

elsa

:zap: elsa(eleme simple admin)基于 element-ui 封装 el-form,el-table 等组件,适用于快速开发后台管理项目。

Quickstart

npm i elsa-vue -S
// vue main.js
import Vue from 'vue'
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import Elsa from 'base-elsa-vue'

Vue.use(Element)
Vue.use(Elsa)

Feature

  • else-card
    • 支持主副标题的设置
  • else-table
    • 可配置列表列
    • 支持分页控件
    • 支持树形数据展示及懒加载
  • elsa-form
    • 支持的表单组件
      • el-input
      • el-radio
      • el-checkbox
      • el-select
      • el-upload
      • el-xxx-picker
    • 自定义布局
    • 表单校验和重置
    • 嵌套对象 nest 的解析
    • 表单整体 disabled 设置
    • 表单项的提示 tip 信息
    • 表单项:动态/联动
      • 禁用/可用
      • 显示/隐藏
      • 动态修改多选项 options

todo

  • 结构优化.精简冗余配置以及依赖

elsa-table

用法:

  1. 获取 Array 类型的数据源 dataSource
  2. 根据 dataSource 中的对象属性,配置显示的列 columns 信息
  3. 设置分页参数 pagination
<elsa-table border :columns="columns" :dataSource="dataSource" :pagination="pagination" />
export default {
  data() {
    return {
      dataSource: [
        { name: 'eminoda', age: 30 },
        { name: 'foo', age: 40 },
        { name: 'bar', age: 50 },
      ],
      columns: [
        { label: '序号', align: 'center', type: 'index', width: '50' },
        { label: '姓名', align: 'center', prop: 'name', width: '100' },
        { label: '年龄', align: 'center', prop: 'age', width: '100' },
      ],
      pagination: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
        currentChange: (currentPage) => {},
        sizeChange: (pageSize) => {},
      },
    }
  },
}

ElsaTable Attributes

参数说明类型可选值默认值
columns列信息Array
dataSource数据源Array
pagination分页信息Object
...elPropsel-table 属性

ElsaTable.columns

参数说明类型可选值默认值
typeselection 添加选择框列 index 添加序号列 expand 展示更多内容Stringselection/index/expand
label标题String
prop解析字段String
width对应列的宽度String
fixed列是否固定在左侧或者右侧,true 表示固定在左侧String/Booleantrue, left, right
formatter数据格式化Function(row, column, cellValue)
show-overflow-tooltip当内容过长被隐藏时显示 tooltipBoolean

更多详见:el-table column

ElsaTable.elProps

参数说明类型可选值默认值
data以 dataSource 代替
border是否带有纵向边框Booleanfalse
size尺寸Stringmedium / small / mini
fit列的宽度是否自撑开Booleantrue

更多详见:el-table attributes

ElsaTable Events

参数说明类型可选值默认值
selection-change当选择项发生变化时会触发该事件Function(selections)

更多详见:el-table events

😬 注:部分 Events 根据现在文件结构实现较困难(比如:排序,过滤,合并表单...),可把 config 文件内容定义在 data 中来实现(而非 import 方式)

elsa-form

用法:

  1. 定义表单数据模型 model
  2. 配置表单项 field ,定义布局(可选)
<elsa-form :config="fields" :model="model" labelWidth="auto" label-suffix=":">
  <el-row type="flex" justify="center">
    <el-button @click="submit" type="primary">提交</el-button>
    <el-button @click="reset" type="warning" style="margin-left:10px;">重置</el-button>
  </el-row>
</elsa-form>
export default {
  data() {
    return {
      fields: {
        name: {
          label: '用户名',
          elTag: 'el-input',
          elAttrs: {
            placeholder: '请输入用户名',
          },
          customRender: 'nameCheck',
          rules: [{ required: true, message: '用户名不能为空', trigger: 'change' }],
        },
        password: {
          label: '密码',
          elTag: 'el-input',
          elAttrs: {
            type: 'password',
            showPassword: true,
          },
          rules: [{ required: true, trigger: 'change' }],
        },
      },
      model: {
        name: '',
        password: '',
      },
    }
  },
}

ElsaForm Attributes

参数说明类型可选值默认值
config表单项配置Object
model表单数据模型Object
layout表单布局Arrray
disabled表单整体禁用Booleanfalse
...elProps表单项配置Object

ElsaForm.config

参数说明类型可选值默认值
field表单项字段,与 model 属性对Object
field.label名称String
field.elTagelement 表单标签Stringel-input/select/radio/cascader/date-picker/time-picker/upload
field.elAttrs表单项属性(参考 elTag 对应组件)Object
field.elStyle表单项 style 样式Object
field.extra提示信息String
field.extraIcon提示信息 icon 图标Stringel-icon-warning-outline
field.rules表单校验规则Array
field.options当为 check,select 作为数据展示Array
field.visible联动,可根据 modelfiled 来控制 显示隐藏Boolean/String/Function({model})
field.customRender展示于 elTag 右侧的模板String
field.slotRenderelTag 内部的模板(比如:upload 中的内容)String

更多详见:el-form-item methods

ElsaForm.field.elAttrs

示例一些特殊属性

参数说明类型可选值默认值
disabled禁用Function({model})/ Boolean
isRemoteelTag 为 el-select 的延迟加载Boolean
remoteMethodelTag 为 el-select 的延迟加载Function(done,{model}) / Boolean
lazyelTag 为 el-cascader 的延迟加载Boolean
lazyLoadelTag 为 el-cascader 的延迟加载Function(node, resolve, { done }) / Boolean

ElsaForm.layout

参数说明类型可选值默认值
elTagelement 表单标签Stringel-row/col
elAttrs表单项属性(参考 elTag 对应组件)Object
children子项Object
field表单项字段String

ElsaForm.elProps

参数说明类型可选值默认值
label-width表单域标签的宽度String
label-suffix表单域标签的后缀String
size尺寸Stringmedium / small / mini

更多详见:el-form attributes

ElsaForm Methods

参数说明类型可选值默认值
validate表单数据校验Function(err,model)
resetFields重置表单项Function(props<Array | String>)
clearValidate校验结果清空Function(props<Array | String>)

更多详见:el-form methods

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago