190 lines
5.0 KiB
Vue
190 lines
5.0 KiB
Vue
<script lang="ts" setup>
|
||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
||
|
||
import { ref } from 'vue';
|
||
|
||
import { Page, useVbenModal } from '@vben/common-ui';
|
||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||
|
||
import { message } from 'ant-design-vue';
|
||
|
||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||
import {
|
||
deleteDemo01Contact,
|
||
deleteDemo01ContactList,
|
||
exportDemo01Contact,
|
||
getDemo01ContactPage,
|
||
} from '#/api/infra/demo/demo01';
|
||
import { $t } from '#/locales';
|
||
|
||
import { useGridColumns, useGridFormSchema } from './data';
|
||
import Form from './modules/form.vue';
|
||
|
||
const [FormModal, formModalApi] = useVbenModal({
|
||
connectedComponent: Form,
|
||
destroyOnClose: true,
|
||
});
|
||
|
||
/** 刷新表格 */
|
||
function onRefresh() {
|
||
gridApi.query();
|
||
}
|
||
|
||
/** 创建示例联系人 */
|
||
function handleCreate() {
|
||
formModalApi.setData({}).open();
|
||
}
|
||
|
||
/** 编辑示例联系人 */
|
||
function handleEdit(row: Demo01ContactApi.Demo01Contact) {
|
||
formModalApi.setData(row).open();
|
||
}
|
||
|
||
/** 删除示例联系人 */
|
||
async function handleDelete(row: Demo01ContactApi.Demo01Contact) {
|
||
const hideLoading = message.loading({
|
||
content: $t('ui.actionMessage.deleting', [row.id]),
|
||
duration: 0,
|
||
key: 'action_process_msg',
|
||
});
|
||
try {
|
||
await deleteDemo01Contact(row.id as number);
|
||
message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||
onRefresh();
|
||
} finally {
|
||
hideLoading();
|
||
}
|
||
}
|
||
|
||
/** 批量删除示例联系人 */
|
||
async function handleDeleteBatch() {
|
||
const hideLoading = message.loading({
|
||
content: $t('ui.actionMessage.deleting'),
|
||
duration: 0,
|
||
key: 'action_process_msg',
|
||
});
|
||
try {
|
||
await deleteDemo01ContactList(checkedIds.value);
|
||
message.success($t('ui.actionMessage.deleteSuccess'));
|
||
onRefresh();
|
||
} finally {
|
||
hideLoading();
|
||
}
|
||
}
|
||
|
||
// TODO @puhui999:方法名,改成 handleRowCheckboxChange;注释:处理选中表格行
|
||
// TODO @puhui999:deleteIds => checkedIds;然后注释去掉?
|
||
const checkedIds = ref<number[]>([]); // 待删除示例联系人 ID
|
||
function setCheckedIds({
|
||
records,
|
||
}: {
|
||
records: Demo01ContactApi.Demo01Contact[];
|
||
}) {
|
||
checkedIds.value = records.map((item) => item.id);
|
||
}
|
||
|
||
/** 导出表格 */
|
||
async function handleExport() {
|
||
const data = await exportDemo01Contact(await gridApi.formApi.getValues());
|
||
downloadFileFromBlobPart({ fileName: '示例联系人.xls', source: data });
|
||
}
|
||
|
||
const [Grid, gridApi] = useVbenVxeGrid({
|
||
formOptions: {
|
||
schema: useGridFormSchema(),
|
||
},
|
||
gridOptions: {
|
||
columns: useGridColumns(),
|
||
height: 'auto',
|
||
pagerConfig: {
|
||
enabled: true,
|
||
},
|
||
proxyConfig: {
|
||
ajax: {
|
||
query: async ({ page }, formValues) => {
|
||
return await getDemo01ContactPage({
|
||
pageNo: page.currentPage,
|
||
pageSize: page.pageSize,
|
||
...formValues,
|
||
});
|
||
},
|
||
},
|
||
},
|
||
rowConfig: {
|
||
keyField: 'id',
|
||
isHover: true,
|
||
},
|
||
toolbarConfig: {
|
||
refresh: { code: 'query' },
|
||
search: true,
|
||
},
|
||
} as VxeTableGridOptions<Demo01ContactApi.Demo01Contact>,
|
||
gridEvents: {
|
||
checkboxAll: setCheckedIds,
|
||
checkboxChange: setCheckedIds,
|
||
},
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<Page auto-content-height>
|
||
<FormModal @success="onRefresh" />
|
||
|
||
<Grid table-title="示例联系人列表">
|
||
<template #toolbar-tools>
|
||
<TableAction
|
||
:actions="[
|
||
{
|
||
label: $t('ui.actionTitle.create', ['示例联系人']),
|
||
type: 'primary',
|
||
icon: ACTION_ICON.ADD,
|
||
auth: ['infra:demo01-contact:create'],
|
||
onClick: handleCreate,
|
||
},
|
||
{
|
||
label: $t('ui.actionTitle.export'),
|
||
type: 'primary',
|
||
icon: ACTION_ICON.DOWNLOAD,
|
||
auth: ['infra:demo01-contact:export'],
|
||
onClick: handleExport,
|
||
},
|
||
{
|
||
label: '批量删除',
|
||
type: 'primary',
|
||
danger: true,
|
||
icon: ACTION_ICON.DELETE,
|
||
auth: ['infra:demo01-contact:delete'],
|
||
onClick: handleDeleteBatch,
|
||
},
|
||
]"
|
||
/>
|
||
</template>
|
||
<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>
|
||
</Grid>
|
||
</Page>
|
||
</template>
|