1.1.0 • Published 8 months ago

trap-ui v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

components => Vue3+element-plus+vite 组件的二次封装,通过json可配置项,方便复用;

组件名描述
SearchForm列表搜索框
TableList列表Json配置
custom-select业务组件修改ui复选框支持城市多选
v-charts按需echarts基础封装,传入options,适配当前屏幕
TableList列表单元格支持编辑输入框操作,下拉;双向绑定支持校验, (closeEdit: () => false关闭当前单元格编辑)

注意:本包是vue项目;全局引入: 本包需依赖element-plus组件库。包构建并没有将element-plus组等生产依赖进行打包,避免造成重复依赖

安装使用
// 添加项目依赖: npm install table-form-list -S
// main.js中引入
1. import router from "./router";
2. import ElementPlus from 'element-plus'
3. import * as ElementPlusIconsVue from '@element-plus/icons-vue'
4. import mingfuUi from "trap-ui"
5. Vue.use(mingfuUi);

灵活使用,复制项目文件中的lib/TableFormList.vue文件在自己项目中,方便更改扩展

table-form-list

使用案例
  • 指定表格的数据源 dataSource 为一个数组,配置相关属性json;
<template>
  <div>
    <span>本地测试引入表格组件库开发</span>
    <br />
    <SearchForm
      :rules="rules"
      :search="search"
      :isShowSearch="true"
      :is-show-reset="false"
      style="margin-top: 16px"
      @handleSearch="handleSearch"
    >
     <template #pre_form_content>
        <el-button style="margin-right: 10px" type="primary">添加</el-button>
      </template>
    </SearchForm>
     <TableList
      ref="multipleTableRefs" 
      :httpRequest="httpRequest" 
      :is-footer-extend="false" 
      :columns="columns()" 
    />
    // 新增echarts按需引入公共处理部分 BarChart, LineChart, PieChart, GaugeChart
    <v-charts :isWatch="isActiveName" :options="setOptions" />
  </div>
</template>

<script>
// 搜索设置
const search = [
  {
    label: "姓名ID/手机号",
    inputType: "number",
    maxlength: 11,
    value: "name",
    rulesLength: true,
    labelProps: {
      "label-width": "130"
    }
  },
  {
    type: "select",
    label: "是否添加微信",
    value: "joinWeChatStatus",
    children: [
      {
        label: "未添加",
        value: "1"
      },
      {
        label: "已添加",
        value: "0"
      }
    ]
  },
  {
    type: "picker",
    label: "操作时间",
    value: "operate",
    props: {
      size: "mini",
      type: "datetimerange",
      "range-separator": "至",
      "start-placeholder": "开始日期",
      "end-placeholder": "结束日期",
      "value-format": "x"
    }
  },
   {
    type: "cascader",
    label: "城市",
    value: "city",
    props: {
      size: "mini",
      expandTrigger: 'hover'
    },
    options: []
  }
];

// 表格头设置
const columns = ({ handleNewJump }) => [
  {
    label: "姓名",
    prop: "name",
    props: {
      sortable: "sortable"
    }
  },
  {
    label: "性别",
    prop: "sex",
    formatter: (row, column, index) => {
      return row.sex === 0 ? "男" : "女";
    }
  },
  {
    label: "住址",
    prop: "address",
    newjump: (row, columns, index) => {
      return `www.baidu.com/studentInfo/index/${row.accountId}`;
    }
  },
  {
    label: "手机号",
    render: (h, parmas) => {
      return [
        h("i", {
          class: "el-icon-phone-outline",
          style: "fontSize: 16px; color: red"
        }),
        h("span", parmas.row.mobileNum)
      ];
    }
  }, 
  {
    label: '操作',
    children: [
      {
        label: "编辑",
        isShow: row => {
          return row.status !== 2;
        },
        disabled: row => {
          return row.disabled === 2;
        },
        method: row => {
          handleNewJump(row);
        }
      }
    ]
  }
];

// 服务器请求返回值
const dataSource = [
  {
    key: "1",
    name: "胡彦斌",
    age: 32,
    sex: 0,
    address: "西湖区湖底公园1号"
  },
  {
    key: "2",
    name: "胡彦祖",
    age: 42,
    sex: 1,
    disabled: 2,
    address: "西湖区湖底公园1号"
  }
];

