feat(@vben/web-antd): 优化角色管理
This commit is contained in:
parent
996a8972ff
commit
16e04a5fc0
@ -9,6 +9,7 @@ export namespace RoleApi {
|
|||||||
deptId: string;
|
deptId: string;
|
||||||
remark?: string;
|
remark?: string;
|
||||||
createBy: string;
|
createBy: string;
|
||||||
|
menuIds: [];
|
||||||
createTime: string;
|
createTime: string;
|
||||||
createId: string;
|
createId: string;
|
||||||
// authorities: (number | undefined)[];
|
// authorities: (number | undefined)[];
|
||||||
@ -56,7 +57,7 @@ export function updateRole(id: any, data: RoleApi.Role) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取详情
|
// 获取详情
|
||||||
export function getDetail(id: string) {
|
export function roleDetail(id: string) {
|
||||||
return requestClient.get<RoleApi.Role>(`/rest/role/${id}`);
|
return requestClient.get<RoleApi.Role>(`/rest/role/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,13 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
componentProps: {
|
componentProps: {
|
||||||
buttonStyle: 'solid',
|
buttonStyle: 'solid',
|
||||||
options: [
|
options: [
|
||||||
{ label: $t('common.enabled'), value: 1 },
|
{ label: $t('common.enabled'), value: true },
|
||||||
{ label: $t('common.disabled'), value: 0 },
|
{ label: $t('common.disabled'), value: false },
|
||||||
],
|
],
|
||||||
optionType: 'button',
|
optionType: 'button',
|
||||||
},
|
},
|
||||||
defaultValue: 1,
|
defaultValue: true,
|
||||||
fieldName: 'status',
|
fieldName: 'enable',
|
||||||
label: '状态',
|
label: '状态',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -33,7 +33,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
fieldName: 'permissions',
|
fieldName: 'menuIds',
|
||||||
formItemClass: 'items-start',
|
formItemClass: 'items-start',
|
||||||
label: '权限',
|
label: '权限',
|
||||||
modelPropName: 'modelValue',
|
modelPropName: 'modelValue',
|
||||||
@ -48,7 +48,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
fieldName: 'name',
|
fieldName: 'name',
|
||||||
label: '角色名称',
|
label: '角色名称',
|
||||||
},
|
},
|
||||||
{ component: 'Input', fieldName: 'id', label: '角色ID' },
|
// { component: 'Input', fieldName: 'id', label: '角色ID' },
|
||||||
{
|
{
|
||||||
component: 'Select',
|
component: 'Select',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
@ -61,16 +61,20 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
fieldName: 'enabled',
|
fieldName: 'enabled',
|
||||||
label: '状态',
|
label: '状态',
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
component: 'Input',
|
// component: 'Input',
|
||||||
fieldName: 'remark',
|
// fieldName: 'remark',
|
||||||
label: '备注',
|
// label: '备注',
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
component: 'RangePicker',
|
// component: 'RangePicker',
|
||||||
fieldName: 'createTime',
|
// fieldName: 'createTime',
|
||||||
label: '创建时间',
|
// componentProps: {
|
||||||
},
|
// format: 'YYYY-M-D HH:mm:ss', // 设置日期时间格式
|
||||||
|
// showTime: true, // 确保选择器支持时间选择
|
||||||
|
// },
|
||||||
|
// label: '创建时间',
|
||||||
|
// },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +109,7 @@ export function useColumns<T = RoleApi.Role>(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'createTime',
|
field: 'createTime',
|
||||||
|
slots: { default: 'createTime' },
|
||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
width: 200,
|
width: 200,
|
||||||
},
|
},
|
||||||
@ -113,7 +118,7 @@ export function useColumns<T = RoleApi.Role>(
|
|||||||
cellRender: {
|
cellRender: {
|
||||||
attrs: {
|
attrs: {
|
||||||
nameField: 'name',
|
nameField: 'name',
|
||||||
nameTitle: $t('system.role.name'),
|
nameTitle: '角色',
|
||||||
onClick: onActionClick,
|
onClick: onActionClick,
|
||||||
},
|
},
|
||||||
name: 'CellOperation',
|
name: 'CellOperation',
|
||||||
|
@ -11,6 +11,7 @@ import { Page, useVbenDrawer } from '@vben/common-ui';
|
|||||||
import { Plus } from '@vben/icons';
|
import { Plus } from '@vben/icons';
|
||||||
|
|
||||||
import { Button, message, Modal } from 'ant-design-vue';
|
import { Button, message, Modal } from 'ant-design-vue';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { enabledRole, queryRoleList, removeRole } from '#/api';
|
import { enabledRole, queryRoleList, removeRole } from '#/api';
|
||||||
@ -159,6 +160,9 @@ function onCreate() {
|
|||||||
{{ $t('ui.actionTitle.create', ['角色']) }}
|
{{ $t('ui.actionTitle.create', ['角色']) }}
|
||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
|
<template #createTime="{ row }">
|
||||||
|
{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm') }}
|
||||||
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
@ -8,12 +8,12 @@ import type { RoleApi } from '#/api';
|
|||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
import { useVbenDrawer, VbenTree } from '@vben/common-ui';
|
import { useVbenDrawer, VbenTree } from '@vben/common-ui';
|
||||||
import { IconifyIcon } from '@vben/icons';
|
// import { IconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { Spin } from 'ant-design-vue';
|
import { Spin } from 'ant-design-vue';
|
||||||
|
|
||||||
import { useVbenForm } from '#/adapter/form';
|
import { useVbenForm } from '#/adapter/form';
|
||||||
import { createRole, queryMenuList, updateRole } from '#/api';
|
import { createRole, queryMenuList, roleDetail, updateRole } from '#/api';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useFormSchema } from '../data';
|
import { useFormSchema } from '../data';
|
||||||
@ -27,7 +27,7 @@ const [Form, formApi] = useVbenForm({
|
|||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const permissions = ref<DataNode[]>([]);
|
const menuIds = ref<DataNode[]>([]);
|
||||||
const loadingPermissions = ref(false);
|
const loadingPermissions = ref(false);
|
||||||
|
|
||||||
const id = ref();
|
const id = ref();
|
||||||
@ -46,19 +46,24 @@ const [Drawer, drawerApi] = useVbenDrawer({
|
|||||||
drawerApi.unlock();
|
drawerApi.unlock();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onOpenChange(isOpen) {
|
async onOpenChange(isOpen) {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
const data = drawerApi.getData<RoleApi.Role>();
|
const data = drawerApi.getData<RoleApi.Role>();
|
||||||
formApi.resetForm();
|
await formApi.resetForm();
|
||||||
if (data) {
|
if (data.id) {
|
||||||
formData.value = data;
|
const roleDetailData = await roleDetail(data.id);
|
||||||
|
formData.value = roleDetailData;
|
||||||
|
|
||||||
|
// 提取 menus 中的 id 并赋值给 menuIds
|
||||||
|
formData.value.menuIds = roleDetailData.menus.map((menu) => menu.id);
|
||||||
|
|
||||||
id.value = data.id;
|
id.value = data.id;
|
||||||
formApi.setValues(data);
|
formApi.setValues(roleDetailData);
|
||||||
} else {
|
} else {
|
||||||
id.value = undefined;
|
id.value = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (permissions.value.length === 0) {
|
if (menuIds.value.length === 0) {
|
||||||
loadPermissions();
|
loadPermissions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +74,12 @@ async function loadPermissions() {
|
|||||||
loadingPermissions.value = true;
|
loadingPermissions.value = true;
|
||||||
try {
|
try {
|
||||||
const res = await queryMenuList('all');
|
const res = await queryMenuList('all');
|
||||||
permissions.value = res as unknown as DataNode[];
|
menuIds.value = res.map((item) => ({
|
||||||
|
key: item.id,
|
||||||
|
title: item.name,
|
||||||
|
children: item.children || null,
|
||||||
|
meta: item.meta,
|
||||||
|
}));
|
||||||
} finally {
|
} finally {
|
||||||
loadingPermissions.value = false;
|
loadingPermissions.value = false;
|
||||||
}
|
}
|
||||||
@ -96,10 +106,10 @@ function getNodeClass(node: Recordable<any>) {
|
|||||||
<template>
|
<template>
|
||||||
<Drawer :title="getDrawerTitle">
|
<Drawer :title="getDrawerTitle">
|
||||||
<Form>
|
<Form>
|
||||||
<template #permissions="slotProps">
|
<template #menuIds="slotProps">
|
||||||
<Spin :spinning="loadingPermissions" wrapper-class-name="w-full">
|
<Spin :spinning="loadingPermissions" wrapper-class-name="w-full">
|
||||||
<VbenTree
|
<VbenTree
|
||||||
:tree-data="permissions"
|
:tree-data="menuIds"
|
||||||
multiple
|
multiple
|
||||||
bordered
|
bordered
|
||||||
:default-expanded-level="2"
|
:default-expanded-level="2"
|
||||||
@ -110,8 +120,8 @@ function getNodeClass(node: Recordable<any>) {
|
|||||||
icon-field="meta.icon"
|
icon-field="meta.icon"
|
||||||
>
|
>
|
||||||
<template #node="{ value }">
|
<template #node="{ value }">
|
||||||
<IconifyIcon v-if="value.meta.icon" :icon="value.meta.icon" />
|
<!-- <IconifyIcon v-if="value.meta.icon" :icon="value.meta.icon" />-->
|
||||||
{{ $t(value.meta.title) }}
|
{{ value.meta.locale }}
|
||||||
</template>
|
</template>
|
||||||
</VbenTree>
|
</VbenTree>
|
||||||
</Spin>
|
</Spin>
|
||||||
|
Loading…
Reference in New Issue
Block a user