Files
xk-admin/playground/src/views/system/user/data.ts
xingyu 04fbb7a556 chore: 升级 shadcn-vue 组件到v4最新版 (#7972)
* fix: useStore is deprecated

* chore: update deps

* feat: 升级shadcn-ui v4

* fix: workbench style

* feat: 升级shadcn-ui v4 step2

* feat: 升级shadcn-ui v4 step3

* chore: 升级shadcn v4

* fix: pagination

* fix: dark style

* fix: doc import

* feat: 增加详情组件,参考 antdv-next

* docs: descriptions docs

* docs: Browser Support

* feat: add table action

* feat: icon use vbenIcon

* fix: type error

* fix: dropdown popConfirm

* feat: 使用默认的文字交互

* feat: 优化渲染性能
2026-05-31 15:18:46 +08:00

165 lines
3.8 KiB
TypeScript

import type { DescriptionsItemType } from '@vben/common-ui';
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridColumns } from '#/adapter/vxe-table';
import type { SystemUserApi } from '#/api';
import { h } from 'vue';
import { Tag } from 'antdv-next';
import { getDeptList } from '#/api';
import { $t } from '#/locales';
export function useFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'name',
label: $t('system.user.name'),
rules: 'required',
},
{
component: 'ApiTreeSelect',
componentProps: {
allowClear: true,
api: getDeptList,
class: 'w-full',
labelField: 'name',
valueField: 'id',
childrenField: 'children',
},
fieldName: 'deptId',
label: $t('system.user.dept'),
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: $t('system.user.status'),
},
{
component: 'Textarea',
fieldName: 'remark',
label: $t('system.user.remark'),
},
];
}
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'name',
label: $t('system.user.name'),
},
{ component: 'Input', fieldName: 'id', label: $t('system.user.id') },
{
component: 'Select',
componentProps: {
allowClear: true,
options: [
{ label: $t('common.enabled'), value: 1 },
{ label: $t('common.disabled'), value: 0 },
],
},
fieldName: 'status',
label: $t('system.user.status'),
},
{
component: 'Input',
fieldName: 'remark',
label: $t('system.user.remark'),
},
{
component: 'RangePicker',
fieldName: 'createTime',
label: $t('system.user.createTime'),
},
];
}
/**
* 用户详情描述列表项
* @param row 用户数据
*/
export function useDescriptionItems(
row?: SystemUserApi.SystemUser,
): DescriptionsItemType[] {
const enabled = row?.status === 1;
return [
{ label: $t('system.user.name'), content: row?.name },
{ label: $t('system.user.id'), content: row?.id },
{ label: $t('system.user.dept'), content: row?.deptId },
{
label: $t('system.user.status'),
content: () =>
h(
Tag,
{
color: enabled ? 'success' : 'error',
},
{
default: () =>
enabled ? $t('common.enabled') : $t('common.disabled'),
},
),
},
{ label: $t('system.user.createTime'), content: row?.createTime },
{ label: $t('system.user.remark'), content: row?.remark },
];
}
export function useColumns<T = SystemUserApi.SystemUser>(
onStatusChange?: (newStatus: any, row: T) => PromiseLike<boolean | undefined>,
): VxeTableGridColumns {
return [
{
field: 'name',
title: $t('system.user.name'),
width: 200,
},
{
field: 'id',
title: $t('system.user.id'),
width: 200,
},
{
cellRender: {
attrs: { beforeChange: onStatusChange },
name: onStatusChange ? 'CellSwitch' : 'CellTag',
},
field: 'status',
title: $t('system.user.status'),
width: 100,
},
{
field: 'remark',
minWidth: 100,
title: $t('system.user.remark'),
},
{
field: 'createTime',
title: $t('system.user.createTime'),
width: 200,
},
{
align: 'center',
field: 'operation',
fixed: 'right',
slots: { default: 'action' },
title: $t('system.user.operation'),
width: 180,
},
];
}