fix: actions
parent
09f26320f7
commit
70247fd5f1
|
@ -1,19 +1,15 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type {
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
OnActionClickParams,
|
|
||||||
VxeTableGridOptions,
|
|
||||||
} from '#/adapter/vxe-table';
|
|
||||||
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
||||||
|
|
||||||
import { h, ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Download, Plus, Trash2 } from '@vben/icons';
|
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
|
||||||
|
|
||||||
import { Button, message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
deleteDemo01Contact,
|
deleteDemo01Contact,
|
||||||
deleteDemo01ContactListByIds,
|
deleteDemo01ContactListByIds,
|
||||||
|
@ -36,17 +32,17 @@ function onRefresh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建示例联系人 */
|
/** 创建示例联系人 */
|
||||||
function onCreate() {
|
function handleCreate() {
|
||||||
formModalApi.setData({}).open();
|
formModalApi.setData({}).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 编辑示例联系人 */
|
/** 编辑示例联系人 */
|
||||||
function onEdit(row: Demo01ContactApi.Demo01Contact) {
|
function handleEdit(row: Demo01ContactApi.Demo01Contact) {
|
||||||
formModalApi.setData(row).open();
|
formModalApi.setData(row).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除示例联系人 */
|
/** 删除示例联系人 */
|
||||||
async function onDelete(row: Demo01ContactApi.Demo01Contact) {
|
async function handleDelete(row: Demo01ContactApi.Demo01Contact) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
|
@ -62,14 +58,14 @@ async function onDelete(row: Demo01ContactApi.Demo01Contact) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 批量删除示例联系人 */
|
/** 批量删除示例联系人 */
|
||||||
async function onDeleteBatch() {
|
async function handleDeleteBatch() {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting'),
|
content: $t('ui.actionMessage.deleting'),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
key: 'action_process_msg',
|
key: 'action_process_msg',
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteDemo01ContactListByIds(deleteIds.value);
|
await deleteDemo01ContactListByIds(checkedIds.value);
|
||||||
message.success($t('ui.actionMessage.deleteSuccess'));
|
message.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -79,44 +75,27 @@ async function onDeleteBatch() {
|
||||||
|
|
||||||
// TODO @puhui999:方法名,改成 handleRowCheckboxChange;注释:处理选中表格行
|
// TODO @puhui999:方法名,改成 handleRowCheckboxChange;注释:处理选中表格行
|
||||||
// TODO @puhui999:deleteIds => checkedIds;然后注释去掉?
|
// TODO @puhui999:deleteIds => checkedIds;然后注释去掉?
|
||||||
const deleteIds = ref<number[]>([]); // 待删除示例联系人 ID
|
const checkedIds = ref<number[]>([]); // 待删除示例联系人 ID
|
||||||
function setDeleteIds({
|
function setCheckedIds({
|
||||||
records,
|
records,
|
||||||
}: {
|
}: {
|
||||||
records: Demo01ContactApi.Demo01Contact[];
|
records: Demo01ContactApi.Demo01Contact[];
|
||||||
}) {
|
}) {
|
||||||
deleteIds.value = records.map((item) => item.id);
|
checkedIds.value = records.map((item) => item.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 导出表格 */
|
/** 导出表格 */
|
||||||
async function onExport() {
|
async function handleExport() {
|
||||||
const data = await exportDemo01Contact(await gridApi.formApi.getValues());
|
const data = await exportDemo01Contact(await gridApi.formApi.getValues());
|
||||||
downloadFileFromBlobPart({ fileName: '示例联系人.xls', source: data });
|
downloadFileFromBlobPart({ fileName: '示例联系人.xls', source: data });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 表格操作按钮的回调函数 */
|
|
||||||
function onActionClick({
|
|
||||||
code,
|
|
||||||
row,
|
|
||||||
}: OnActionClickParams<Demo01ContactApi.Demo01Contact>) {
|
|
||||||
switch (code) {
|
|
||||||
case 'delete': {
|
|
||||||
onDelete(row);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'edit': {
|
|
||||||
onEdit(row);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
},
|
},
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: useGridColumns(onActionClick),
|
columns: useGridColumns(),
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
pagerConfig: {
|
pagerConfig: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -142,8 +121,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<Demo01ContactApi.Demo01Contact>,
|
} as VxeTableGridOptions<Demo01ContactApi.Demo01Contact>,
|
||||||
gridEvents: {
|
gridEvents: {
|
||||||
checkboxAll: setDeleteIds,
|
checkboxAll: setCheckedIds,
|
||||||
checkboxChange: setDeleteIds,
|
checkboxChange: setCheckedIds,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -154,34 +133,56 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
|
||||||
<Grid table-title="示例联系人列表">
|
<Grid table-title="示例联系人列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<Button
|
<TableAction
|
||||||
:icon="h(Plus)"
|
:actions="[
|
||||||
type="primary"
|
{
|
||||||
@click="onCreate"
|
label: $t('ui.actionTitle.create', ['示例联系人']),
|
||||||
v-access:code="['infra:demo01-contact:create']"
|
type: 'primary',
|
||||||
>
|
icon: ACTION_ICON.ADD,
|
||||||
{{ $t('ui.actionTitle.create', ['示例联系人']) }}
|
auth: ['infra:demo01-contact:create'],
|
||||||
</Button>
|
onClick: handleCreate,
|
||||||
<Button
|
},
|
||||||
:icon="h(Download)"
|
{
|
||||||
type="primary"
|
label: $t('ui.actionTitle.export'),
|
||||||
class="ml-2"
|
type: 'primary',
|
||||||
@click="onExport"
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
v-access:code="['infra:demo01-contact:export']"
|
auth: ['infra:demo01-contact:export'],
|
||||||
>
|
onClick: handleExport,
|
||||||
{{ $t('ui.actionTitle.export') }}
|
},
|
||||||
</Button>
|
{
|
||||||
<Button
|
label: '批量删除',
|
||||||
:icon="h(Trash2)"
|
type: 'primary',
|
||||||
type="primary"
|
danger: true,
|
||||||
danger
|
icon: ACTION_ICON.DELETE,
|
||||||
class="ml-2"
|
auth: ['infra:demo01-contact:delete'],
|
||||||
:disabled="isEmpty(deleteIds)"
|
onClick: handleDeleteBatch,
|
||||||
@click="onDeleteBatch"
|
},
|
||||||
v-access:code="['infra:demo01-contact:delete']"
|
]"
|
||||||
>
|
/>
|
||||||
批量删除
|
</template>
|
||||||
</Button>
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'link',
|
||||||
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['infra:demo01-contact:update'],
|
||||||
|
onClick: handleEdit.bind(null, row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.delete'),
|
||||||
|
type: 'link',
|
||||||
|
danger: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['infra:demo01-contact:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
Loading…
Reference in New Issue