223 lines
4.9 KiB
TypeScript
223 lines
4.9 KiB
TypeScript
import { type VbenFormSchema, z } from '#/adapter/form';
|
||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||
import type { SystemUserApi } from '#/api/system/user';
|
||
|
||
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||
import { CommonStatusEnum } from '#/utils/constants';
|
||
|
||
/** 新增/修改的表单 */
|
||
export function useFormSchema(): VbenFormSchema[] {
|
||
return [
|
||
{
|
||
component: 'Input',
|
||
fieldName: 'id',
|
||
label: 'id',
|
||
dependencies: {
|
||
triggerFields: [''],
|
||
show: () => false,
|
||
},
|
||
},
|
||
{
|
||
component: 'Input',
|
||
fieldName: 'username',
|
||
label: '用户名称',
|
||
rules: 'required',
|
||
},
|
||
{
|
||
component: 'Input',
|
||
fieldName: 'nickname',
|
||
label: '用户昵称',
|
||
rules: 'required',
|
||
},
|
||
{
|
||
fieldName: 'deptId',
|
||
label: '归属部门',
|
||
component: 'ApiTreeSelect',
|
||
componentProps: {
|
||
api: () => Promise.resolve([]),
|
||
fieldNames: {
|
||
label: 'name',
|
||
key: 'id',
|
||
value: 'id',
|
||
},
|
||
},
|
||
rules: 'required',
|
||
},
|
||
{
|
||
fieldName: 'postIds',
|
||
label: '岗位',
|
||
component: 'ApiSelect',
|
||
componentProps: {
|
||
api: () => Promise.resolve([]),
|
||
labelField: 'name',
|
||
valueField: 'id',
|
||
mode: 'multiple',
|
||
},
|
||
rules: 'required',
|
||
},
|
||
{
|
||
fieldName: 'email',
|
||
label: '邮箱',
|
||
component: 'Input',
|
||
rules: z.string().email('邮箱格式不正确').optional(),
|
||
},
|
||
{
|
||
fieldName: 'mobile',
|
||
label: '手机号码',
|
||
component: 'Input',
|
||
},
|
||
{
|
||
fieldName: 'sex',
|
||
label: '用户性别',
|
||
component: 'RadioGroup',
|
||
componentProps: {
|
||
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||
buttonStyle: 'solid',
|
||
optionType: 'button',
|
||
},
|
||
rules: z.number().default(1),
|
||
},
|
||
{
|
||
fieldName: 'status',
|
||
label: '用户状态',
|
||
component: 'RadioGroup',
|
||
componentProps: {
|
||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||
buttonStyle: 'solid',
|
||
optionType: 'button',
|
||
},
|
||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||
},
|
||
{
|
||
fieldName: 'remark',
|
||
label: '备注',
|
||
component: 'Textarea',
|
||
},
|
||
];
|
||
}
|
||
|
||
/** 列表的搜索表单 */
|
||
export function useGridFormSchema(): VbenFormSchema[] {
|
||
return [
|
||
{
|
||
fieldName: 'username',
|
||
label: '用户名称',
|
||
component: 'Input',
|
||
componentProps: {
|
||
placeholder: '请输入用户名称',
|
||
allowClear: true,
|
||
},
|
||
},
|
||
{
|
||
fieldName: 'mobile',
|
||
label: '手机号码',
|
||
component: 'Input',
|
||
componentProps: {
|
||
placeholder: '请输入手机号码',
|
||
allowClear: true,
|
||
},
|
||
},
|
||
{
|
||
fieldName: 'status',
|
||
label: '状态',
|
||
component: 'Select',
|
||
componentProps: {
|
||
placeholder: '请输入用户状态',
|
||
allowClear: true,
|
||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||
},
|
||
},
|
||
{
|
||
fieldName: 'createTime',
|
||
label: '创建时间',
|
||
component: 'RangePicker',
|
||
componentProps: {
|
||
allowClear: true,
|
||
showTime: true,
|
||
format: 'YYYY-MM-DD HH:mm:ss',
|
||
placeholder: ['开始日期', '结束日期'],
|
||
},
|
||
},
|
||
];
|
||
}
|
||
|
||
/** 列表的字段 */
|
||
export function useGridColumns<T = SystemUserApi.SystemUser>(
|
||
onActionClick: OnActionClickFn<T>,
|
||
): VxeTableGridOptions['columns'] {
|
||
return [
|
||
{
|
||
field: 'id',
|
||
title: '用户编号',
|
||
minWidth: 100,
|
||
},
|
||
{
|
||
field: 'username',
|
||
title: '用户名称',
|
||
minWidth: 120,
|
||
},
|
||
{
|
||
field: 'nickname',
|
||
title: '用户昵称',
|
||
minWidth: 120,
|
||
},
|
||
{
|
||
field: 'deptName',
|
||
title: '部门',
|
||
minWidth: 120,
|
||
},
|
||
{
|
||
field: 'mobile',
|
||
title: '手机号码',
|
||
minWidth: 120,
|
||
},
|
||
// TODO @芋艿:switch 的接入
|
||
{
|
||
field: 'status',
|
||
title: '状态',
|
||
minWidth: 100,
|
||
align: 'center',
|
||
cellRender: {
|
||
name: 'CellSwitch',
|
||
props: {
|
||
activeValue: 0,
|
||
inactiveValue: 1
|
||
},
|
||
},
|
||
},
|
||
{
|
||
field: 'createTime',
|
||
title: '创建时间',
|
||
minWidth: 180,
|
||
formatter: 'formatDateTime',
|
||
},
|
||
{
|
||
field: 'operation',
|
||
title: '操作',
|
||
minWidth: 160,
|
||
fixed: 'right',
|
||
align: 'center',
|
||
cellRender: {
|
||
attrs: {
|
||
nameField: 'name',
|
||
nameTitle: '角色',
|
||
onClick: onActionClick,
|
||
},
|
||
name: 'CellOperation',
|
||
options: [
|
||
'edit', // 默认的编辑按钮
|
||
'delete', // 默认的删除按钮
|
||
{
|
||
code: 'assign-data-permission',
|
||
text: '数据权限',
|
||
},
|
||
{
|
||
code: 'assign-menu',
|
||
text: '菜单权限',
|
||
}
|
||
],
|
||
},
|
||
},
|
||
];
|
||
}
|