Files
iot-device-management-frontend/apps/web-antd/src/views/system/post/index.vue

116 lines
2.6 KiB
Vue
Raw Normal View History

2025-03-24 21:17:25 +08:00
<script lang="ts" setup>
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { Page, useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
2025-03-24 21:17:25 +08:00
import { Button, message } from 'ant-design-vue';
2025-03-24 21:17:25 +08:00
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { exportPost, getPostPage, type PostVO } from '#/api/system/post';
import { columns, formSchema } from './post.data';
import PostModal from './PostModal.vue';
2025-03-24 21:17:25 +08:00
2025-03-26 19:31:54 +08:00
defineOptions({ name: 'SystemPost' });
2025-03-24 21:17:25 +08:00
const formOptions: VbenFormProps = {
// 默认展开
collapsed: false,
schema: formSchema,
2025-03-24 21:17:25 +08:00
// 控制表单是否显示折叠按钮
showCollapseButton: true,
// 按下回车时是否提交表单
submitOnEnter: false,
};
const gridOptions: VxeGridProps<PostVO> = {
checkboxConfig: {
highlight: true,
labelField: 'id',
2025-03-24 21:17:25 +08:00
},
columns,
2025-03-24 21:17:25 +08:00
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getPostPage({
page: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
};
const [Grid, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: PostModal,
});
function handleCreate() {
formModalApi.setData({
valuse: {},
});
formModalApi.open();
}
async function handleEdit(id: number) {
formModalApi.setData({ id });
formModalApi.open();
}
// TODO
function handleDelete(id: number) {
message.success(id);
}
// TODO
async function handleExport() {
await exportPost(tableApi.formApi.form.values);
}
2025-03-24 21:17:25 +08:00
</script>
<template>
<Page auto-content-height>
<Grid>
<template #toolbar-actions>
<Button
type="primary"
v-access:code="['system:post:create']"
@click="handleCreate"
>
{{ $t('page.action.add') }}
</Button>
<Button
class="ml-4"
v-access:code="['system:post:export']"
@click="handleExport"
>
{{ $t('page.action.export') }}
</Button>
</template>
<template #action="{ row }">
<Button
type="link"
v-access:code="['system:post:update']"
@click="handleEdit(row.id)"
>
{{ $t('page.action.edit') }}
</Button>
<Button
danger
type="link"
v-access:code="['system:post:delete']"
@click="handleDelete(row.id)"
>
{{ $t('page.action.delete') }}
</Button>
2025-03-24 21:17:25 +08:00
</template>
</Grid>
<FormModal />
2025-03-24 21:17:25 +08:00
</Page>
</template>