Compare commits

...

2 Commits

Author SHA1 Message Date
roymondchen
0dd7f54ebc feat(form): table支持配置操作按钮的icon 2025-12-02 15:25:34 +08:00
roymondchen
69ac90fe22 feat(form): table支持配置拖动操作中的按钮排序而不是拖动整行 2025-12-01 21:09:11 +08:00
6 changed files with 30 additions and 9 deletions

View File

@ -721,6 +721,10 @@ export interface TableConfig extends FormItem {
defaultSort?: SortProp;
/** 是否支持拖拽排序 */
dropSort?: boolean;
dropSortHandle?: boolean;
dropActionButtonIcon?: any;
copyActionButtonIcon?: any;
deleteActionButtonIcon?: any;
/** 是否显示全屏按钮 */
enableFullscreen?: boolean;
fixed?: boolean | 'left' | 'right';

View File

@ -1,12 +1,21 @@
<template>
<slot name="operateCol" :scope="{ $index: index, row: row }"></slot>
<TMagicTooltip v-if="config.dropSort && config.dropSortHandle" content="拖动排序" placement="left-start">
<TMagicButton
size="small"
link
:class="{ 'tmagic-form-table-drag-target': config.dropSortHandle }"
:icon="config.dropActionButtonIcon || Sort"
>
</TMagicButton>
</TMagicTooltip>
<TMagicButton
v-show="showDelete(index + 1 + currentPage * pageSize - 1)"
size="small"
type="danger"
link
title="删除"
:icon="Delete"
:icon="config.deleteActionButtonIcon || Delete"
@click="removeHandler(index + 1 + currentPage * pageSize - 1)"
></TMagicButton>
@ -16,7 +25,7 @@
size="small"
type="primary"
title="复制"
:icon="DocumentCopy"
:icon="config.copyActionButtonIcon || DocumentCopy"
:disabled="disabled"
@click="copyHandler(index + 1 + currentPage * pageSize - 1)"
></TMagicButton>
@ -24,10 +33,10 @@
<script setup lang="ts">
import { inject } from 'vue';
import { Delete, DocumentCopy } from '@element-plus/icons-vue';
import { Delete, DocumentCopy, Sort } from '@element-plus/icons-vue';
import { cloneDeep } from 'lodash-es';
import { TMagicButton } from '@tmagic/design';
import { TMagicButton, TMagicTooltip } from '@tmagic/design';
import type { FormState, TableConfig } from '../schema';

View File

@ -8,7 +8,11 @@
>
<div class="m-fields-table" :class="{ 'm-fields-table-item-extra': config.itemExtra }">
<span v-if="config.extra" style="color: rgba(0, 0, 0, 0.45)" v-html="config.extra"></span>
<TMagicTooltip content="拖拽可排序" placement="left-start" :disabled="config.dropSort !== true">
<TMagicTooltip
content="拖拽可排序"
placement="left-start"
:disabled="config.dropSort !== true || config.dropSortHandle"
>
<TMagicTable
v-if="model[modelName]"
ref="tMagicTable"

View File

@ -30,6 +30,7 @@ export const useSortable = (
filter: 'input', // 表单组件选字操作和触发拖拽会冲突,优先保证选字操作
preventOnFilter: false, // 允许选字
direction: 'vertical',
handle: props.config.dropSortHandle ? '.tmagic-form-table-drag-target' : undefined,
onEnd: ({ newIndex, oldIndex }: SortableEvent) => {
if (typeof newIndex === 'undefined') return;
if (typeof oldIndex === 'undefined') return;
@ -38,10 +39,9 @@ export const useSortable = (
emit('change', newData);
mForm?.$emit('field-change', newData);
sortable?.destroy();
sortable = undefined;
nextTick(() => {
sortable?.destroy();
sortable = undefined;
updateKey.value += 1;
});
},

View File

@ -111,7 +111,7 @@ export const useTableColumns = (
props: {
label: '操作',
fixed: actionFixed,
width: props.config.operateColWidth || 112,
width: props.config.operateColWidth ?? (props.config.dropSortHandle && props.config.dropSort ? 132 : 112),
align: 'center',
},
cell: ({ row, $index }: any) =>

View File

@ -65,4 +65,8 @@
.el-form-item {
margin-bottom: 0;
}
.tmagic-form-table-drag-target {
cursor: move;
}
}