fix: bug
This commit is contained in:
@@ -164,6 +164,8 @@
|
||||
actions?: ((row: any) => TableAction[]) | null
|
||||
/** 操作列宽度 */
|
||||
actionsWidth?: number
|
||||
/** 直接显示的操作按钮数量,默认2个 */
|
||||
inlineActionsCount?: number
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<TableProps>(), {
|
||||
@@ -192,7 +194,8 @@
|
||||
treeProps: undefined,
|
||||
defaultExpandAll: false,
|
||||
actions: null,
|
||||
actionsWidth: 140
|
||||
actionsWidth: 140,
|
||||
inlineActionsCount: 2
|
||||
})
|
||||
|
||||
/*
|
||||
@@ -371,8 +374,8 @@
|
||||
)
|
||||
}
|
||||
|
||||
// 如果操作数量 <= 3,直接显示所有按钮
|
||||
if (actionList.length <= 3) {
|
||||
// 如果操作数量 <= inlineActionsCount,直接显示所有按钮
|
||||
if (actionList.length <= props.inlineActionsCount) {
|
||||
return h(
|
||||
'div',
|
||||
{ style: 'display: flex; gap: 8px;' },
|
||||
@@ -390,19 +393,21 @@
|
||||
)
|
||||
}
|
||||
|
||||
// 如果操作数量 > 3,显示第一个 + 更多下拉菜单
|
||||
const firstAction = actionList[0]
|
||||
const moreActions = actionList.slice(1)
|
||||
// 如果操作数量 > inlineActionsCount,显示前 inlineActionsCount 个 + 更多下拉菜单
|
||||
const inlineActions = actionList.slice(0, props.inlineActionsCount)
|
||||
const moreActions = actionList.slice(props.inlineActionsCount)
|
||||
|
||||
return h('div', { style: 'display: flex; gap: 12px; align-items: center;' }, [
|
||||
h(
|
||||
ElButton,
|
||||
{
|
||||
type: firstAction.type === 'danger' ? 'danger' : 'primary',
|
||||
link: true,
|
||||
onClick: () => firstAction.handler(row)
|
||||
},
|
||||
() => firstAction.label
|
||||
...inlineActions.map((action) =>
|
||||
h(
|
||||
ElButton,
|
||||
{
|
||||
type: action.type === 'danger' ? 'danger' : 'primary',
|
||||
link: true,
|
||||
onClick: () => action.handler(row)
|
||||
},
|
||||
() => action.label
|
||||
)
|
||||
),
|
||||
h(
|
||||
ElDropdown,
|
||||
|
||||
@@ -35,7 +35,8 @@
|
||||
:total="pagination.total"
|
||||
:marginTop="10"
|
||||
:actions="getActions"
|
||||
:actionsWidth="250"
|
||||
:actionsWidth="230"
|
||||
:inlineActionsCount="2"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user