Skip to content

PageContent 数据表格

配置化生成数据表格,支持列定义、分页、工具栏、操作列、自定义插槽、导入导出。

Props

参数说明类型默认值
content-config列表配置IContentConfig

IContentConfig

属性说明类型默认值
indexAction列表查询接口(必填)(params) => Promise<PageResult>
cols列配置(必填)IColumn[]
pk主键字段名string'id'
permPrefix权限前缀string
toolbar左侧工具栏按钮Array<ToolbarLeft | IToolsButton>
defaultToolbar右侧工具栏图标Array<ToolbarRight | IToolsButton>
tableElTable 属性Partial<TableProps>
pagination分页配置,false 关闭分页boolean | Partial<PaginationProps>
pagePosition分页位置"left" | "right""left"
request分页参数字段名{ pageName, limitName }
deleteAction删除接口(ids: string) => Promise<any>
exportAction后端导出接口(params) => Promise<any>
exportsAction前端导出接口(params) => Promise<TItem[]>
importAction后端导入接口(file: File) => Promise<any>
importsAction前端导入处理函数(data: IObject[]) => Promise<any>
importTemplate导入模板(URL 或获取函数)string | (() => Promise<any>)
modifyAction行内编辑接口(data) => Promise<any>

toolbar 可选值

"add" / "delete" / "import" / "export" / 自定义按钮对象

defaultToolbar 可选值

"refresh" / "filter" / "imports" / "exports" / "search" / 自定义按钮对象

列配置

属性说明类型默认值
prop数据字段名string
label列标题string
width列宽string | number
align对齐方式"left" | "center" | "right"
type内置列类型"selection" | "index" | "expand""default"
templet列模板类型ITemplet
slotName自定义插槽名(templet: "custom" 时使用)string
operat操作列按钮(templet: "tool" 时使用)Array<ToolbarTable | IToolsButton>
show是否显示该列booleantrue
columnKey列 key,用于筛选string
filters列筛选选项Array<{ text, value }>
filterMultiple筛选是否多选boolean
filterJoin筛选值拼接符string
initFn列初始化函数(用于异步加载筛选选项等)(item) => void

templet 可选值

image / list / url / switch / input / price / percent / icon / date / tool / custom

配置示例

typescript
const contentConfig: IContentConfig<UserPageQuery> = reactive({
  permPrefix: "sys:user",
  pk: "id",

  table: {
    border: true,
    highlightCurrentRow: true,
  },

  pagination: {
    background: true,
    layout: "prev,pager,next,jumper,total,sizes",
    pageSize: 20,
    pageSizes: [10, 20, 30, 50],
  },

  indexAction: UserAPI.getPage,
  deleteAction: UserAPI.deleteByIds,
  exportAction: UserAPI.export,

  toolbar: ["add", "delete", "import", "export"],

  defaultToolbar: ["refresh", "filter", "search"],

  cols: [
    { type: "selection", width: 50, align: "center" },
    { label: "编号", prop: "id", width: 100, align: "center" },
    { label: "用户名", prop: "username", align: "center" },
    { label: "头像", prop: "avatar", templet: "image", align: "center" },
    {
      label: "性别",
      prop: "gender",
      templet: "custom",
      slotName: "gender",
      align: "center",
      width: 100,
    },
    {
      label: "操作",
      align: "center",
      fixed: "right",
      width: 220,
      templet: "tool",
      operat: ["edit", "delete"],
    },
  ],
});

自定义列插槽

vue
<page-content ref="contentRef" :content-config="contentConfig">
  <template #gender="scope">
    <DictTag v-model="scope.row[scope.prop]" code="gender" />
  </template>

  <template #status="scope">
    <el-tag :type="scope.row.status == 1 ? 'success' : 'info'">
      {{ scope.row.status == 1 ? "启用" : "禁用" }}
    </el-tag>
  </template>
</page-content>

Events

事件名说明回调参数
add-click点击新增按钮()
export-click点击导出按钮()
toolbar-click点击工具栏自定义按钮(name: string)
operate-click点击操作列按钮(data: IOperateData)
filter-change列筛选变化(filters: any)

实例方法

方法说明
fetchPageData(formData?, isRestart?)拉取列表数据,isRestart=true 重置到第一页
exportPageData(formData?)导出数据
getFilterParams()获取列筛选条件
getSelectionData()获取勾选行数据
handleRefresh(isRestart?)刷新列表

基于 MIT 许可发布 · 如需部署协助或二开定制,请查看 支持与合作