feat:完善 dept 部门 30%(列表)

pull/62/head
YunaiV 2025-03-29 09:32:14 +08:00
parent 923f1de7f7
commit 32e0ce0325
4 changed files with 118 additions and 81 deletions

View File

@ -0,0 +1,47 @@
import { requestClient } from '#/api/request';
export namespace SystemDeptApi {
/** 部门信息 */
export interface SystemDept {
id?: number;
name: string;
parentId?: number;
status: number;
sort: number;
leaderUserId: number;
phone: string;
email: string;
createTime: Date;
children?: SystemDept[];
}
}
/** 查询部门(精简)列表 */
export async function getSimpleDeptList() {
return requestClient.get<SystemDeptApi.SystemDept[]>('/system/dept/simple-list');
}
/** 查询部门列表 */
export async function getDeptList() {
return requestClient.get('/system/dept/list');
}
/** 查询部门详情 */
export async function getDept(id: number) {
return requestClient.get<SystemDeptApi.SystemDept>(`/system/dept/get?id=${id}`);
}
/** 新增部门 */
export async function createDept(data: SystemDeptApi.SystemDept) {
return requestClient.post('/system/dept/create', data);
}
/** 修改部门 */
export async function updateDept(data: SystemDeptApi.SystemDept) {
return requestClient.put('/system/dept/update', data);
}
/** 删除部门 */
export async function deleteDept(id: number) {
return requestClient.delete(`/system/dept/delete?id=${id}`);
}

View File

