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

139 lines
3.2 KiB
Vue
Raw Normal View History

2025-04-06 21:00:29 +08:00
<script lang="ts" setup>
2025-04-22 22:10:33 +08:00
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
2025-04-06 21:00:29 +08:00
import type { InfraConfigApi } from '#/api/infra/config';
import { Page, useVbenModal } from '@vben/common-ui';
2025-04-22 22:10:33 +08:00
import { Download, Plus } from '@vben/icons';
2025-04-06 21:00:29 +08:00
import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
2025-04-22 22:10:33 +08:00
import { deleteConfig, exportConfig, getConfigPage } from '#/api/infra/config';
import { $t } from '#/locales';
2025-04-06 21:00:29 +08:00
import { downloadByData } from '#/utils/download';
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();
}
/** 导出表格 */
async function onExport() {
const data = await exportConfig(await gridApi.formApi.getValues());
downloadByData(data, '参数配置.xls');
}
/** 创建参数 */
function onCreate() {
formModalApi.setData(null).open();
}
/** 编辑参数 */
2025-04-22 22:10:33 +08:00
function onEdit(row: InfraConfigApi.Config) {
2025-04-06 21:00:29 +08:00
formModalApi.setData(row).open();
}
/** 删除参数 */
2025-04-22 22:10:33 +08:00
async function onDelete(row: InfraConfigApi.Config) {
2025-04-06 21:00:29 +08:00
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteConfig(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_process_msg',
});
onRefresh();
2025-04-22 22:10:33 +08:00
} catch {
2025-04-06 21:00:29 +08:00
hideLoading();
}
}
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
2025-04-22 22:10:33 +08:00
}: OnActionClickParams<InfraConfigApi.Config>) {
2025-04-06 21:00:29 +08:00
switch (code) {
case 'delete': {
onDelete(row);
break;
}
2025-04-22 22:10:33 +08:00
case 'edit': {
onEdit(row);
break;
}
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: {
columns: useGridColumns(onActionClick),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getConfigPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
2025-04-22 22:10:33 +08:00
} as VxeTableGridOptions<InfraConfigApi.Config>,
2025-04-06 21:00:29 +08:00
});
</script>
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<Grid table-title="参数列表">
<template #toolbar-tools>
2025-04-22 22:10:33 +08:00
<Button
type="primary"
@click="onCreate"
v-access:code="['infra:config:create']"
>
2025-04-06 21:00:29 +08:00
<Plus class="size-5" />
{{ $t('ui.actionTitle.create', ['参数']) }}
</Button>
2025-04-22 22:10:33 +08:00
<Button
type="primary"
class="ml-2"
@click="onExport"
v-access:code="['infra:config:export']"
>
2025-04-06 21:00:29 +08:00
<Download class="size-5" />
{{ $t('ui.actionTitle.export') }}
</Button>
</template>
</Grid>
</Page>
2025-04-11 18:43:25 +08:00
</template>