Commit 540423ecf741a815d28d7a6baa1541ac884efe95

Authored by 无木
1 parent 9cf070dd

feat(table): add `headerTop` slot

为表格添加`headerTop`插槽(表格头部的标题之上),以及相关演示

close: #881
CHANGELOG.zh_CN.md
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 - **Table** 3 - **Table**
4 - 修复滚动条样式问题 4 - 修复滚动条样式问题
5 - 修复树形表格的带有展开图标的单元格的内容对齐问题 5 - 修复树形表格的带有展开图标的单元格的内容对齐问题
  6 + - 新增`headerTop`插槽
6 - **AppSearch** 修复可能会搜索隐藏菜单的问题 7 - **AppSearch** 修复可能会搜索隐藏菜单的问题
7 - **其它** 8 - **其它**
8 - 修复菜单默认折叠的配置不起作用的问题 9 - 修复菜单默认折叠的配置不起作用的问题
src/components/Table/src/components/TableHeader.vue
1 <template> 1 <template>
2 - <slot name="tableTitle" v-if="$slots.tableTitle"></slot>  
3 -  
4 - <TableTitle :helpMessage="titleHelpMessage" :title="title" v-if="!$slots.tableTitle && title" />  
5 -  
6 - <div :class="`${prefixCls}__toolbar`">  
7 - <slot name="toolbar"></slot>  
8 - <Divider type="vertical" v-if="$slots.toolbar && showTableSetting" />  
9 - <TableSetting  
10 - :setting="tableSetting"  
11 - v-if="showTableSetting"  
12 - @columns-change="handleColumnChange"  
13 - /> 2 + <div style="width: 100%">
  3 + <div v-if="$slots.headerTop" style="margin: 5px">
  4 + <slot name="headerTop"></slot>
  5 + </div>
  6 + <div style="width: 100%; display: flex">
  7 + <slot name="tableTitle" v-if="$slots.tableTitle"></slot>
  8 + <TableTitle
  9 + :helpMessage="titleHelpMessage"
  10 + :title="title"
  11 + v-if="!$slots.tableTitle && title"
  12 + />
  13 + <div :class="`${prefixCls}__toolbar`">
  14 + <slot name="toolbar"></slot>
  15 + <Divider type="vertical" v-if="$slots.toolbar && showTableSetting" />
  16 + <TableSetting
  17 + :setting="tableSetting"
  18 + v-if="showTableSetting"
  19 + @columns-change="handleColumnChange"
  20 + />
  21 + </div>
  22 + </div>
14 </div> 23 </div>
15 </template> 24 </template>
16 <script lang="ts"> 25 <script lang="ts">
src/components/Table/src/hooks/useTableHeader.ts
@@ -41,6 +41,11 @@ export function useTableHeader( @@ -41,6 +41,11 @@ export function useTableHeader(
41 tableTitle: () => getSlot(slots, 'tableTitle'), 41 tableTitle: () => getSlot(slots, 'tableTitle'),
42 } 42 }
43 : {}), 43 : {}),
  44 + ...(slots.headerTop
  45 + ? {
  46 + headerTop: () => getSlot(slots, 'headerTop'),
  47 + }
  48 + : {}),
44 } 49 }
45 ), 50 ),
46 }; 51 };
src/views/demo/table/FormTable.vue
1 <template> 1 <template>
2 - <BasicTable @register="registerTable"> 2 + <BasicTable
  3 + @register="registerTable"
  4 + :rowSelection="{ type: 'checkbox', selectedRowKeys: checkedKeys, onChange: onSelectChange }"
  5 + >
3 <template #form-custom> custom-slot </template> 6 <template #form-custom> custom-slot </template>
4 - 7 + <template #headerTop>
  8 + <a-alert type="info" show-icon>
  9 + <template #message>
  10 + <template v-if="checkedKeys.length > 0">
  11 + <span>已选中{{ checkedKeys.length }}条记录(可跨页)</span>
  12 + <a-button type="link" @click="checkedKeys = []" size="small">清空</a-button>
  13 + </template>
  14 + <template v-else>
  15 + <span>未选中任何项目</span>
  16 + </template>
  17 + </template>
  18 + </a-alert>
  19 + </template>
5 <template #toolbar> 20 <template #toolbar>
6 <a-button type="primary" @click="getFormValues">获取表单数据</a-button> 21 <a-button type="primary" @click="getFormValues">获取表单数据</a-button>
7 </template> 22 </template>
8 </BasicTable> 23 </BasicTable>
9 </template> 24 </template>
10 <script lang="ts"> 25 <script lang="ts">
11 - import { defineComponent } from 'vue'; 26 + import { defineComponent, ref } from 'vue';
12 import { BasicTable, useTable } from '/@/components/Table'; 27 import { BasicTable, useTable } from '/@/components/Table';
13 import { getBasicColumns, getFormConfig } from './tableData'; 28 import { getBasicColumns, getFormConfig } from './tableData';
  29 + import { Alert } from 'ant-design-vue';
14 30
15 import { demoListApi } from '/@/api/demo/table'; 31 import { demoListApi } from '/@/api/demo/table';
16 32
17 export default defineComponent({ 33 export default defineComponent({
18 - components: { BasicTable }, 34 + components: { BasicTable, AAlert: Alert },
19 setup() { 35 setup() {
  36 + const checkedKeys = ref<Array<string | number>>([]);
20 const [registerTable, { getForm }] = useTable({ 37 const [registerTable, { getForm }] = useTable({
21 title: '开启搜索区域', 38 title: '开启搜索区域',
22 api: demoListApi, 39 api: demoListApi,
@@ -24,16 +41,24 @@ @@ -24,16 +41,24 @@
24 useSearchForm: true, 41 useSearchForm: true,
25 formConfig: getFormConfig(), 42 formConfig: getFormConfig(),
26 showTableSetting: true, 43 showTableSetting: true,
27 - rowSelection: { type: 'checkbox' }, 44 + showIndexColumn: false,
  45 + rowKey: 'id',
28 }); 46 });
29 47
30 function getFormValues() { 48 function getFormValues() {
31 console.log(getForm().getFieldsValue()); 49 console.log(getForm().getFieldsValue());
32 } 50 }
33 51
  52 + function onSelectChange(selectedRowKeys: (string | number)[]) {
  53 + console.log(selectedRowKeys);
  54 + checkedKeys.value = selectedRowKeys;
  55 + }
  56 +
34 return { 57 return {
35 registerTable, 58 registerTable,
36 getFormValues, 59 getFormValues,
  60 + checkedKeys,
  61 + onSelectChange,
37 }; 62 };
38 }, 63 },
39 }); 64 });
src/views/demo/table/tableData.tsx
@@ -31,13 +31,13 @@ export function getBasicColumns(): BasicColumn[] { @@ -31,13 +31,13 @@ export function getBasicColumns(): BasicColumn[] {
31 }, 31 },
32 { 32 {
33 title: '开始时间', 33 title: '开始时间',
34 - width: 120, 34 + width: 150,
35 sorter: true, 35 sorter: true,
36 dataIndex: 'beginTime', 36 dataIndex: 'beginTime',
37 }, 37 },
38 { 38 {
39 title: '结束时间', 39 title: '结束时间',
40 - width: 120, 40 + width: 150,
41 sorter: true, 41 sorter: true,
42 dataIndex: 'endTime', 42 dataIndex: 'endTime',
43 }, 43 },