@ -1,18 +1,30 @@
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table'; import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn } from '#/adapter/vxe-table'; import type { OnActionClickFn } from '#/adapter/vxe-table';
// import type { SystemDeptApi } from '#/api/system/dept'; import type { SystemDeptApi } from '#/api/system/dept';
import { z } from '#/adapter/form'; import { z } from '#/adapter/form';
// import { getDeptList } from '#/api/system/dept'; import { getDeptList } from '#/api/system/dept';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { DICT_TYPE } from '#/utils/dict';
/** /** 获取编辑表单的字段配置 */
* 使export // TODO @芋艿:表单的整理
*/
export function useSchema(): VbenFormSchema[] { export function useSchema(): VbenFormSchema[] {
return [ return [
{
component: 'ApiTreeSelect',
componentProps: {
allowClear: true,
api: getDeptList,
class: 'w-full',
labelField: 'name',
valueField: 'id',
childrenField: 'children'
},
fieldName: 'parentId',
label: '上级部门',
},
{ {
component: 'Input', component: 'Input',
fieldName: 'name', fieldName: 'name',
@ -25,19 +37,6 @@ export function useSchema(): VbenFormSchema[] {
$t('ui.formRules.maxLength', [$t('system.dept.deptName'), 20]), $t('ui.formRules.maxLength', [$t('system.dept.deptName'), 20]),
), ),
}, },
// {
// component: 'ApiTreeSelect',
// componentProps: {
// allowClear: true,
// api: getDeptList,
// class: 'w-full',
// labelField: 'name',
// valueField: 'id',
// childrenField: 'children',
// },
// fieldName: 'pid',
// label: $t('system.dept.parentDept'),
// },
{ {
component: 'RadioGroup', component: 'RadioGroup',
componentProps: { componentProps: {
@ -69,11 +68,7 @@ export function useSchema(): VbenFormSchema[] {
]; ];
} }
/** /** 获取表格列配置 */
*
* @description 使exportArray
* @param onActionClick
*/
export function useColumns( export function useColumns(
onActionClick?: OnActionClickFn<SystemDeptApi.SystemDept>, onActionClick?: OnActionClickFn<SystemDeptApi.SystemDept>,
): VxeTableGridOptions<SystemDeptApi.SystemDept>['columns'] { ): VxeTableGridOptions<SystemDeptApi.SystemDept>['columns'] {
@ -82,31 +77,39 @@ export function useColumns(
align: 'left', align: 'left',
field: 'name', field: 'name',
fixed: 'left', fixed: 'left',
title: $t('system.dept.deptName'), title: '部门名称',
treeNode: true, treeNode: true,
width: 150, minWidth: 150,
},
// TODO @芋艿:需要通过 userList 翻译
{
field: 'leader',
title: '负责人',
minWidth: 150,
}, },
{ {
cellRender: { name: 'CellTag' }, field: 'sort',
title: '排序',
minWidth: 100,
},
{
cellRender: { name: 'CellDict', props: { type: DICT_TYPE.COMMON_STATUS } },
field: 'status', field: 'status',
title: $t('system.dept.status'), title: '状态',
width: 100, minWidth: 100,
}, },
{ {
field: 'createTime', field: 'createTime',
title: $t('system.dept.createTime'), title: '创建时间',
width: 180, minWidth: 180,
}, formatter: 'formatDateTime',
{
field: 'remark',
title: $t('system.dept.remark'),
}, },
{ {
align: 'right', align: 'right',
cellRender: { cellRender: {
attrs: { attrs: {
nameField: 'name', nameField: 'name',
nameTitle: $t('system.dept.name'), nameTitle: '部门',
onClick: onActionClick, onClick: onActionClick,
}, },
name: 'CellOperation', name: 'CellOperation',
@ -128,8 +131,8 @@ export function useColumns(
fixed: 'right', fixed: 'right',
headerAlign: 'center', headerAlign: 'center',
showOverflow: false, showOverflow: false,
title: $t('system.dept.operation'), title: '操作',
width: 200, minWidth: 200,
}, },
]; ];
} }

View File

@ -1,18 +1,14 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
OnActionClickParams, import type { SystemDeptApi } from '#/api/system/dept';
VxeTableGridOptions,
} from '#/adapter/vxe-table'; import { $t } from '#/locales';
// import type { SystemDeptApi } from '#/api/system/dept'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteDept, getDeptList } from '#/api/system/dept';
import { Page, useVbenModal } from '@vben/common-ui'; import { Page, useVbenModal } from '@vben/common-ui';
import { Plus } from '@vben/icons';
import { Button, message } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
import { Plus } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
// import { deleteDept, getDeptList } from '#/api/system/dept';
import { $t } from '#/locales';
import { useColumns } from './data'; import { useColumns } from './data';
import Form from './modules/form.vue'; import Form from './modules/form.vue';
@ -22,40 +18,30 @@ const [FormModal, formModalApi] = useVbenModal({
destroyOnClose: true, destroyOnClose: true,
}); });
/** /** 编辑部门 */
* 编辑部门
* @param row
*/
function onEdit(row: SystemDeptApi.SystemDept) { function onEdit(row: SystemDeptApi.SystemDept) {
formModalApi.setData(row).open(); formModalApi.setData(row).open();
} }
/** /** 添加下级部门 */
* 添加下级部门
* @param row
*/
function onAppend(row: SystemDeptApi.SystemDept) { function onAppend(row: SystemDeptApi.SystemDept) {
formModalApi.setData({ pid: row.id }).open(); formModalApi.setData({ pid: row.id }).open();
} }
/** /** 创建新部门 */
* 创建新部门
*/
function onCreate() { function onCreate() {
formModalApi.setData(null).open(); formModalApi.setData(null).open();
} }
/** /** 删除部门 */
* 删除部门
* @param row
*/
function onDelete(row: SystemDeptApi.SystemDept) { function onDelete(row: SystemDeptApi.SystemDept) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]), content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0, duration: 0,
key: 'action_process_msg', key: 'action_process_msg',
}); });
deleteDept(row.id) // TODO @ await
deleteDept(row.id as number)
.then(() => { .then(() => {
message.success({ message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]), content: $t('ui.actionMessage.deleteSuccess', [row.name]),
@ -68,9 +54,7 @@ function onDelete(row: SystemDeptApi.SystemDept) {
}); });
} }
/** /** 表格操作按钮的回调函数 */
* 表格操作按钮的回调函数
*/
function onActionClick({ function onActionClick({
code, code,
row, row,
@ -114,19 +98,20 @@ const [Grid, gridApi] = useVbenVxeGrid({
zoom: true, zoom: true,
}, },
treeConfig: { treeConfig: {
parentField: 'pid', parentField: 'parentId',
rowField: 'id', rowField: 'id',
transform: false, transform: true,
expandAll: true,
}, },
} as VxeTableGridOptions, } as VxeTableGridOptions,
}); });
/** /** 刷新表格 */
* 刷新表格
*/
function refreshGrid() { function refreshGrid() {
gridApi.query(); gridApi.query();
} }
// TODO @/
// TODO @
</script> </script>
<template> <template>
<Page auto-content-height> <Page auto-content-height>
@ -135,7 +120,7 @@ function refreshGrid() {
<template #toolbar-tools> <template #toolbar-tools>
<Button type="primary" @click="onCreate"> <Button type="primary" @click="onCreate">
<Plus class="size-5" /> <Plus class="size-5" />
{{ $t('ui.actionTitle.create', [$t('system.dept.name')]) }} {{ $t('ui.actionTitle.create', ['部门']) }}
</Button> </Button>
</template> </template>
</Grid> </Grid>

View File

@ -1,14 +1,13 @@
<script lang="ts" setup> <script lang="ts" setup>
// import type { SystemDeptApi } from '#/api/system/dept'; import type { SystemDeptApi } from '#/api/system/dept';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { Button } from 'ant-design-vue'; import { Button } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form'; import { useVbenForm } from '#/adapter/form';
// import { createDept, updateDept } from '#/api/system/dept'; import { createDept, updateDept } from '#/api/system/dept';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { useSchema } from '../data'; import { useSchema } from '../data';
@ -17,8 +16,8 @@ const emit = defineEmits(['success']);
const formData = ref<SystemDeptApi.SystemDept>(); const formData = ref<SystemDeptApi.SystemDept>();
const getTitle = computed(() => { const getTitle = computed(() => {
return formData.value?.id return formData.value?.id
? $t('ui.actionTitle.edit', [$t('system.dept.name')]) ? $t('ui.actionTitle.edit', ['部门'])
: $t('ui.actionTitle.create', [$t('system.dept.name')]); : $t('ui.actionTitle.create', ['部门']);
}); });
const [Form, formApi] = useVbenForm({ const [Form, formApi] = useVbenForm({
@ -32,6 +31,7 @@ function resetForm() {
formApi.setValues(formData.value || {}); formApi.setValues(formData.value || {});
} }
// TODO @
const [Modal, modalApi] = useVbenModal({ const [Modal, modalApi] = useVbenModal({
async onConfirm() { async onConfirm() {
const { valid } = await formApi.validate(); const { valid } = await formApi.validate();
@ -50,11 +50,13 @@ const [Modal, modalApi] = useVbenModal({
} }
}, },
onOpenChange(isOpen) { onOpenChange(isOpen) {
// TODO @
if (isOpen) { if (isOpen) {
const data = modalApi.getData<SystemDeptApi.SystemDept>(); const data = modalApi.getData<SystemDeptApi.SystemDept>();
if (data) { if (data) {
if (data.pid === 0) { // TODO @
data.pid = undefined; if (data.parentId === 0) {
data.parentId = undefined;
} }
formData.value = data; formData.value = data;
formApi.setValues(formData.value); formApi.setValues(formData.value);