|
1
|
<template>
|
|
2
|
<BasicTable @register="registerTable">
|
vben
authored
|
3
|
<template #form-custom> custom-slot </template>
|
|
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<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>
|
Vben
authored
|
17
18
19
|
<template #toolbar>
<a-button type="primary" @click="getFormValues">获取表单数据</a-button>
</template>
|
vben
authored
|
20
|
</BasicTable>
|
|
21
22
|
</template>
<script lang="ts">
|
|
23
|
import { defineComponent, ref } from 'vue';
|
|
24
25
|
import { BasicTable, useTable } from '/@/components/Table';
import { getBasicColumns, getFormConfig } from './tableData';
|
|
26
|
import { Alert } from 'ant-design-vue';
|
|
27
28
29
30
|
import { demoListApi } from '/@/api/demo/table';
export default defineComponent({
|
|
31
|
components: { BasicTable, AAlert: Alert },
|
|
32
|
setup() {
|
|
33
|
const checkedKeys = ref<Array<string | number>>([]);
|
Vben
authored
|
34
|
const [registerTable, { getForm }] = useTable({
|
|
35
36
37
38
39
|
title: '开启搜索区域',
api: demoListApi,
columns: getBasicColumns(),
useSearchForm: true,
formConfig: getFormConfig(),
|
vben
authored
|
40
|
showTableSetting: true,
|
|
41
|
tableSetting: { fullScreen: true },
|
|
42
43
|
showIndexColumn: false,
rowKey: 'id',
|
|
44
45
46
|
rowSelection: {
type: 'checkbox',
selectedRowKeys: checkedKeys,
|
luojz
authored
|
47
48
|
onSelect: onSelect,
onSelectAll: onSelectAll,
|
|
49
|
},
|
|
50
51
|
});
|
Vben
authored
|
52
53
54
55
|
function getFormValues() {
console.log(getForm().getFieldsValue());
}
|
luojz
authored
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
function onSelect(record, selected) {
if (selected) {
checkedKeys.value = [...checkedKeys.value, record.id];
} else {
checkedKeys.value = checkedKeys.value.filter((id) => id !== record.id);
}
}
function onSelectAll(selected, selectedRows, changeRows) {
const changeIds = changeRows.map((item) => item.id);
if (selected) {
checkedKeys.value = [...checkedKeys.value, ...changeIds];
} else {
checkedKeys.value = checkedKeys.value.filter((id) => {
return !changeIds.includes(id);
});
}
|
|
72
73
|
}
|
|
74
75
|
return {
registerTable,
|
Vben
authored
|
76
|
getFormValues,
|
|
77
|
checkedKeys,
|
luojz
authored
|
78
79
|
onSelect,
onSelectAll,
|
|
80
81
82
83
|
};
},
});
</script>
|