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: 'enabled', label: '状态', }, { component: 'Input', fieldName: 'remark', label: '备注', }, { component: 'RangePicker', fieldName: 'createTime', label: '创建时间', }, ]; } export function useColumns( onActionClick: OnActionClickFn, onStatusChange?: (newStatus: any, row: T) => PromiseLike, ): VxeTableGridOptions['columns'] { return [ { field: 'id', title: '角色ID', width: 200, }, { field: 'name', title: '角色名称', width: 200, }, { cellRender: { attrs: { beforeChange: onStatusChange }, name: onStatusChange ? 'CellSwitch' : 'CellTag', }, field: 'enabled', 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: 200, }, ]; }