Skip to content
On this page

BaseTablePage-table 页面

column 配置项参考 el-table

javascript
const state = reactive({
  baseModelOptions: baseModelOptions, //新增、修改弹窗  动态组件数组
  baseFilterOptions: baseFilterOptions, //上方搜索  动态组件数组
  title: "用户管理", //页面标题,不设置则隐藏标题区域
  getTableFn: getUser, //查询接口 --Promise
  pageInfo: { total: 0, base: { limit: 8, current: 1 } }, //分页信息
});
1
2
3
4
5
6
7
html
<BaseTablePage :tableOptions="state">
  <template v-slot:addButton>
    <!-- 添加按钮内部插槽 -->
  </template>
  <template #column>
    <!-- 表格column插槽,不包含操作按钮 -->
    <el-table-column align="center" prop="username" label="用户名" />
    <el-table-column align="center" prop="gender" label="性别">
      <template #default="scope">
        <span style="margin-left: 10px"
          >{{ scope.row.gender==1?'男':scope.row.gender==2?'女':'未知' }}</span
        >
      </template>
    </el-table-column>
  </template>
  <template #control="baseScope">
  <!-- 表格control插槽,重写操作按钮区域 -->
    <el-table-column  label="操作" width="350">
      <template #default="scope">
        <template v-if="scope.row.status != 2">
            <el-button type="warning" :disabled="scope.row.status == 2"  @click="doSometing(scope.$index, scope.row)"
            >修改</el-button
          >
          <el-popconfirm @confirm="baseScope.control.deleteTableData(scope.$index, scope.row)" title="确定删除该条数据?">
            <template #reference>
              <el-button
                :disabled="scope.row.status == 2"
                type="danger"
                >删除</el-button
              >
            </template>
          </el-popconfirm>
        </template>
    </el-table-column>
  </template>
</BaseTablePage>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

调用组件方法

html
<BaseTablePage :tableOptions="state" ref="table"></BaseTablePage>
1
javascript
const table = ref();
onMounted(() => {
  const {
    doFilter, //点击搜索后执行的函数
    getTableData, //查询表格数据执行的函数
    editTableData, //修改弹窗,点击确定执行的函数
    deleteTableData, //删除弹窗,点击确定执行的函数
  } = table.value;
  //示例:3s后主动执行一次查询
  setTimeout(() => {
    getTableData();
  }, 3000);
});
1
2
3
4
5
6
7
8
9
10
11
12
13

tableOptions 属性

function相关

名称描述必填参数类型默认值
handleAdd添加按钮执行的 func(覆盖默认的调用 function)Functionnull
handleAdd添加按钮执行的 func(覆盖默认的调用 function)Functionnull
handleEdit点击编辑按钮执行的 func(覆盖默认的调用 function)Function(index,row)null
handleDelete点击删除按钮执行的 func(覆盖默认的调用 function)Function(index,row)null
beforeSubmit提交修改前事件,F(params)Functionnull
beforeShowEdit点击编辑按钮事件,弹窗显示前执行(同步) F(params)Functionnull
beforeEdit与 beforeShowEdit 执行时机一致(异步)(Promise)Function(row)null
beforeDelete执行删除前调用Function(row)null
afterSubmit表单提交后调用(支持普通 fn 与 return Promise)(Promise)Function(row)null
afterDelete数据删除后调用(支持普通 fn 与 return Promise)(Promise)Function(row)null

配置属性

名称描述必填参数类型默认值
baseModelOptions新增、修改弹窗 动态组件数组Arraynull
baseFilterOptions上方搜索 动态组件数组Arraynull
showRest是否显示重置搜索按钮Booleanfalse
autoQuery是否页面初始化自动进行查询 tableBooleantrue
title页面标题,不设置则隐藏标题区域Stringnull
showLoading是否显示加载动画,默认 true,且只有值为 false 不显示Boolantrue
rowKey当 row 中包含 children 字段时,被视为树形数据,指定 row-key,开启树形数据展示Stringnull
showBack是否显示返回按钮Booleanfalse
baseModelName弹窗标题Stringnull
hideControl隐藏操作列Booleannull
showAddBtn是否显示添加按钮,仅为 false 不显示Booleannull
addBtnName添加操作 按钮名称 ,为空则不显示按钮Stringnull
addBtnIcon添加按钮的 iconStringnull
showEditBtn是否显示修改按钮,仅为 false 不显示Booleannull
editBtnName修改操作 按钮名称Stringnull
showDelBtn是否显示删除按钮,仅为 false 不显示Booleannull
delBtnName删除操作 按钮名称Stringnull
primaryKey修改、删除操作 主键名称Stringnull
baseQuery查询接口默认参数Objectnull
baseAdd添加接口默认参数Objectnull
baseUpdate修改接口默认参数Objectnull
getTableFn查询接口(Promise) Functionnull
addFn新增接口(Promise) Functionnull
editFn修改接口(Promise) Functionnull
detailFn查询详情接口,点击修改触发,为 null 时,使用 table-row 的数据(Promise) Functionnull
deleteFn删除接口(Promise) Functionnull
multipleDelete是否批量删除 --批量删除会自动将 id 包裹在数组中,并未支持批量选择Booleanfalse
pageInfo分页信息Object{ total: 0, base:{limit: 10,current: 1} }

插槽

名称描述scope
addButton顶部添加按钮的内部插槽none
columntable-column 内容
control操作(操作按钮)scope.control.'table 相关 methods'