perf: use table action

pull/110/MERGE
xingyu4j 2025-05-19 16:19:53 +08:00
parent bc8b79a38a
commit 0a9b2ba383
2 changed files with 34 additions and 36 deletions

View File

@ -312,7 +312,7 @@ export function useGridColumns<T = SystemUserApi.User>(
}, },
{ {
title: '操作', title: '操作',
width: 160, width: 180,
fixed: 'right', fixed: 'right',
slots: { default: 'actions' }, slots: { default: 'actions' },
}, },

View File

@ -6,10 +6,9 @@ import type { SystemUserApi } from '#/api/system/user';
import { ref } from 'vue'; import { ref } from 'vue';
import { confirm, Page, useVbenModal } from '@vben/common-ui'; import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { Download, Plus, Upload } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils'; import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
@ -19,7 +18,7 @@ import {
updateUserStatus, updateUserStatus,
} from '#/api/system/user'; } from '#/api/system/user';
import { DocAlert } from '#/components/doc-alert'; import { DocAlert } from '#/components/doc-alert';
import { ACTION_KEY, TableAction } from '#/components/table-action'; import { ACTION_ICON, TableAction } from '#/components/table-action';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { DICT_TYPE, getDictLabel } from '#/utils'; import { DICT_TYPE, getDictLabel } from '#/utils';
@ -87,12 +86,12 @@ function onEdit(row: SystemUserApi.User) {
async function onDelete(row: SystemUserApi.User) { async function onDelete(row: SystemUserApi.User) {
message.loading({ message.loading({
content: $t('ui.actionMessage.deleting', [row.username]), content: $t('ui.actionMessage.deleting', [row.username]),
key: ACTION_KEY, key: 'action_key_msg',
}); });
await deleteUser(row.id as number); await deleteUser(row.id as number);
message.success({ message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.username]), content: $t('ui.actionMessage.deleteSuccess', [row.username]),
key: ACTION_KEY, key: 'action_key_msg',
}); });
onRefresh(); onRefresh();
} }
@ -189,32 +188,31 @@ const [Grid, gridApi] = useVbenVxeGrid({
<div class="w-5/6"> <div class="w-5/6">
<Grid table-title=""> <Grid table-title="">
<template #toolbar-tools> <template #toolbar-tools>
<Button <TableAction
type="primary" :actions="[
@click="onCreate" {
v-access:code="['system:user:create']" label: $t('ui.actionTitle.create', ['用户']),
> type: 'primary',
<Plus class="size-5" /> icon: ACTION_ICON.ADD,
{{ $t('ui.actionTitle.create', ['用户']) }} auth: ['system:user:create'],
</Button> onClick: onCreate,
<Button },
type="primary" {
class="ml-2" label: $t('ui.actionTitle.export'),
@click="onExport" type: 'primary',
v-access:code="['system:user:export']" icon: ACTION_ICON.DOWNLOAD,
> auth: ['system:user:export'],
<Download class="size-5" /> onClick: onExport,
{{ $t('ui.actionTitle.export') }} },
</Button> {
<Button label: $t('ui.actionTitle.import', ['用户']),
type="primary" type: 'primary',
class="ml-2" icon: ACTION_ICON.UPLOAD,
@click="onImport" auth: ['system:user:import'],
v-access:code="['system:user:import']" onClick: onImport,
> },
<Upload class="size-5" /> ]"
{{ $t('ui.actionTitle.import', ['用户']) }} />
</Button>
</template> </template>
<template #actions="{ row }"> <template #actions="{ row }">
<TableAction <TableAction
@ -222,7 +220,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
{ {
label: $t('common.edit'), label: $t('common.edit'),
type: 'link', type: 'link',
icon: 'ant-design:edit-outlined', icon: ACTION_ICON.EDIT,
auth: ['system:user:update'], auth: ['system:user:update'],
onClick: onEdit.bind(null, row), onClick: onEdit.bind(null, row),
}, },
@ -230,7 +228,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
label: $t('common.delete'), label: $t('common.delete'),
type: 'link', type: 'link',
danger: true, danger: true,
icon: 'ant-design:delete-outlined', icon: ACTION_ICON.DELETE,
auth: ['system:user:delete'], auth: ['system:user:delete'],
popConfirm: { popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]), title: $t('ui.actionMessage.deleteConfirm', [row.name]),
@ -240,13 +238,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
]" ]"
:drop-down-actions="[ :drop-down-actions="[
{ {
label: '数据权限', label: '分配角色',
type: 'link', type: 'link',
auth: ['system:permission:assign-user-role'], auth: ['system:permission:assign-user-role'],
onClick: onAssignRole.bind(null, row), onClick: onAssignRole.bind(null, row),
}, },
{ {
label: '菜单权限', label: '重置密码',
type: 'link', type: 'link',
auth: ['system:user:update-password'], auth: ['system:user:update-password'],
onClick: onResetPassword.bind(null, row), onClick: onResetPassword.bind(null, row),