Files
aiot-platform-ui/apps/web-antd/src/views/infra/config/index.vue

186 lines
4.7 KiB
Vue
Raw Normal View History

2025-04-06 21:00:29 +08:00
<script lang="ts" setup>
2025-05-20 16:45:38 +08:00
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
2025-04-06 21:00:29 +08:00
import type { InfraConfigApi } from '#/api/infra/config';
import { ref } from 'vue';
import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
2025-04-22 22:10:33 +08:00
2025-05-20 16:45:38 +08:00
import { message } from 'ant-design-vue';
2025-04-06 21:00:29 +08:00
2025-05-20 16:45:38 +08:00
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteConfig,
deleteConfigList,
exportConfig,
getConfigPage,
} from '#/api/infra/config';
2025-04-22 22:10:33 +08:00
import { $t } from '#/locales';
2025-04-06 21:00:29 +08:00
2025-04-22 22:10:33 +08:00
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
2025-04-06 21:00:29 +08:00
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 导出表格 */
2025-05-20 16:45:38 +08:00
async function handleExport() {
2025-04-06 21:00:29 +08:00
const data = await exportConfig(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '参数配置.xls', source: data });
2025-04-06 21:00:29 +08:00
}
/** 创建参数 */
2025-05-20 16:45:38 +08:00
function handleCreate() {
2025-04-06 21:00:29 +08:00
formModalApi.setData(null).open();
}
/** 编辑参数 */
2025-05-20 16:45:38 +08:00
function handleEdit(row: InfraConfigApi.Config) {
2025-04-06 21:00:29 +08:00
formModalApi.setData(row).open();
}
/** 删除参数 */
2025-05-20 16:45:38 +08:00
async function handleDelete(row: InfraConfigApi.Config) {
2025-04-06 21:00:29 +08:00
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
});
try {
await deleteConfig(row.id as number);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
2025-04-06 21:00:29 +08:00
onRefresh();
2025-05-20 16:45:38 +08:00
} finally {
2025-04-06 21:00:29 +08:00
hideLoading();
}
}
/** 批量删除参数 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
});
try {
await deleteConfigList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: InfraConfigApi.Config[];
}) {
checkedIds.value = records.map((item) => item.id!);
}
2025-04-06 21:00:29 +08:00
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
2025-04-22 22:10:33 +08:00
schema: useGridFormSchema(),
2025-04-06 21:00:29 +08:00
},
gridOptions: {
2025-05-20 16:45:38 +08:00
columns: useGridColumns(),
2025-04-06 21:00:29 +08:00
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getConfigPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
2025-04-06 21:00:29 +08:00
},
toolbarConfig: {
2025-07-19 17:15:39 +08:00
refresh: true,
2025-04-06 21:00:29 +08:00
search: true,
},
2025-04-22 22:10:33 +08:00
} as VxeTableGridOptions<InfraConfigApi.Config>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
2025-04-06 21:00:29 +08:00
});
</script>
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<Grid table-title="参数列表">
<template #toolbar-tools>
2025-05-20 16:45:38 +08:00
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['参数']),
2025-05-20 16:45:38 +08:00
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['infra:config:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['infra:config:export'],
onClick: handleExport,
},
{
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['infra:config:delete'],
onClick: handleDeleteBatch,
},
2025-05-20 16:45:38 +08:00
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['infra:config:update'],
2025-05-20 16:45:38 +08:00
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['infra:config:delete'],
2025-05-20 16:45:38 +08:00
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
2025-04-06 21:00:29 +08:00
</template>
</Grid>
</Page>
2025-04-11 18:43:25 +08:00
</template>