feat(@vben/web-antd): 优化部门管理
This commit is contained in:
parent
16e04a5fc0
commit
dcda8635f5
@ -4,10 +4,26 @@ import type { VbenFormSchema } from '#/adapter/form';
|
|||||||
import type { OnActionClickFn } from '#/adapter/vxe-table';
|
import type { OnActionClickFn } from '#/adapter/vxe-table';
|
||||||
import type { DeptApi } from '#/api';
|
import type { DeptApi } from '#/api';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { z } from '#/adapter/form';
|
import { z } from '#/adapter/form';
|
||||||
import { getAllDeptTree } from '#/api';
|
import { getAllDeptTree } from '#/api';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
|
const treeData = ref([]);
|
||||||
|
|
||||||
|
function transformToTreeData(data: any) {
|
||||||
|
return data.map((item) => ({
|
||||||
|
value: item.id,
|
||||||
|
label: item.name,
|
||||||
|
...(item.children && { children: transformToTreeData(item.children) }),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用示例
|
||||||
|
getAllDeptTree(1).then((res) => {
|
||||||
|
treeData.value = transformToTreeData(res);
|
||||||
|
});
|
||||||
/**
|
/**
|
||||||
* 获取编辑表单的字段配置。如果没有使用多语言,可以直接export一个数组常量
|
* 获取编辑表单的字段配置。如果没有使用多语言,可以直接export一个数组常量
|
||||||
*/
|
*/
|
||||||
@ -20,10 +36,11 @@ export function useSchema(): VbenFormSchema[] {
|
|||||||
rules: z.string(),
|
rules: z.string(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'ApiTreeSelect',
|
component: 'TreeSelect',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
api: getAllDeptTree(1),
|
// api: getAllDeptTree(1),
|
||||||
|
treeData,
|
||||||
class: 'w-full',
|
class: 'w-full',
|
||||||
labelField: 'name',
|
labelField: 'name',
|
||||||
valueField: 'id',
|
valueField: 'id',
|
||||||
@ -60,6 +77,38 @@ export function useSchema(): VbenFormSchema[] {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
// return [
|
||||||
|
// {
|
||||||
|
// component: 'Input',
|
||||||
|
// fieldName: 'name',
|
||||||
|
// label: '部门名称',
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// component: 'Select',
|
||||||
|
// componentProps: {
|
||||||
|
// allowClear: true,
|
||||||
|
// options: [
|
||||||
|
// { label: $t('common.enabled'), value: true },
|
||||||
|
// { label: $t('common.disabled'), value: false },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// fieldName: 'enable',
|
||||||
|
// label: '状态',
|
||||||
|
// },
|
||||||
|
// // {
|
||||||
|
// // component: 'Input',
|
||||||
|
// // fieldName: 'remark',
|
||||||
|
// // label: '备注',
|
||||||
|
// // },
|
||||||
|
// // {
|
||||||
|
// // component: 'RangePicker',
|
||||||
|
// // fieldName: 'createTime',
|
||||||
|
// // label: '创建时间',
|
||||||
|
// // },
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取表格列配置
|
* 获取表格列配置
|
||||||
* @description 使用函数的形式返回列数据而不是直接export一个Array常量,是为了响应语言切换时重新翻译表头
|
* @description 使用函数的形式返回列数据而不是直接export一个Array常量,是为了响应语言切换时重新翻译表头
|
||||||
@ -85,15 +134,16 @@ export function useColumns(
|
|||||||
title: '状态',
|
title: '状态',
|
||||||
width: 100,
|
width: 100,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
field: 'createTime',
|
|
||||||
title: '创建时间',
|
|
||||||
width: 180,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
field: 'remark',
|
field: 'remark',
|
||||||
title: '备注',
|
title: '备注',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
field: 'createTime',
|
||||||
|
slots: { default: 'createTime' },
|
||||||
|
title: '创建时间',
|
||||||
|
width: 180,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
align: 'right',
|
align: 'right',
|
||||||
cellRender: {
|
cellRender: {
|
||||||
|
@ -9,6 +9,7 @@ import { Page, useVbenModal } from '@vben/common-ui';
|
|||||||
import { Plus } from '@vben/icons';
|
import { Plus } from '@vben/icons';
|
||||||
|
|
||||||
import { Button, message } from 'ant-design-vue';
|
import { Button, message } from 'ant-design-vue';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { getAllDeptTree, removeDept } from '#/api';
|
import { getAllDeptTree, removeDept } from '#/api';
|
||||||
@ -89,6 +90,10 @@ function onActionClick({ code, row }: OnActionClickParams<DeptApi.Dept>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
// formOptions: {
|
||||||
|
// fieldMappingTime: [['createTime', ['startTime', 'endTime']]],
|
||||||
|
// schema: useGridFormSchema(),
|
||||||
|
// },
|
||||||
gridEvents: {},
|
gridEvents: {},
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: useColumns(onActionClick),
|
columns: useColumns(onActionClick),
|
||||||
@ -138,6 +143,9 @@ function refreshGrid() {
|
|||||||
{{ $t('ui.actionTitle.create', ['部门']) }}
|
{{ $t('ui.actionTitle.create', ['部门']) }}
|
||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
|
<template #createTime="{ row }">
|
||||||
|
{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm') }}
|
||||||
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user