<script lang="ts" setup>
import common from '@/api/common'
import { search, columns } from './list'
import { ref, reactive, onBeforeMount } from 'vue'
import type { FormRules } from 'element-plus'

const multipleTableRefs = ref(null)

const httpRequest = reactive({
  httpApi: '',
  params: {},
  response: {
    classA: 'list',
    customPage: 'page'
  }
})

const rules = reactive<FormRules>({
  name: { required: true, message: '名称信息不能为空', trigger: 'blur' },
  startTime: { required: true, message: '日期信息不能为空', trigger: 'blur' }
})

// 检索条件
const handleSearch = (searchVal) => {
  httpRequest.params = searchVal
  // baseUrl 当前域名或者全局自定义请求地址
  httpRequest.httpApi = baseUrl + '/api/getlist'
}
</script>
API使用
TableList
参数说明类型默认值必填项
type是否显示该行索引/复选框'index' 'selection' String-
border是否展示外边框和列边框Booleanfalse
sizeTable 的尺寸string-
optionstable参数扩展属性 Table AttributesObject-
columns表格列的配置描述,表头部分Array[]-
dataSource数据数组Array[]-
pagination分页的配置项Object-
dataTotal数据总数Number0
httpRequest内部请求及自定义响应labelobject{}
Columns

列描述数据对象,是 columns 中的一项,与Element-Ui Columns 使用相同的 API在props中填写。使用用法:

参数说明类型默认值必填项
label列头显示文字String-
prop列数据在数据项中对应的 keyString-
align设置列的对齐方式'left' 'right' 'center''left'
width列宽度string number-
props列表参数扩展属性Table-column AttributesObject-
render生成复杂数据的渲染函数,参数分别为createElement,当前行数据Function(h, record) {}-
formatter数据格式化Function(row, columns, index) {}-
newjumpurl页面跳转Function(row, columns, index) {}-
const columns = [
{
  label: '姓名',
  prop: 'name',
  props: {
    sortable: 'sortable',
  }
}]
search type []

列表搜索条件对象描述,同FormItem API相同,同理在props中填写。使用用法:

参数说明类型默认值必填项
label表单label名称String-
value表单名称对应的keyString-
type表单类型(可选:select/picker/cascader)Stringinput
inputTypeinput type: numberString'number'
maxlength最大输入的长度'string' 'number'-
rulesLength输入文本校验长度控制Boolean-
children展示有子选项值type:selectArray[]-
props任意表单的属性扩展Object-
rules是否添加搜索条件的校验Object-
handleSearch数据验证成功后回调事件Function(e:Event)-
handleReset重置所有组件Function()-
const tableSearch = [{
  type: "picker",
  label: "操作时间",
  value: "operate",
  props: {
    size: "mini",
    type: "datetimerange",
    "range-separator": "至",
    "start-placeholder": "开始日期",
    "end-placeholder": "结束日期",
    "value-format": "timestamp"
    }
  },
  {
    type: "cascader",
    label: "城市",
    value: "city",
    props: {
      size: "mini",
      expandTrigger: 'hover'
    },
    options: []
  }
操作列表 columns.children type []

列表操作列对象描述,使用用法:

参数说明类型默认值必填项
label列文本显示String-
typebutton按钮类型Stringtext
icon按钮icon图标String-
plain是否朴素按钮Booleanfalse
isShow依据状态是否显示,第一个参数当前行数据,第二个参数当前行索引Function(row, index) {}-
disabled是否禁用状态Function(row, index) {}-
methodevent 事件Function(row, index) {}-
TableList Events
事件名说明类型默认值必填项
current-change页码改变的回调,参数是改变后的页码及每页条数Function(currentPage)-
size-change每页条数改变的回调,参数是改变后的页码及每页条数Function(size)-
handleSelectionChange当选择项发生变化时会触发该事件Function(selection)-
toggleRowSelection设置当前选中项回显、清空复选框事件Function(dom节点)-
1.1.0

8 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago