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', }, { fieldName: 'mobile', label: '手机号码', component: 'Input', }, { fieldName: 'status', label: '状态', component: 'Select', componentProps: { allowClear: true, options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), }, }, { fieldName: 'createTime', label: '创建时间', component: 'RangePicker', componentProps: { allowClear: true, }, }, ]; } /** 列表的字段 */ export function useGridColumns( onActionClick: OnActionClickFn, ): VxeTableGridOptions['columns'] { return [ { field: 'id', title: '用户编号', minWidth: 100, }, { field: 'username', title: '用户名称', minWidth: 120, }, { field: 'nickname', title: '用户昵称', minWidth: 120, }, { field: 'deptId', title: '部门', minWidth: 120, }, { field: 'mobile', title: '手机号码', minWidth: 120, }, { field: 'status', title: '状态', minWidth: 100, cellRender: { name: 'CellDict', props: { type: DICT_TYPE.COMMON_STATUS }, }, }, { field: 'createTime', title: '创建时间', minWidth: 180, formatter: 'formatDateTime', }, { field: 'operation', title: '操作', minWidth: 180, align: 'center', fixed: 'right', cellRender: { attrs: { nameField: 'username', nameTitle: '用户', onClick: onActionClick, }, name: 'CellOperation', }, }, ]; }