vue-vben-admin/apps/web-antd/src/views/dept/data.ts

123 lines
2.9 KiB
TypeScript
Raw Normal View History

import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn } from '#/adapter/vxe-table';
import type { DeptApi } from '#/api';
import { z } from '#/adapter/form';
import { getAllDeptTree } from '#/api';
import { $t } from '#/locales';
/**
* 使export一个数组常量
*/
export function useSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'name',
label: '部门名称',
rules: z.string(),
},
{
component: 'ApiTreeSelect',
componentProps: {
allowClear: true,
api: getAllDeptTree(1),
class: 'w-full',
labelField: 'name',
valueField: 'id',
childrenField: 'children',
},
fieldName: 'pid',
label: '上级部门',
},
{
component: 'RadioGroup',
componentProps: {
buttonStyle: 'solid',
options: [
{ label: $t('common.enabled'), value: 1 },
{ label: $t('common.disabled'), value: 0 },
],
optionType: 'button',
},
defaultValue: 1,
fieldName: 'status',
label: '状态',
},
{
component: 'Textarea',
componentProps: {
maxLength: 50,
rows: 3,
showCount: true,
},
fieldName: 'remark',
label: '备注',
rules: z.string().optional(),
},
];
}
/**
*
* @description 使export一个Array常量
* @param onActionClick
*/
export function useColumns(
onActionClick?: OnActionClickFn<DeptApi.Dept>,
): VxeTableGridOptions<DeptApi.Dept>['columns'] {
return [
{
align: 'left',
field: 'name',
fixed: 'left',
title: '部门名称',
treeNode: true,
width: 150,
},
{
cellRender: { name: 'CellTag' },
field: 'enable',
title: '状态',
width: 100,
},
{
field: 'createTime',
title: '创建时间',
width: 180,
},
{
align: 'right',
cellRender: {
attrs: {
nameField: 'name',
nameTitle: '部门',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'append',
text: '新增下级',
},
'edit', // 默认的编辑按钮
{
code: 'delete', // 默认的删除按钮
disabled: (row: DeptApi.Dept) => {
return !!(row.children && row.children.length > 0);
},
},
],
},
field: 'operation',
fixed: 'right',
headerAlign: 'center',
showOverflow: false,
title: '操作',
width: 200,
},
];
}