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 { getPopupContainer } from '@vben/utils';
import { type FormSchemaGetter, z } from '#/adapter';
import { type FormSchemaGetter, type VxeGridProps, z } from '#/adapter';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';
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 = () => [
{
component: 'Input',
@ -76,7 +116,7 @@ export const drawerSchema: FormSchemaGetter = () => [
label: '联系电话',
rules: z
.string()
.regex(/^\d{1,3}-\d{8,11}$/, { message: '请输入正确的手机号' })
.regex(/^1[3,4578]\d{9}$/, { message: '请输入正确的手机号' })
.optional(),
},
{

View File

@ -1,62 +1,146 @@
<script setup lang="ts">
import { Page, useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales';
import type { Recordable } from '@vben/types';
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';
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({
connectedComponent: deptDrawer,
});
function handleAdd() {
drawerApi.setData({});
drawerApi.setData({ update: false });
drawerApi.open();
}
function handleTest(id: number | string) {
drawerApi.setData({ id });
async function handleEdit(record: Recordable<any>) {
drawerApi.setData({ id: record.deptId, update: true });
drawerApi.open();
}
const [QueryForm] = useVbenForm({
//
collapsed: false,
//
commonConfig: {
//
componentProps: {
class: 'w-full',
},
},
schema: querySchema(),
//
showCollapseButton: true,
submitButtonOptions: {
text: '查询',
},
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
});
async function handleDelete(row: Recordable<any>) {
await deptRemove(row.deptId);
await tableApi.reload();
}
function expandAll() {
tableApi.grid?.setAllTreeExpand(true);
}
function collapseAll() {
tableApi.grid?.setAllTreeExpand(false);
}
</script>
<template>
<Page content-class="flex flex-col gap-4">
<Card>
<QueryForm />
</Card>
<Card>
<div class="flex justify-end gap-2">
<a-button type="primary" @click="handleAdd">
{{ $t('pages.common.add') }}
</a-button>
<a-button @click="handleTest(103)"> 新增 上级id=103 </a-button>
<a-button @click="handleTest(105)"> 新增 上级id=105 </a-button>
</div>
</Card>
<DeptDrawer />
<Page :auto-content-height="true">
<BasicTable>
<template #toolbar-actions>
<span class="pl-[7px] text-[16px]">部门列表</span>
</template>
<template #toolbar-tools>
<Space>
<a-button @click="collapseAll">
{{ $t('pages.common.collapse') }}
</a-button>
<a-button @click="expandAll">
{{ $t('pages.common.expand') }}
</a-button>
<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>
</template>

View File

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