feat: use action buttons

pull/49/MERGE
xingyu4j 2024-11-26 17:21:54 +08:00
parent 0dcfa13d3b
commit b1553923fd
3 changed files with 62 additions and 37 deletions

View File

@ -2,6 +2,7 @@
import { ref } from 'vue'; import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { useVbenForm } from '#/adapter/form'; import { useVbenForm } from '#/adapter/form';
import { createPost, getPost, updatePost } from '#/api/system/post'; import { createPost, getPost, updatePost } from '#/api/system/post';
@ -29,14 +30,15 @@ const [Modal, modalApi] = useVbenModal({
async onOpenChange(isOpen: boolean) { async onOpenChange(isOpen: boolean) {
if (isOpen) { if (isOpen) {
const { id } = modalApi.getData<Record<string, any>>(); const { id } = modalApi.getData<Record<string, any>>();
isUpdate.value = !!id;
isUpdate.value = !isEmpty(id);
if (id) { if (id) {
const values = await getPost(id); const values = await getPost(id);
formApi.setValues(values); formApi.setValues(values);
} }
modalApi.setState({ title: isUpdate.value ? '编辑岗位' : '新增岗位' });
} }
}, },
title: isUpdate.value ? '新增岗位' : '编辑岗位',
}); });
async function onSubmit(values: Record<string, any>) { async function onSubmit(values: Record<string, any>) {
@ -48,7 +50,7 @@ async function onSubmit(values: Record<string, any>) {
} }
</script> </script>
<template> <template>
<Modal class="w-1/2"> <Modal class="w-1/3">
<Form /> <Form />
</Modal> </Modal>
</template> </template>

View File

@ -5,10 +5,11 @@ import type { VxeGridProps } from '#/adapter/vxe-table';
import { Page, useVbenModal } from '@vben/common-ui'; import { Page, useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { Button, message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { exportPost, getPostPage, type PostVO } from '#/api/system/post'; import { exportPost, getPostPage, type PostVO } from '#/api/system/post';
import { ActionButtons, IconEnum } from '#/components/action-buttons';
import { columns, formSchema } from './post.data'; import { columns, formSchema } from './post.data';
import PostModal from './PostModal.vue'; import PostModal from './PostModal.vue';
@ -54,9 +55,7 @@ const [FormModal, formModalApi] = useVbenModal({
}); });
function handleCreate() { function handleCreate() {
formModalApi.setData({ formModalApi.setData({});
valuse: {},
});
formModalApi.open(); formModalApi.open();
} }
async function handleEdit(id: number) { async function handleEdit(id: number) {
@ -77,37 +76,44 @@ async function handleExport() {
<Page auto-content-height> <Page auto-content-height>
<Grid> <Grid>
<template #toolbar-actions> <template #toolbar-actions>
<Button <ActionButtons
type="primary" :actions="[
v-access:code="['system:post:create']" {
@click="handleCreate" type: 'primary',
> label: $t('page.action.add'),
{{ $t('page.action.add') }} preIcon: IconEnum.ADD,
</Button> auth: ['system:post:create'],
<Button onClick: handleCreate.bind(null),
class="ml-4" },
v-access:code="['system:post:export']" {
@click="handleExport" label: $t('page.action.export'),
> preIcon: IconEnum.EXPORT,
{{ $t('page.action.export') }} auth: ['system:post:export'],
</Button> onClick: handleExport.bind(null),
},
]"
/>
</template> </template>
<template #action="{ row }"> <template #action="{ row }">
<Button <ActionButtons
type="link" :actions="[
v-access:code="['system:post:update']" {
@click="handleEdit(row.id)" type: 'link',
> label: $t('page.action.edit'),
{{ $t('page.action.edit') }} preIcon: IconEnum.EDIT,
</Button> auth: ['system:post:update'],
<Button onClick: handleEdit.bind(null, row.id),
danger },
type="link" {
v-access:code="['system:post:delete']" type: 'link',
@click="handleDelete(row.id)" danger: true,
> label: $t('page.action.delete'),
{{ $t('page.action.delete') }} preIcon: IconEnum.DELETE,
</Button> auth: ['system:post:delete'],
onClick: handleDelete.bind(null, row.id),
},
]"
/>
</template> </template>
</Grid> </Grid>
<FormModal /> <FormModal />

View File

@ -15,4 +15,21 @@ interface AuthPermissionInfo {
user: ExUserInfo; user: ExUserInfo;
} }
export type { AuthPermissionInfo, ExUserInfo }; /** 用户信息 */
interface UserInfo extends BasicUserInfo {
/**
*
*/
desc: string;
/**
*
*/
homePath: string;
/**
* accessToken
*/
token: string;
}
export type { AuthPermissionInfo, ExUserInfo, UserInfo };