feat: 部门

This commit is contained in:
dap 2024-10-05 15:56:13 +08:00
parent caf8681e24
commit abcc08832d
3 changed files with 166 additions and 50 deletions

View File

@ -1,8 +1,9 @@
import { DictEnum } from '@vben/constants'; import { DictEnum } from '@vben/constants';
import { getPopupContainer } from '@vben/utils'; import { getPopupContainer } from '@vben/utils';
import { type FormSchemaGetter, z } from '#/adapter'; import { type FormSchemaGetter, type VxeGridProps, z } from '#/adapter';
import { getDictOptions } from '#/utils/dict'; import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';
export const querySchema: FormSchemaGetter = () => [ export const querySchema: FormSchemaGetter = () => [
{ {
@ -21,6 +22,45 @@ export const querySchema: FormSchemaGetter = () => [
}, },
]; ];
export const columns: VxeGridProps['columns'] = [
{
field: 'deptName',
title: '部门名称',
treeNode: true,
width: 200,
},
{
field: 'deptCategory',
title: '类别编码',
},
{
field: 'orderNum',
title: '排序',
width: 180,
},
{
field: 'status',
width: 180,
title: '状态',
slots: {
default: ({ row }) => {
return renderDict(row.status, DictEnum.SYS_NORMAL_DISABLE);
},
},
},
{
field: 'createTime',
title: '创建时间',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
];
export const drawerSchema: FormSchemaGetter = () => [ export const drawerSchema: FormSchemaGetter = () => [
{ {
component: 'Input', component: 'Input',
@ -76,7 +116,7 @@ export const drawerSchema: FormSchemaGetter = () => [
label: '联系电话', label: '联系电话',
rules: z rules: z
.string() .string()
.regex(/^\d{1,3}-\d{8,11}$/, { message: '请输入正确的手机号' }) .regex(/^1[3,4578]\d{9}$/, { message: '请输入正确的手机号' })
.optional(), .optional(),
}, },
{ {

View File

@ -1,62 +1,146 @@
<script setup lang="ts"> <script setup lang="ts">
import { Page, useVbenDrawer } from '@vben/common-ui'; import type { Recordable } from '@vben/types';
import { $t } from '@vben/locales';
import { Card } from 'ant-design-vue'; import { nextTick } from 'vue';
import { useVbenForm } from '#/adapter'; import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
import { listToTree } from '@vben/utils';
import { querySchema } from './data'; import { Popconfirm, Space } from 'ant-design-vue';
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
import { deptList, deptRemove } from '#/api/system/dept';
import { columns, querySchema } from './data';
import deptDrawer from './dept-drawer.vue'; import deptDrawer from './dept-drawer.vue';
const formOptions: VbenFormProps = {
schema: querySchema(),
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
};
const gridOptions: VxeGridProps = {
columns,
height: 'auto',
keepSource: true,
pagerConfig: {
enabled: false,
},
proxyConfig: {
ajax: {
query: async (_, formValues) => {
const resp = await deptList({
...formValues,
});
const treeData = listToTree(resp, {
id: 'deptId',
pid: 'parentId',
children: 'children',
});
return { rows: treeData };
},
//
querySuccess: () => {
nextTick(() => {
expandAll();
});
},
},
},
rowConfig: {
isHover: true,
keyField: 'deptId',
},
round: true,
align: 'center',
showOverflow: true,
treeConfig: {
parentField: 'parentId',
rowField: 'deptId',
transform: false,
},
};
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
const [DeptDrawer, drawerApi] = useVbenDrawer({ const [DeptDrawer, drawerApi] = useVbenDrawer({
connectedComponent: deptDrawer, connectedComponent: deptDrawer,
}); });
function handleAdd() { function handleAdd() {
drawerApi.setData({}); drawerApi.setData({ update: false });
drawerApi.open(); drawerApi.open();
} }
function handleTest(id: number | string) { async function handleEdit(record: Recordable<any>) {
drawerApi.setData({ id }); drawerApi.setData({ id: record.deptId, update: true });
drawerApi.open(); drawerApi.open();
} }
const [QueryForm] = useVbenForm({ async function handleDelete(row: Recordable<any>) {
// await deptRemove(row.deptId);
collapsed: false, await tableApi.reload();
// }
commonConfig: {
// function expandAll() {
componentProps: { tableApi.grid?.setAllTreeExpand(true);
class: 'w-full', }
},
}, function collapseAll() {
schema: querySchema(), tableApi.grid?.setAllTreeExpand(false);
// }
showCollapseButton: true,
submitButtonOptions: {
text: '查询',
},
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
});
</script> </script>
<template> <template>
<Page content-class="flex flex-col gap-4"> <Page :auto-content-height="true">
<Card> <BasicTable>
<QueryForm /> <template #toolbar-actions>
</Card> <span class="pl-[7px] text-[16px]">部门列表</span>
<Card> </template>
<div class="flex justify-end gap-2"> <template #toolbar-tools>
<a-button type="primary" @click="handleAdd"> <Space>
{{ $t('pages.common.add') }} <a-button @click="collapseAll">
</a-button> {{ $t('pages.common.collapse') }}
<a-button @click="handleTest(103)"> 新增 上级id=103 </a-button> </a-button>
<a-button @click="handleTest(105)"> 新增 上级id=105 </a-button> <a-button @click="expandAll">
</div> {{ $t('pages.common.expand') }}
</Card> </a-button>
<DeptDrawer /> <a-button
type="primary"
v-access:code="['system:dept:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<a-button
size="small"
type="link"
v-access:code="['system:dept:edit']"
@click="handleEdit(row)"
>
{{ $t('pages.common.edit') }}
</a-button>
<Popconfirm
placement="left"
title="确认删除?"
@confirm="handleDelete(row)"
>
<a-button
danger
size="small"
type="link"
v-access:code="['system:dept:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</a-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<DeptDrawer @reload="tableApi.reload()" />
</Page> </Page>
</template> </template>

View File

@ -18,14 +18,6 @@ const formOptions: VbenFormProps = {
}; };
const gridOptions: VxeGridProps = { const gridOptions: VxeGridProps = {
checkboxConfig: {
//
highlight: true,
//
reserve: true,
//
// trigger: 'row',
},
columns, columns,
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,