128 lines
2.7 KiB
TypeScript
128 lines
2.7 KiB
TypeScript
|
import type { VbenFormSchema } from '#/adapter/form';
|
||
|
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||
|
import type { RoleApi } from '#/api';
|
||
|
|
||
|
import { $t } from '#/locales';
|
||
|
|
||
|
export function useFormSchema(): VbenFormSchema[] {
|
||
|
return [
|
||
|
{
|
||
|
component: 'Input',
|
||
|
fieldName: 'name',
|
||
|
label: '角色名称',
|
||
|
rules: 'required',
|
||
|
},
|
||
|
{
|
||
|
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',
|
||
|
fieldName: 'remark',
|
||
|
label: '备注',
|
||
|
},
|
||
|
{
|
||
|
component: 'Input',
|
||
|
fieldName: 'permissions',
|
||
|
formItemClass: 'items-start',
|
||
|
label: '权限',
|
||
|
modelPropName: 'modelValue',
|
||
|
},
|
||
|
];
|
||
|
}
|
||
|
|
||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||
|
return [
|
||
|
{
|
||
|
component: 'Input',
|
||
|
fieldName: 'name',
|
||
|
label: '角色名称',
|
||
|
},
|
||
|
{ component: 'Input', fieldName: 'id', label: '角色ID' },
|
||
|
{
|
||
|
component: 'Select',
|
||
|
componentProps: {
|
||
|
allowClear: true,
|
||
|
options: [
|
||
|
{ label: $t('common.enabled'), value: 1 },
|
||
|
{ label: $t('common.disabled'), value: 0 },
|
||
|
],
|
||
|
},
|
||
|
fieldName: 'status',
|
||
|
label: '状态',
|
||
|
},
|
||
|
{
|
||
|
component: 'Input',
|
||
|
fieldName: 'remark',
|
||
|
label: '备注',
|
||
|
},
|
||
|
{
|
||
|
component: 'RangePicker',
|
||
|
fieldName: 'createTime',
|
||
|
label: '创建时间',
|
||
|
},
|
||
|
];
|
||
|
}
|
||
|
|
||
|
export function useColumns<T = RoleApi.Role>(
|
||
|
onActionClick: OnActionClickFn<T>,
|
||
|
onStatusChange?: (newStatus: any, row: T) => PromiseLike<boolean | undefined>,
|
||
|
): VxeTableGridOptions['columns'] {
|
||
|
return [
|
||
|
{
|
||
|
field: 'name',
|
||
|
title: '角色名称',
|
||
|
width: 200,
|
||
|
},
|
||
|
{
|
||
|
field: 'id',
|
||
|
title: '角色ID',
|
||
|
width: 200,
|
||
|
},
|
||
|
{
|
||
|
cellRender: {
|
||
|
attrs: { beforeChange: onStatusChange },
|
||
|
name: onStatusChange ? 'CellSwitch' : 'CellTag',
|
||
|
},
|
||
|
field: 'status',
|
||
|
title: '角色状态',
|
||
|
width: 100,
|
||
|
},
|
||
|
{
|
||
|
field: 'remark',
|
||
|
minWidth: 100,
|
||
|
title: '备注',
|
||
|
},
|
||
|
{
|
||
|
field: 'createTime',
|
||
|
title: '创建时间',
|
||
|
width: 200,
|
||
|
},
|
||
|
{
|
||
|
align: 'center',
|
||
|
cellRender: {
|
||
|
attrs: {
|
||
|
nameField: 'name',
|
||
|
nameTitle: $t('system.role.name'),
|
||
|
onClick: onActionClick,
|
||
|
},
|
||
|
name: 'CellOperation',
|
||
|
},
|
||
|
field: 'operation',
|
||
|
fixed: 'right',
|
||
|
title: '操作',
|
||
|
width: 130,
|
||
|
},
|
||
|
];
|
||
|
}
|