Files
tydata-admin/apps/web-antd/src/views/system/user/data.ts
liangzai 7743cdc29a
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
fix: c
2025-12-24 14:42:57 +08:00

138 lines
3.3 KiB
TypeScript

import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemUserApi } from '#/api';
import { ref } from 'vue';
import { $t } from '#/locales';
// 角色列表引用,可以在加载后更新
export const roleOptions = ref<{ label: string; value: number | string }[]>([]);
export function useFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'username',
label: $t('system.user.userName'),
rules: 'required',
},
{
component: 'Input',
fieldName: 'real_name',
label: $t('system.user.realName'),
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: 'Select',
componentProps: {
mode: 'multiple',
allowClear: true,
options: roleOptions,
class: 'w-full',
},
fieldName: 'role_ids',
formItemClass: 'items-start',
label: $t('system.user.setPermissions'),
},
];
}
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'username',
label: $t('system.user.userName'),
},
{
component: 'Input',
fieldName: 'real_name',
label: $t('system.user.realName'),
},
{
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: 'RangePicker',
fieldName: 'create_time',
label: $t('system.user.createTime'),
},
];
}
export function useColumns<T = SystemUserApi.SystemUser>(
onActionClick: OnActionClickFn<T>,
onStatusChange?: (newStatus: any, row: T) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] {
return [
{
field: 'username',
title: $t('system.user.userName'),
minWidth: 200,
},
{
field: 'real_name',
title: $t('system.user.realName'),
minWidth: 200,
},
{
cellRender: {
attrs: { beforeChange: onStatusChange },
name: onStatusChange ? 'CellSwitch' : 'CellTag',
},
field: 'status',
title: $t('system.user.status'),
minWidth: 100,
},
{
field: 'create_time',
title: $t('system.user.createTime'),
minWidth: 200,
},
{
align: 'center',
cellRender: {
attrs: {
nameField: 'username',
nameTitle: $t('system.user.userName'),
onClick: onActionClick,
},
options: [
{ code: 'edit', text: '编辑' },
{ code: 'resetPassword', text: '重置密码' },
{ code: 'delete', text: '删除' },
],
name: 'CellOperation',
},
field: 'operation',
fixed: 'right',
title: $t('system.user.operation'),
width: 200,
},
];
}