parent
e72f82d4ee
commit
a37a16c70e
@ -1,224 +0,0 @@
|
|||||||
import type { FormSchemaGetter } from '#/adapter/form';
|
|
||||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
||||||
|
|
||||||
import { getDictOptions } from '#/utils/dict';
|
|
||||||
import { DictEnum } from '@vben/constants';
|
|
||||||
import { getPopupContainer } from '@vben/utils';
|
|
||||||
import { Tag } from 'ant-design-vue';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* authScopeOptions user也会用到
|
|
||||||
*/
|
|
||||||
export const authScopeOptions = [
|
|
||||||
{ color: 'green', label: '全部数据权限', value: '1' },
|
|
||||||
{ color: 'default', label: '自定数据权限', value: '2' },
|
|
||||||
{ color: 'orange', label: '本部门数据权限', value: '3' },
|
|
||||||
{ color: 'cyan', label: '本部门及以下数据权限', value: '4' },
|
|
||||||
{ color: 'error', label: '仅本人数据权限', value: '5' },
|
|
||||||
{ color: 'default', label: '部门及以下或本人数据权限', value: '6' },
|
|
||||||
];
|
|
||||||
|
|
||||||
export const querySchema: FormSchemaGetter = () => [
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'roleName',
|
|
||||||
label: '角色名称',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'roleKey',
|
|
||||||
label: '权限字符',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Select',
|
|
||||||
componentProps: {
|
|
||||||
options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
|
|
||||||
},
|
|
||||||
fieldName: 'status',
|
|
||||||
label: '状态',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'RangePicker',
|
|
||||||
fieldName: 'createTime',
|
|
||||||
label: '创建时间',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
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 = () => [
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
dependencies: {
|
|
||||||
show: () => false,
|
|
||||||
triggerFields: [''],
|
|
||||||
},
|
|
||||||
fieldName: 'roleId',
|
|
||||||
label: '角色ID',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'roleName',
|
|
||||||
label: '角色名称',
|
|
||||||
rules: 'required',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'roleKey',
|
|
||||||
help: '如: test simpleUser等',
|
|
||||||
label: '权限标识',
|
|
||||||
rules: 'required',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'InputNumber',
|
|
||||||
fieldName: 'roleSort',
|
|
||||||
label: '角色排序',
|
|
||||||
rules: 'required',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Select',
|
|
||||||
componentProps: {
|
|
||||||
allowClear: false,
|
|
||||||
options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
|
|
||||||
getPopupContainer,
|
|
||||||
},
|
|
||||||
defaultValue: '0',
|
|
||||||
fieldName: 'status',
|
|
||||||
help: '修改后, 拥有该角色的用户将自动下线.',
|
|
||||||
label: '角色状态',
|
|
||||||
rules: 'required',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Radio',
|
|
||||||
dependencies: {
|
|
||||||
show: () => false,
|
|
||||||
triggerFields: [''],
|
|
||||||
},
|
|
||||||
fieldName: 'menuCheckStrictly',
|
|
||||||
label: '菜单权限',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
defaultValue: [],
|
|
||||||
fieldName: 'menuIds',
|
|
||||||
label: '菜单权限',
|
|
||||||
formItemClass: 'col-span-2',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Textarea',
|
|
||||||
defaultValue: '',
|
|
||||||
fieldName: 'remark',
|
|
||||||
formItemClass: 'items-baseline col-span-2',
|
|
||||||
label: '备注',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const authModalSchemas: FormSchemaGetter = () => [
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
dependencies: {
|
|
||||||
show: () => false,
|
|
||||||
triggerFields: [''],
|
|
||||||
},
|
|
||||||
fieldName: 'roleId',
|
|
||||||
label: '角色ID',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Radio',
|
|
||||||
dependencies: {
|
|
||||||
show: () => false,
|
|
||||||
triggerFields: [''],
|
|
||||||
},
|
|
||||||
fieldName: 'deptCheckStrictly',
|
|
||||||
label: 'deptCheckStrictly',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
componentProps: {
|
|
||||||
disabled: true,
|
|
||||||
},
|
|
||||||
fieldName: 'roleName',
|
|
||||||
label: '角色名称',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Input',
|
|
||||||
componentProps: {
|
|
||||||
disabled: true,
|
|
||||||
},
|
|
||||||
fieldName: 'roleKey',
|
|
||||||
label: '权限标识',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'Select',
|
|
||||||
componentProps: {
|
|
||||||
allowClear: false,
|
|
||||||
getPopupContainer,
|
|
||||||
options: authScopeOptions,
|
|
||||||
},
|
|
||||||
fieldName: 'dataScope',
|
|
||||||
help: '更改后需要用户重新登录才能生效',
|
|
||||||
label: '权限范围',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: 'TreeSelect',
|
|
||||||
defaultValue: [],
|
|
||||||
dependencies: {
|
|
||||||
show: (values) => values.dataScope === '2',
|
|
||||||
triggerFields: ['dataScope'],
|
|
||||||
},
|
|
||||||
fieldName: 'deptIds',
|
|
||||||
formItemClass: 'items-baseline',
|
|
||||||
help: '更改后立即生效',
|
|
||||||
label: '部门权限',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@ -1,239 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
||||||
import type { VbenFormProps } from '@vben/common-ui';
|
|
||||||
import type { Recordable } from '@vben/types';
|
|
||||||
|
|
||||||
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
|
|
||||||
import {
|
|
||||||
roleChangeStatus,
|
|
||||||
roleExport,
|
|
||||||
roleList,
|
|
||||||
roleRemove,
|
|
||||||
} from '#/api/system/role';
|
|
||||||
import { TableSwitch } from '#/components/table';
|
|
||||||
import { commonDownloadExcel } from '#/utils/file/download';
|
|
||||||
import { useAccess } from '@vben/access';
|
|
||||||
import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
|
|
||||||
import { getVxePopupContainer } from '@vben/utils';
|
|
||||||
import {
|
|
||||||
Dropdown,
|
|
||||||
Menu,
|
|
||||||
MenuItem,
|
|
||||||
Modal,
|
|
||||||
Popconfirm,
|
|
||||||
Space,
|
|
||||||
} from 'ant-design-vue';
|
|
||||||
import { computed } from 'vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import { columns, querySchema } from './data';
|
|
||||||
import roleAuthModal from './role-auth-modal.vue';
|
|
||||||
import roleDrawer from './role-drawer.vue';
|
|
||||||
|
|
||||||
const formOptions: VbenFormProps = {
|
|
||||||
commonConfig: {
|
|
||||||
labelWidth: 80,
|
|
||||||
componentProps: {
|
|
||||||
allowClear: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
schema: querySchema(),
|
|
||||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
|
||||||
// 日期选择格式化
|
|
||||||
fieldMappingTime: [
|
|
||||||
[
|
|
||||||
'createTime',
|
|
||||||
['params[beginTime]', 'params[endTime]'],
|
|
||||||
['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const gridOptions: VxeGridProps = {
|
|
||||||
checkboxConfig: {
|
|
||||||
// 高亮
|
|
||||||
highlight: true,
|
|
||||||
// 翻页时保留选中状态
|
|
||||||
reserve: true,
|
|
||||||
// 点击行选中
|
|
||||||
// trigger: 'row',
|
|
||||||
checkMethod: ({ row }) => row.roleId !== 1,
|
|
||||||
},
|
|
||||||
columns,
|
|
||||||
height: 'auto',
|
|
||||||
keepSource: true,
|
|
||||||
pagerConfig: {},
|
|
||||||
proxyConfig: {
|
|
||||||
ajax: {
|
|
||||||
query: async ({ page }, formValues = {}) => {
|
|
||||||
return await roleList({
|
|
||||||
pageNum: page.currentPage,
|
|
||||||
pageSize: page.pageSize,
|
|
||||||
...formValues,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
rowConfig: {
|
|
||||||
isHover: true,
|
|
||||||
keyField: 'roleId',
|
|
||||||
},
|
|
||||||
id: 'system-role-index',
|
|
||||||
};
|
|
||||||
|
|
||||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
|
||||||
formOptions,
|
|
||||||
gridOptions,
|
|
||||||
});
|
|
||||||
const [RoleDrawer, drawerApi] = useVbenDrawer({
|
|
||||||
connectedComponent: roleDrawer,
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleAdd() {
|
|
||||||
drawerApi.setData({});
|
|
||||||
drawerApi.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleEdit(record: Recordable<any>) {
|
|
||||||
drawerApi.setData({ id: record.roleId });
|
|
||||||
drawerApi.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleDelete(row: Recordable<any>) {
|
|
||||||
await roleRemove(row.roleId);
|
|
||||||
await tableApi.query();
|
|
||||||
}
|
|
||||||
|
|
||||||
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.query();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDownloadExcel() {
|
|
||||||
commonDownloadExcel(roleExport, '角色数据', tableApi.formApi.form.values, {
|
|
||||||
fieldMappingTime: formOptions.fieldMappingTime,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const { hasAccessByCodes, hasAccessByRoles } = useAccess();
|
|
||||||
|
|
||||||
const isSuperAdmin = computed(() => hasAccessByRoles(['superadmin']));
|
|
||||||
|
|
||||||
const [RoleAuthModal, authModalApi] = useVbenModal({
|
|
||||||
connectedComponent: roleAuthModal,
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleAuthEdit(record: Recordable<any>) {
|
|
||||||
authModalApi.setData({ id: record.roleId });
|
|
||||||
authModalApi.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
function handleAssignRole(record: Recordable<any>) {
|
|
||||||
router.push(`/system/role-assign/${record.roleId}`);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Page :auto-content-height="true">
|
|
||||||
<BasicTable table-title="角色列表">
|
|
||||||
<template #toolbar-tools>
|
|
||||||
<Space>
|
|
||||||
<a-button
|
|
||||||
v-access:code="['system:role:export']"
|
|
||||||
@click="handleDownloadExcel"
|
|
||||||
>
|
|
||||||
{{ $t('pages.common.export') }}
|
|
||||||
</a-button>
|
|
||||||
<a-button
|
|
||||||
:disabled="!vxeCheckboxChecked(tableApi)"
|
|
||||||
danger
|
|
||||||
type="primary"
|
|
||||||
v-access:code="['system:role:remove']"
|
|
||||||
@click="handleMultiDelete"
|
|
||||||
>
|
|
||||||
{{ $t('pages.common.delete') }}
|
|
||||||
</a-button>
|
|
||||||
<a-button
|
|
||||||
type="primary"
|
|
||||||
v-access:code="['system:role:add']"
|
|
||||||
@click="handleAdd"
|
|
||||||
>
|
|
||||||
{{ $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.query()"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
<template #action="{ row }">
|
|
||||||
<!-- 租户管理员不可修改admin角色 防止误操作 -->
|
|
||||||
<!-- 超级管理员可通过租户切换来操作租户管理员角色 -->
|
|
||||||
<template
|
|
||||||
v-if="!row.superAdmin && (row.roleKey !== 'admin' || isSuperAdmin)"
|
|
||||||
>
|
|
||||||
<Space>
|
|
||||||
<ghost-button
|
|
||||||
v-access:code="['system:role:edit']"
|
|
||||||
@click.stop="handleEdit(row)"
|
|
||||||
>
|
|
||||||
{{ $t('pages.common.edit') }}
|
|
||||||
</ghost-button>
|
|
||||||
<Popconfirm
|
|
||||||
:get-popup-container="getVxePopupContainer"
|
|
||||||
placement="left"
|
|
||||||
title="确认删除?"
|
|
||||||
@confirm="handleDelete(row)"
|
|
||||||
>
|
|
||||||
<ghost-button
|
|
||||||
danger
|
|
||||||
v-access:code="['system:role:remove']"
|
|
||||||
@click.stop=""
|
|
||||||
>
|
|
||||||
{{ $t('pages.common.delete') }}
|
|
||||||
</ghost-button>
|
|
||||||
</Popconfirm>
|
|
||||||
</Space>
|
|
||||||
<Dropdown
|
|
||||||
:get-popup-container="getVxePopupContainer"
|
|
||||||
placement="bottomRight"
|
|
||||||
>
|
|
||||||
<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">
|
|
||||||
{{ $t('pages.common.more') }}
|
|
||||||
</a-button>
|
|
||||||
</Dropdown>
|
|
||||||
</template>
|
|
||||||
</template>
|
|
||||||
</BasicTable>
|
|
||||||
<RoleDrawer @reload="tableApi.query()" />
|
|
||||||
<RoleAuthModal @reload="tableApi.query()" />
|
|
||||||
</Page>
|
|
||||||
</template>
|
|
||||||
Loading…
Reference in new issue