Commit 808012b544b8c6f3cf467f42653c2783dbe8be6b
1 parent
40e3cb04
feat(table-action): add stopButtonPropagation prop
为TableAction组件添加stopButtonPropagation来配置是否要阻止操作列的按钮的点击事件冒泡。 close #699
Showing
2 changed files
with
56 additions
and
8 deletions
src/components/Table/src/components/TableAction.vue
1 | 1 | <template> |
2 | - <div :class="[prefixCls, getAlign]"> | |
2 | + <div :class="[prefixCls, getAlign]" @click="onCellClick"> | |
3 | 3 | <template v-for="(action, index) in getActions" :key="`${index}-${action.label}`"> |
4 | 4 | <PopConfirmButton v-bind="action"> |
5 | 5 | <Icon :icon="action.icon" class="mr-1" v-if="action.icon" /> |
... | ... | @@ -56,6 +56,7 @@ |
56 | 56 | }, |
57 | 57 | divider: propTypes.bool.def(true), |
58 | 58 | outside: propTypes.bool, |
59 | + stopButtonPropagation: propTypes.bool.def(false), | |
59 | 60 | }, |
60 | 61 | setup(props) { |
61 | 62 | const { prefixCls } = useDesign('basic-table-action'); |
... | ... | @@ -122,7 +123,15 @@ |
122 | 123 | return actionColumn?.align ?? 'left'; |
123 | 124 | }); |
124 | 125 | |
125 | - return { prefixCls, getActions, getDropdownList, getAlign }; | |
126 | + function onCellClick(e: MouseEvent) { | |
127 | + if (!props.stopButtonPropagation) return; | |
128 | + const target = e.target as HTMLElement; | |
129 | + if (target.tagName === 'BUTTON') { | |
130 | + e.stopPropagation(); | |
131 | + } | |
132 | + } | |
133 | + | |
134 | + return { prefixCls, getActions, getDropdownList, getAlign, onCellClick }; | |
126 | 135 | }, |
127 | 136 | }); |
128 | 137 | </script> | ... | ... |
src/views/demo/table/ExpandTable.vue
1 | 1 | <template> |
2 | - <div class="p-4"> | |
2 | + <PageWrapper | |
3 | + title="可展开表格" | |
4 | + content="不可与scroll共用。TableAction组件可配置stopButtonPropagation来阻止操作按钮的点击事件冒泡,以便配合Table组件的expandRowByClick" | |
5 | + > | |
3 | 6 | <BasicTable @register="registerTable"> |
4 | 7 | <template #expandedRowRender="{ record }"> |
5 | 8 | <span>No: {{ record.no }} </span> |
6 | 9 | </template> |
10 | + <template #action="{ record }"> | |
11 | + <TableAction | |
12 | + stopButtonPropagation | |
13 | + :actions="[ | |
14 | + { | |
15 | + label: '删除', | |
16 | + icon: 'ic:outline-delete-outline', | |
17 | + onClick: handleDelete.bind(null, record), | |
18 | + }, | |
19 | + ]" | |
20 | + :dropDownActions="[ | |
21 | + { | |
22 | + label: '启用', | |
23 | + popConfirm: { | |
24 | + title: '是否启用?', | |
25 | + confirm: handleOpen.bind(null, record), | |
26 | + }, | |
27 | + }, | |
28 | + ]" | |
29 | + /> | |
30 | + </template> | |
7 | 31 | </BasicTable> |
8 | - </div> | |
32 | + </PageWrapper> | |
9 | 33 | </template> |
10 | 34 | <script lang="ts"> |
11 | 35 | import { defineComponent } from 'vue'; |
12 | - import { BasicTable, useTable } from '/@/components/Table'; | |
36 | + import { BasicTable, useTable, TableAction } from '/@/components/Table'; | |
37 | + import { PageWrapper } from '/@/components/Page'; | |
13 | 38 | import { getBasicColumns } from './tableData'; |
14 | 39 | |
15 | 40 | import { demoListApi } from '/@/api/demo/table'; |
16 | 41 | |
17 | 42 | export default defineComponent({ |
18 | - components: { BasicTable }, | |
43 | + components: { BasicTable, TableAction, PageWrapper }, | |
19 | 44 | setup() { |
20 | 45 | const [registerTable] = useTable({ |
21 | - title: '可展开表格', | |
22 | 46 | api: demoListApi, |
23 | - titleHelpMessage: '不能与scroll共用', | |
47 | + title: '可展开表格演示', | |
48 | + titleHelpMessage: ['已启用expandRowByClick', '已启用stopButtonPropagation'], | |
24 | 49 | columns: getBasicColumns(), |
25 | 50 | rowKey: 'id', |
26 | 51 | canResize: false, |
52 | + expandRowByClick: true, | |
53 | + actionColumn: { | |
54 | + width: 160, | |
55 | + title: 'Action', | |
56 | + slots: { customRender: 'action' }, | |
57 | + }, | |
27 | 58 | }); |
59 | + function handleDelete(record: Recordable) { | |
60 | + console.log('点击了删除', record); | |
61 | + } | |
62 | + function handleOpen(record: Recordable) { | |
63 | + console.log('点击了启用', record); | |
64 | + } | |
28 | 65 | |
29 | 66 | return { |
30 | 67 | registerTable, |
68 | + handleDelete, | |
69 | + handleOpen, | |
31 | 70 | }; |
32 | 71 | }, |
33 | 72 | }); | ... | ... |