Files
aiot-platform-ui/apps/web-antd/src/views/system/user/data.ts

223 lines
4.9 KiB
TypeScript
Raw Normal View History

2025-04-03 09:02:44 +08:00
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',
2025-04-03 22:56:03 +08:00
componentProps: {
placeholder: '请输入用户名称',
allowClear: true,
},
2025-04-03 09:02:44 +08:00
},
{
fieldName: 'mobile',
label: '手机号码',
component: 'Input',
2025-04-03 22:56:03 +08:00
componentProps: {
placeholder: '请输入手机号码',
allowClear: true,
},
2025-04-03 09:02:44 +08:00
},
{
fieldName: 'status',
label: '状态',
component: 'Select',
componentProps: {
2025-04-03 22:56:03 +08:00
placeholder: '请输入用户状态',
2025-04-03 09:02:44 +08:00
allowClear: true,
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
},
},
{
fieldName: 'createTime',
label: '创建时间',
component: 'RangePicker',
componentProps: {
allowClear: true,
2025-04-03 22:56:03 +08:00
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
placeholder: ['开始日期', '结束日期'],
2025-04-03 09:02:44 +08:00
},
},
];
}
/** 列表的字段 */
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,
},
{
2025-04-03 22:56:03 +08:00
field: 'deptName',
2025-04-03 09:02:44 +08:00
title: '部门',
minWidth: 120,
},
{
field: 'mobile',
title: '手机号码',
minWidth: 120,
},
2025-04-03 22:56:03 +08:00
// TODO @芋艿switch 的接入
2025-04-03 09:02:44 +08:00
{
field: 'status',
title: '状态',
minWidth: 100,
2025-04-03 22:56:03 +08:00
align: 'center',
2025-04-03 09:02:44 +08:00
cellRender: {
2025-04-03 22:56:03 +08:00
name: 'CellSwitch',
props: {
activeValue: 0,
inactiveValue: 1
},
2025-04-03 09:02:44 +08:00
},
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'operation',
title: '操作',
2025-04-03 22:56:03 +08:00
minWidth: 160,
2025-04-03 09:02:44 +08:00
fixed: 'right',
2025-04-03 22:56:03 +08:00
align: 'center',
2025-04-03 09:02:44 +08:00
cellRender: {
attrs: {
2025-04-03 22:56:03 +08:00
nameField: 'name',
nameTitle: '角色',
2025-04-03 09:02:44 +08:00
onClick: onActionClick,
},
name: 'CellOperation',
2025-04-03 22:56:03 +08:00
options: [
'edit', // 默认的编辑按钮
'delete', // 默认的删除按钮
{
code: 'assign-data-permission',
text: '数据权限',
},
{
code: 'assign-menu',
text: '菜单权限',
}
],
2025-04-03 09:02:44 +08:00
},
},
];
}