FormTable.vue
2.52 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template>
<BasicTable @register="registerTable">
<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>
<a-button type="primary" @click="getFormValues">获取表单数据</a-button>
</template>
</BasicTable>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import { BasicTable, useTable } from '/@/components/Table';
import { getBasicColumns, getFormConfig } from './tableData';
import { Alert } from 'ant-design-vue';
import { demoListApi } from '/@/api/demo/table';
export default defineComponent({
components: { BasicTable, AAlert: Alert },
setup() {
const checkedKeys = ref<Array<string | number>>([]);
const [registerTable, { getForm }] = useTable({
title: '开启搜索区域',
api: demoListApi,
columns: getBasicColumns(),
useSearchForm: true,
formConfig: getFormConfig(),
showTableSetting: true,
tableSetting: { fullScreen: true },
showIndexColumn: false,
rowKey: 'id',
rowSelection: {
type: 'checkbox',
selectedRowKeys: checkedKeys,
onSelect: onSelect,
onSelectAll: onSelectAll,
},
});
function getFormValues() {
console.log(getForm().getFieldsValue());
}
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);
});
}
}
return {
registerTable,
getFormValues,
checkedKeys,
onSelect,
onSelectAll,
};
},
});
</script>