feat: 角色管理
This commit is contained in:
parent
34c2117aa0
commit
e6fa2be3eb
@ -1,8 +1,10 @@
|
|||||||
import type { FormSchemaGetter } from '#/adapter';
|
import type { FormSchemaGetter, VxeGridProps } from '#/adapter';
|
||||||
|
|
||||||
import { DictEnum } from '@vben/constants';
|
import { DictEnum } from '@vben/constants';
|
||||||
import { getPopupContainer } from '@vben/utils';
|
import { getPopupContainer } from '@vben/utils';
|
||||||
|
|
||||||
|
import { Tag } from 'ant-design-vue';
|
||||||
|
|
||||||
import { getDictOptions } from '#/utils/dict';
|
import { getDictOptions } from '#/utils/dict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +44,58 @@ export const querySchema: FormSchemaGetter = () => [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const columns: VxeGridProps['columns'] = [
|
||||||
|
{ type: 'checkbox', width: 60 },
|
||||||
|
{
|
||||||
|
title: '角色名称',
|
||||||
|
field: 'roleName',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '权限字符',
|
||||||
|
field: 'roleKey',
|
||||||
|
slots: {
|
||||||
|
default: ({ row }) => {
|
||||||
|
return <Tag color="processing">{row.roleKey}</Tag>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据权限',
|
||||||
|
field: 'dataScope',
|
||||||
|
slots: {
|
||||||
|
default: ({ row }) => {
|
||||||
|
const found = authScopeOptions.find(
|
||||||
|
(item) => item.value === row.dataScope,
|
||||||
|
);
|
||||||
|
if (found) {
|
||||||
|
return <Tag color={found.color}>{found.label}</Tag>;
|
||||||
|
}
|
||||||
|
return <Tag>{row.dataScope}</Tag>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '排序',
|
||||||
|
field: 'roleSort',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
field: 'status',
|
||||||
|
slots: { default: 'status' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
field: 'createTime',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'action',
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'action' },
|
||||||
|
title: '操作',
|
||||||
|
width: 180,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
export const drawerSchema: FormSchemaGetter = () => [
|
export const drawerSchema: FormSchemaGetter = () => [
|
||||||
{
|
{
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
@ -1,41 +1,95 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Recordable } from '@vben/types';
|
import type { Recordable } from '@vben/types';
|
||||||
import type { ColumnsType } from 'ant-design-vue/es/table';
|
|
||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
|
import { useAccess } from '@vben/access';
|
||||||
import { $t } from '@vben/locales';
|
import {
|
||||||
|
Page,
|
||||||
|
useVbenDrawer,
|
||||||
|
useVbenModal,
|
||||||
|
type VbenFormProps,
|
||||||
|
} from '@vben/common-ui';
|
||||||
|
|
||||||
import { Card, Space, Table } from 'ant-design-vue';
|
import {
|
||||||
|
Dropdown,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Space,
|
||||||
|
} from 'ant-design-vue';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { useVbenForm } from '#/adapter';
|
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
|
||||||
import { roleList } from '#/api/system/role';
|
import {
|
||||||
|
roleChangeStatus,
|
||||||
|
roleExport,
|
||||||
|
roleList,
|
||||||
|
roleRemove,
|
||||||
|
} from '#/api/system/role';
|
||||||
|
import { TableSwitch } from '#/components/table';
|
||||||
|
import { downloadExcel } from '#/utils/file/download';
|
||||||
|
|
||||||
import { querySchema } from './data';
|
import { columns, querySchema } from './data';
|
||||||
import roleAuthModal from './role-auth-modal.vue';
|
import roleAuthModal from './role-auth-modal.vue';
|
||||||
import roleDrawer from './role-drawer.vue';
|
import roleDrawer from './role-drawer.vue';
|
||||||
|
|
||||||
const [QueryForm] = useVbenForm({
|
const formOptions: VbenFormProps = {
|
||||||
// 默认展开
|
schema: querySchema(),
|
||||||
collapsed: false,
|
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||||
// 所有表单项共用,可单独在表单内覆盖
|
};
|
||||||
commonConfig: {
|
|
||||||
// 所有表单项
|
const gridOptions: VxeGridProps = {
|
||||||
componentProps: {
|
checkboxConfig: {
|
||||||
class: 'w-full',
|
// 高亮
|
||||||
|
highlight: true,
|
||||||
|
// 翻页时保留选中状态
|
||||||
|
reserve: true,
|
||||||
|
// 点击行选中
|
||||||
|
// trigger: 'row',
|
||||||
|
checkMethod: ({ row }) => row.roleId !== 1,
|
||||||
|
},
|
||||||
|
columns,
|
||||||
|
height: 'auto',
|
||||||
|
keepSource: true,
|
||||||
|
pagerConfig: {},
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
// 区间选择器处理
|
||||||
|
if (formValues?.createTime) {
|
||||||
|
formValues.params = {
|
||||||
|
beginTime: dayjs(formValues.createTime[0]).format(
|
||||||
|
'YYYY-MM-DD 00:00:00',
|
||||||
|
),
|
||||||
|
endTime: dayjs(formValues.createTime[1]).format(
|
||||||
|
'YYYY-MM-DD 23:59:59',
|
||||||
|
),
|
||||||
|
};
|
||||||
|
Reflect.deleteProperty(formValues, 'createTime');
|
||||||
|
} else {
|
||||||
|
Reflect.deleteProperty(formValues, 'params');
|
||||||
|
}
|
||||||
|
|
||||||
|
return await roleList({
|
||||||
|
pageNum: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
schema: querySchema(),
|
rowConfig: {
|
||||||
// 是否可展开
|
isHover: true,
|
||||||
showCollapseButton: true,
|
keyField: 'roleId',
|
||||||
submitButtonOptions: {
|
|
||||||
text: '查询',
|
|
||||||
},
|
},
|
||||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
round: true,
|
||||||
});
|
align: 'center',
|
||||||
|
showOverflow: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
||||||
const [RoleDrawer, drawerApi] = useVbenDrawer({
|
const [RoleDrawer, drawerApi] = useVbenDrawer({
|
||||||
connectedComponent: roleDrawer,
|
connectedComponent: roleDrawer,
|
||||||
});
|
});
|
||||||
@ -45,49 +99,32 @@ function handleAdd() {
|
|||||||
drawerApi.open();
|
drawerApi.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType = [
|
async function handleEdit(record: Recordable<any>) {
|
||||||
{
|
|
||||||
dataIndex: 'roleName',
|
|
||||||
title: '角色名称',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataIndex: 'roleKey',
|
|
||||||
title: '权限字符',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataIndex: 'dataScope',
|
|
||||||
title: '数据权限',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataIndex: 'roleSort',
|
|
||||||
title: '排序',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataIndex: 'status',
|
|
||||||
title: '状态',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dataIndex: 'createTime',
|
|
||||||
title: '创建时间',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
align: 'center',
|
|
||||||
dataIndex: 'action',
|
|
||||||
title: '操作',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const dataSource = ref([]);
|
|
||||||
onMounted(async () => {
|
|
||||||
const resp = await roleList();
|
|
||||||
dataSource.value = (resp as any).rows;
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleEdit(record: Recordable<any>) {
|
|
||||||
drawerApi.setData({ id: record.roleId });
|
drawerApi.setData({ id: record.roleId });
|
||||||
drawerApi.open();
|
drawerApi.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleDelete(row: Recordable<any>) {
|
||||||
|
await roleRemove(row.roleId);
|
||||||
|
await tableApi.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMultiDelete() {
|
||||||
|
const rows = tableApi.grid.getCheckboxRecords();
|
||||||
|
const ids = rows.map((row: any) => row.roleId);
|
||||||
|
Modal.confirm({
|
||||||
|
title: '提示',
|
||||||
|
okType: 'danger',
|
||||||
|
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||||
|
onOk: async () => {
|
||||||
|
await roleRemove(ids);
|
||||||
|
await tableApi.reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const { hasAccessByCodes } = useAccess();
|
||||||
|
|
||||||
const [RoleAuthModal, authModalApi] = useVbenModal({
|
const [RoleAuthModal, authModalApi] = useVbenModal({
|
||||||
connectedComponent: roleAuthModal,
|
connectedComponent: roleAuthModal,
|
||||||
});
|
});
|
||||||
@ -104,31 +141,90 @@ function handleAssignRole(record: Recordable<any>) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page content-class="flex flex-col gap-[16px]">
|
<Page :auto-content-height="true">
|
||||||
<Card class="flex-1">
|
<BasicTable>
|
||||||
<QueryForm />
|
<template #toolbar-actions>
|
||||||
</Card>
|
<span class="pl-[7px] text-[16px]">参数列表</span>
|
||||||
<a-button @click="handleAdd">{{ $t('pages.common.add') }}</a-button>
|
</template>
|
||||||
<RoleDrawer />
|
<template #toolbar-tools>
|
||||||
<RoleAuthModal />
|
<Space>
|
||||||
<div class="bg-background rounded-lg p-[16px]">
|
<a-button
|
||||||
<Table :columns="columns" :data-source="dataSource">
|
v-access:code="['system:role:export']"
|
||||||
<template #bodyCell="{ column, record }">
|
@click="downloadExcel(roleExport, '角色数据', {})"
|
||||||
<template v-if="column.dataIndex === 'action'">
|
>
|
||||||
<Space>
|
{{ $t('pages.common.export') }}
|
||||||
<a-button size="small" type="primary" @click="handleEdit(record)">
|
</a-button>
|
||||||
编辑
|
<a-button
|
||||||
</a-button>
|
danger
|
||||||
<a-button size="small" @click="handleAuthEdit(record)">
|
type="primary"
|
||||||
数据权限
|
v-access:code="['system:role:delete']"
|
||||||
</a-button>
|
@click="handleMultiDelete"
|
||||||
<a-button size="small" @click="handleAssignRole(record)">
|
>
|
||||||
分配角色
|
{{ $t('pages.common.delete') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
</Space>
|
<a-button
|
||||||
</template>
|
type="primary"
|
||||||
</template>
|
v-access:code="['system:role:add']"
|
||||||
</Table>
|
@click="handleAdd"
|
||||||
</div>
|
>
|
||||||
|
{{ $t('pages.common.add') }}
|
||||||
|
</a-button>
|
||||||
|
</Space>
|
||||||
|
</template>
|
||||||
|
<template #status="{ row }">
|
||||||
|
<TableSwitch
|
||||||
|
v-model="row.status"
|
||||||
|
:api="() => roleChangeStatus(row)"
|
||||||
|
:disabled="
|
||||||
|
row.roleId === 1 ||
|
||||||
|
row.roleKey === 'admin' ||
|
||||||
|
!hasAccessByCodes(['system:role:edit'])
|
||||||
|
"
|
||||||
|
:reload="() => tableApi.reload()"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #action="{ row }">
|
||||||
|
<Space v-if="row.roleId !== 1">
|
||||||
|
<a-button
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
v-access:code="['system:role:edit']"
|
||||||
|
@click.stop="handleEdit(row)"
|
||||||
|
>
|
||||||
|
{{ $t('pages.common.edit') }}
|
||||||
|
</a-button>
|
||||||
|
<Popconfirm
|
||||||
|
placement="left"
|
||||||
|
title="确认删除?"
|
||||||
|
@confirm="handleDelete(row)"
|
||||||
|
>
|
||||||
|
<a-button
|
||||||
|
danger
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
v-access:code="['system:role:delete']"
|
||||||
|
@click.stop=""
|
||||||
|
>
|
||||||
|
{{ $t('pages.common.delete') }}
|
||||||
|
</a-button>
|
||||||
|
</Popconfirm>
|
||||||
|
<Dropdown>
|
||||||
|
<template #overlay>
|
||||||
|
<Menu>
|
||||||
|
<MenuItem key="1" @click="handleAuthEdit(row)">
|
||||||
|
数据权限
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem key="2" @click="handleAssignRole(row)">
|
||||||
|
分配用户
|
||||||
|
</MenuItem>
|
||||||
|
</Menu>
|
||||||
|
</template>
|
||||||
|
<a-button size="small" type="link">更多</a-button>
|
||||||
|
</Dropdown>
|
||||||
|
</Space>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<RoleDrawer @reload="tableApi.reload()" />
|
||||||
|
<RoleAuthModal @reload="tableApi.reload()" />
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user