feat(table): add `headerTop` slot
为表格添加`headerTop`插槽(表格头部的标题之上),以及相关演示 close: #881
This commit is contained in:
parent
9cf070dd63
commit
540423ecf7
|
|
@ -3,6 +3,7 @@
|
||||||
- **Table**
|
- **Table**
|
||||||
- 修复滚动条样式问题
|
- 修复滚动条样式问题
|
||||||
- 修复树形表格的带有展开图标的单元格的内容对齐问题
|
- 修复树形表格的带有展开图标的单元格的内容对齐问题
|
||||||
|
- 新增`headerTop`插槽
|
||||||
- **AppSearch** 修复可能会搜索隐藏菜单的问题
|
- **AppSearch** 修复可能会搜索隐藏菜单的问题
|
||||||
- **其它**
|
- **其它**
|
||||||
- 修复菜单默认折叠的配置不起作用的问题
|
- 修复菜单默认折叠的配置不起作用的问题
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div style="width: 100%">
|
||||||
|
<div v-if="$slots.headerTop" style="margin: 5px">
|
||||||
|
<slot name="headerTop"></slot>
|
||||||
|
</div>
|
||||||
|
<div style="width: 100%; display: flex">
|
||||||
<slot name="tableTitle" v-if="$slots.tableTitle"></slot>
|
<slot name="tableTitle" v-if="$slots.tableTitle"></slot>
|
||||||
|
<TableTitle
|
||||||
<TableTitle :helpMessage="titleHelpMessage" :title="title" v-if="!$slots.tableTitle && title" />
|
:helpMessage="titleHelpMessage"
|
||||||
|
:title="title"
|
||||||
|
v-if="!$slots.tableTitle && title"
|
||||||
|
/>
|
||||||
<div :class="`${prefixCls}__toolbar`">
|
<div :class="`${prefixCls}__toolbar`">
|
||||||
<slot name="toolbar"></slot>
|
<slot name="toolbar"></slot>
|
||||||
<Divider type="vertical" v-if="$slots.toolbar && showTableSetting" />
|
<Divider type="vertical" v-if="$slots.toolbar && showTableSetting" />
|
||||||
|
|
@ -12,6 +19,8 @@
|
||||||
@columns-change="handleColumnChange"
|
@columns-change="handleColumnChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { TableSetting, ColumnChangeParam } from '../types/table';
|
import type { TableSetting, ColumnChangeParam } from '../types/table';
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,11 @@ export function useTableHeader(
|
||||||
tableTitle: () => getSlot(slots, 'tableTitle'),
|
tableTitle: () => getSlot(slots, 'tableTitle'),
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
|
...(slots.headerTop
|
||||||
|
? {
|
||||||
|
headerTop: () => getSlot(slots, 'headerTop'),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,39 @@
|
||||||
<template>
|
<template>
|
||||||
<BasicTable @register="registerTable">
|
<BasicTable
|
||||||
|
@register="registerTable"
|
||||||
|
:rowSelection="{ type: 'checkbox', selectedRowKeys: checkedKeys, onChange: onSelectChange }"
|
||||||
|
>
|
||||||
<template #form-custom> custom-slot </template>
|
<template #form-custom> custom-slot </template>
|
||||||
|
<template #headerTop>
|
||||||
|
<a-alert type="info" show-icon>
|
||||||
|
<template #message>
|
||||||
|
<template v-if="checkedKeys.length > 0">
|
||||||
|
<span>已选中{{ checkedKeys.length }}条记录(可跨页)</span>
|
||||||
|
<a-button type="link" @click="checkedKeys = []" size="small">清空</a-button>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<span>未选中任何项目</span>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</a-alert>
|
||||||
|
</template>
|
||||||
<template #toolbar>
|
<template #toolbar>
|
||||||
<a-button type="primary" @click="getFormValues">获取表单数据</a-button>
|
<a-button type="primary" @click="getFormValues">获取表单数据</a-button>
|
||||||
</template>
|
</template>
|
||||||
</BasicTable>
|
</BasicTable>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent, ref } from 'vue';
|
||||||
import { BasicTable, useTable } from '/@/components/Table';
|
import { BasicTable, useTable } from '/@/components/Table';
|
||||||
import { getBasicColumns, getFormConfig } from './tableData';
|
import { getBasicColumns, getFormConfig } from './tableData';
|
||||||
|
import { Alert } from 'ant-design-vue';
|
||||||
|
|
||||||
import { demoListApi } from '/@/api/demo/table';
|
import { demoListApi } from '/@/api/demo/table';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: { BasicTable },
|
components: { BasicTable, AAlert: Alert },
|
||||||
setup() {
|
setup() {
|
||||||
|
const checkedKeys = ref<Array<string | number>>([]);
|
||||||
const [registerTable, { getForm }] = useTable({
|
const [registerTable, { getForm }] = useTable({
|
||||||
title: '开启搜索区域',
|
title: '开启搜索区域',
|
||||||
api: demoListApi,
|
api: demoListApi,
|
||||||
|
|
@ -24,16 +41,24 @@
|
||||||
useSearchForm: true,
|
useSearchForm: true,
|
||||||
formConfig: getFormConfig(),
|
formConfig: getFormConfig(),
|
||||||
showTableSetting: true,
|
showTableSetting: true,
|
||||||
rowSelection: { type: 'checkbox' },
|
showIndexColumn: false,
|
||||||
|
rowKey: 'id',
|
||||||
});
|
});
|
||||||
|
|
||||||
function getFormValues() {
|
function getFormValues() {
|
||||||
console.log(getForm().getFieldsValue());
|
console.log(getForm().getFieldsValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onSelectChange(selectedRowKeys: (string | number)[]) {
|
||||||
|
console.log(selectedRowKeys);
|
||||||
|
checkedKeys.value = selectedRowKeys;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
registerTable,
|
registerTable,
|
||||||
getFormValues,
|
getFormValues,
|
||||||
|
checkedKeys,
|
||||||
|
onSelectChange,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,13 @@ export function getBasicColumns(): BasicColumn[] {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '开始时间',
|
title: '开始时间',
|
||||||
width: 120,
|
width: 150,
|
||||||
sorter: true,
|
sorter: true,
|
||||||
dataIndex: 'beginTime',
|
dataIndex: 'beginTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '结束时间',
|
title: '结束时间',
|
||||||
width: 120,
|
width: 150,
|
||||||
sorter: true,
|
sorter: true,
|
||||||
dataIndex: 'endTime',
|
dataIndex: 'endTime',
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue